diff options
Diffstat (limited to 'java')
| -rw-r--r-- | java/base.go | 18 | ||||
| -rw-r--r-- | java/bootclasspath_fragment_test.go | 6 | ||||
| -rw-r--r-- | java/droiddoc.go | 13 | ||||
| -rw-r--r-- | java/droidstubs_test.go | 4 | ||||
| -rw-r--r-- | java/hiddenapi_singleton_test.go | 4 | ||||
| -rw-r--r-- | java/java.go | 5 | ||||
| -rw-r--r-- | java/java_test.go | 12 | ||||
| -rw-r--r-- | java/sdk_library_test.go | 50 | ||||
| -rw-r--r-- | java/system_modules.go | 36 | ||||
| -rw-r--r-- | java/system_modules_test.go | 6 |
10 files changed, 53 insertions, 101 deletions
diff --git a/java/base.go b/java/base.go index d5605c67b..5f89b1fea 100644 --- a/java/base.go +++ b/java/base.go @@ -2373,16 +2373,24 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { case bootClasspathTag: // If a system modules dependency has been added to the bootclasspath // then add its libs to the bootclasspath. - sm := module.(SystemModulesProvider) - deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...) + if sm, ok := android.OtherModuleProvider(ctx, module, SystemModulesProvider); ok { + depHeaderJars := sm.HeaderJars + deps.bootClasspath = append(deps.bootClasspath, depHeaderJars...) + } else { + ctx.PropertyErrorf("boot classpath dependency %q does not provide SystemModulesProvider", + ctx.OtherModuleName(module)) + } case systemModulesTag: if deps.systemModules != nil { panic("Found two system module dependencies") } - sm := module.(SystemModulesProvider) - outputDir, outputDeps := sm.OutputDirAndDeps() - deps.systemModules = &systemModules{outputDir, outputDeps} + if sm, ok := android.OtherModuleProvider(ctx, module, SystemModulesProvider); ok { + deps.systemModules = &systemModules{sm.OutputDir, sm.OutputDirDeps} + } else { + ctx.PropertyErrorf("system modules dependency %q does not provide SystemModulesProvider", + ctx.OtherModuleName(module)) + } case instrumentationForTag: ctx.PropertyErrorf("instrumentation_for", "dependency %q of type %q does not provide JavaInfo so is unsuitable for use with this property", ctx.OtherModuleName(module), ctx.OtherModuleType(module)) diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go index 8bc0a7ef6..d72417afa 100644 --- a/java/bootclasspath_fragment_test.go +++ b/java/bootclasspath_fragment_test.go @@ -222,11 +222,7 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) { PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary", "mycoreplatform"), FixtureConfigureApexBootJars("someapex:mysdklibrary"), - android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.BuildFlags = map[string]string{ - "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true", - } - }), + android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"), ).RunTestWithBp(t, ` bootclasspath_fragment { name: "myfragment", diff --git a/java/droiddoc.go b/java/droiddoc.go index 730f23696..f81c5bac5 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -365,10 +365,10 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { case bootClasspathTag: if dep, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok { deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars...) - } else if sm, ok := module.(SystemModulesProvider); ok { + } else if sm, ok := android.OtherModuleProvider(ctx, module, SystemModulesProvider); ok { // A system modules dependency has been added to the bootclasspath // so add its libs to the bootclasspath. - deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...) + deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars...) } else { panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) } @@ -396,9 +396,12 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { if deps.systemModules != nil { panic("Found two system module dependencies") } - sm := module.(SystemModulesProvider) - outputDir, outputDeps := sm.OutputDirAndDeps() - deps.systemModules = &systemModules{outputDir, outputDeps} + if sm, ok := android.OtherModuleProvider(ctx, module, SystemModulesProvider); ok { + deps.systemModules = &systemModules{sm.OutputDir, sm.OutputDirDeps} + } else { + ctx.PropertyErrorf("boot classpath dependency %q does not provide SystemModulesProvider", + ctx.OtherModuleName(module)) + } case aconfigDeclarationTag: if dep, ok := android.OtherModuleProvider(ctx, module, android.AconfigDeclarationsProviderKey); ok { deps.aconfigProtoFiles = append(deps.aconfigProtoFiles, dep.IntermediateCacheOutputPath) diff --git a/java/droidstubs_test.go b/java/droidstubs_test.go index 6a14f3645..1e8362cf2 100644 --- a/java/droidstubs_test.go +++ b/java/droidstubs_test.go @@ -421,11 +421,9 @@ func TestReleaseExportRuntimeApis(t *testing.T) { result := android.GroupFixturePreparers( prepareForJavaTest, android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.BuildFlags = map[string]string{ - "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true", - } variables.ExportRuntimeApis = proptools.BoolPtr(true) }), + android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"), android.FixtureMergeMockFs(map[string][]byte{ "a/A.java": nil, "a/current.txt": nil, diff --git a/java/hiddenapi_singleton_test.go b/java/hiddenapi_singleton_test.go index 62297978c..afe8b4c8e 100644 --- a/java/hiddenapi_singleton_test.go +++ b/java/hiddenapi_singleton_test.go @@ -203,10 +203,8 @@ func TestHiddenAPISingletonSdks(t *testing.T) { FixtureConfigureBootJars("platform:foo"), android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { variables.Always_use_prebuilt_sdks = proptools.BoolPtr(tc.unbundledBuild) - variables.BuildFlags = map[string]string{ - "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true", - } }), + android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"), ).RunTestWithBp(t, ` java_library { name: "foo", diff --git a/java/java.go b/java/java.go index be3f90b20..126d8f3a4 100644 --- a/java/java.go +++ b/java/java.go @@ -2261,8 +2261,9 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { staticLibs = append(staticLibs, provider.HeaderJars...) } case systemModulesTag: - module := dep.(SystemModulesProvider) - systemModulesPaths = append(systemModulesPaths, module.HeaderJars()...) + if sm, ok := android.OtherModuleProvider(ctx, dep, SystemModulesProvider); ok { + systemModulesPaths = append(systemModulesPaths, sm.HeaderJars...) + } case metalavaCurrentApiTimestampTag: if currentApiTimestampProvider, ok := dep.(currentApiTimestampProvider); ok { al.validationPaths = append(al.validationPaths, currentApiTimestampProvider.CurrentApiTimestamp()) diff --git a/java/java_test.go b/java/java_test.go index 2d4fca240..86bfe9fe4 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -2634,11 +2634,7 @@ func TestMultiplePrebuilts(t *testing.T) { for _, tc := range testCases { ctx := android.GroupFixturePreparers( prepareForJavaTest, - android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.BuildFlags = map[string]string{ - "RELEASE_APEX_CONTRIBUTIONS_ADSERVICES": "myapex_contributions", - } - }), + android.PrepareForTestWithBuildFlag("RELEASE_APEX_CONTRIBUTIONS_ADSERVICES", "myapex_contributions"), ).RunTestWithBp(t, fmt.Sprintf(bp, tc.selectedDependencyName)) // check that rdep gets the correct variation of dep @@ -2708,11 +2704,7 @@ func TestMultiplePlatformCompatConfigPrebuilts(t *testing.T) { ctx := android.GroupFixturePreparers( prepareForJavaTest, PrepareForTestWithPlatformCompatConfig, - android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.BuildFlags = map[string]string{ - "RELEASE_APEX_CONTRIBUTIONS_ADSERVICES": "myapex_contributions", - } - }), + android.PrepareForTestWithBuildFlag("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") diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go index 911e8b1e4..368eca7f2 100644 --- a/java/sdk_library_test.go +++ b/java/sdk_library_test.go @@ -35,11 +35,7 @@ func TestJavaSdkLibrary(t *testing.T) { "29": {"foo"}, "30": {"bar", "barney", "baz", "betty", "foo", "fred", "quuz", "wilma"}, }), - android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.BuildFlags = map[string]string{ - "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true", - } - }), + android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"), ).RunTestWithBp(t, ` droiddoc_exported_dir { name: "droiddoc-templates-sdk", @@ -537,11 +533,7 @@ func TestJavaSdkLibrary_Deps(t *testing.T) { prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("sdklib"), - android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.BuildFlags = map[string]string{ - "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true", - } - }), + android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"), ).RunTestWithBp(t, ` java_sdk_library { name: "sdklib", @@ -934,11 +926,7 @@ func TestJavaSdkLibraryImport_WithSource(t *testing.T) { prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("sdklib"), - android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.BuildFlags = map[string]string{ - "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true", - } - }), + android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"), ).RunTestWithBp(t, ` java_sdk_library { name: "sdklib", @@ -987,11 +975,7 @@ func testJavaSdkLibraryImport_Preferred(t *testing.T, prefer string, preparer an PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("sdklib"), preparer, - android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.BuildFlags = map[string]string{ - "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true", - } - }), + android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"), ).RunTestWithBp(t, ` java_sdk_library { name: "sdklib", @@ -1183,11 +1167,7 @@ func TestSdkLibraryImport_MetadataModuleSupersedesPreferred(t *testing.T) { prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("sdklib.source_preferred_using_legacy_flags", "sdklib.prebuilt_preferred_using_legacy_flags"), - android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.BuildFlags = map[string]string{ - "RELEASE_APEX_CONTRIBUTIONS_ADSERVICES": "my_mainline_module_contributions", - } - }), + android.PrepareForTestWithBuildFlag("RELEASE_APEX_CONTRIBUTIONS_ADSERVICES", "my_mainline_module_contributions"), ).RunTestWithBp(t, bp) // Make sure that rdeps get the correct source vs prebuilt based on mainline_module_contributions @@ -1369,11 +1349,7 @@ func TestJavaSdkLibraryDist(t *testing.T) { "sdklib_group_foo", "sdklib_owner_foo", "foo"), - android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.BuildFlags = map[string]string{ - "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true", - } - }), + android.PrepareForTestWithBuildFlag("RELEASE_HIDDEN_API_EXPORTABLE_STUBS", "true"), ).RunTestWithBp(t, ` java_sdk_library { name: "sdklib_no_group", @@ -1785,12 +1761,8 @@ func TestStubResolutionOfJavaSdkLibraryInLibs(t *testing.T) { prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("sdklib"), - android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.BuildFlags = map[string]string{ - // We can use any of the apex contribution build flags from build/soong/android/config.go#mainlineApexContributionBuildFlags here - "RELEASE_APEX_CONTRIBUTIONS_ADSERVICES": "my_mainline_module_contributions", - } - }), + // We can use any of the apex contribution build flags from build/soong/android/config.go#mainlineApexContributionBuildFlags here + android.PrepareForTestWithBuildFlag("RELEASE_APEX_CONTRIBUTIONS_ADSERVICES", "my_mainline_module_contributions"), ) result := fixture.RunTestWithBp(t, bp) @@ -1873,11 +1845,7 @@ func TestMultipleSdkLibraryPrebuilts(t *testing.T) { prepareForJavaTest, PrepareForTestWithJavaSdkLibraryFiles, FixtureWithLastReleaseApis("sdklib", "sdklib.v1", "sdklib.v2"), - android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.BuildFlags = map[string]string{ - "RELEASE_APEX_CONTRIBUTIONS_ADSERVICES": "my_mainline_module_contributions", - } - }), + android.PrepareForTestWithBuildFlag("RELEASE_APEX_CONTRIBUTIONS_ADSERVICES", "my_mainline_module_contributions"), ) for _, tc := range testCases { diff --git a/java/system_modules.go b/java/system_modules.go index 48b33ba57..5b00079f7 100644 --- a/java/system_modules.go +++ b/java/system_modules.go @@ -120,14 +120,16 @@ func SystemModulesFactory() android.Module { return module } -type SystemModulesProvider interface { - HeaderJars() android.Paths - OutputDirAndDeps() (android.Path, android.Paths) -} +type SystemModulesProviderInfo struct { + // The aggregated header jars from all jars specified in the libs property. + // Used when system module is added as a dependency to bootclasspath. + HeaderJars android.Paths -var _ SystemModulesProvider = (*SystemModules)(nil) + OutputDir android.Path + OutputDirDeps android.Paths +} -var _ SystemModulesProvider = (*systemModulesImport)(nil) +var SystemModulesProvider = blueprint.NewProvider[*SystemModulesProviderInfo]() type SystemModules struct { android.ModuleBase @@ -135,9 +137,6 @@ type SystemModules struct { properties SystemModulesProperties - // The aggregated header jars from all jars specified in the libs property. - // Used when system module is added as a dependency to bootclasspath. - headerJars android.Paths outputDir android.Path outputDeps android.Paths } @@ -147,17 +146,6 @@ type SystemModulesProperties struct { Libs []string } -func (system *SystemModules) HeaderJars() android.Paths { - return system.headerJars -} - -func (system *SystemModules) OutputDirAndDeps() (android.Path, android.Paths) { - if system.outputDir == nil || len(system.outputDeps) == 0 { - panic("Missing directory for system module dependency") - } - return system.outputDir, system.outputDeps -} - func (system *SystemModules) GenerateAndroidBuildActions(ctx android.ModuleContext) { var jars android.Paths @@ -167,9 +155,13 @@ func (system *SystemModules) GenerateAndroidBuildActions(ctx android.ModuleConte } }) - system.headerJars = jars - system.outputDir, system.outputDeps = TransformJarsToSystemModules(ctx, jars) + + android.SetProvider(ctx, SystemModulesProvider, &SystemModulesProviderInfo{ + HeaderJars: jars, + OutputDir: system.outputDir, + OutputDirDeps: system.outputDeps, + }) } // ComponentDepsMutator is called before prebuilt modules without a corresponding source module are diff --git a/java/system_modules_test.go b/java/system_modules_test.go index 336dd2134..1a8d0b5d5 100644 --- a/java/system_modules_test.go +++ b/java/system_modules_test.go @@ -182,11 +182,7 @@ func TestMultipleSystemModulesPrebuilts(t *testing.T) { for _, tc := range testCases { res := android.GroupFixturePreparers( prepareForJavaTest, - android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { - variables.BuildFlags = map[string]string{ - "RELEASE_APEX_CONTRIBUTIONS_ADSERVICES": "myapex_contributions", - } - }), + android.PrepareForTestWithBuildFlag("RELEASE_APEX_CONTRIBUTIONS_ADSERVICES", "myapex_contributions"), ).RunTestWithBp(t, fmt.Sprintf(bp, tc.selectedDependencyName)) // check that rdep gets the correct variation of system_modules |