diff --git a/apex/apex_test.go b/apex/apex_test.go index a2dbbfc35..f62ee680b 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -11738,3 +11738,121 @@ func TestUpdatableApexMinSdkVersionCurrent(t *testing.T) { } `) } + +func TestPrebuiltStubNoinstall(t *testing.T) { + testFunc := func(t *testing.T, expectLibfooOnSystemLib bool, fs android.MockFS) { + result := android.GroupFixturePreparers( + prepareForApexTest, + android.PrepareForTestWithAndroidMk, + android.PrepareForTestWithMakevars, + android.FixtureMergeMockFs(fs), + ).RunTest(t) + + ldRule := result.ModuleForTests("installedlib", "android_arm64_armv8-a_shared").Rule("ld") + android.AssertStringDoesContain(t, "", ldRule.Args["libFlags"], "android_arm64_armv8-a_shared/libfoo.so") + + installRules := result.InstallMakeRulesForTesting(t) + + var installedlibRule *android.InstallMakeRule + for i, rule := range installRules { + if rule.Target == "out/target/product/test_device/system/lib/installedlib.so" { + if installedlibRule != nil { + t.Errorf("Duplicate install rules for %s", rule.Target) + } + installedlibRule = &installRules[i] + } + } + if installedlibRule == nil { + t.Errorf("No install rule found for installedlib") + return + } + + if expectLibfooOnSystemLib { + android.AssertStringListContains(t, + "installedlib doesn't have install dependency on libfoo impl", + installedlibRule.OrderOnlyDeps, + "out/target/product/test_device/system/lib/libfoo.so") + } else { + android.AssertStringListDoesNotContain(t, + "installedlib has install dependency on libfoo stub", + installedlibRule.Deps, + "out/target/product/test_device/system/lib/libfoo.so") + android.AssertStringListDoesNotContain(t, + "installedlib has order-only install dependency on libfoo stub", + installedlibRule.OrderOnlyDeps, + "out/target/product/test_device/system/lib/libfoo.so") + } + } + + prebuiltLibfooBp := []byte(` + cc_prebuilt_library { + name: "libfoo", + prefer: true, + srcs: ["libfoo.so"], + stubs: { + versions: ["1"], + }, + apex_available: ["apexfoo"], + } + `) + + apexfooBp := []byte(` + apex { + name: "apexfoo", + key: "apexfoo.key", + native_shared_libs: ["libfoo"], + updatable: false, + compile_multilib: "both", + } + apex_key { + name: "apexfoo.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + `) + + installedlibBp := []byte(` + cc_library { + name: "installedlib", + shared_libs: ["libfoo"], + } + `) + + t.Run("prebuilt stub (without source): no install", func(t *testing.T) { + testFunc( + t, + /*expectLibfooOnSystemLib=*/ false, + android.MockFS{ + "prebuilts/module_sdk/art/current/Android.bp": prebuiltLibfooBp, + "apexfoo/Android.bp": apexfooBp, + "system/sepolicy/apex/apexfoo-file_contexts": nil, + "Android.bp": installedlibBp, + }, + ) + }) + + disabledSourceLibfooBp := []byte(` + cc_library { + name: "libfoo", + enabled: false, + stubs: { + versions: ["1"], + }, + apex_available: ["apexfoo"], + } + `) + + t.Run("prebuilt stub (with disabled source): no install", func(t *testing.T) { + testFunc( + t, + /*expectLibfooOnSystemLib=*/ false, + android.MockFS{ + "prebuilts/module_sdk/art/current/Android.bp": prebuiltLibfooBp, + "impl/Android.bp": disabledSourceLibfooBp, + "apexfoo/Android.bp": apexfooBp, + "system/sepolicy/apex/apexfoo-file_contexts": nil, + "Android.bp": installedlibBp, + }, + ) + }) +} diff --git a/cc/prebuilt.go b/cc/prebuilt.go index e9f790f73..e023a324c 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -205,17 +205,6 @@ func (p *prebuiltLibraryLinker) link(ctx ModuleContext, TableOfContents: p.tocFile, }) - // TODO(b/220898484): Mainline module sdk prebuilts of stub libraries use a stub - // library as their source and must not be installed, but other prebuilts like - // libclang_rt.* libraries set `stubs` property because they are LLNDK libraries, - // but use an implementation library as their source and need to be installed. - // This discrepancy should be resolved without the prefix hack below. - isModuleSdkPrebuilts := android.HasAnyPrefix(ctx.ModuleDir(), []string{ - "prebuilts/runtime/mainline/", "prebuilts/module_sdk/"}) - if p.hasStubsVariants() && !p.buildStubs() && !ctx.Host() && isModuleSdkPrebuilts { - ctx.Module().MakeUninstallable() - } - return outputFile } } diff --git a/cc/prebuilt_test.go b/cc/prebuilt_test.go index 71b7e4369..86e6af96a 100644 --- a/cc/prebuilt_test.go +++ b/cc/prebuilt_test.go @@ -385,112 +385,6 @@ func TestPrebuiltLibrarySanitized(t *testing.T) { assertString(t, static2.OutputFile().Path().Base(), "libf.hwasan.a") } -func TestPrebuiltStubNoinstall(t *testing.T) { - testFunc := func(t *testing.T, expectLibfooOnSystemLib bool, fs android.MockFS) { - result := android.GroupFixturePreparers( - prepareForPrebuiltTest, - android.PrepareForTestWithMakevars, - android.FixtureMergeMockFs(fs), - ).RunTest(t) - - ldRule := result.ModuleForTests("installedlib", "android_arm64_armv8-a_shared").Rule("ld") - android.AssertStringDoesContain(t, "", ldRule.Args["libFlags"], "android_arm64_armv8-a_shared/libfoo.so") - - installRules := result.InstallMakeRulesForTesting(t) - var installedlibRule *android.InstallMakeRule - for i, rule := range installRules { - if rule.Target == "out/target/product/test_device/system/lib/installedlib.so" { - if installedlibRule != nil { - t.Errorf("Duplicate install rules for %s", rule.Target) - } - installedlibRule = &installRules[i] - } - } - if installedlibRule == nil { - t.Errorf("No install rule found for installedlib") - return - } - - if expectLibfooOnSystemLib { - android.AssertStringListContains(t, - "installedlib doesn't have install dependency on libfoo impl", - installedlibRule.OrderOnlyDeps, - "out/target/product/test_device/system/lib/libfoo.so") - } else { - android.AssertStringListDoesNotContain(t, - "installedlib has install dependency on libfoo stub", - installedlibRule.Deps, - "out/target/product/test_device/system/lib/libfoo.so") - android.AssertStringListDoesNotContain(t, - "installedlib has order-only install dependency on libfoo stub", - installedlibRule.OrderOnlyDeps, - "out/target/product/test_device/system/lib/libfoo.so") - } - } - - prebuiltLibfooBp := []byte(` - cc_prebuilt_library { - name: "libfoo", - prefer: true, - srcs: ["libfoo.so"], - stubs: { - versions: ["1"], - }, - } - `) - - installedlibBp := []byte(` - cc_library { - name: "installedlib", - shared_libs: ["libfoo"], - } - `) - - t.Run("prebuilt stub (without source): no install", func(t *testing.T) { - testFunc( - t, - /*expectLibfooOnSystemLib=*/ false, - android.MockFS{ - "prebuilts/module_sdk/art/current/Android.bp": prebuiltLibfooBp, - "Android.bp": installedlibBp, - }, - ) - }) - - disabledSourceLibfooBp := []byte(` - cc_library { - name: "libfoo", - enabled: false, - stubs: { - versions: ["1"], - }, - } - `) - - t.Run("prebuilt stub (with disabled source): no install", func(t *testing.T) { - testFunc( - t, - /*expectLibfooOnSystemLib=*/ false, - android.MockFS{ - "prebuilts/module_sdk/art/current/Android.bp": prebuiltLibfooBp, - "impl/Android.bp": disabledSourceLibfooBp, - "Android.bp": installedlibBp, - }, - ) - }) - - t.Run("prebuilt impl (with `stubs` property set): install", func(t *testing.T) { - testFunc( - t, - /*expectLibfooOnSystemLib=*/ true, - android.MockFS{ - "impl/Android.bp": prebuiltLibfooBp, - "Android.bp": installedlibBp, - }, - ) - }) -} - func TestPrebuiltBinaryNoSrcsNoError(t *testing.T) { const bp = ` cc_prebuilt_binary {