diff options
Diffstat (limited to 'java/java.go')
| -rw-r--r-- | java/java.go | 86 |
1 files changed, 82 insertions, 4 deletions
diff --git a/java/java.go b/java/java.go index dd44d06aa..c3e2c9656 100644 --- a/java/java.go +++ b/java/java.go @@ -23,12 +23,14 @@ import ( "path/filepath" "strconv" "strings" + "sync" "github.com/google/blueprint" "github.com/google/blueprint/pathtools" "github.com/google/blueprint/proptools" "android/soong/android" + "android/soong/dexpreopt" "android/soong/java/config" "android/soong/tradefed" ) @@ -52,6 +54,8 @@ func init() { PropertyName: "java_tests", }, }) + + android.PostDepsMutators(RegisterPostDepsMutators) } func RegisterJavaBuildComponents(ctx android.RegistrationContext) { @@ -72,10 +76,52 @@ func RegisterJavaBuildComponents(ctx android.RegistrationContext) { ctx.RegisterModuleType("java_host_for_device", HostForDeviceFactory) ctx.RegisterModuleType("dex_import", DexImportFactory) + ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) { + ctx.BottomUp("dexpreopt_tool_deps", dexpreoptToolDepsMutator).Parallel() + }) + ctx.RegisterSingletonType("logtags", LogtagsSingleton) ctx.RegisterSingletonType("kythe_java_extract", kytheExtractJavaFactory) } +func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) { + ctx.BottomUp("ordered_system_server_jars", systemServerJarsDepsMutator) +} + +var ( + dexpreoptedSystemServerJarsKey = android.NewOnceKey("dexpreoptedSystemServerJars") + dexpreoptedSystemServerJarsLock sync.Mutex +) + +func DexpreoptedSystemServerJars(config android.Config) *[]string { + return config.Once(dexpreoptedSystemServerJarsKey, func() interface{} { + return &[]string{} + }).(*[]string) +} + +// A PostDepsMutator pass that enforces total order on non-updatable system server jars. A total +// order is neededed because such jars must be dexpreopted together (each jar on the list must have +// all preceding jars in its class loader context). The total order must be compatible with the +// partial order imposed by genuine dependencies between system server jars (which is not always +// respected by the PRODUCT_SYSTEM_SERVER_JARS variable). +// +// An earlier mutator pass creates genuine dependencies, and this pass traverses the jars in that +// order (which is partial and non-deterministic). This pass adds additional dependencies between +// jars, making the order total and deterministic. It also constructs a global ordered list. +func systemServerJarsDepsMutator(ctx android.BottomUpMutatorContext) { + jars := dexpreopt.NonUpdatableSystemServerJars(ctx, dexpreopt.GetGlobalConfig(ctx)) + name := ctx.ModuleName() + if android.InList(name, jars) { + dexpreoptedSystemServerJarsLock.Lock() + defer dexpreoptedSystemServerJarsLock.Unlock() + jars := DexpreoptedSystemServerJars(ctx.Config()) + for _, dep := range *jars { + ctx.AddDependency(ctx.Module(), dexpreopt.SystemServerDepTag, dep) + } + *jars = append(*jars, name) + } +} + func (j *Module) checkSdkVersion(ctx android.ModuleContext) { if j.SocSpecific() || j.DeviceSpecific() || (j.ProductSpecific() && ctx.Config().EnforceProductPartitionInterface()) { @@ -659,6 +705,11 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { } else if j.shouldInstrumentStatic(ctx) { ctx.AddVariationDependencies(nil, staticLibTag, "jacocoagent") } + + // services depend on com.android.location.provider, but dependency in not registered in a Blueprint file + if ctx.ModuleName() == "services" { + ctx.AddDependency(ctx.Module(), dexpreopt.SystemServerForcedDepTag, "com.android.location.provider") + } } func hasSrcExt(srcs []string, ext string) bool { @@ -756,6 +807,7 @@ const ( javaSdk javaSystem javaModule + javaSystemServer javaPlatform ) @@ -789,6 +841,10 @@ func (m *Module) getLinkType(name string) (ret linkType, stubs bool) { return javaModule, true case ver.kind == sdkModule: return javaModule, false + case name == "services-stubs": + return javaSystemServer, true + case ver.kind == sdkSystemServer: + return javaSystemServer, false case ver.kind == sdkPrivate || ver.kind == sdkNone || ver.kind == sdkCorePlatform: return javaPlatform, false case !ver.valid(): @@ -824,17 +880,23 @@ func checkLinkType(ctx android.ModuleContext, from *Module, to linkTypeContext, } break case javaSystem: - if otherLinkType == javaPlatform || otherLinkType == javaModule { + if otherLinkType == javaPlatform || otherLinkType == javaModule || otherLinkType == javaSystemServer { ctx.ModuleErrorf("compiles against system API, but dependency %q is compiling against private API."+commonMessage, ctx.OtherModuleName(to)) } break case javaModule: - if otherLinkType == javaPlatform { + if otherLinkType == javaPlatform || otherLinkType == javaSystemServer { ctx.ModuleErrorf("compiles against module API, but dependency %q is compiling against private API."+commonMessage, ctx.OtherModuleName(to)) } break + case javaSystemServer: + if otherLinkType == javaPlatform { + ctx.ModuleErrorf("compiles against system server API, but dependency %q is compiling against private API."+commonMessage, + ctx.OtherModuleName(to)) + } + break case javaPlatform: // no restriction on link-type break @@ -1475,6 +1537,16 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { j.implementationAndResourcesJar = implementationAndResourcesJar + // Enable dex compilation for the APEX variants, unless it is disabled explicitly + if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !j.IsForPlatform() { + if j.deviceProperties.Compile_dex == nil { + j.deviceProperties.Compile_dex = proptools.BoolPtr(true) + } + if j.deviceProperties.Hostdex == nil { + j.deviceProperties.Hostdex = proptools.BoolPtr(true) + } + } + if ctx.Device() && j.hasCode(ctx) && (Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) { // Dex compilation @@ -1724,6 +1796,10 @@ func (j *Module) JacocoReportClassesFile() android.Path { return j.jacocoReportClassesFile } +func (j *Module) IsInstallable() bool { + return Bool(j.properties.Installable) +} + // // Java libraries (.jar file) // @@ -1761,7 +1837,6 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.checkSdkVersion(ctx) j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar") j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary - j.dexpreopter.isInstallable = Bool(j.properties.Installable) j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter) j.deviceProperties.UncompressDex = j.dexpreopter.uncompressedDex j.compile(ctx, nil) @@ -2518,13 +2593,16 @@ func (j *DexImport) Stem() string { return proptools.StringDefault(j.properties.Stem, j.ModuleBase.Name()) } +func (j *DexImport) IsInstallable() bool { + return true +} + 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", j.Stem()+".jar") - j.dexpreopter.isInstallable = true j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter) inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars") |