diff --git a/java/android_manifest_test.go b/java/android_manifest_test.go index 0a39dca86..5909b1e6a 100644 --- a/java/android_manifest_test.go +++ b/java/android_manifest_test.go @@ -78,10 +78,7 @@ func TestManifestMerger(t *testing.T) { } ` - result := android.GroupFixturePreparers( - PrepareForTestWithJavaDefaultModules, - PrepareForTestWithOverlayBuildComponents, - ).RunTestWithBp(t, bp) + result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, bp) manifestMergerRule := result.ModuleForTests("app", "android_common").Rule("manifestMerger") android.AssertPathRelativeToTopEquals(t, "main manifest", @@ -129,10 +126,7 @@ func TestManifestValuesApplicationIdSetsPackageName(t *testing.T) { ` - result := android.GroupFixturePreparers( - PrepareForTestWithJavaDefaultModules, - PrepareForTestWithOverlayBuildComponents, - ).RunTestWithBp(t, bp) + result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(t, bp) manifestMergerRule := result.ModuleForTests("test", "android_common").Rule("manifestMerger") android.AssertStringMatches(t, diff --git a/java/android_resources.go b/java/android_resources.go index 8c5908f69..038a260d9 100644 --- a/java/android_resources.go +++ b/java/android_resources.go @@ -21,14 +21,6 @@ import ( "android/soong/android" ) -func init() { - registerOverlayBuildComponents(android.InitRegistrationContext) -} - -func registerOverlayBuildComponents(ctx android.RegistrationContext) { - ctx.RegisterPreSingletonType("overlay", OverlaySingletonFactory) -} - var androidResourceIgnoreFilenames = []string{ ".svn", ".git", @@ -84,7 +76,38 @@ type globbedResourceDir struct { func overlayResourceGlob(ctx android.ModuleContext, a *aapt, dir android.Path) (res []globbedResourceDir, rroDirs []rroDir) { - overlayData := ctx.Config().Get(overlayDataKey).([]overlayGlobResult) + overlayData := ctx.Config().Once(overlayDataKey, func() interface{} { + var overlayData []overlayGlobResult + + appendOverlayData := func(overlayDirs []string, t overlayType) { + for i := range overlayDirs { + // Iterate backwards through the list of overlay directories so that the later, lower-priority + // directories in the list show up earlier in the command line to aapt2. + overlay := overlayDirs[len(overlayDirs)-1-i] + var result overlayGlobResult + result.dir = overlay + result.overlayType = t + + files, err := ctx.GlobWithDeps(filepath.Join(overlay, "**/*"), androidResourceIgnoreFilenames) + if err != nil { + ctx.ModuleErrorf("failed to glob resource dir %q: %s", overlay, err.Error()) + continue + } + var paths android.Paths + for _, f := range files { + if !strings.HasSuffix(f, "/") { + paths = append(paths, android.PathForSource(ctx, f)) + } + } + result.paths = android.PathsToDirectorySortedPaths(paths) + overlayData = append(overlayData, result) + } + } + + appendOverlayData(ctx.Config().DeviceResourceOverlays(), device) + appendOverlayData(ctx.Config().ProductResourceOverlays(), product) + return overlayData + }).([]overlayGlobResult) // Runtime resource overlays (RRO) may be turned on by the product config for some modules rroEnabled := a.IsRROEnforced(ctx) @@ -110,44 +133,3 @@ func overlayResourceGlob(ctx android.ModuleContext, a *aapt, dir android.Path) ( return res, rroDirs } - -func OverlaySingletonFactory() android.Singleton { - return overlaySingleton{} -} - -type overlaySingleton struct{} - -func (overlaySingleton) GenerateBuildActions(ctx android.SingletonContext) { - var overlayData []overlayGlobResult - - appendOverlayData := func(overlayDirs []string, t overlayType) { - for i := range overlayDirs { - // Iterate backwards through the list of overlay directories so that the later, lower-priority - // directories in the list show up earlier in the command line to aapt2. - overlay := overlayDirs[len(overlayDirs)-1-i] - var result overlayGlobResult - result.dir = overlay - result.overlayType = t - - files, err := ctx.GlobWithDeps(filepath.Join(overlay, "**/*"), androidResourceIgnoreFilenames) - if err != nil { - ctx.Errorf("failed to glob resource dir %q: %s", overlay, err.Error()) - continue - } - var paths android.Paths - for _, f := range files { - if !strings.HasSuffix(f, "/") { - paths = append(paths, android.PathForSource(ctx, f)) - } - } - result.paths = android.PathsToDirectorySortedPaths(paths) - overlayData = append(overlayData, result) - } - } - - appendOverlayData(ctx.Config().DeviceResourceOverlays(), device) - appendOverlayData(ctx.Config().ProductResourceOverlays(), product) - ctx.Config().Once(overlayDataKey, func() interface{} { - return overlayData - }) -} diff --git a/java/app_test.go b/java/app_test.go index 4d3b2dc4d..5cb4a2301 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -558,7 +558,6 @@ func TestResourceDirs(t *testing.T) { t.Run(testCase.name, func(t *testing.T) { result := android.GroupFixturePreparers( PrepareForTestWithJavaDefaultModules, - PrepareForTestWithOverlayBuildComponents, fs.AddToFixture(), ).RunTestWithBp(t, fmt.Sprintf(bp, testCase.prop)) @@ -1283,7 +1282,6 @@ func TestAndroidResourceProcessor(t *testing.T) { result := android.GroupFixturePreparers( PrepareForTestWithJavaDefaultModules, - PrepareForTestWithOverlayBuildComponents, fs.AddToFixture(), ).RunTestWithBp(t, bp) @@ -1566,7 +1564,6 @@ func TestAndroidResourceOverlays(t *testing.T) { t.Run(testCase.name, func(t *testing.T) { result := android.GroupFixturePreparers( PrepareForTestWithJavaDefaultModules, - PrepareForTestWithOverlayBuildComponents, fs.AddToFixture(), android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { variables.DeviceResourceOverlays = deviceResourceOverlays diff --git a/java/java_test.go b/java/java_test.go index c54c0e68f..81119a79e 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -47,10 +47,6 @@ var prepareForJavaTest = android.GroupFixturePreparers( cc.PrepareForTestWithCcBuildComponents, // Include all the default java modules. PrepareForTestWithDexpreopt, - PrepareForTestWithOverlayBuildComponents, - android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { - ctx.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory) - }), ) func TestMain(m *testing.M) { diff --git a/java/rro_test.go b/java/rro_test.go index 8067a4703..c4a4d04be 100644 --- a/java/rro_test.go +++ b/java/rro_test.go @@ -62,7 +62,6 @@ func TestRuntimeResourceOverlay(t *testing.T) { result := android.GroupFixturePreparers( PrepareForTestWithJavaDefaultModules, - PrepareForTestWithOverlayBuildComponents, android.FixtureModifyConfig(android.SetKatiEnabledForTests), fs.AddToFixture(), ).RunTestWithBp(t, bp) @@ -330,7 +329,6 @@ func TestEnforceRRO_propagatesToDependencies(t *testing.T) { t.Run(testCase.name, func(t *testing.T) { result := android.GroupFixturePreparers( PrepareForTestWithJavaDefaultModules, - PrepareForTestWithOverlayBuildComponents, fs.AddToFixture(), android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { variables.ProductResourceOverlays = productResourceOverlays diff --git a/java/sdk.go b/java/sdk.go index ddd99bb33..ad71fb236 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -17,8 +17,6 @@ package java import ( "fmt" "path/filepath" - "sort" - "strconv" "android/soong/android" "android/soong/java/config" @@ -27,12 +25,10 @@ import ( ) func init() { - android.RegisterPreSingletonType("sdk_versions", sdkPreSingletonFactory) android.RegisterParallelSingletonType("sdk", sdkSingletonFactory) android.RegisterMakeVarsProvider(pctx, sdkMakeVars) } -var sdkVersionsKey = android.NewOnceKey("sdkVersionsKey") var sdkFrameworkAidlPathKey = android.NewOnceKey("sdkFrameworkAidlPathKey") var nonUpdatableFrameworkAidlPathKey = android.NewOnceKey("nonUpdatableFrameworkAidlPathKey") var apiFingerprintPathKey = android.NewOnceKey("apiFingerprintPathKey") @@ -213,44 +209,6 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) } } -func sdkPreSingletonFactory() android.Singleton { - return sdkPreSingleton{} -} - -type sdkPreSingleton struct{} - -func (sdkPreSingleton) GenerateBuildActions(ctx android.SingletonContext) { - sdkJars, err := ctx.GlobWithDeps("prebuilts/sdk/*/public/android.jar", nil) - if err != nil { - ctx.Errorf("failed to glob prebuilts/sdk/*/public/android.jar: %s", err.Error()) - } - - var sdkVersions []int - for _, sdkJar := range sdkJars { - dir := filepath.Base(filepath.Dir(filepath.Dir(sdkJar))) - v, err := strconv.Atoi(dir) - if scerr, ok := err.(*strconv.NumError); ok && scerr.Err == strconv.ErrSyntax { - continue - } else if err != nil { - ctx.Errorf("invalid sdk jar %q, %s, %v", sdkJar, err.Error()) - } - sdkVersions = append(sdkVersions, v) - } - - sort.Ints(sdkVersions) - - ctx.Config().Once(sdkVersionsKey, func() interface{} { return sdkVersions }) -} - -func LatestSdkVersionInt(ctx android.EarlyModuleContext) int { - sdkVersions := ctx.Config().Get(sdkVersionsKey).([]int) - latestSdkVersion := 0 - if len(sdkVersions) > 0 { - latestSdkVersion = sdkVersions[len(sdkVersions)-1] - } - return latestSdkVersion -} - func sdkSingletonFactory() android.Singleton { return sdkSingleton{} } diff --git a/java/testing.go b/java/testing.go index 16bdd80a1..e883bcb4c 100644 --- a/java/testing.go +++ b/java/testing.go @@ -118,8 +118,6 @@ var PrepareForTestWithDexpreoptWithoutFakeDex2oatd = android.GroupFixturePrepare dexpreopt.PrepareForTestByEnablingDexpreopt, ) -var PrepareForTestWithOverlayBuildComponents = android.FixtureRegisterWithContext(registerOverlayBuildComponents) - // Prepare a fixture to use all java module types, mutators and singletons fully. // // This should only be used by tests that want to run with as much of the build enabled as possible.