mixed builds correctly reference stubs libs
Bug: 270408757 Test: go test Test: m NeuralNetworksTest_shared_partial --bazel-mode-staging && verify that Ninja commands link libneuralnetworks via stubs Change-Id: I19bf5a829cea7fd00c0f82511ad2bddbc40fae4f
This commit is contained in:
@@ -149,6 +149,7 @@ sharedLibraries = []
|
|||||||
rootSharedLibraries = []
|
rootSharedLibraries = []
|
||||||
|
|
||||||
shared_info_tag = "//build/bazel/rules/cc:cc_library_shared.bzl%CcSharedLibraryOutputInfo"
|
shared_info_tag = "//build/bazel/rules/cc:cc_library_shared.bzl%CcSharedLibraryOutputInfo"
|
||||||
|
stubs_tag = "//build/bazel/rules/cc:cc_stub_library.bzl%CcStubInfo"
|
||||||
unstripped_tag = "//build/bazel/rules/cc:stripped_cc_common.bzl%CcUnstrippedInfo"
|
unstripped_tag = "//build/bazel/rules/cc:stripped_cc_common.bzl%CcUnstrippedInfo"
|
||||||
unstripped = ""
|
unstripped = ""
|
||||||
|
|
||||||
@@ -160,6 +161,8 @@ if shared_info_tag in p:
|
|||||||
unstripped = path
|
unstripped = path
|
||||||
if unstripped_tag in p:
|
if unstripped_tag in p:
|
||||||
unstripped = p[unstripped_tag].unstripped.path
|
unstripped = p[unstripped_tag].unstripped.path
|
||||||
|
elif stubs_tag in p:
|
||||||
|
rootSharedLibraries.extend([f.path for f in target.files.to_list()])
|
||||||
else:
|
else:
|
||||||
for linker_input in linker_inputs:
|
for linker_input in linker_inputs:
|
||||||
for library in linker_input.libraries:
|
for library in linker_input.libraries:
|
||||||
|
@@ -1249,3 +1249,40 @@ cc_library_shared {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCcLibrarySharedStubsDessertVersionConversion(t *testing.T) {
|
||||||
|
runCcLibrarySharedTestCase(t, Bp2buildTestCase{
|
||||||
|
Description: "cc_library_shared converts dessert codename versions to numerical versions",
|
||||||
|
Blueprint: `
|
||||||
|
cc_library_shared {
|
||||||
|
name: "a",
|
||||||
|
include_build_directory: false,
|
||||||
|
stubs: {
|
||||||
|
symbol_file: "a.map.txt",
|
||||||
|
versions: [
|
||||||
|
"Q",
|
||||||
|
"R",
|
||||||
|
"31",
|
||||||
|
"current",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
ExpectedBazelTargets: []string{
|
||||||
|
makeCcStubSuiteTargets("a", AttrNameToString{
|
||||||
|
"soname": `"a.so"`,
|
||||||
|
"source_library_label": `"//:a"`,
|
||||||
|
"stubs_symbol_file": `"a.map.txt"`,
|
||||||
|
"stubs_versions": `[
|
||||||
|
"29",
|
||||||
|
"30",
|
||||||
|
"31",
|
||||||
|
"current",
|
||||||
|
]`,
|
||||||
|
}),
|
||||||
|
MakeBazelTarget("cc_library_shared", "a", AttrNameToString{
|
||||||
|
"stubs_symbol_file": `"a.map.txt"`,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@@ -762,8 +762,10 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module)
|
|||||||
|
|
||||||
if libraryProps, ok := archVariantLibraryProperties[axis][cfg].(*LibraryProperties); ok {
|
if libraryProps, ok := archVariantLibraryProperties[axis][cfg].(*LibraryProperties); ok {
|
||||||
if axis == bazel.NoConfigAxis {
|
if axis == bazel.NoConfigAxis {
|
||||||
|
versions := android.CopyOf(libraryProps.Stubs.Versions)
|
||||||
|
normalizeVersions(ctx, versions)
|
||||||
compilerAttrs.stubsSymbolFile = libraryProps.Stubs.Symbol_file
|
compilerAttrs.stubsSymbolFile = libraryProps.Stubs.Symbol_file
|
||||||
compilerAttrs.stubsVersions.SetSelectValue(axis, cfg, libraryProps.Stubs.Versions)
|
compilerAttrs.stubsVersions.SetSelectValue(axis, cfg, versions)
|
||||||
}
|
}
|
||||||
if suffix := libraryProps.Suffix; suffix != nil {
|
if suffix := libraryProps.Suffix; suffix != nil {
|
||||||
compilerAttrs.suffix.SetSelectValue(axis, cfg, suffix)
|
compilerAttrs.suffix.SetSelectValue(axis, cfg, suffix)
|
||||||
|
19
cc/cc.go
19
cc/cc.go
@@ -1960,6 +1960,17 @@ func (c *Module) ProcessBazelQueryResponse(ctx android.ModuleContext) {
|
|||||||
c.maybeInstall(mctx, apexInfo)
|
c.maybeInstall(mctx, apexInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func moduleContextFromAndroidModuleContext(actx android.ModuleContext, c *Module) ModuleContext {
|
||||||
|
ctx := &moduleContext{
|
||||||
|
ModuleContext: actx,
|
||||||
|
moduleContextImpl: moduleContextImpl{
|
||||||
|
mod: c,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
ctx.ctx = ctx
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
||||||
// Handle the case of a test module split by `test_per_src` mutator.
|
// Handle the case of a test module split by `test_per_src` mutator.
|
||||||
//
|
//
|
||||||
@@ -1979,13 +1990,7 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
|||||||
|
|
||||||
c.makeLinkType = GetMakeLinkType(actx, c)
|
c.makeLinkType = GetMakeLinkType(actx, c)
|
||||||
|
|
||||||
ctx := &moduleContext{
|
ctx := moduleContextFromAndroidModuleContext(actx, c)
|
||||||
ModuleContext: actx,
|
|
||||||
moduleContextImpl: moduleContextImpl{
|
|
||||||
mod: c,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
ctx.ctx = ctx
|
|
||||||
|
|
||||||
deps := c.depsToPaths(ctx)
|
deps := c.depsToPaths(ctx)
|
||||||
if ctx.Failed() {
|
if ctx.Failed() {
|
||||||
|
127
cc/cc_test.go
127
cc/cc_test.go
@@ -3680,6 +3680,133 @@ func TestStubsForLibraryInMultipleApexes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMixedBuildUsesStubs(t *testing.T) {
|
||||||
|
// TODO(b/275313114): Test exposes non-determinism which should be corrected and the test
|
||||||
|
// reenabled.
|
||||||
|
t.Skip()
|
||||||
|
t.Parallel()
|
||||||
|
bp := `
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libFoo",
|
||||||
|
bazel_module: { label: "//:libFoo" },
|
||||||
|
srcs: ["foo.c"],
|
||||||
|
stubs: {
|
||||||
|
symbol_file: "foo.map.txt",
|
||||||
|
versions: ["current"],
|
||||||
|
},
|
||||||
|
apex_available: ["bar", "a1"],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libBar",
|
||||||
|
srcs: ["bar.c"],
|
||||||
|
shared_libs: ["libFoo"],
|
||||||
|
apex_available: ["a1"],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libA1",
|
||||||
|
srcs: ["a1.c"],
|
||||||
|
shared_libs: ["libFoo"],
|
||||||
|
apex_available: ["a1"],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libBarA1",
|
||||||
|
srcs: ["bara1.c"],
|
||||||
|
shared_libs: ["libFoo"],
|
||||||
|
apex_available: ["bar", "a1"],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libAnyApex",
|
||||||
|
srcs: ["anyApex.c"],
|
||||||
|
shared_libs: ["libFoo"],
|
||||||
|
apex_available: ["//apex_available:anyapex"],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libBaz",
|
||||||
|
srcs: ["baz.c"],
|
||||||
|
shared_libs: ["libFoo"],
|
||||||
|
apex_available: ["baz"],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libQux",
|
||||||
|
srcs: ["qux.c"],
|
||||||
|
shared_libs: ["libFoo"],
|
||||||
|
apex_available: ["qux", "bar"],
|
||||||
|
}`
|
||||||
|
|
||||||
|
result := android.GroupFixturePreparers(
|
||||||
|
prepareForCcTest,
|
||||||
|
android.FixtureModifyConfig(func(config android.Config) {
|
||||||
|
config.BazelContext = android.MockBazelContext{
|
||||||
|
OutputBaseDir: "out/bazel",
|
||||||
|
LabelToCcInfo: map[string]cquery.CcInfo{
|
||||||
|
"//:libFoo": {
|
||||||
|
RootDynamicLibraries: []string{"libFoo.so"},
|
||||||
|
},
|
||||||
|
"//:libFoo_stub_libs-current": {
|
||||||
|
RootDynamicLibraries: []string{"libFoo_stub_libs-current.so"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
).RunTestWithBp(t, bp)
|
||||||
|
ctx := result.TestContext
|
||||||
|
|
||||||
|
variants := ctx.ModuleVariantsForTests("libFoo")
|
||||||
|
expectedVariants := []string{
|
||||||
|
"android_arm64_armv8-a_shared",
|
||||||
|
"android_arm64_armv8-a_shared_current",
|
||||||
|
"android_arm_armv7-a-neon_shared",
|
||||||
|
"android_arm_armv7-a-neon_shared_current",
|
||||||
|
}
|
||||||
|
variantsMismatch := false
|
||||||
|
if len(variants) != len(expectedVariants) {
|
||||||
|
variantsMismatch = true
|
||||||
|
} else {
|
||||||
|
for _, v := range expectedVariants {
|
||||||
|
if !inList(v, variants) {
|
||||||
|
variantsMismatch = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if variantsMismatch {
|
||||||
|
t.Errorf("variants of libFoo expected:\n")
|
||||||
|
for _, v := range expectedVariants {
|
||||||
|
t.Errorf("%q\n", v)
|
||||||
|
}
|
||||||
|
t.Errorf(", but got:\n")
|
||||||
|
for _, v := range variants {
|
||||||
|
t.Errorf("%q\n", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
linkAgainstFoo := []string{"libBarA1"}
|
||||||
|
linkAgainstFooStubs := []string{"libBar", "libA1", "libBaz", "libQux", "libAnyApex"}
|
||||||
|
|
||||||
|
libFooPath := "out/bazel/execroot/__main__/libFoo.so"
|
||||||
|
for _, lib := range linkAgainstFoo {
|
||||||
|
libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld")
|
||||||
|
libFlags := libLinkRule.Args["libFlags"]
|
||||||
|
if !strings.Contains(libFlags, libFooPath) {
|
||||||
|
t.Errorf("%q: %q is not found in %q", lib, libFooPath, libFlags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
libFooStubPath := "out/bazel/execroot/__main__/libFoo_stub_libs-current.so"
|
||||||
|
for _, lib := range linkAgainstFooStubs {
|
||||||
|
libLinkRule := ctx.ModuleForTests(lib, "android_arm64_armv8-a_shared").Rule("ld")
|
||||||
|
libFlags := libLinkRule.Args["libFlags"]
|
||||||
|
if !strings.Contains(libFlags, libFooStubPath) {
|
||||||
|
t.Errorf("%q: %q is not found in %q", lib, libFooStubPath, libFlags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestVersioningMacro(t *testing.T) {
|
func TestVersioningMacro(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
for _, tc := range []struct{ moduleName, expected string }{
|
for _, tc := range []struct{ moduleName, expected string }{
|
||||||
|
@@ -931,9 +931,17 @@ func (handler *ccLibraryBazelHandler) generateSharedBazelBuildActions(ctx androi
|
|||||||
func (handler *ccLibraryBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
|
func (handler *ccLibraryBazelHandler) QueueBazelCall(ctx android.BaseModuleContext, label string) {
|
||||||
bazelCtx := ctx.Config().BazelContext
|
bazelCtx := ctx.Config().BazelContext
|
||||||
bazelCtx.QueueBazelRequest(label, cquery.GetCcInfo, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
bazelCtx.QueueBazelRequest(label, cquery.GetCcInfo, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
||||||
|
if v := handler.module.library.stubsVersion(); v != "" {
|
||||||
|
stubsLabel := label + "_stub_libs-" + v
|
||||||
|
bazelCtx.QueueBazelRequest(stubsLabel, cquery.GetCcInfo, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler *ccLibraryBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
|
func (handler *ccLibraryBazelHandler) ProcessBazelQueryResponse(ctx android.ModuleContext, label string) {
|
||||||
|
if v := handler.module.library.stubsVersion(); v != "" {
|
||||||
|
// if we are a stubs variant, just use the Bazel stubs target
|
||||||
|
label = label + "_stub_libs-" + v
|
||||||
|
}
|
||||||
bazelCtx := ctx.Config().BazelContext
|
bazelCtx := ctx.Config().BazelContext
|
||||||
ccInfo, err := bazelCtx.GetCcInfo(label, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
ccInfo, err := bazelCtx.GetCcInfo(label, android.GetConfigKeyApexVariant(ctx, GetApexConfigKey(ctx)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -962,6 +970,9 @@ func (handler *ccLibraryBazelHandler) ProcessBazelQueryResponse(ctx android.Modu
|
|||||||
}
|
}
|
||||||
|
|
||||||
handler.module.setAndroidMkVariablesFromCquery(ccInfo.CcAndroidMkInfo)
|
handler.module.setAndroidMkVariablesFromCquery(ccInfo.CcAndroidMkInfo)
|
||||||
|
|
||||||
|
cctx := moduleContextFromAndroidModuleContext(ctx, handler.module)
|
||||||
|
addStubDependencyProviders(cctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) setFlagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) {
|
func (library *libraryDecorator) setFlagExporterInfoFromCcInfo(ctx android.ModuleContext, ccInfo cquery.CcInfo) {
|
||||||
@@ -1787,6 +1798,12 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
|
|||||||
Target: ctx.Target(),
|
Target: ctx.Target(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
addStubDependencyProviders(ctx)
|
||||||
|
|
||||||
|
return unstrippedOutputFile
|
||||||
|
}
|
||||||
|
|
||||||
|
func addStubDependencyProviders(ctx ModuleContext) {
|
||||||
stubs := ctx.GetDirectDepsWithTag(stubImplDepTag)
|
stubs := ctx.GetDirectDepsWithTag(stubImplDepTag)
|
||||||
if len(stubs) > 0 {
|
if len(stubs) > 0 {
|
||||||
var stubsInfo []SharedStubLibrary
|
var stubsInfo []SharedStubLibrary
|
||||||
@@ -1801,12 +1818,9 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
|
|||||||
}
|
}
|
||||||
ctx.SetProvider(SharedLibraryStubsProvider, SharedLibraryStubsInfo{
|
ctx.SetProvider(SharedLibraryStubsProvider, SharedLibraryStubsInfo{
|
||||||
SharedStubLibraries: stubsInfo,
|
SharedStubLibraries: stubsInfo,
|
||||||
|
IsLLNDK: ctx.IsLlndk(),
|
||||||
IsLLNDK: ctx.IsLlndk(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return unstrippedOutputFile
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) unstrippedOutputFilePath() android.Path {
|
func (library *libraryDecorator) unstrippedOutputFilePath() android.Path {
|
||||||
@@ -2648,7 +2662,7 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
// normalizeVersions modifies `versions` in place, so that each raw version
|
// normalizeVersions modifies `versions` in place, so that each raw version
|
||||||
// string becomes its normalized canonical form.
|
// string becomes its normalized canonical form.
|
||||||
// Validates that the versions in `versions` are specified in least to greatest order.
|
// Validates that the versions in `versions` are specified in least to greatest order.
|
||||||
func normalizeVersions(ctx android.BaseModuleContext, versions []string) {
|
func normalizeVersions(ctx android.BazelConversionPathContext, versions []string) {
|
||||||
var previous android.ApiLevel
|
var previous android.ApiLevel
|
||||||
for i, v := range versions {
|
for i, v := range versions {
|
||||||
ver, err := android.ApiLevelFromUser(ctx, v)
|
ver, err := android.ApiLevelFromUser(ctx, v)
|
||||||
|
Reference in New Issue
Block a user