diff options
Diffstat (limited to 'java')
| -rw-r--r-- | java/dexpreopt.go | 14 | ||||
| -rw-r--r-- | java/java.go | 18 | ||||
| -rw-r--r-- | java/sdk_library.go | 120 | ||||
| -rw-r--r-- | java/system_modules.go | 53 |
4 files changed, 149 insertions, 56 deletions
diff --git a/java/dexpreopt.go b/java/dexpreopt.go index da6866031..5faec0817 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -106,8 +106,18 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo global := dexpreoptGlobalConfig(ctx) bootImage := defaultBootImageConfig(ctx) + dexFiles := bootImage.dexPathsDeps.Paths() + dexLocations := bootImage.dexLocationsDeps + if global.UseArtImage { + bootImage = artBootImageConfig(ctx) + } if global.UseApexImage { bootImage = frameworkJZBootImageConfig(ctx) + dexFiles = bootImage.dexPathsDeps.Paths() + dexLocations = bootImage.dexLocationsDeps + if global.UseArtImage { + bootImage = artJZBootImageConfig(ctx) + } } var archs []android.ArchType @@ -178,8 +188,8 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo DexPreoptImagesDeps: imagesDeps, DexPreoptImageLocations: bootImage.imageLocations, - PreoptBootClassPathDexFiles: bootImage.dexPathsDeps.Paths(), - PreoptBootClassPathDexLocations: bootImage.dexLocationsDeps, + PreoptBootClassPathDexFiles: dexFiles, + PreoptBootClassPathDexLocations: dexLocations, PreoptExtractedApk: false, diff --git a/java/java.go b/java/java.go index c94ea8293..dd44d06aa 100644 --- a/java/java.go +++ b/java/java.go @@ -37,14 +37,7 @@ func init() { RegisterJavaBuildComponents(android.InitRegistrationContext) // Register sdk member types. - android.RegisterSdkMemberType(&headerLibrarySdkMemberType{ - librarySdkMemberType{ - android.SdkMemberTypeBase{ - PropertyName: "java_header_libs", - SupportsSdk: true, - }, - }, - }) + android.RegisterSdkMemberType(javaHeaderLibsSdkMemberType) android.RegisterSdkMemberType(&implLibrarySdkMemberType{ librarySdkMemberType{ @@ -1849,6 +1842,15 @@ func (mt *librarySdkMemberType) buildSnapshot( module.AddProperty("jars", []string{snapshotRelativeJavaLibPath}) } +var javaHeaderLibsSdkMemberType android.SdkMemberType = &headerLibrarySdkMemberType{ + librarySdkMemberType{ + android.SdkMemberTypeBase{ + PropertyName: "java_header_libs", + SupportsSdk: true, + }, + }, +} + type headerLibrarySdkMemberType struct { librarySdkMemberType } diff --git a/java/sdk_library.go b/java/sdk_library.go index fb8ae95de..f1c565fd0 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -16,6 +16,7 @@ package java import ( "android/soong/android" + "android/soong/genrule" "fmt" "io" @@ -264,17 +265,22 @@ func (module *SdkLibrary) getActiveApiScopes() apiScopes { } } +var xmlPermissionsFileTag = dependencyTag{name: "xml-permissions-file"} + func (module *SdkLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { - useBuiltStubs := !ctx.Config().UnbundledBuildUsePrebuiltSdks() for _, apiScope := range module.getActiveApiScopes() { // Add dependencies to the stubs library - if useBuiltStubs { - ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsName(apiScope)) - } + ctx.AddVariationDependencies(nil, apiScope.stubsTag, module.stubsName(apiScope)) + // And the api file ctx.AddVariationDependencies(nil, apiScope.apiFileTag, module.docsName(apiScope)) } + if !proptools.Bool(module.sdkLibraryProperties.Api_only) { + // Add dependency to the rule for generating the xml permissions file + ctx.AddDependency(module, xmlPermissionsFileTag, module.genXmlPermissionsFileName()) + } + module.Library.deps(ctx) } @@ -284,8 +290,6 @@ func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) module.Library.GenerateAndroidBuildActions(ctx) } - module.buildPermissionsFile(ctx) - // Record the paths to the header jars of the library (stubs and impl). // When this java_sdk_library is depended upon from others via "libs" property, // the recorded paths will be returned depending on the link type of the caller. @@ -310,33 +314,21 @@ func (module *SdkLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) ctx.ModuleErrorf("depends on module %q of unknown tag %q", otherName, tag) } } + if tag == xmlPermissionsFileTag { + if genRule, ok := to.(genrule.SourceFileGenerator); ok { + pf := genRule.GeneratedSourceFiles() + if len(pf) != 1 { + ctx.ModuleErrorf("%q failed to generate permission XML", otherName) + } else { + module.permissionsFile = pf[0] + } + } else { + ctx.ModuleErrorf("depends on module %q to generate xml permissions file but it does not provide any outputs", otherName) + } + } }) } -func (module *SdkLibrary) buildPermissionsFile(ctx android.ModuleContext) { - xmlContent := fmt.Sprintf(permissionsTemplate, module.BaseModuleName(), module.implPath()) - permissionsFile := android.PathForModuleOut(ctx, module.xmlFileName()) - - ctx.Build(pctx, android.BuildParams{ - Rule: android.WriteFile, - Output: permissionsFile, - Description: "Generating " + module.BaseModuleName() + " permissions", - Args: map[string]string{ - "content": xmlContent, - }, - }) - - module.permissionsFile = permissionsFile -} - -func (module *SdkLibrary) OutputFiles(tag string) (android.Paths, error) { - switch tag { - case ".xml": - return android.Paths{module.permissionsFile}, nil - } - return module.Library.OutputFiles(tag) -} - func (module *SdkLibrary) AndroidMkEntries() []android.AndroidMkEntries { if proptools.Bool(module.sdkLibraryProperties.Api_only) { return nil @@ -423,6 +415,11 @@ func (module *SdkLibrary) xmlFileName() string { return module.BaseModuleName() + sdkXmlFileSuffix } +// Module name of the rule for generating the XML permissions file +func (module *SdkLibrary) genXmlPermissionsFileName() string { + return "gen-" + module.BaseModuleName() + sdkXmlFileSuffix +} + // Get the sdk version for use when compiling the stubs library. func (module *SdkLibrary) sdkVersionForStubsLibrary(mctx android.LoadHookContext, apiScope *apiScope) string { sdkDep := decodeSdkDep(mctx, sdkContext(&module.Library)) @@ -466,9 +463,6 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiSc Compile_dex *bool Java_version *string Product_variables struct { - Unbundled_build struct { - Enabled *bool - } Pdk struct { Enabled *bool } @@ -487,10 +481,6 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.LoadHookContext, apiSc props.System_modules = module.Library.Module.deviceProperties.System_modules props.Installable = proptools.BoolPtr(false) props.Libs = module.sdkLibraryProperties.Stub_only_libs - // Unbundled apps will use the prebult one from /prebuilts/sdk - if mctx.Config().UnbundledBuildUsePrebuiltSdks() { - props.Product_variables.Unbundled_build.Enabled = proptools.BoolPtr(false) - } props.Product_variables.Pdk.Enabled = proptools.BoolPtr(false) props.Openjdk9.Srcs = module.Library.Module.properties.Openjdk9.Srcs props.Openjdk9.Javacflags = module.Library.Module.properties.Openjdk9.Javacflags @@ -623,8 +613,34 @@ func (module *SdkLibrary) createStubsSources(mctx android.LoadHookContext, apiSc mctx.CreateModule(DroidstubsFactory, &props) } +func (module *SdkLibrary) XmlPermissionsFile() android.Path { + return module.permissionsFile +} + +func (module *SdkLibrary) XmlPermissionsFileContent() string { + return fmt.Sprintf(permissionsTemplate, module.BaseModuleName(), module.implPath()) +} + // Creates the xml file that publicizes the runtime library func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) { + + xmlContent := module.XmlPermissionsFileContent() + + genRuleName := module.genXmlPermissionsFileName() + + // Create a genrule module to create the XML permissions file. + genRuleProps := struct { + Name *string + Cmd *string + Out []string + }{ + Name: proptools.StringPtr(genRuleName), + Cmd: proptools.StringPtr("echo -e '" + xmlContent + "' > '$(out)'"), + Out: []string{module.xmlFileName()}, + } + + mctx.CreateModule(genrule.GenRuleFactory, &genRuleProps) + // creates a prebuilt_etc module to actually place the xml file under // <partition>/etc/permissions etcProps := struct { @@ -637,7 +653,7 @@ func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) { System_ext_specific *bool }{} etcProps.Name = proptools.StringPtr(module.xmlFileName()) - etcProps.Src = proptools.StringPtr(":" + module.BaseModuleName() + "{.xml}") + etcProps.Src = proptools.StringPtr(":" + genRuleName) etcProps.Sub_dir = proptools.StringPtr("permissions") if module.SocSpecific() { etcProps.Soc_specific = proptools.BoolPtr(true) @@ -651,7 +667,7 @@ func (module *SdkLibrary) createXmlFile(mctx android.LoadHookContext) { mctx.CreateModule(android.PrebuiltEtcFactory, &etcProps) } -func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, s sdkSpec) android.Paths { +func PrebuiltJars(ctx android.BaseModuleContext, baseName string, s sdkSpec) android.Paths { var ver sdkVersion var kind sdkKind if s.usePrebuilt(ctx) { @@ -665,7 +681,7 @@ func (module *SdkLibrary) PrebuiltJars(ctx android.BaseModuleContext, s sdkSpec) } dir := filepath.Join("prebuilts", "sdk", ver.String(), kind.String()) - jar := filepath.Join(dir, module.BaseModuleName()+".jar") + jar := filepath.Join(dir, baseName+".jar") jarPath := android.ExistentPathForSource(ctx, jar) if !jarPath.Valid() { if ctx.Config().AllowMissingDependencies() { @@ -683,10 +699,9 @@ func (module *SdkLibrary) sdkJars( sdkVersion sdkSpec, headerJars bool) android.Paths { - // If a specific numeric version has been requested or the build is explicitly configured - // for it then use prebuilt versions of the sdk. - if sdkVersion.version.isNumbered() || ctx.Config().UnbundledBuildUsePrebuiltSdks() { - return module.PrebuiltJars(ctx, sdkVersion) + // If a specific numeric version has been requested then use prebuilt versions of the sdk. + if sdkVersion.version.isNumbered() { + return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion) } else { if !sdkVersion.specified() { if headerJars { @@ -899,6 +914,11 @@ func (module *sdkLibraryImport) Name() string { func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookContext) { + // If the build is configured to use prebuilts then force this to be preferred. + if mctx.Config().UnbundledBuildUsePrebuiltSdks() { + module.prebuilt.ForcePrefer() + } + for apiScope, scopeProperties := range module.scopeProperties() { if len(scopeProperties.Jars) == 0 { continue @@ -914,6 +934,7 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookConte Sdk_version *string Libs []string Jars []string + Prefer *bool }{} props.Name = proptools.StringPtr(apiScope.stubsModuleName(module.BaseModuleName())) @@ -933,6 +954,12 @@ func (module *sdkLibraryImport) createInternalModules(mctx android.LoadHookConte props.System_ext_specific = proptools.BoolPtr(true) } + // If the build should use prebuilt sdks then set prefer to true on the stubs library. + // That will cause the prebuilt version of the stubs to override the source version. + if mctx.Config().UnbundledBuildUsePrebuiltSdks() { + props.Prefer = proptools.BoolPtr(true) + } + mctx.CreateModule(ImportFactory, &props) } @@ -980,6 +1007,11 @@ func (module *sdkLibraryImport) sdkJars( ctx android.BaseModuleContext, sdkVersion sdkSpec) android.Paths { + // If a specific numeric version has been requested then use prebuilt versions of the sdk. + if sdkVersion.version.isNumbered() { + return PrebuiltJars(ctx, module.BaseModuleName(), sdkVersion) + } + var apiScope *apiScope switch sdkVersion.kind { case sdkSystem: diff --git a/java/system_modules.go b/java/system_modules.go index 92297c416..731503fd0 100644 --- a/java/system_modules.go +++ b/java/system_modules.go @@ -31,6 +31,15 @@ func init() { RegisterSystemModulesBuildComponents(android.InitRegistrationContext) pctx.SourcePathVariable("moduleInfoJavaPath", "build/soong/scripts/jars-to-module-info-java.sh") + + // Register sdk member types. + android.RegisterSdkMemberType(&systemModulesSdkMemberType{ + android.SdkMemberTypeBase{ + PropertyName: "java_system_modules", + SupportsSdk: true, + TransitiveSdkMembers: true, + }, + }) } func RegisterSystemModulesBuildComponents(ctx android.RegistrationContext) { @@ -66,6 +75,10 @@ var ( }, }, "classpath", "outDir", "workDir") + + // Dependency tag that causes the added dependencies to be added as java_header_libs + // to the sdk/module_exports/snapshot. + systemModulesLibsTag = android.DependencyTagForSdkMemberType(javaHeaderLibsSdkMemberType) ) func TransformJarsToSystemModules(ctx android.ModuleContext, jars android.Paths) (android.Path, android.Paths) { @@ -107,6 +120,7 @@ func SystemModulesFactory() android.Module { type SystemModules struct { android.ModuleBase android.DefaultableModuleBase + android.SdkBase properties SystemModulesProperties @@ -125,7 +139,7 @@ type SystemModulesProperties struct { func (system *SystemModules) GenerateAndroidBuildActions(ctx android.ModuleContext) { var jars android.Paths - ctx.VisitDirectDepsWithTag(libTag, func(module android.Module) { + ctx.VisitDirectDepsWithTag(systemModulesLibsTag, func(module android.Module) { dep, _ := module.(Dependency) jars = append(jars, dep.HeaderJars()...) }) @@ -136,7 +150,7 @@ func (system *SystemModules) GenerateAndroidBuildActions(ctx android.ModuleConte } func (system *SystemModules) DepsMutator(ctx android.BottomUpMutatorContext) { - ctx.AddVariationDependencies(nil, libTag, system.properties.Libs...) + ctx.AddVariationDependencies(nil, systemModulesLibsTag, system.properties.Libs...) } func (system *SystemModules) AndroidMk() android.AndroidMkData { @@ -173,6 +187,7 @@ func systemModulesImportFactory() android.Module { android.InitPrebuiltModule(module, &module.properties.Libs) android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) android.InitDefaultableModule(module) + android.InitSdkAwareModule(module) return module } @@ -188,3 +203,37 @@ func (system *systemModulesImport) Name() string { func (system *systemModulesImport) Prebuilt() *android.Prebuilt { return &system.prebuilt } + +type systemModulesSdkMemberType struct { + android.SdkMemberTypeBase +} + +func (mt *systemModulesSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { + mctx.AddVariationDependencies(nil, dependencyTag, names...) +} + +func (mt *systemModulesSdkMemberType) IsInstance(module android.Module) bool { + if _, ok := module.(*SystemModules); ok { + // A prebuilt system module cannot be added as a member of an sdk because the source and + // snapshot instances would conflict. + _, ok := module.(*systemModulesImport) + return !ok + } + return false +} + +func (mt *systemModulesSdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) { + variants := member.Variants() + if len(variants) != 1 { + sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name()) + for _, variant := range variants { + sdkModuleContext.ModuleErrorf(" %q", variant) + } + } + variant := variants[0] + systemModule := variant.(*SystemModules) + + pbm := builder.AddPrebuiltModule(member, "java_system_modules_import") + // Add the references to the libraries that form the system module. + pbm.AddPropertyWithTag("libs", systemModule.properties.Libs, builder.SdkMemberReferencePropertyTag()) +} |