Add alias variations to linkageMutator

Alias the shared variation if it exists, otherwise the static variation.
This allows modules that are not aware of shared library variations
(like cc_genrule) to depend on shared libraries by depending on
just the normal image, os and arch variations.

Bug: 162437057
Test: TestLibraryGenruleCmd
Change-Id: Icec57d43538e01ab05cc50d4e3f9a11cc55f0162
This commit is contained in:
Colin Cross 2020-08-06 17:46:48 -07:00
parent 094faa5b26
commit 81ca6cd407
2 changed files with 49 additions and 0 deletions

View File

@ -76,3 +76,42 @@ func TestArchGenruleCmd(t *testing.T) {
t.Errorf(`want arm64 inputs %v, got %v`, expected, gen.Inputs.Strings())
}
}
func TestLibraryGenruleCmd(t *testing.T) {
bp := `
cc_library {
name: "libboth",
}
cc_library_shared {
name: "libshared",
}
cc_library_static {
name: "libstatic",
}
cc_genrule {
name: "gen",
tool_files: ["tool"],
srcs: [
":libboth",
":libshared",
":libstatic",
],
cmd: "$(location tool) $(in) $(out)",
out: ["out"],
}
`
ctx := testCc(t, bp)
gen := ctx.ModuleForTests("gen", "android_arm_armv7-a-neon").Output("out")
expected := []string{"libboth.so", "libshared.so", "libstatic.a"}
var got []string
for _, input := range gen.Inputs {
got = append(got, input.Base())
}
if !reflect.DeepEqual(expected, got) {
t.Errorf(`want inputs %v, got %v`, expected, got)
}
}

View File

@ -1469,6 +1469,12 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) {
static.linker.(prebuiltLibraryInterface).setStatic()
shared.linker.(prebuiltLibraryInterface).setShared()
if library.buildShared() {
mctx.AliasVariation("shared")
} else if library.buildStatic() {
mctx.AliasVariation("static")
}
if !library.buildStatic() {
static.linker.(prebuiltLibraryInterface).disablePrebuilt()
}
@ -1500,18 +1506,22 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) {
if _, ok := library.(*Module); ok {
reuseStaticLibrary(mctx, static.(*Module), shared.(*Module))
}
mctx.AliasVariation("shared")
} else if library.BuildStaticVariant() {
variations := append([]string{"static"}, variations...)
modules := mctx.CreateLocalVariations(variations...)
modules[0].(LinkableInterface).SetStatic()
mctx.AliasVariation("static")
} else if library.BuildSharedVariant() {
variations := append([]string{"shared"}, variations...)
modules := mctx.CreateLocalVariations(variations...)
modules[0].(LinkableInterface).SetShared()
mctx.AliasVariation("shared")
} else if len(variations) > 0 {
mctx.CreateLocalVariations(variations...)
mctx.AliasVariation(variations[0])
}
}
}