diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/aar.go | 10 | ||||
-rw-r--r-- | java/aar_test.go | 47 | ||||
-rwxr-xr-x | java/app.go | 53 | ||||
-rw-r--r-- | java/app_import.go | 13 | ||||
-rw-r--r-- | java/app_set.go | 35 | ||||
-rw-r--r-- | java/app_test.go | 17 | ||||
-rw-r--r-- | java/base.go | 64 | ||||
-rw-r--r-- | java/builder.go | 2 | ||||
-rw-r--r-- | java/droiddoc.go | 3 | ||||
-rw-r--r-- | java/droidstubs.go | 33 | ||||
-rw-r--r-- | java/java.go | 23 | ||||
-rw-r--r-- | java/java_test.go | 99 | ||||
-rw-r--r-- | java/platform_compat_config.go | 10 | ||||
-rw-r--r-- | java/system_modules.go | 1 |
14 files changed, 335 insertions, 75 deletions
diff --git a/java/aar.go b/java/aar.go index 27dd38b3f..283579280 100644 --- a/java/aar.go +++ b/java/aar.go @@ -104,6 +104,9 @@ type aaptProperties struct { // Filter only specified product and ignore other products Filter_product *string `blueprint:"mutated"` + + // Names of aconfig_declarations modules that specify aconfig flags that the module depends on. + Flags_packages []string } type aapt struct { @@ -804,6 +807,10 @@ func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) { a.aapt.deps(ctx, sdkDep) } a.usesLibrary.deps(ctx, false) + + for _, aconfig_declaration := range a.aaptProperties.Flags_packages { + ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfig_declaration) + } } func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -817,13 +824,14 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) sdkContext: android.SdkContext(a), classLoaderContexts: a.classLoaderContexts, enforceDefaultTargetSdkVersion: false, + aconfigTextFiles: getAconfigFilePaths(ctx), }, ) apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) a.hideApexVariantFromMake = !apexInfo.IsForPlatform() - a.stem = proptools.StringDefault(a.overridableDeviceProperties.Stem, ctx.ModuleName()) + a.stem = proptools.StringDefault(a.overridableProperties.Stem, ctx.ModuleName()) ctx.CheckbuildFile(a.aapt.proguardOptionsFile) ctx.CheckbuildFile(a.aapt.exportPackage) diff --git a/java/aar_test.go b/java/aar_test.go index 4d4e5d025..6bd53f228 100644 --- a/java/aar_test.go +++ b/java/aar_test.go @@ -81,3 +81,50 @@ func TestAarImportProducesJniPackages(t *testing.T) { }) } } + +func TestLibraryFlagsPackages(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForJavaTest, + ).RunTestWithBp(t, ` + android_library { + name: "foo", + srcs: ["a.java"], + sdk_version: "current", + flags_packages: [ + "bar", + "baz", + ], + } + aconfig_declarations { + name: "bar", + package: "com.example.package.bar", + srcs: [ + "bar.aconfig", + ], + } + aconfig_declarations { + name: "baz", + package: "com.example.package.baz", + srcs: [ + "baz.aconfig", + ], + } + `) + + foo := result.ModuleForTests("foo", "android_common") + + // android_library module depends on aconfig_declarations listed in flags_packages + android.AssertBoolEquals(t, "foo expected to depend on bar", true, + CheckModuleHasDependency(t, result.TestContext, "foo", "android_common", "bar")) + + android.AssertBoolEquals(t, "foo expected to depend on baz", true, + CheckModuleHasDependency(t, result.TestContext, "foo", "android_common", "baz")) + + aapt2LinkRule := foo.Rule("android/soong/java.aapt2Link") + linkInFlags := aapt2LinkRule.Args["inFlags"] + android.AssertStringDoesContain(t, + "aapt2 link command expected to pass feature flags arguments", + linkInFlags, + "--feature-flags @out/soong/.intermediates/bar/intermediate.txt --feature-flags @out/soong/.intermediates/baz/intermediate.txt", + ) +} diff --git a/java/app.go b/java/app.go index 8209d4c61..4656888b4 100755 --- a/java/app.go +++ b/java/app.go @@ -169,9 +169,6 @@ type overridableAppProperties struct { // binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed // from PRODUCT_PACKAGES. Overrides []string - - // Names of aconfig_declarations modules that specify aconfig flags that the app depends on. - Flags_packages []string } type AndroidApp struct { @@ -290,6 +287,10 @@ func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) { } a.usesLibrary.deps(ctx, sdkDep.hasFrameworkLibs()) + + for _, aconfig_declaration := range a.aaptProperties.Flags_packages { + ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfig_declaration) + } } func (a *AndroidApp) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) { @@ -317,10 +318,6 @@ func (a *AndroidApp) OverridablePropertiesDepsMutator(ctx android.BottomUpMutato `must be names of android_app_certificate modules in the form ":module"`) } } - - for _, aconfig_declaration := range a.overridableAppProperties.Flags_packages { - ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfig_declaration) - } } func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -457,6 +454,21 @@ func (a *AndroidApp) renameResourcesPackage() bool { return proptools.BoolDefault(a.overridableAppProperties.Rename_resources_package, true) } +func getAconfigFilePaths(ctx android.ModuleContext) (aconfigTextFilePaths android.Paths) { + ctx.VisitDirectDepsWithTag(aconfigDeclarationTag, func(dep android.Module) { + if provider, ok := android.OtherModuleProvider(ctx, dep, android.AconfigDeclarationsProviderKey); ok { + aconfigTextFilePaths = append(aconfigTextFilePaths, provider.IntermediateDumpOutputPath) + } else { + ctx.ModuleErrorf("Only aconfig_declarations module type is allowed for "+ + "flags_packages property, but %s is not aconfig_declarations module type", + dep.Name(), + ) + } + }) + + return aconfigTextFilePaths +} + func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { usePlatformAPI := proptools.Bool(a.Module.deviceProperties.Platform_apis) if ctx.Module().(android.SdkContext).SdkVersion(ctx).Kind == android.SdkModule { @@ -507,18 +519,6 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { a.aapt.defaultManifestVersion = android.DefaultUpdatableModuleVersion } - var aconfigTextFilePaths android.Paths - ctx.VisitDirectDepsWithTag(aconfigDeclarationTag, func(dep android.Module) { - if provider, ok := android.OtherModuleProvider(ctx, dep, android.AconfigDeclarationsProviderKey); ok { - aconfigTextFilePaths = append(aconfigTextFilePaths, provider.IntermediateDumpOutputPath) - } else { - ctx.ModuleErrorf("Only aconfig_declarations module type is allowed for "+ - "flags_packages property, but %s is not aconfig_declarations module type", - dep.Name(), - ) - } - }) - a.aapt.buildActions(ctx, aaptBuildActionOptions{ sdkContext: android.SdkContext(a), @@ -526,7 +526,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { excludedLibs: a.usesLibraryProperties.Exclude_uses_libs, enforceDefaultTargetSdkVersion: a.enforceDefaultTargetSdkVersion(), extraLinkFlags: aaptLinkFlags, - aconfigTextFiles: aconfigTextFilePaths, + aconfigTextFiles: getAconfigFilePaths(ctx), }, ) @@ -755,7 +755,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { // Unlike installApkName, a.stem should respect base module name for override_android_app. // Therefore, use ctx.ModuleName() instead of a.Name(). - a.stem = proptools.StringDefault(a.overridableDeviceProperties.Stem, ctx.ModuleName()) + a.stem = proptools.StringDefault(a.overridableProperties.Stem, ctx.ModuleName()) // Check if the install APK name needs to be overridden. // Both android_app and override_android_app module are expected to possess @@ -763,7 +763,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { // from the base module. Therefore, use a.Name() which represents // the module name for both android_app and override_android_app. a.installApkName = ctx.DeviceConfig().OverridePackageNameFor( - proptools.StringDefault(a.overridableDeviceProperties.Stem, a.Name())) + proptools.StringDefault(a.overridableProperties.Stem, a.Name())) if ctx.ModuleName() == "framework-res" { // framework-res.apk is installed as system/framework/framework-res.apk @@ -912,6 +912,13 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { } a.buildAppDependencyInfo(ctx) + + providePrebuiltInfo(ctx, + prebuiltInfoProps{ + baseModuleName: a.BaseModuleName(), + isPrebuilt: false, + }, + ) } type appDepsInterface interface { @@ -1500,7 +1507,7 @@ func (i *OverrideAndroidApp) GenerateAndroidBuildActions(_ android.ModuleContext func OverrideAndroidAppModuleFactory() android.Module { m := &OverrideAndroidApp{} m.AddProperties( - &OverridableDeviceProperties{}, + &OverridableProperties{}, &overridableAppProperties{}, ) diff --git a/java/app_import.go b/java/app_import.go index dc84fc26d..7387e168c 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -150,6 +150,11 @@ type AndroidAppImportProperties struct { // If unspecified, follows the naming convention that the source module of // the prebuilt is Name() without "prebuilt_" prefix Source_module_name *string + + // Path to the .prebuilt_info file of the prebuilt app. + // In case of mainline modules, the .prebuilt_info file contains the build_id that was used + // to generate the prebuilt. + Prebuilt_info *string `android:"path"` } func (a *AndroidAppImport) IsInstallable() bool { @@ -413,6 +418,14 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext } android.CollectDependencyAconfigFiles(ctx, &a.mergedAconfigFiles) + providePrebuiltInfo(ctx, + prebuiltInfoProps{ + baseModuleName: a.BaseModuleName(), + isPrebuilt: true, + prebuiltInfo: a.properties.Prebuilt_info, + }, + ) + // TODO: androidmk converter jni libs } diff --git a/java/app_set.go b/java/app_set.go index d2d3b06ba..33d3adec2 100644 --- a/java/app_set.go +++ b/java/app_set.go @@ -48,6 +48,11 @@ type AndroidAppSetProperties struct { // Names of modules to be overridden. Listed modules can only be other apps // (in Make or Soong). Overrides []string + + // Path to the .prebuilt_info file of the prebuilt app. + // In case of mainline modules, the .prebuilt_info file contains the build_id that was used + // to generate the prebuilt. + Prebuilt_info *string `android:"path"` } type AndroidAppSet struct { @@ -117,6 +122,27 @@ func SupportedAbis(ctx android.ModuleContext, excludeNativeBridgeAbis bool) []st return result } +type prebuiltInfoProps struct { + baseModuleName string + isPrebuilt bool + prebuiltInfo *string +} + +// Set prebuiltInfoProvider. This will be used by `apex_prebuiltinfo_singleton` to print out a metadata file +// with information about whether source or prebuilt of an apex was used during the build. +func providePrebuiltInfo(ctx android.ModuleContext, p prebuiltInfoProps) { + info := android.PrebuiltInfo{ + Name: p.baseModuleName, + Is_prebuilt: p.isPrebuilt, + } + // If Prebuilt_info information is available in the soong module definition, add it to prebuilt_info.json. + if p.prebuiltInfo != nil { + prebuiltInfoFile := android.PathForModuleSrc(ctx, *p.prebuiltInfo) + info.Prebuilt_info_file_path = prebuiltInfoFile.String() + } + android.SetProvider(ctx, android.PrebuiltInfoProvider, info) +} + func (as *AndroidAppSet) GenerateAndroidBuildActions(ctx android.ModuleContext) { as.packedOutput = android.PathForModuleOut(ctx, ctx.ModuleName()+".zip") as.primaryOutput = android.PathForModuleOut(ctx, as.BaseModuleName()+".apk") @@ -157,6 +183,15 @@ func (as *AndroidAppSet) GenerateAndroidBuildActions(ctx android.ModuleContext) installDir = android.PathForModuleInstall(ctx, "app", as.BaseModuleName()) } ctx.InstallFileWithExtraFilesZip(installDir, as.BaseModuleName()+".apk", as.primaryOutput, as.packedOutput) + + providePrebuiltInfo(ctx, + prebuiltInfoProps{ + baseModuleName: as.BaseModuleName(), + isPrebuilt: true, + prebuiltInfo: as.properties.Prebuilt_info, + }, + ) + } func (as *AndroidAppSet) InstallBypassMake() bool { return true } diff --git a/java/app_test.go b/java/app_test.go index 5d7b048b3..b75cb1678 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -4401,3 +4401,20 @@ func TestNoDexpreoptOptionalUsesLibDoesNotHaveImpl(t *testing.T) { dexpreopt := result.ModuleForTests("app", "android_common").MaybeRule("dexpreopt").Rule android.AssertBoolEquals(t, "dexpreopt should be disabled if optional_uses_libs does not have an implementation", true, dexpreopt == nil) } + +func TestAppStem(t *testing.T) { + ctx := testApp(t, ` + android_app { + name: "foo", + srcs: ["a.java"], + stem: "foo-new", + sdk_version: "current", + }`) + + foo := ctx.ModuleForTests("foo", "android_common") + + outputs := fmt.Sprint(foo.AllOutputs()) + if !strings.Contains(outputs, "foo-new.apk") { + t.Errorf("Module output does not contain expected apk %s", "foo-new.apk") + } +} diff --git a/java/base.go b/java/base.go index d8ccec6c6..be286fe33 100644 --- a/java/base.go +++ b/java/base.go @@ -26,7 +26,6 @@ import ( "github.com/google/blueprint/pathtools" "github.com/google/blueprint/proptools" - "android/soong/aconfig" "android/soong/android" "android/soong/dexpreopt" "android/soong/java/config" @@ -306,8 +305,8 @@ type DeviceProperties struct { HiddenAPIFlagFileProperties } -// Device properties that can be overridden by overriding module (e.g. override_android_app) -type OverridableDeviceProperties struct { +// Properties that can be overridden by overriding module (e.g. override_android_app) +type OverridableProperties struct { // set the name of the output. If not set, `name` is used. // To override a module with this property set, overriding module might need to set this as well. // Otherwise, both the overridden and the overriding modules will have the same output name, which @@ -435,7 +434,7 @@ type Module struct { protoProperties android.ProtoProperties deviceProperties DeviceProperties - overridableDeviceProperties OverridableDeviceProperties + overridableProperties OverridableProperties // jar file containing header classes including static library dependencies, suitable for // inserting into the bootclasspath/classpath of another compile @@ -617,6 +616,7 @@ func (j *Module) checkHeadersOnly(ctx android.ModuleContext) { func (j *Module) addHostProperties() { j.AddProperties( &j.properties, + &j.overridableProperties, &j.protoProperties, &j.usesLibraryProperties, ) @@ -626,7 +626,6 @@ func (j *Module) addHostAndDeviceProperties() { j.addHostProperties() j.AddProperties( &j.deviceProperties, - &j.overridableDeviceProperties, &j.dexer.dexProperties, &j.dexpreoptProperties, &j.linter.properties, @@ -1220,14 +1219,15 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath } android.SetProvider(ctx, JavaInfoProvider, JavaInfo{ - HeaderJars: android.PathsIfNonNil(j.headerJarFile), - TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars, - TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars, - AidlIncludeDirs: j.exportAidlIncludeDirs, - ExportedPlugins: j.exportedPluginJars, - ExportedPluginClasses: j.exportedPluginClasses, - ExportedPluginDisableTurbine: j.exportedDisableTurbine, - StubsLinkType: j.stubsLinkType, + HeaderJars: android.PathsIfNonNil(j.headerJarFile), + TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars, + TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars, + AidlIncludeDirs: j.exportAidlIncludeDirs, + ExportedPlugins: j.exportedPluginJars, + ExportedPluginClasses: j.exportedPluginClasses, + ExportedPluginDisableTurbine: j.exportedDisableTurbine, + StubsLinkType: j.stubsLinkType, + AconfigIntermediateCacheOutputPaths: deps.aconfigProtoFiles, }) j.outputFile = j.headerJarFile @@ -1730,22 +1730,23 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath android.CollectDependencyAconfigFiles(ctx, &j.mergedAconfigFiles) android.SetProvider(ctx, JavaInfoProvider, JavaInfo{ - HeaderJars: android.PathsIfNonNil(j.headerJarFile), - RepackagedHeaderJars: android.PathsIfNonNil(j.repackagedHeaderJarFile), - TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars, - TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars, - ImplementationAndResourcesJars: android.PathsIfNonNil(j.implementationAndResourcesJar), - ImplementationJars: android.PathsIfNonNil(j.implementationJarFile), - ResourceJars: android.PathsIfNonNil(j.resourceJar), - AidlIncludeDirs: j.exportAidlIncludeDirs, - SrcJarArgs: j.srcJarArgs, - SrcJarDeps: j.srcJarDeps, - TransitiveSrcFiles: j.transitiveSrcFiles, - ExportedPlugins: j.exportedPluginJars, - ExportedPluginClasses: j.exportedPluginClasses, - ExportedPluginDisableTurbine: j.exportedDisableTurbine, - JacocoReportClassesFile: j.jacocoReportClassesFile, - StubsLinkType: j.stubsLinkType, + HeaderJars: android.PathsIfNonNil(j.headerJarFile), + RepackagedHeaderJars: android.PathsIfNonNil(j.repackagedHeaderJarFile), + TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars, + TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars, + ImplementationAndResourcesJars: android.PathsIfNonNil(j.implementationAndResourcesJar), + ImplementationJars: android.PathsIfNonNil(j.implementationJarFile), + ResourceJars: android.PathsIfNonNil(j.resourceJar), + AidlIncludeDirs: j.exportAidlIncludeDirs, + SrcJarArgs: j.srcJarArgs, + SrcJarDeps: j.srcJarDeps, + TransitiveSrcFiles: j.transitiveSrcFiles, + ExportedPlugins: j.exportedPluginJars, + ExportedPluginClasses: j.exportedPluginClasses, + ExportedPluginDisableTurbine: j.exportedDisableTurbine, + JacocoReportClassesFile: j.jacocoReportClassesFile, + StubsLinkType: j.stubsLinkType, + AconfigIntermediateCacheOutputPaths: deps.aconfigProtoFiles, }) // Save the output file with no relative path so that it doesn't end up in a subdirectory when used as a resource @@ -2296,6 +2297,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { // annotation processor that generates API is incompatible with the turbine // optimization. deps.disableTurbine = deps.disableTurbine || dep.ExportedPluginDisableTurbine + deps.aconfigProtoFiles = append(deps.aconfigProtoFiles, dep.AconfigIntermediateCacheOutputPaths...) case pluginTag: if plugin, ok := module.(*Plugin); ok { if plugin.pluginProperties.Processor_class != nil { @@ -2354,6 +2356,8 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { deps.staticJars = append(deps.staticJars, dep.Srcs()...) deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...) } + } else if dep, ok := android.OtherModuleProvider(ctx, module, android.CodegenInfoProvider); ok { + deps.aconfigProtoFiles = append(deps.aconfigProtoFiles, dep.IntermediateCacheOutputPaths...) } else { switch tag { case bootClasspathTag: @@ -2551,7 +2555,7 @@ func collectDirectDepsProviders(ctx android.ModuleContext) (result *JarJarProvid default: return RenameUseExclude, "srcfile" } - } else if _, ok := android.OtherModuleProvider(ctx, m, aconfig.CodegenInfoProvider); ok { + } else if _, ok := android.OtherModuleProvider(ctx, m, android.CodegenInfoProvider); ok { return RenameUseInclude, "aconfig_declarations_group" } else { switch tag { diff --git a/java/builder.go b/java/builder.go index b07a622e4..5d84d0b43 100644 --- a/java/builder.go +++ b/java/builder.go @@ -120,6 +120,8 @@ var ( `--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED ` + `--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED ` + `--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED ` + + `--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED ` + + `--add-exports=jdk.internal.opt/jdk.internal.opt=ALL-UNNAMED ` + `-jar ${config.JavaKytheExtractorJar} ` + `${config.JavacHeapFlags} ${config.CommonJdkFlags} ` + `$processorpath $processor $javacFlags $bootClasspath $classpath ` + diff --git a/java/droiddoc.go b/java/droiddoc.go index 6a66f45ec..aec40b312 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -21,7 +21,6 @@ import ( "github.com/google/blueprint/proptools" - "android/soong/aconfig" "android/soong/android" "android/soong/java/config" ) @@ -414,7 +413,7 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { case aconfigDeclarationTag: if dep, ok := android.OtherModuleProvider(ctx, module, android.AconfigDeclarationsProviderKey); ok { deps.aconfigProtoFiles = append(deps.aconfigProtoFiles, dep.IntermediateCacheOutputPath) - } else if dep, ok := android.OtherModuleProvider(ctx, module, aconfig.CodegenInfoProvider); ok { + } else if dep, ok := android.OtherModuleProvider(ctx, module, android.CodegenInfoProvider); ok { deps.aconfigProtoFiles = append(deps.aconfigProtoFiles, dep.IntermediateCacheOutputPaths...) } else { ctx.ModuleErrorf("Only aconfig_declarations and aconfig_declarations_group "+ diff --git a/java/droidstubs.go b/java/droidstubs.go index 76c8d8890..9556e956a 100644 --- a/java/droidstubs.go +++ b/java/droidstubs.go @@ -368,7 +368,7 @@ func (d *Droidstubs) ApiFilePath(stubsType StubsType) (ret android.Path, err err ret, err = nil, fmt.Errorf("api file path not supported for the stub type %s", stubsType.String()) } if ret == nil && err == nil { - err = fmt.Errorf("stubs srcjar is null for the stub type %s", stubsType.String()) + err = fmt.Errorf("api file is null for the stub type %s", stubsType.String()) } return ret, err } @@ -478,34 +478,41 @@ func (d *Droidstubs) sdkValuesFlags(ctx android.ModuleContext, cmd *android.Rule } func (d *Droidstubs) stubsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, stubsDir android.OptionalPath, stubsType StubsType, checkApi bool) { - if checkApi || String(d.properties.Api_filename) != "" { - filename := proptools.StringDefault(d.properties.Api_filename, ctx.ModuleName()+"_api.txt") - uncheckedApiFile := android.PathForModuleOut(ctx, stubsType.String(), filename) - cmd.FlagWithOutput("--api ", uncheckedApiFile) + apiFileName := proptools.StringDefault(d.properties.Api_filename, ctx.ModuleName()+"_api.txt") + uncheckedApiFile := android.PathForModuleOut(ctx, stubsType.String(), apiFileName) + cmd.FlagWithOutput("--api ", uncheckedApiFile) + if checkApi || String(d.properties.Api_filename) != "" { if stubsType == Everything { d.apiFile = uncheckedApiFile } else if stubsType == Exportable { d.exportableApiFile = uncheckedApiFile } } else if sourceApiFile := proptools.String(d.properties.Check_api.Current.Api_file); sourceApiFile != "" { - // If check api is disabled then make the source file available for export. - d.apiFile = android.PathForModuleSrc(ctx, sourceApiFile) + if stubsType == Everything { + // If check api is disabled then make the source file available for export. + d.apiFile = android.PathForModuleSrc(ctx, sourceApiFile) + } else if stubsType == Exportable { + d.exportableApiFile = uncheckedApiFile + } } + removedApiFileName := proptools.StringDefault(d.properties.Removed_api_filename, ctx.ModuleName()+"_removed.txt") + uncheckedRemovedFile := android.PathForModuleOut(ctx, stubsType.String(), removedApiFileName) + cmd.FlagWithOutput("--removed-api ", uncheckedRemovedFile) if checkApi || String(d.properties.Removed_api_filename) != "" { - filename := proptools.StringDefault(d.properties.Removed_api_filename, ctx.ModuleName()+"_removed.txt") - uncheckedRemovedFile := android.PathForModuleOut(ctx, stubsType.String(), filename) - cmd.FlagWithOutput("--removed-api ", uncheckedRemovedFile) - if stubsType == Everything { d.removedApiFile = uncheckedRemovedFile } else if stubsType == Exportable { d.exportableRemovedApiFile = uncheckedRemovedFile } } else if sourceRemovedApiFile := proptools.String(d.properties.Check_api.Current.Removed_api_file); sourceRemovedApiFile != "" { - // If check api is disabled then make the source removed api file available for export. - d.removedApiFile = android.PathForModuleSrc(ctx, sourceRemovedApiFile) + if stubsType == Everything { + // If check api is disabled then make the source removed api file available for export. + d.removedApiFile = android.PathForModuleSrc(ctx, sourceRemovedApiFile) + } else if stubsType == Exportable { + d.exportableRemovedApiFile = uncheckedRemovedFile + } } if stubsDir.Valid() { diff --git a/java/java.go b/java/java.go index 6423eebff..ad10cbd77 100644 --- a/java/java.go +++ b/java/java.go @@ -24,7 +24,6 @@ import ( "sort" "strings" - "android/soong/aconfig" "android/soong/remoteexec" "android/soong/testing" @@ -310,6 +309,10 @@ type JavaInfo struct { // implementation jars. If the provider is set by java_sdk_library, the link type is "unknown" // and selection between the stub jar vs implementation jar is deferred to SdkLibrary.sdkJars(...) StubsLinkType StubsLinkType + + // AconfigIntermediateCacheOutputPaths is a path to the cache files collected from the + // java_aconfig_library modules that are statically linked to this module. + AconfigIntermediateCacheOutputPaths android.Paths } var JavaInfoProvider = blueprint.NewProvider[JavaInfo]() @@ -346,6 +349,12 @@ func (j *Module) XrefJavaFiles() android.Paths { return j.kytheFiles } +func (d dependencyTag) PropagateAconfigValidation() bool { + return d.static +} + +var _ android.PropagateAconfigValidationDependencyTag = dependencyTag{} + type dependencyTag struct { blueprint.BaseDependencyTag name string @@ -355,6 +364,8 @@ type dependencyTag struct { // True if the dependency is a toolchain, for example an annotation processor. toolchain bool + + static bool } // installDependencyTag is a dependency tag that is annotated to cause the installed files of the @@ -400,7 +411,7 @@ func IsJniDepTag(depTag blueprint.DependencyTag) bool { var ( dataNativeBinsTag = dependencyTag{name: "dataNativeBins"} dataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"} - staticLibTag = dependencyTag{name: "staticlib"} + staticLibTag = dependencyTag{name: "staticlib", static: true} libTag = dependencyTag{name: "javalib", runtimeLinked: true} sdkLibTag = dependencyTag{name: "sdklib", runtimeLinked: true} java9LibTag = dependencyTag{name: "java9lib", runtimeLinked: true} @@ -890,7 +901,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { } } - j.stem = proptools.StringDefault(j.overridableDeviceProperties.Stem, ctx.ModuleName()) + j.stem = proptools.StringDefault(j.overridableProperties.Stem, ctx.ModuleName()) proguardSpecInfo := j.collectProguardSpecInfo(ctx) android.SetProvider(ctx, ProguardSpecInfoProvider, proguardSpecInfo) @@ -1687,7 +1698,7 @@ func (j *Binary) HostToolPath() android.OptionalPath { } func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) { - j.stem = proptools.StringDefault(j.overridableDeviceProperties.Stem, ctx.ModuleName()) + j.stem = proptools.StringDefault(j.overridableProperties.Stem, ctx.ModuleName()) if ctx.Arch().ArchType == android.Common { // Compile the jar @@ -2173,7 +2184,7 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { case aconfigDeclarationTag: if provider, ok := android.OtherModuleProvider(ctx, dep, android.AconfigDeclarationsProviderKey); ok { al.aconfigProtoFiles = append(al.aconfigProtoFiles, provider.IntermediateCacheOutputPath) - } else if provider, ok := android.OtherModuleProvider(ctx, dep, aconfig.CodegenInfoProvider); ok { + } else if provider, ok := android.OtherModuleProvider(ctx, dep, android.CodegenInfoProvider); ok { al.aconfigProtoFiles = append(al.aconfigProtoFiles, provider.IntermediateCacheOutputPaths...) } else { ctx.ModuleErrorf("Only aconfig_declarations and aconfig_declarations_group "+ @@ -2998,7 +3009,7 @@ func DefaultsFactory() android.Module { module.AddProperties( &CommonProperties{}, &DeviceProperties{}, - &OverridableDeviceProperties{}, + &OverridableProperties{}, &DexProperties{}, &DexpreoptProperties{}, &android.ProtoProperties{}, diff --git a/java/java_test.go b/java/java_test.go index 2f3ccb98d..194f9d974 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -2643,6 +2643,70 @@ func TestMultiplePrebuilts(t *testing.T) { } } +func TestMultiplePlatformCompatConfigPrebuilts(t *testing.T) { + bp := ` + // multiple variations of platform_compat_config + // source + platform_compat_config { + name: "myconfig", + } + // prebuilt "v1" + prebuilt_platform_compat_config { + name: "myconfig", + metadata: "myconfig.xml", + } + // prebuilt "v2" + prebuilt_platform_compat_config { + name: "myconfig.v2", + source_module_name: "myconfig", // without source_module_name, the singleton will merge two .xml files + metadata: "myconfig.v2.xml", + } + + // selectors + apex_contributions { + name: "myapex_contributions", + contents: ["%v"], + } + ` + testCases := []struct { + desc string + selectedDependencyName string + expectedPlatformCompatConfigXml string + }{ + { + desc: "Source platform_compat_config is selected using apex_contributions", + selectedDependencyName: "myconfig", + expectedPlatformCompatConfigXml: "out/soong/.intermediates/myconfig/android_common/myconfig_meta.xml", + }, + { + desc: "Prebuilt platform_compat_config v1 is selected using apex_contributions", + selectedDependencyName: "prebuilt_myconfig", + expectedPlatformCompatConfigXml: "myconfig.xml", + }, + { + desc: "Prebuilt platform_compat_config v2 is selected using apex_contributions", + selectedDependencyName: "prebuilt_myconfig.v2", + expectedPlatformCompatConfigXml: "myconfig.v2.xml", + }, + } + + for _, tc := range testCases { + ctx := android.GroupFixturePreparers( + prepareForJavaTest, + PrepareForTestWithPlatformCompatConfig, + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.BuildFlags = map[string]string{ + "RELEASE_APEX_CONTRIBUTIONS_ADSERVICES": "myapex_contributions", + } + }), + ).RunTestWithBp(t, fmt.Sprintf(bp, tc.selectedDependencyName)) + + mergedGlobalConfig := ctx.SingletonForTests("platform_compat_config_singleton").Output("compat_config/merged_compat_config.xml") + android.AssertIntEquals(t, "The merged compat config file should only have a single dependency", 1, len(mergedGlobalConfig.Implicits)) + android.AssertStringEquals(t, "The merged compat config file is missing the appropriate platform compat config", mergedGlobalConfig.Implicits[0].String(), tc.expectedPlatformCompatConfigXml) + } +} + func TestApiLibraryAconfigDeclarations(t *testing.T) { result := android.GroupFixturePreparers( prepareForJavaTest, @@ -2693,3 +2757,38 @@ func TestApiLibraryAconfigDeclarations(t *testing.T) { cmdline := String(android.RuleBuilderSboxProtoForTests(t, result.TestContext, manifest).Commands[0].Command) android.AssertStringDoesContain(t, "flagged api hide command not included", cmdline, "revert-annotations-exportable.txt") } + +func TestJavaLibHostWithStem(t *testing.T) { + ctx, _ := testJava(t, ` + java_library_host { + name: "foo", + srcs: ["a.java"], + stem: "foo-new", + } + `) + + buildOS := ctx.Config().BuildOS.String() + foo := ctx.ModuleForTests("foo", buildOS+"_common") + + outputs := fmt.Sprint(foo.AllOutputs()) + if !strings.Contains(outputs, "foo-new.jar") { + t.Errorf("Module output does not contain expected jar %s", "foo-new.jar") + } +} + +func TestJavaLibWithStem(t *testing.T) { + ctx, _ := testJava(t, ` + java_library { + name: "foo", + srcs: ["a.java"], + stem: "foo-new", + } + `) + + foo := ctx.ModuleForTests("foo", "android_common") + + outputs := fmt.Sprint(foo.AllOutputs()) + if !strings.Contains(outputs, "foo-new.jar") { + t.Errorf("Module output does not contain expected jar %s", "foo-new.jar") + } +} diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go index 2197304a5..2fc6c02a6 100644 --- a/java/platform_compat_config.go +++ b/java/platform_compat_config.go @@ -20,6 +20,7 @@ import ( "android/soong/android" "github.com/google/blueprint" + "github.com/google/blueprint/proptools" ) func init() { @@ -184,6 +185,11 @@ type prebuiltCompatConfigModule struct { type prebuiltCompatConfigProperties struct { Metadata *string `android:"path"` + + // Name of the source soong module that gets shadowed by this prebuilt + // If unspecified, follows the naming convention that the source module of + // the prebuilt is Name() without "prebuilt_" prefix + Source_module_name *string } func (module *prebuiltCompatConfigModule) Prebuilt() *android.Prebuilt { @@ -198,6 +204,10 @@ func (module *prebuiltCompatConfigModule) compatConfigMetadata() android.Path { return module.metadataFile } +func (module *prebuiltCompatConfigModule) BaseModuleName() string { + return proptools.StringDefault(module.properties.Source_module_name, module.ModuleBase.Name()) +} + var _ platformCompatConfigMetadataProvider = (*prebuiltCompatConfigModule)(nil) func (module *prebuiltCompatConfigModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { diff --git a/java/system_modules.go b/java/system_modules.go index 92e31cdf9..8e2d5d8ff 100644 --- a/java/system_modules.go +++ b/java/system_modules.go @@ -64,6 +64,7 @@ var ( // useful on Android, and (b) it causes errors with later versions of jlink // when the jdk.internal.module is absent from java.base (as it is here). ` --disable-plugin system-modules && ` + + `rm -rf ${workDir} && ` + `cp ${config.JrtFsJar} ${outDir}/lib/`, CommandDeps: []string{ "${moduleInfoJavaPath}", |