From 087af54772282e4380912bfc4dcd5455ea77115a Mon Sep 17 00:00:00 2001 From: Trevor Radcliffe Date: Fri, 16 Sep 2022 15:36:10 +0000 Subject: [PATCH] Create Stub targets for cc_library_(static|shared) Fixes: 246958825 Test: Temporarily allowlist module and inspect BUILD.bazel Change-Id: I4baeec2d873fefabd49ce77508630b82f759820a --- bp2build/cc_library_conversion_test.go | 20 ------------------- bp2build/cc_library_shared_conversion_test.go | 10 ++++++++++ bp2build/testing.go | 20 +++++++++++++++++++ cc/library.go | 6 ++++++ 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index 1949f4d7d..4652a7dba 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -1355,26 +1355,6 @@ func makeCcLibraryTargets(name string, attrs AttrNameToString) []string { return []string{staticTarget, sharedTarget} } -func makeCcStubSuiteTargets(name string, attrs AttrNameToString) string { - if _, hasStubs := attrs["stubs_symbol_file"]; !hasStubs { - return "" - } - STUB_SUITE_ATTRS := map[string]string{ - "stubs_symbol_file": "symbol_file", - "stubs_versions": "versions", - "soname": "soname", - "source_library": "source_library", - } - - stubSuiteAttrs := AttrNameToString{} - for key, _ := range attrs { - if _, stubSuiteAttr := STUB_SUITE_ATTRS[key]; stubSuiteAttr { - stubSuiteAttrs[STUB_SUITE_ATTRS[key]] = attrs[key] - } - } - return MakeBazelTarget("cc_stub_suite", name+"_stub_libs", stubSuiteAttrs) -} - func TestCCLibraryNoLibCrtFalse(t *testing.T) { runCcLibraryTestCase(t, Bp2buildTestCase{ ModuleTypeUnderTest: "cc_library", diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go index 4d8e59b30..4ad98e95f 100644 --- a/bp2build/cc_library_shared_conversion_test.go +++ b/bp2build/cc_library_shared_conversion_test.go @@ -487,6 +487,16 @@ cc_library_shared { ExpectedBazelTargets: []string{MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ "has_stubs": `True`, }), + makeCcStubSuiteTargets("a", AttrNameToString{ + "soname": `"a.so"`, + "source_library": `":a"`, + "stubs_symbol_file": `"a.map.txt"`, + "stubs_versions": `[ + "28", + "29", + "current", + ]`, + }), }, }, ) diff --git a/bp2build/testing.go b/bp2build/testing.go index edc5c4a99..8ce8bb28e 100644 --- a/bp2build/testing.go +++ b/bp2build/testing.go @@ -463,3 +463,23 @@ type ExpectedRuleTarget struct { func (ebr ExpectedRuleTarget) String() string { return makeBazelTargetHostOrDevice(ebr.Rule, ebr.Name, ebr.Attrs, ebr.Hod) } + +func makeCcStubSuiteTargets(name string, attrs AttrNameToString) string { + if _, hasStubs := attrs["stubs_symbol_file"]; !hasStubs { + return "" + } + STUB_SUITE_ATTRS := map[string]string{ + "stubs_symbol_file": "symbol_file", + "stubs_versions": "versions", + "soname": "soname", + "source_library": "source_library", + } + + stubSuiteAttrs := AttrNameToString{} + for key, _ := range attrs { + if _, stubSuiteAttr := STUB_SUITE_ATTRS[key]; stubSuiteAttr { + stubSuiteAttrs[STUB_SUITE_ATTRS[key]] = attrs[key] + } + } + return MakeBazelTarget("cc_stub_suite", name+"_stub_libs", stubSuiteAttrs) +} diff --git a/cc/library.go b/cc/library.go index 93bb26a04..62937cb73 100644 --- a/cc/library.go +++ b/cc/library.go @@ -442,6 +442,10 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) { android.CommonAttributes{Name: m.Name()}, sharedTargetAttrs, sharedAttrs.Enabled) + createStubsBazelTargetIfNeeded(ctx, m, compilerAttrs, exportedIncludes, baseAttributes) +} + +func createStubsBazelTargetIfNeeded(ctx android.TopDownMutatorContext, m *Module, compilerAttrs compilerAttributes, exportedIncludes BazelIncludes, baseAttributes baseAttributes) { if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 { stubSuitesProps := bazel.BazelTargetModuleProperties{ Rule_class: "cc_stub_suite", @@ -2709,6 +2713,8 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo } ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, attrs) + + createStubsBazelTargetIfNeeded(ctx, module, compilerAttrs, exportedIncludes, baseAttributes) } // TODO(b/199902614): Can this be factored to share with the other Attributes?