Mark implementation variant of prebuilts with stubs as not installable

This is necessary to avoid installing them. Previously, when install
dependencies were resolved in make, they weren't installed because they
got a .bootstrap suffix in their mk modules. However when that logic
moved into Soong by resolving transitive dependencies in
computeInstallDeps, they started to get dependencies and hence their
stubs could get installed, e.g. system/lib{,64}/libdexfile.so from
prebuilt_libdexfile.

Test: m nothing
Test: env NINJA_ARGS="-t path droid out/target/product/vsoc_x86_64/system/lib64/libdexfile.so" \
        m SOONG_CONFIG_art_module_source_build=false nothing
  verify that ninja reports no dependency path
Bug: 211770050
Bug: 220898484
Change-Id: Ifbfe31a15428926ce57b9e91b535b7ae79038fbd
This commit is contained in:
Martin Stjernholm 2022-02-06 22:07:45 +00:00
parent 62192b883b
commit 5bdf2d589c
2 changed files with 82 additions and 0 deletions

View file

@ -16,6 +16,7 @@ package cc
import (
"path/filepath"
"strings"
"android/soong/android"
"android/soong/bazel"
@ -188,6 +189,16 @@ 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 libclang_rt.* libraries
// have stubs 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.
if p.hasStubsVariants() && !p.buildStubs() && !ctx.Host() &&
!strings.HasPrefix(ctx.baseModuleName(), "libclang_rt.") {
ctx.Module().MakeUninstallable()
}
return outputFile
}
}

View file

@ -20,6 +20,7 @@ import (
"android/soong/android"
"android/soong/bazel/cquery"
"github.com/google/blueprint"
)
@ -29,6 +30,7 @@ var prepareForPrebuiltTest = android.GroupFixturePreparers(
)
func testPrebuilt(t *testing.T, bp string, fs android.MockFS, handlers ...android.FixturePreparer) *android.TestContext {
t.Helper()
result := android.GroupFixturePreparers(
prepareForPrebuiltTest,
fs.AddToFixture(),
@ -449,3 +451,72 @@ cc_prebuilt_library_shared {
expectedOutputFiles := []string{pathPrefix + "foo.so"}
android.AssertDeepEquals(t, "output files", expectedOutputFiles, outputFiles.Strings())
}
func TestPrebuiltStubNoinstall(t *testing.T) {
testFunc := func(t *testing.T, bp string) {
result := android.GroupFixturePreparers(
prepareForPrebuiltTest,
android.PrepareForTestWithMakevars,
).RunTestWithBp(t, bp)
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
}
android.AssertStringListDoesNotContain(t,
"installedlib has install dependency on stub",
installedlibRule.Deps,
"out/target/product/test_device/system/lib/stublib.so")
android.AssertStringListDoesNotContain(t,
"installedlib has order-only install dependency on stub",
installedlibRule.OrderOnlyDeps,
"out/target/product/test_device/system/lib/stublib.so")
}
const prebuiltStublibBp = `
cc_prebuilt_library {
name: "stublib",
prefer: true,
srcs: ["foo.so"],
stubs: {
versions: ["1"],
},
}
`
const installedlibBp = `
cc_library {
name: "installedlib",
shared_libs: ["stublib"],
}
`
t.Run("prebuilt without source", func(t *testing.T) {
testFunc(t, prebuiltStublibBp+installedlibBp)
})
const disabledSourceStublibBp = `
cc_library {
name: "stublib",
enabled: false,
stubs: {
versions: ["1"],
},
}
`
t.Run("prebuilt with disabled source", func(t *testing.T) {
testFunc(t, disabledSourceStublibBp+prebuiltStublibBp+installedlibBp)
})
}