diff options
author | 2024-11-20 15:07:58 -0800 | |
---|---|---|
committer | 2024-12-12 14:55:28 -0800 | |
commit | af4c8562a29e152cd473f64e938638b44d57078b (patch) | |
tree | 590129592e5da4dc09a68cf3d5e448ebb79f020c | |
parent | 8acea3e421fff22567fbbe21f0b91ca85857cf1c (diff) |
Remove TestApexes from ApexInfo
TestApexes is used to enforce the "Stub libraries should have a single
apex_available" check, but requires propagating information from
multiple apexes in order to filter out the test apexes. Instead,
all test apexes used by stub libraries will set apex_available_name
to masquerade as their non-test counterpart for apex_available
checks.
Bug: 383592644
Test: TestStubLibrariesMultipleApexViolation
Change-Id: I57dcf1e6fabbe70f40d702490b93fc7f28d6eba2
-rw-r--r-- | android/apex.go | 22 | ||||
-rw-r--r-- | apex/apex.go | 5 | ||||
-rw-r--r-- | apex/apex_test.go | 31 | ||||
-rw-r--r-- | cc/cc.go | 6 | ||||
-rw-r--r-- | java/dexpreopt.go | 11 |
5 files changed, 25 insertions, 50 deletions
diff --git a/android/apex.go b/android/apex.go index db955b59c..45448b5d1 100644 --- a/android/apex.go +++ b/android/apex.go @@ -69,9 +69,6 @@ type ApexInfo struct { // See Prebuilt.ApexInfoMutator for more information. ForPrebuiltApex bool - // Returns the name of the test apexes that this module is included in. - TestApexes []string - // Returns the name of the overridden apex (com.android.foo) BaseApexName string @@ -283,9 +280,6 @@ type ApexProperties struct { // See ApexModule.UniqueApexVariants() UniqueApexVariationsForDeps bool `blueprint:"mutated"` - - // The test apexes that includes this apex variant - TestApexes []string `blueprint:"mutated"` } // Marker interface that identifies dependencies that are excluded from APEX contents. @@ -389,11 +383,6 @@ func (m *ApexModuleBase) IsInstallableToApex() bool { return false } -// Returns the test apexes that this module is included in. -func (m *ApexModuleBase) TestApexes() []string { - return m.ApexProperties.TestApexes -} - // Implements ApexModule func (m *ApexModuleBase) UniqueApexVariations() bool { // If needed, this will bel overridden by concrete types inheriting @@ -543,12 +532,10 @@ func mergeApexVariations(apexInfos []ApexInfo) (merged []ApexInfo, aliases [][2] // Platform APIs is allowed for this module only when all APEXes containing // the module are with `use_platform_apis: true`. merged[index].UsePlatformApis = merged[index].UsePlatformApis && apexInfo.UsePlatformApis - merged[index].TestApexes = append(merged[index].TestApexes, apexInfo.TestApexes...) } else { seen[mergedName] = len(merged) apexInfo.ApexVariationName = mergedName apexInfo.InApexVariants = CopyOf(apexInfo.InApexVariants) - apexInfo.TestApexes = CopyOf(apexInfo.TestApexes) merged = append(merged, apexInfo) } aliases = append(aliases, [2]string{variantName, mergedName}) @@ -656,15 +643,6 @@ func MutateApexTransition(ctx BaseModuleContext, variation string) { SetProvider(ctx, ApexInfoProvider, thisApexInfo) } - - // Set the value of TestApexes in every single apex variant. - // This allows each apex variant to be aware of the test apexes in the user provided apex_available. - var testApexes []string - for _, a := range apexInfos { - testApexes = append(testApexes, a.TestApexes...) - } - base.ApexProperties.TestApexes = testApexes - } func ApexInfoMutator(ctx TopDownMutatorContext, module ApexModule) { diff --git a/apex/apex.go b/apex/apex.go index fb0d73068..2848ddcd6 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -995,17 +995,12 @@ func (a *apexBundle) ApexInfoMutator(mctx android.TopDownMutatorContext) { } a.properties.ApexVariationName = apexVariationName - testApexes := []string{} - if a.testApex { - testApexes = []string{apexVariationName} - } apexInfo := android.ApexInfo{ ApexVariationName: apexVariationName, MinSdkVersion: minSdkVersion, Updatable: a.Updatable(), UsePlatformApis: a.UsePlatformApis(), InApexVariants: []string{apexVariationName}, - TestApexes: testApexes, BaseApexName: mctx.ModuleName(), ApexAvailableName: proptools.String(a.properties.Apex_available_name), } diff --git a/apex/apex_test.go b/apex/apex_test.go index ced3c46d5..a03bb4492 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -10165,9 +10165,9 @@ func TestStubLibrariesMultipleApexViolation(t *testing.T) { expectedError: "Stub libraries should have a single apex_available.*myapex.*otherapex", }, { - desc: "stub library can be available to a core apex and a test apex", + desc: "stub library can be available to a core apex and a test apex using apex_available_name", hasStubs: true, - apexAvailable: `["myapex", "test_myapex"]`, + apexAvailable: `["myapex"]`, }, } bpTemplate := ` @@ -10192,25 +10192,28 @@ func TestStubLibrariesMultipleApexViolation(t *testing.T) { key: "apex.key", updatable: false, native_shared_libs: ["libfoo"], + apex_available_name: "myapex", } apex_key { name: "apex.key", } ` for _, tc := range testCases { - stubs := "" - if tc.hasStubs { - stubs = `stubs: {symbol_file: "libfoo.map.txt"},` - } - bp := fmt.Sprintf(bpTemplate, stubs, tc.apexAvailable) - mockFsFixturePreparer := android.FixtureModifyMockFS(func(fs android.MockFS) { - fs["system/sepolicy/apex/test_myapex-file_contexts"] = nil + t.Run(tc.desc, func(t *testing.T) { + stubs := "" + if tc.hasStubs { + stubs = `stubs: {symbol_file: "libfoo.map.txt"},` + } + bp := fmt.Sprintf(bpTemplate, stubs, tc.apexAvailable) + mockFsFixturePreparer := android.FixtureModifyMockFS(func(fs android.MockFS) { + fs["system/sepolicy/apex/test_myapex-file_contexts"] = nil + }) + if tc.expectedError == "" { + testApex(t, bp, mockFsFixturePreparer) + } else { + testApexError(t, tc.expectedError, bp, mockFsFixturePreparer) + } }) - if tc.expectedError == "" { - testApex(t, bp, mockFsFixturePreparer) - } else { - testApexError(t, tc.expectedError, bp, mockFsFixturePreparer) - } } } @@ -1904,13 +1904,13 @@ func (c *Module) stubLibraryMultipleApexViolation(ctx android.ModuleContext) boo return false } - _, aaWithoutTestApexes, _ := android.ListSetDifference(c.ApexAvailable(), c.TestApexes()) // Stub libraries should not have more than one apex_available - if len(aaWithoutTestApexes) > 1 { + apexAvailable := android.FirstUniqueStrings(c.ApexAvailable()) + if len(apexAvailable) > 1 { return true } // Stub libraries should not use the wildcard - if aaWithoutTestApexes[0] == android.AvailableToAnyApex { + if apexAvailable[0] == android.AvailableToAnyApex { return true } // Default: no violation diff --git a/java/dexpreopt.go b/java/dexpreopt.go index 5928446e3..44ba80a10 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -211,20 +211,19 @@ func disableSourceApexVariant(ctx android.BaseModuleContext) bool { }) // Find the apex variant for this module - apexVariantsWithoutTestApexes := []string{} + apexVariants := []string{} if apexInfo.BaseApexName != "" { // This is a transitive dependency of an override_apex - apexVariantsWithoutTestApexes = append(apexVariantsWithoutTestApexes, apexInfo.BaseApexName) + apexVariants = append(apexVariants, apexInfo.BaseApexName) } else { - _, variants, _ := android.ListSetDifference(apexInfo.InApexVariants, apexInfo.TestApexes) - apexVariantsWithoutTestApexes = append(apexVariantsWithoutTestApexes, variants...) + apexVariants = append(apexVariants, apexInfo.InApexVariants...) } if apexInfo.ApexAvailableName != "" { - apexVariantsWithoutTestApexes = append(apexVariantsWithoutTestApexes, apexInfo.ApexAvailableName) + apexVariants = append(apexVariants, apexInfo.ApexAvailableName) } disableSource := false // find the selected apexes - for _, apexVariant := range apexVariantsWithoutTestApexes { + for _, apexVariant := range apexVariants { if len(psi.GetSelectedModulesForApiDomain(apexVariant)) > 0 { // If the apex_contribution for this api domain is non-empty, disable the source variant disableSource = true |