Merge changes I5f6f3da7,Ia37b8b93,Ie79a2e78
* changes: Get dex jar resources from classpath jar Add -stripFile argument to merge_zips Change default jar time to match ziptime
This commit is contained in:
@@ -29,26 +29,26 @@ import (
|
|||||||
"android/soong/third_party/zip"
|
"android/soong/third_party/zip"
|
||||||
)
|
)
|
||||||
|
|
||||||
type stripDir struct{}
|
type fileList []string
|
||||||
|
|
||||||
func (s *stripDir) String() string {
|
func (f *fileList) String() string {
|
||||||
return `""`
|
return `""`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stripDir) Set(dir string) error {
|
func (f *fileList) Set(name string) error {
|
||||||
stripDirs = append(stripDirs, filepath.Clean(dir))
|
*f = append(*f, filepath.Clean(name))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type zipToNotStrip struct{}
|
type zipsToNotStripSet map[string]bool
|
||||||
|
|
||||||
func (s *zipToNotStrip) String() string {
|
func (s zipsToNotStripSet) String() string {
|
||||||
return `""`
|
return `""`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *zipToNotStrip) Set(zip_path string) error {
|
func (s zipsToNotStripSet) Set(zip_path string) error {
|
||||||
zipsToNotStrip[zip_path] = true
|
s[zip_path] = true
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -56,15 +56,17 @@ func (s *zipToNotStrip) Set(zip_path string) error {
|
|||||||
var (
|
var (
|
||||||
sortEntries = flag.Bool("s", false, "sort entries (defaults to the order from the input zip files)")
|
sortEntries = flag.Bool("s", false, "sort entries (defaults to the order from the input zip files)")
|
||||||
emulateJar = flag.Bool("j", false, "sort zip entries using jar ordering (META-INF first)")
|
emulateJar = flag.Bool("j", false, "sort zip entries using jar ordering (META-INF first)")
|
||||||
stripDirs []string
|
stripDirs fileList
|
||||||
zipsToNotStrip = make(map[string]bool)
|
stripFiles fileList
|
||||||
|
zipsToNotStrip = make(zipsToNotStripSet)
|
||||||
stripDirEntries = flag.Bool("D", false, "strip directory entries from the output zip file")
|
stripDirEntries = flag.Bool("D", false, "strip directory entries from the output zip file")
|
||||||
manifest = flag.String("m", "", "manifest file to insert in jar")
|
manifest = flag.String("m", "", "manifest file to insert in jar")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.Var(&stripDir{}, "stripDir", "the prefix of file path to be excluded from the output zip")
|
flag.Var(&stripDirs, "stripDir", "the prefix of file path to be excluded from the output zip")
|
||||||
flag.Var(&zipToNotStrip{}, "zipToNotStrip", "the input zip file which is not applicable for stripping")
|
flag.Var(&stripFiles, "stripFile", "filenames to be excluded from the output zip, accepts wildcards")
|
||||||
|
flag.Var(&zipsToNotStrip, "zipToNotStrip", "the input zip file which is not applicable for stripping")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -243,20 +245,9 @@ func mergeZips(readers []namedZipReader, writer *zip.Writer, manifest string,
|
|||||||
|
|
||||||
for _, namedReader := range readers {
|
for _, namedReader := range readers {
|
||||||
_, skipStripThisZip := zipsToNotStrip[namedReader.path]
|
_, skipStripThisZip := zipsToNotStrip[namedReader.path]
|
||||||
FileLoop:
|
|
||||||
for _, file := range namedReader.reader.File {
|
for _, file := range namedReader.reader.File {
|
||||||
if !skipStripThisZip {
|
if !skipStripThisZip && shouldStripFile(emulateJar, file.Name) {
|
||||||
for _, dir := range stripDirs {
|
continue
|
||||||
if strings.HasPrefix(file.Name, dir+"/") {
|
|
||||||
if emulateJar {
|
|
||||||
if file.Name != jar.MetaDir && file.Name != jar.ManifestFile {
|
|
||||||
continue FileLoop
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
continue FileLoop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if stripDirEntries && file.FileInfo().IsDir() {
|
if stripDirEntries && file.FileInfo().IsDir() {
|
||||||
@@ -310,6 +301,28 @@ func mergeZips(readers []namedZipReader, writer *zip.Writer, manifest string,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func shouldStripFile(emulateJar bool, name string) bool {
|
||||||
|
for _, dir := range stripDirs {
|
||||||
|
if strings.HasPrefix(name, dir+"/") {
|
||||||
|
if emulateJar {
|
||||||
|
if name != jar.MetaDir && name != jar.ManifestFile {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, pattern := range stripFiles {
|
||||||
|
if match, err := filepath.Match(pattern, filepath.Base(name)); err != nil {
|
||||||
|
panic(fmt.Errorf("%s: %s", err.Error(), pattern))
|
||||||
|
} else if match {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func jarSort(files []fileMapping) {
|
func jarSort(files []fileMapping) {
|
||||||
sort.SliceStable(files, func(i, j int) bool {
|
sort.SliceStable(files, func(i, j int) bool {
|
||||||
return jar.EntryNamesLess(files[i].dest, files[j].dest)
|
return jar.EntryNamesLess(files[i].dest, files[j].dest)
|
||||||
|
@@ -31,7 +31,7 @@ const (
|
|||||||
ModuleInfoClass = "module-info.class"
|
ModuleInfoClass = "module-info.class"
|
||||||
)
|
)
|
||||||
|
|
||||||
var DefaultTime = time.Date(2009, 1, 1, 0, 0, 0, 0, time.UTC)
|
var DefaultTime = time.Date(2008, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||||
|
|
||||||
var MetaDirExtra = [2]byte{0xca, 0xfe}
|
var MetaDirExtra = [2]byte{0xca, 0xfe}
|
||||||
|
|
||||||
|
@@ -99,10 +99,12 @@ var (
|
|||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
||||||
`${config.DxCmd} --dex --output=$outDir $dxFlags $in && ` +
|
`${config.DxCmd} --dex --output=$outDir $dxFlags $in && ` +
|
||||||
`${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir`,
|
`${config.SoongZipCmd} -o $outDir/classes.dex.jar -C $outDir -D $outDir && ` +
|
||||||
|
`${config.MergeZipsCmd} -D -stripFile "*.class" $out $outDir/classes.dex.jar $in`,
|
||||||
CommandDeps: []string{
|
CommandDeps: []string{
|
||||||
"${config.DxCmd}",
|
"${config.DxCmd}",
|
||||||
"${config.SoongZipCmd}",
|
"${config.SoongZipCmd}",
|
||||||
|
"${config.MergeZipsCmd}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"outDir", "dxFlags")
|
"outDir", "dxFlags")
|
||||||
@@ -298,11 +300,13 @@ func TransformDesugar(ctx android.ModuleContext, classesJar android.Path,
|
|||||||
return outputFile
|
return outputFile
|
||||||
}
|
}
|
||||||
|
|
||||||
func TransformClassesJarToDexJar(ctx android.ModuleContext, classesJar android.Path,
|
// Converts a classes.jar file to classes*.dex, then combines the dex files with any resources
|
||||||
|
// in the classes.jar file into a dex jar.
|
||||||
|
func TransformClassesJarToDexJar(ctx android.ModuleContext, stem string, classesJar android.Path,
|
||||||
flags javaBuilderFlags) android.Path {
|
flags javaBuilderFlags) android.Path {
|
||||||
|
|
||||||
outDir := android.PathForModuleOut(ctx, "dex")
|
outDir := android.PathForModuleOut(ctx, "dex")
|
||||||
outputFile := android.PathForModuleOut(ctx, "classes.dex.jar")
|
outputFile := android.PathForModuleOut(ctx, stem)
|
||||||
|
|
||||||
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
ctx.ModuleBuild(pctx, android.ModuleBuildParams{
|
||||||
Rule: dx,
|
Rule: dx,
|
||||||
|
29
java/java.go
29
java/java.go
@@ -153,9 +153,6 @@ type Module struct {
|
|||||||
// output file containing classes.dex
|
// output file containing classes.dex
|
||||||
dexJarFile android.Path
|
dexJarFile android.Path
|
||||||
|
|
||||||
// output files containing resources
|
|
||||||
resourceJarFiles android.Paths
|
|
||||||
|
|
||||||
// output file suitable for installing or running
|
// output file suitable for installing or running
|
||||||
outputFile android.Path
|
outputFile android.Path
|
||||||
|
|
||||||
@@ -173,7 +170,6 @@ type Module struct {
|
|||||||
|
|
||||||
type Dependency interface {
|
type Dependency interface {
|
||||||
ClasspathFiles() android.Paths
|
ClasspathFiles() android.Paths
|
||||||
ResourceJarFiles() android.Paths
|
|
||||||
AidlIncludeDirs() android.Paths
|
AidlIncludeDirs() android.Paths
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,7 +376,6 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
|
|||||||
case staticLibTag:
|
case staticLibTag:
|
||||||
deps.classpath = append(deps.classpath, dep.ClasspathFiles()...)
|
deps.classpath = append(deps.classpath, dep.ClasspathFiles()...)
|
||||||
deps.staticJars = append(deps.staticJars, dep.ClasspathFiles()...)
|
deps.staticJars = append(deps.staticJars, dep.ClasspathFiles()...)
|
||||||
deps.staticJarResources = append(deps.staticJarResources, dep.ResourceJarFiles()...)
|
|
||||||
case frameworkResTag:
|
case frameworkResTag:
|
||||||
if ctx.ModuleName() == "framework" {
|
if ctx.ModuleName() == "framework" {
|
||||||
// framework.jar has a one-off dependency on the R.java and Manifest.java files
|
// framework.jar has a one-off dependency on the R.java and Manifest.java files
|
||||||
@@ -492,20 +487,14 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(resArgs) > 0 {
|
if len(resArgs) > 0 {
|
||||||
// Combine classes + resources into classes-full-debug.jar
|
|
||||||
resourceJar := TransformResourcesToJar(ctx, resArgs, resDeps)
|
resourceJar := TransformResourcesToJar(ctx, resArgs, resDeps)
|
||||||
if ctx.Failed() {
|
if ctx.Failed() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
j.resourceJarFiles = append(j.resourceJarFiles, resourceJar)
|
|
||||||
jars = append(jars, resourceJar)
|
jars = append(jars, resourceJar)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Propagate the resources from the transitive closure of static dependencies for copying
|
|
||||||
// into dex jars
|
|
||||||
j.resourceJarFiles = append(j.resourceJarFiles, deps.staticJarResources...)
|
|
||||||
|
|
||||||
// static classpath jars have the resources in them, so the resource jars aren't necessary here
|
// static classpath jars have the resources in them, so the resource jars aren't necessary here
|
||||||
jars = append(jars, deps.staticJars...)
|
jars = append(jars, deps.staticJars...)
|
||||||
|
|
||||||
@@ -580,17 +569,12 @@ func (j *Module) compile(ctx android.ModuleContext) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile classes.jar into classes.dex
|
// Compile classes.jar into classes.dex and then javalib.jar
|
||||||
dexJarFile := TransformClassesJarToDexJar(ctx, desugarJar, flags)
|
outputFile = TransformClassesJarToDexJar(ctx, "javalib.jar", desugarJar, flags)
|
||||||
if ctx.Failed() {
|
if ctx.Failed() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
jars := android.Paths{dexJarFile}
|
|
||||||
jars = append(jars, j.resourceJarFiles...)
|
|
||||||
|
|
||||||
outputFile = TransformJarsToJar(ctx, "javalib.jar", jars, android.OptionalPath{}, true)
|
|
||||||
|
|
||||||
j.dexJarFile = outputFile
|
j.dexJarFile = outputFile
|
||||||
}
|
}
|
||||||
ctx.CheckbuildFile(outputFile)
|
ctx.CheckbuildFile(outputFile)
|
||||||
@@ -607,10 +591,6 @@ func (j *Module) ClasspathFiles() android.Paths {
|
|||||||
return android.Paths{j.classpathFile}
|
return android.Paths{j.classpathFile}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Module) ResourceJarFiles() android.Paths {
|
|
||||||
return j.resourceJarFiles
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *Module) AidlIncludeDirs() android.Paths {
|
func (j *Module) AidlIncludeDirs() android.Paths {
|
||||||
return j.exportAidlIncludeDirs
|
return j.exportAidlIncludeDirs
|
||||||
}
|
}
|
||||||
@@ -777,11 +757,6 @@ func (j *Import) ClasspathFiles() android.Paths {
|
|||||||
return j.classpathFiles
|
return j.classpathFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *Import) ResourceJarFiles() android.Paths {
|
|
||||||
// resources are in the ClasspathFiles
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (j *Import) AidlIncludeDirs() android.Paths {
|
func (j *Import) AidlIncludeDirs() android.Paths {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user