From 81ca6cd4072add2b910ca68cc1f945ea77bf7660 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 6 Aug 2020 17:46:48 -0700 Subject: [PATCH] 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 --- cc/genrule_test.go | 39 +++++++++++++++++++++++++++++++++++++++ cc/library.go | 10 ++++++++++ 2 files changed, 49 insertions(+) diff --git a/cc/genrule_test.go b/cc/genrule_test.go index d38cf27f0..a366f765c 100644 --- a/cc/genrule_test.go +++ b/cc/genrule_test.go @@ -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) + } +} diff --git a/cc/library.go b/cc/library.go index ad152d526..9e6297420 100644 --- a/cc/library.go +++ b/cc/library.go @@ -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]) } } }