diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/Android.bp | 1 | ||||
-rw-r--r-- | java/app_test.go | 180 | ||||
-rw-r--r-- | java/boot_image.go | 5 | ||||
-rw-r--r-- | java/droiddoc.go | 10 | ||||
-rw-r--r-- | java/java_test.go | 10 | ||||
-rw-r--r-- | java/kotlin.go | 4 | ||||
-rw-r--r-- | java/lint.go | 11 | ||||
-rw-r--r-- | java/platform_compat_config.go | 140 | ||||
-rw-r--r-- | java/platform_compat_config_test.go | 53 |
9 files changed, 258 insertions, 156 deletions
diff --git a/java/Android.bp b/java/Android.bp index 9e2db8314..56cc40129 100644 --- a/java/Android.bp +++ b/java/Android.bp @@ -75,6 +75,7 @@ bootstrap_go_package { "java_test.go", "jdeps_test.go", "kotlin_test.go", + "platform_compat_config_test.go", "plugin_test.go", "rro_test.go", "sdk_test.go", diff --git a/java/app_test.go b/java/app_test.go index c189ee5d3..7168a9645 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -370,11 +370,15 @@ func TestUpdatableApps(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { - if test.expectedError == "" { - testJava(t, test.bp) - } else { - testJavaError(t, test.expectedError, test.bp) + errorHandler := android.FixtureExpectsNoErrors + if test.expectedError != "" { + errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(test.expectedError) } + javaFixtureFactory. + Extend(FixtureWithPrebuiltApis(map[string][]string{ + "29": {"foo"}, + })). + ExtendWithErrorHandler(errorHandler).RunTestWithBp(t, test.bp) }) } } @@ -984,12 +988,8 @@ func TestAndroidResources(t *testing.T) { } } -func checkSdkVersion(t *testing.T, config android.Config, expectedSdkVersion string) { - ctx := testContext(config) - - run(t, ctx, config) - - foo := ctx.ModuleForTests("foo", "android_common") +func checkSdkVersion(t *testing.T, result *android.TestResult, expectedSdkVersion string) { + foo := result.ModuleForTests("foo", "android_common") link := foo.Output("package-res.apk") linkFlags := strings.Split(link.Args["flags"], " ") min := android.IndexList("--min-sdk-version", linkFlags) @@ -1002,15 +1002,9 @@ func checkSdkVersion(t *testing.T, config android.Config, expectedSdkVersion str gotMinSdkVersion := linkFlags[min+1] gotTargetSdkVersion := linkFlags[target+1] - if gotMinSdkVersion != expectedSdkVersion { - t.Errorf("incorrect --min-sdk-version, expected %q got %q", - expectedSdkVersion, gotMinSdkVersion) - } + android.AssertStringEquals(t, "incorrect --min-sdk-version", expectedSdkVersion, gotMinSdkVersion) - if gotTargetSdkVersion != expectedSdkVersion { - t.Errorf("incorrect --target-sdk-version, expected %q got %q", - expectedSdkVersion, gotTargetSdkVersion) - } + android.AssertStringEquals(t, "incorrect --target-sdk-version", expectedSdkVersion, gotTargetSdkVersion) } func TestAppSdkVersion(t *testing.T) { @@ -1083,13 +1077,19 @@ func TestAppSdkVersion(t *testing.T) { %s }`, moduleType, test.sdkVersion, platformApiProp) - config := testAppConfig(nil, bp, nil) - config.TestProductVariables.Platform_sdk_version = &test.platformSdkInt - config.TestProductVariables.Platform_sdk_codename = &test.platformSdkCodename - config.TestProductVariables.Platform_version_active_codenames = test.activeCodenames - config.TestProductVariables.Platform_sdk_final = &test.platformSdkFinal - checkSdkVersion(t, config, test.expectedMinSdkVersion) - + result := javaFixtureFactory.Extend( + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.Platform_sdk_version = &test.platformSdkInt + variables.Platform_sdk_codename = &test.platformSdkCodename + variables.Platform_version_active_codenames = test.activeCodenames + variables.Platform_sdk_final = &test.platformSdkFinal + }), + FixtureWithPrebuiltApis(map[string][]string{ + "14": {"foo"}, + }), + ).RunTestWithBp(t, bp) + + checkSdkVersion(t, result, test.expectedMinSdkVersion) }) } } @@ -1145,13 +1145,22 @@ func TestVendorAppSdkVersion(t *testing.T) { vendor: true, }`, moduleType, sdkKind, test.sdkVersion) - config := testAppConfig(nil, bp, nil) - config.TestProductVariables.Platform_sdk_version = &test.platformSdkInt - config.TestProductVariables.Platform_sdk_codename = &test.platformSdkCodename - config.TestProductVariables.Platform_sdk_final = &test.platformSdkFinal - config.TestProductVariables.DeviceCurrentApiLevelForVendorModules = &test.deviceCurrentApiLevelForVendorModules - config.TestProductVariables.DeviceSystemSdkVersions = []string{"28", "29"} - checkSdkVersion(t, config, test.expectedMinSdkVersion) + result := javaFixtureFactory.Extend( + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.Platform_sdk_version = &test.platformSdkInt + variables.Platform_sdk_codename = &test.platformSdkCodename + variables.Platform_sdk_final = &test.platformSdkFinal + variables.DeviceCurrentApiLevelForVendorModules = &test.deviceCurrentApiLevelForVendorModules + variables.DeviceSystemSdkVersions = []string{"28", "29"} + }), + FixtureWithPrebuiltApis(map[string][]string{ + "28": {"foo"}, + "29": {"foo"}, + "current": {"foo"}, + }), + ).RunTestWithBp(t, bp) + + checkSdkVersion(t, result, test.expectedMinSdkVersion) }) } } @@ -2360,15 +2369,16 @@ func TestUsesLibraries(t *testing.T) { } ` - config := testAppConfig(nil, bp, nil) - config.TestProductVariables.MissingUsesLibraries = []string{"baz"} + result := javaFixtureFactory.Extend( + PrepareForTestWithJavaSdkLibraryFiles, + FixtureWithLastReleaseApis("runtime-library", "foo", "quuz", "qux", "bar", "fred"), + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.MissingUsesLibraries = []string{"baz"} + }), + ).RunTestWithBp(t, bp) - ctx := testContext(config) - - run(t, ctx, config) - - app := ctx.ModuleForTests("app", "android_common") - prebuilt := ctx.ModuleForTests("prebuilt", "android_common") + app := result.ModuleForTests("app", "android_common") + prebuilt := result.ModuleForTests("prebuilt", "android_common") // Test that implicit dependencies on java_sdk_library instances are passed to the manifest. // This should not include explicit `uses_libs`/`optional_uses_libs` entries. @@ -2380,10 +2390,7 @@ func TestUsesLibraries(t *testing.T) { `--uses-library com.non.sdk.lib ` + // TODO(b/132357300): "com.non.sdk.lib" should not be passed to manifest_fixer `--uses-library bar ` + // TODO(b/132357300): "bar" should not be passed to manifest_fixer `--uses-library runtime-library` - if actualManifestFixerArgs != expectManifestFixerArgs { - t.Errorf("unexpected manifest_fixer args:\n\texpect: %q\n\tactual: %q", - expectManifestFixerArgs, actualManifestFixerArgs) - } + android.AssertStringEquals(t, "manifest_fixer args", expectManifestFixerArgs, actualManifestFixerArgs) // Test that all libraries are verified (library order matters). verifyCmd := app.Rule("verify_uses_libraries").RuleParams.Command @@ -2394,9 +2401,7 @@ func TestUsesLibraries(t *testing.T) { `--uses-library runtime-library ` + `--optional-uses-library bar ` + `--optional-uses-library baz ` - if !strings.Contains(verifyCmd, verifyArgs) { - t.Errorf("wanted %q in %q", verifyArgs, verifyCmd) - } + android.AssertStringDoesContain(t, "verify cmd args", verifyCmd, verifyArgs) // Test that all libraries are verified for an APK (library order matters). verifyApkCmd := prebuilt.Rule("verify_uses_libraries").RuleParams.Command @@ -2405,9 +2410,7 @@ func TestUsesLibraries(t *testing.T) { `--uses-library android.test.runner ` + `--optional-uses-library bar ` + `--optional-uses-library baz ` - if !strings.Contains(verifyApkCmd, verifyApkArgs) { - t.Errorf("wanted %q in %q", verifyApkArgs, verifyApkCmd) - } + android.AssertStringDoesContain(t, "verify apk cmd args", verifyApkCmd, verifyApkArgs) // Test that all present libraries are preopted, including implicit SDK dependencies, possibly stubs cmd := app.Rule("dexpreopt").RuleParams.Command @@ -2418,46 +2421,39 @@ func TestUsesLibraries(t *testing.T) { `PCL[/system/framework/non-sdk-lib.jar]#` + `PCL[/system/framework/bar.jar]#` + `PCL[/system/framework/runtime-library.jar]` - if !strings.Contains(cmd, w) { - t.Errorf("wanted %q in %q", w, cmd) - } + android.AssertStringDoesContain(t, "dexpreopt app cmd args", cmd, w) // Test conditional context for target SDK version 28. - if w := `--target-context-for-sdk 28` + - ` PCL[/system/framework/org.apache.http.legacy.jar] `; !strings.Contains(cmd, w) { - t.Errorf("wanted %q in %q", w, cmd) - } + android.AssertStringDoesContain(t, "dexpreopt app cmd 28", cmd, + `--target-context-for-sdk 28`+ + ` PCL[/system/framework/org.apache.http.legacy.jar] `) // Test conditional context for target SDK version 29. - if w := `--target-context-for-sdk 29` + - ` PCL[/system/framework/android.hidl.manager-V1.0-java.jar]` + - `#PCL[/system/framework/android.hidl.base-V1.0-java.jar] `; !strings.Contains(cmd, w) { - t.Errorf("wanted %q in %q", w, cmd) - } + android.AssertStringDoesContain(t, "dexpreopt app cmd 29", cmd, + `--target-context-for-sdk 29`+ + ` PCL[/system/framework/android.hidl.manager-V1.0-java.jar]`+ + `#PCL[/system/framework/android.hidl.base-V1.0-java.jar] `) // Test conditional context for target SDK version 30. // "android.test.mock" is absent because "android.test.runner" is not used. - if w := `--target-context-for-sdk 30` + - ` PCL[/system/framework/android.test.base.jar] `; !strings.Contains(cmd, w) { - t.Errorf("wanted %q in %q", w, cmd) - } + android.AssertStringDoesContain(t, "dexpreopt app cmd 30", cmd, + `--target-context-for-sdk 30`+ + ` PCL[/system/framework/android.test.base.jar] `) cmd = prebuilt.Rule("dexpreopt").RuleParams.Command - if w := `--target-context-for-sdk any` + - ` PCL[/system/framework/foo.jar]` + - `#PCL[/system/framework/non-sdk-lib.jar]` + - `#PCL[/system/framework/android.test.runner.jar]` + - `#PCL[/system/framework/bar.jar] `; !strings.Contains(cmd, w) { - t.Errorf("wanted %q in %q", w, cmd) - } + android.AssertStringDoesContain(t, "dexpreopt prebuilt cmd", cmd, + `--target-context-for-sdk any`+ + ` PCL[/system/framework/foo.jar]`+ + `#PCL[/system/framework/non-sdk-lib.jar]`+ + `#PCL[/system/framework/android.test.runner.jar]`+ + `#PCL[/system/framework/bar.jar] `) // Test conditional context for target SDK version 30. // "android.test.mock" is present because "android.test.runner" is used. - if w := `--target-context-for-sdk 30` + - ` PCL[/system/framework/android.test.base.jar]` + - `#PCL[/system/framework/android.test.mock.jar] `; !strings.Contains(cmd, w) { - t.Errorf("wanted %q in %q", w, cmd) - } + android.AssertStringDoesContain(t, "dexpreopt prebuilt cmd 30", cmd, + `--target-context-for-sdk 30`+ + ` PCL[/system/framework/android.test.base.jar]`+ + `#PCL[/system/framework/android.test.mock.jar] `) } func TestCodelessApp(t *testing.T) { @@ -2722,28 +2718,24 @@ func TestUncompressDex(t *testing.T) { test := func(t *testing.T, bp string, want bool, unbundled bool) { t.Helper() - config := testAppConfig(nil, bp, nil) - if unbundled { - config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) - config.TestProductVariables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) - } - - ctx := testContext(config) - - run(t, ctx, config) + result := javaFixtureFactory.Extend( + PrepareForTestWithPrebuiltsOfCurrentApi, + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + if unbundled { + variables.Unbundled_build = proptools.BoolPtr(true) + variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) + } + }), + ).RunTestWithBp(t, bp) - foo := ctx.ModuleForTests("foo", "android_common") + foo := result.ModuleForTests("foo", "android_common") dex := foo.Rule("r8") uncompressedInDexJar := strings.Contains(dex.Args["zipFlags"], "-L 0") aligned := foo.MaybeRule("zipalign").Rule != nil - if uncompressedInDexJar != want { - t.Errorf("want uncompressed in dex %v, got %v", want, uncompressedInDexJar) - } + android.AssertBoolEquals(t, "uncompressed in dex", want, uncompressedInDexJar) - if aligned != want { - t.Errorf("want aligned %v, got %v", want, aligned) - } + android.AssertBoolEquals(t, "aligne", want, aligned) } for _, tt := range testCases { diff --git a/java/boot_image.go b/java/boot_image.go index 12e287459..25a4f17f4 100644 --- a/java/boot_image.go +++ b/java/boot_image.go @@ -20,6 +20,7 @@ import ( "android/soong/android" "android/soong/dexpreopt" + "github.com/google/blueprint" ) @@ -56,9 +57,9 @@ type BootImageModule struct { func bootImageFactory() android.Module { m := &BootImageModule{} m.AddProperties(&m.properties) - android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon) android.InitApexModule(m) android.InitSdkAwareModule(m) + android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon) return m } @@ -210,11 +211,11 @@ func (module *prebuiltBootImageModule) Name() string { func prebuiltBootImageFactory() android.Module { m := &prebuiltBootImageModule{} m.AddProperties(&m.properties) - android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon) // This doesn't actually have any prebuilt files of its own so pass a placeholder for the srcs // array. android.InitPrebuiltModule(m, &[]string{"placeholder"}) android.InitApexModule(m) android.InitSdkAwareModule(m) + android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibCommon) return m } diff --git a/java/droiddoc.go b/java/droiddoc.go index f0decec74..da13c621b 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -812,7 +812,7 @@ func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs andro BuiltTool("soong_javac_wrapper").Tool(config.JavadocCmd(ctx)). Flag(config.JavacVmFlags). FlagWithArg("-encoding ", "UTF-8"). - FlagWithRspFileInputList("@", srcs). + FlagWithRspFileInputList("@", android.PathForModuleOut(ctx, "javadoc.rsp"), srcs). FlagWithInput("@", srcJarList) // TODO(ccross): Remove this if- statement once we finish migration for all Doclava @@ -1243,7 +1243,7 @@ func metalavaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, javaVersi Flag("-J--add-opens=java.base/java.util=ALL-UNNAMED"). FlagWithArg("-encoding ", "UTF-8"). FlagWithArg("-source ", javaVersion.String()). - FlagWithRspFileInputList("@", srcs). + FlagWithRspFileInputList("@", android.PathForModuleOut(ctx, "metalava.rsp"), srcs). FlagWithInput("@", srcJarList) if javaHome := ctx.Config().Getenv("ANDROID_JAVA_HOME"); javaHome != "" { @@ -1446,7 +1446,9 @@ func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { // add a large number of inputs to a file without exceeding bash command length limits (which // would happen if we use the WriteFile rule). The cp is needed because RuleBuilder sets the // rsp file to be ${output}.rsp. - impCmd.Text("cp").FlagWithRspFileInputList("", cmd.GetImplicits()).Output(implicitsRsp) + impCmd.Text("cp"). + FlagWithRspFileInputList("", android.PathForModuleOut(ctx, "metalava-implicits.rsp"), cmd.GetImplicits()). + Output(implicitsRsp) impRule.Build("implicitsGen", "implicits generation") cmd.Implicit(implicitsRsp) @@ -1750,7 +1752,7 @@ func (p *PrebuiltStubsSources) GenerateAndroidBuildActions(ctx android.ModuleCon Flag("-jar"). FlagWithOutput("-o ", p.stubsSrcJar). FlagWithArg("-C ", srcDir.String()). - FlagWithRspFileInputList("-r ", srcPaths) + FlagWithRspFileInputList("-r ", p.stubsSrcJar.ReplaceExtension(ctx, "rsp"), srcPaths) rule.Restat() diff --git a/java/java_test.go b/java/java_test.go index 2eb724185..b68945fd1 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -48,19 +48,19 @@ func tearDown() { os.RemoveAll(buildDir) } +var emptyFixtureFactory = android.NewFixtureFactory(&buildDir) + // Factory to use to create fixtures for tests in this package. -var javaFixtureFactory = android.NewFixtureFactory( - &buildDir, +var javaFixtureFactory = emptyFixtureFactory.Extend( genrule.PrepareForTestWithGenRuleBuildComponents, // Get the CC build components but not default modules. cc.PrepareForTestWithCcBuildComponents, // Include all the default java modules. PrepareForTestWithJavaDefaultModules, + python.PrepareForTestWithPythonBuildComponents, android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { ctx.RegisterModuleType("java_plugin", PluginFactory) - ctx.RegisterModuleType("python_binary_host", python.PythonBinaryHostFactory) - ctx.PreDepsMutators(python.RegisterPythonPreDepsMutators) ctx.RegisterPreSingletonType("overlay", OverlaySingletonFactory) ctx.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory) }), @@ -100,11 +100,9 @@ func testContext(config android.Config) *android.TestContext { RegisterRequiredBuildComponentsForTest(ctx) ctx.RegisterModuleType("java_plugin", PluginFactory) ctx.RegisterModuleType("filegroup", android.FileGroupFactory) - ctx.RegisterModuleType("python_binary_host", python.PythonBinaryHostFactory) ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators) ctx.PreArchMutators(android.RegisterComponentsMutator) - ctx.PreDepsMutators(python.RegisterPythonPreDepsMutators) ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators) ctx.RegisterPreSingletonType("overlay", OverlaySingletonFactory) ctx.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory) diff --git a/java/kotlin.go b/java/kotlin.go index 8067ad521..2960f819d 100644 --- a/java/kotlin.go +++ b/java/kotlin.go @@ -64,7 +64,9 @@ func kotlinCommonSrcsList(ctx android.ModuleContext, commonSrcFiles android.Path // Insert a second rule to write out the list of resources to a file. commonSrcsList := android.PathForModuleOut(ctx, "kotlinc_common_srcs.list") rule := android.NewRuleBuilder(pctx, ctx) - rule.Command().Text("cp").FlagWithRspFileInputList("", commonSrcFiles).Output(commonSrcsList) + rule.Command().Text("cp"). + FlagWithRspFileInputList("", commonSrcsList.ReplaceExtension(ctx, "rsp"), commonSrcFiles). + Output(commonSrcsList) rule.Build("kotlin_common_srcs_list", "kotlin common_srcs list") return android.OptionalPathForPath(commonSrcsList) } diff --git a/java/lint.go b/java/lint.go index 9f677db3a..fccd1a552 100644 --- a/java/lint.go +++ b/java/lint.go @@ -220,7 +220,9 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.Ru // Insert a second rule to write out the list of resources to a file. resourcesList = android.PathForModuleOut(ctx, "lint", "resources.list") resListRule := android.NewRuleBuilder(pctx, ctx) - resListRule.Command().Text("cp").FlagWithRspFileInputList("", l.resources).Output(resourcesList) + resListRule.Command().Text("cp"). + FlagWithRspFileInputList("", resourcesList.ReplaceExtension(ctx, "rsp"), l.resources). + Output(resourcesList) resListRule.Build("lint_resources_list", "lint resources list") trackRSPDependency(l.resources, resourcesList) } @@ -241,7 +243,10 @@ func (l *linter) writeLintProjectXML(ctx android.ModuleContext, rule *android.Ru // TODO(ccross): some of the files in l.srcs are generated sources and should be passed to // lint separately. srcsList := android.PathForModuleOut(ctx, "lint", "srcs.list") - rule.Command().Text("cp").FlagWithRspFileInputList("", l.srcs).Output(srcsList) + srcsListRsp := android.PathForModuleOut(ctx, "lint-srcs.list.rsp") + rule.Command().Text("cp"). + FlagWithRspFileInputList("", srcsListRsp, l.srcs). + Output(srcsList) trackRSPDependency(l.srcs, srcsList) cmd := rule.Command(). @@ -635,7 +640,7 @@ func lintZip(ctx android.BuilderContext, paths android.Paths, outputPath android rule.Command().BuiltTool("soong_zip"). FlagWithOutput("-o ", outputPath). FlagWithArg("-C ", android.PathForIntermediates(ctx).String()). - FlagWithRspFileInputList("-r ", paths) + FlagWithRspFileInputList("-r ", outputPath.ReplaceExtension(ctx, "rsp"), paths) rule.Build(outputPath.Base(), outputPath.Base()) } diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go index 4bfd4e2f9..3c43a8e55 100644 --- a/java/platform_compat_config.go +++ b/java/platform_compat_config.go @@ -26,6 +26,7 @@ func init() { func registerPlatformCompatConfigBuildComponents(ctx android.RegistrationContext) { ctx.RegisterSingletonType("platform_compat_config_singleton", platformCompatConfigSingletonFactory) ctx.RegisterModuleType("platform_compat_config", PlatformCompatConfigFactory) + ctx.RegisterModuleType("prebuilt_platform_compat_config", prebuiltCompatConfigFactory) ctx.RegisterModuleType("global_compat_config", globalCompatConfigFactory) } @@ -35,10 +36,6 @@ func platformCompatConfigPath(ctx android.PathContext) android.OutputPath { return android.PathForOutput(ctx, "compat_config", "merged_compat_config.xml") } -type platformCompatConfigSingleton struct { - metadata android.Path -} - type platformCompatConfigProperties struct { Src *string `android:"path"` } @@ -52,7 +49,7 @@ type platformCompatConfig struct { metadataFile android.OutputPath } -func (p *platformCompatConfig) compatConfigMetadata() android.OutputPath { +func (p *platformCompatConfig) compatConfigMetadata() android.Path { return p.metadataFile } @@ -64,52 +61,20 @@ func (p *platformCompatConfig) SubDir() string { return "compatconfig" } +type platformCompatConfigMetadataProvider interface { + compatConfigMetadata() android.Path +} + type PlatformCompatConfigIntf interface { android.Module - compatConfigMetadata() android.OutputPath CompatConfig() android.OutputPath // Sub dir under etc dir. SubDir() string } var _ PlatformCompatConfigIntf = (*platformCompatConfig)(nil) - -// compat singleton rules -func (p *platformCompatConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) { - - var compatConfigMetadata android.Paths - - ctx.VisitAllModules(func(module android.Module) { - if c, ok := module.(PlatformCompatConfigIntf); ok { - metadata := c.compatConfigMetadata() - compatConfigMetadata = append(compatConfigMetadata, metadata) - } - }) - - if compatConfigMetadata == nil { - // nothing to do. - return - } - - rule := android.NewRuleBuilder(pctx, ctx) - outputPath := platformCompatConfigPath(ctx) - - rule.Command(). - BuiltTool("process-compat-config"). - FlagForEachInput("--xml ", compatConfigMetadata). - FlagWithOutput("--merged-config ", outputPath) - - rule.Build("merged-compat-config", "Merge compat config") - - p.metadata = outputPath -} - -func (p *platformCompatConfigSingleton) MakeVars(ctx android.MakeVarsContext) { - if p.metadata != nil { - ctx.Strict("INTERNAL_PLATFORM_MERGED_COMPAT_CONFIG", p.metadata.String()) - } -} +var _ platformCompatConfigMetadataProvider = (*platformCompatConfig)(nil) func (p *platformCompatConfig) GenerateAndroidBuildActions(ctx android.ModuleContext) { rule := android.NewRuleBuilder(pctx, ctx) @@ -145,10 +110,6 @@ func (p *platformCompatConfig) AndroidMkEntries() []android.AndroidMkEntries { }} } -func platformCompatConfigSingletonFactory() android.Singleton { - return &platformCompatConfigSingleton{} -} - func PlatformCompatConfigFactory() android.Module { module := &platformCompatConfig{} module.AddProperties(&module.properties) @@ -156,6 +117,93 @@ func PlatformCompatConfigFactory() android.Module { return module } +// A prebuilt version of the platform compat config module. +type prebuiltCompatConfigModule struct { + android.ModuleBase + android.SdkBase + prebuilt android.Prebuilt + + properties prebuiltCompatConfigProperties + + metadataFile android.Path +} + +type prebuiltCompatConfigProperties struct { + Metadata *string `android:"path"` +} + +func (module *prebuiltCompatConfigModule) Prebuilt() *android.Prebuilt { + return &module.prebuilt +} + +func (module *prebuiltCompatConfigModule) Name() string { + return module.prebuilt.Name(module.ModuleBase.Name()) +} + +func (module *prebuiltCompatConfigModule) compatConfigMetadata() android.Path { + return module.metadataFile +} + +var _ platformCompatConfigMetadataProvider = (*prebuiltCompatConfigModule)(nil) + +func (module *prebuiltCompatConfigModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { + module.metadataFile = module.prebuilt.SingleSourcePath(ctx) +} + +// A prebuilt version of platform_compat_config that provides the metadata. +func prebuiltCompatConfigFactory() android.Module { + m := &prebuiltCompatConfigModule{} + m.AddProperties(&m.properties) + android.InitSingleSourcePrebuiltModule(m, &m.properties, "Metadata") + android.InitSdkAwareModule(m) + android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon) + return m +} + +// compat singleton rules +type platformCompatConfigSingleton struct { + metadata android.Path +} + +func (p *platformCompatConfigSingleton) GenerateBuildActions(ctx android.SingletonContext) { + + var compatConfigMetadata android.Paths + + ctx.VisitAllModules(func(module android.Module) { + if c, ok := module.(platformCompatConfigMetadataProvider); ok { + metadata := c.compatConfigMetadata() + compatConfigMetadata = append(compatConfigMetadata, metadata) + } + }) + + if compatConfigMetadata == nil { + // nothing to do. + return + } + + rule := android.NewRuleBuilder(pctx, ctx) + outputPath := platformCompatConfigPath(ctx) + + rule.Command(). + BuiltTool("process-compat-config"). + FlagForEachInput("--xml ", compatConfigMetadata). + FlagWithOutput("--merged-config ", outputPath) + + rule.Build("merged-compat-config", "Merge compat config") + + p.metadata = outputPath +} + +func (p *platformCompatConfigSingleton) MakeVars(ctx android.MakeVarsContext) { + if p.metadata != nil { + ctx.Strict("INTERNAL_PLATFORM_MERGED_COMPAT_CONFIG", p.metadata.String()) + } +} + +func platformCompatConfigSingletonFactory() android.Singleton { + return &platformCompatConfigSingleton{} +} + //============== merged_compat_config ================= type globalCompatConfigProperties struct { // name of the file into which the metadata will be copied. diff --git a/java/platform_compat_config_test.go b/java/platform_compat_config_test.go new file mode 100644 index 000000000..0c5d001ac --- /dev/null +++ b/java/platform_compat_config_test.go @@ -0,0 +1,53 @@ +// Copyright 2021 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package java + +import ( + "testing" + + "android/soong/android" +) + +func TestPlatformCompatConfig(t *testing.T) { + result := emptyFixtureFactory.RunTest(t, + PrepareForTestWithPlatformCompatConfig, + android.FixtureWithRootAndroidBp(` + platform_compat_config { + name: "myconfig2", + } + platform_compat_config { + name: "myconfig1", + } + platform_compat_config { + name: "myconfig3", + } + `), + ) + + checkMergedCompatConfigInputs(t, result, "myconfig", + "out/soong/.intermediates/myconfig1/myconfig1_meta.xml", + "out/soong/.intermediates/myconfig2/myconfig2_meta.xml", + "out/soong/.intermediates/myconfig3/myconfig3_meta.xml", + ) +} + +// Check that the merged file create by platform_compat_config_singleton has the correct inputs. +func checkMergedCompatConfigInputs(t *testing.T, result *android.TestResult, message string, expectedPaths ...string) { + sourceGlobalCompatConfig := result.SingletonForTests("platform_compat_config_singleton") + allOutputs := sourceGlobalCompatConfig.AllOutputs() + android.AssertIntEquals(t, message+": output len", 1, len(allOutputs)) + output := sourceGlobalCompatConfig.Output(allOutputs[0]) + android.AssertPathsRelativeToTopEquals(t, message+": inputs", expectedPaths, output.Implicits) +} |