diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 134 |
1 files changed, 122 insertions, 12 deletions
diff --git a/java/java.go b/java/java.go index dcd6dbe93..e0da00636 100644 --- a/java/java.go +++ b/java/java.go @@ -46,6 +46,7 @@ func init() { android.RegisterModuleType("java_import_host", ImportFactoryHost) android.RegisterModuleType("java_device_for_host", DeviceForHostFactory) android.RegisterModuleType("java_host_for_device", HostForDeviceFactory) + android.RegisterModuleType("dex_import", DexImportFactory) android.RegisterSingletonType("logtags", LogtagsSingleton) } @@ -288,7 +289,8 @@ type Module struct { proguardDictionary android.Path // output file of the module, which may be a classes jar or a dex jar - outputFile android.Path + outputFile android.Path + extraOutputFiles android.Paths exportAidlIncludeDirs android.Paths @@ -322,7 +324,7 @@ type Module struct { } func (j *Module) Srcs() android.Paths { - return android.Paths{j.outputFile} + return append(android.Paths{j.outputFile}, j.extraOutputFiles...) } func (j *Module) DexJarFile() android.Path { @@ -940,7 +942,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path if flags.javaVersion == "1.9" { j.properties.Srcs = append(j.properties.Srcs, j.properties.Openjdk9.Srcs...) } - srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) + srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs) if hasSrcExt(srcFiles.Strings(), ".proto") { flags = protoFlags(ctx, &j.properties, &j.protoProperties, flags) } @@ -956,7 +958,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, srcFiles.Strings()...) if j.properties.Jarjar_rules != nil { - j.expandJarjarRules = ctx.ExpandSource(*j.properties.Jarjar_rules, "jarjar_rules") + j.expandJarjarRules = android.PathForModuleSrc(ctx, *j.properties.Jarjar_rules) } jarName := ctx.ModuleName() + ".jar" @@ -1131,10 +1133,10 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path manifest := j.overrideManifest if !manifest.Valid() && j.properties.Manifest != nil { - manifest = android.OptionalPathForPath(ctx.ExpandSource(*j.properties.Manifest, "manifest")) + manifest = android.OptionalPathForPath(android.PathForModuleSrc(ctx, *j.properties.Manifest)) } - services := ctx.ExpandSources(j.properties.Services, nil) + services := android.PathsForModuleSrc(ctx, j.properties.Services) if len(services) > 0 { servicesJar := android.PathForModuleOut(ctx, "services", jarName) var zipargs []string @@ -1430,14 +1432,14 @@ type Library struct { Module } -func (j *Library) shouldUncompressDex(ctx android.ModuleContext) bool { +func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool { // Store uncompressed (and do not strip) dex files from boot class path jars. if inList(ctx.ModuleName(), ctx.Config().BootJars()) { return true } // Store uncompressed dex files that are preopted on /system. - if !j.dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, j.dexpreopter.installPath)) { + if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !odexOnSystemOther(ctx, dexpreopter.installPath)) { return true } if ctx.Config().UncompressPrivAppDex() && @@ -1452,7 +1454,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", ctx.ModuleName()+".jar") j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary j.dexpreopter.isInstallable = Bool(j.properties.Installable) - j.dexpreopter.uncompressedDex = j.shouldUncompressDex(ctx) + j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter) j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex j.compile(ctx) @@ -1545,7 +1547,7 @@ type Test struct { func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.testConfig = tradefed.AutoGenJavaTestConfig(ctx, j.testProperties.Test_config, j.testProperties.Test_config_template, j.testProperties.Test_suites) - j.data = ctx.ExpandSources(j.testProperties.Data, nil) + j.data = android.PathsForModuleSrc(ctx, j.testProperties.Data) j.Library.GenerateAndroidBuildActions(ctx) } @@ -1639,7 +1641,7 @@ func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.isWrapperVariant = true if j.binaryProperties.Wrapper != nil { - j.wrapperFile = ctx.ExpandSource(*j.binaryProperties.Wrapper, "wrapper") + j.wrapperFile = android.PathForModuleSrc(ctx, *j.binaryProperties.Wrapper) } else { j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh") } @@ -1763,7 +1765,7 @@ func (j *Import) DepsMutator(ctx android.BottomUpMutatorContext) { } func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { - jars := ctx.ExpandSources(j.properties.Jars, nil) + jars := android.PathsForModuleSrc(ctx, j.properties.Jars) jarName := ctx.ModuleName() + ".jar" outputFile := android.PathForModuleOut(ctx, "combined", jarName) @@ -1900,6 +1902,113 @@ func ImportFactoryHost() android.Module { return module } +// dex_import module + +type DexImportProperties struct { + Jars []string +} + +type DexImport struct { + android.ModuleBase + android.DefaultableModuleBase + prebuilt android.Prebuilt + + properties DexImportProperties + + dexJarFile android.Path + maybeStrippedDexJarFile android.Path + + dexpreopter +} + +func (j *DexImport) Prebuilt() *android.Prebuilt { + return &j.prebuilt +} + +func (j *DexImport) PrebuiltSrcs() []string { + return j.properties.Jars +} + +func (j *DexImport) Name() string { + return j.prebuilt.Name(j.ModuleBase.Name()) +} + +func (j *DexImport) DepsMutator(ctx android.BottomUpMutatorContext) { + android.ExtractSourcesDeps(ctx, j.properties.Jars) +} + +func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { + if len(j.properties.Jars) != 1 { + ctx.PropertyErrorf("jars", "exactly one jar must be provided") + } + + j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", ctx.ModuleName()+".jar") + j.dexpreopter.isInstallable = true + j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter) + + inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars") + dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar") + + if j.dexpreopter.uncompressedDex { + rule := android.NewRuleBuilder() + + temporary := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar.unaligned") + rule.Temporary(temporary) + + // use zip2zip to uncompress classes*.dex files + rule.Command(). + Tool(ctx.Config().HostToolPath(ctx, "zip2zip")). + FlagWithInput("-i ", inputJar). + FlagWithOutput("-o ", temporary). + FlagWithArg("-0 ", "'classes*.dex'") + + // use zipalign to align uncompressed classes*.dex files + rule.Command(). + Tool(ctx.Config().HostToolPath(ctx, "zipalign")). + Flag("-f"). + Text("4"). + Input(temporary). + Output(dexOutputFile) + + rule.DeleteTemporaryFiles() + + rule.Build(pctx, ctx, "uncompress_dex", "uncompress dex") + } else { + ctx.Build(pctx, android.BuildParams{ + Rule: android.Cp, + Input: inputJar, + Output: dexOutputFile, + }) + } + + j.dexJarFile = dexOutputFile + + dexOutputFile = j.dexpreopt(ctx, dexOutputFile) + + j.maybeStrippedDexJarFile = dexOutputFile + + ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), + ctx.ModuleName()+".jar", dexOutputFile) +} + +func (j *DexImport) DexJar() android.Path { + return j.dexJarFile +} + +// dex_import imports a `.jar` file containing classes.dex files. +// +// A dex_import module cannot be used as a dependency of a java_* or android_* module, it can only be installed +// to the device. +func DexImportFactory() android.Module { + module := &DexImport{} + + module.AddProperties(&module.properties) + + android.InitPrebuiltModule(module, &module.properties.Jars) + InitJavaModule(module, android.DeviceSupported) + return module +} + // // Defaults // @@ -1962,6 +2071,7 @@ func DefaultsFactory(props ...interface{}) android.Module { &ImportProperties{}, &AARImportProperties{}, &sdkLibraryProperties{}, + &DexImportProperties{}, ) android.InitDefaultsModule(module) |