From 56ccb1aecd0eb9216c8cde845fc940e82cf0d36d Mon Sep 17 00:00:00 2001 From: Yu Liu Date: Sat, 12 Nov 2022 10:47:07 -0800 Subject: [PATCH] Support abi check in bazel. Bug: 253498204 Test: Manual and unit test. Change-Id: Id23c4f772f67c4ba05704eaad77322133474b42b --- android/allowlists/allowlists.go | 3 ++ bp2build/cc_library_conversion_test.go | 47 ++++++++++++++++++- bp2build/cc_library_shared_conversion_test.go | 43 ++++++++++++++++- cc/library.go | 47 +++++++++++++++++-- 4 files changed, 134 insertions(+), 6 deletions(-) diff --git a/android/allowlists/allowlists.go b/android/allowlists/allowlists.go index ac3158ea1..56585034b 100644 --- a/android/allowlists/allowlists.go +++ b/android/allowlists/allowlists.go @@ -374,9 +374,12 @@ var ( "packages/apps/Music":/* recursive = */ true, "packages/apps/QuickSearchBox":/* recursive = */ true, + "prebuilts/abi-dumps/platform":/* recursive = */ true, + "prebuilts/abi-dumps/ndk":/* recursive = */ true, "prebuilts/bazel":/* recursive = */ true, "prebuilts/bundletool":/* recursive = */ true, "prebuilts/clang/host/linux-x86":/* recursive = */ false, + "prebuilts/clang-tools":/* recursive = */ true, "prebuilts/gcc":/* recursive = */ true, "prebuilts/build-tools":/* recursive = */ true, "prebuilts/jdk/jdk11":/* recursive = */ false, diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go index 61acf6833..edb0c43ab 100644 --- a/bp2build/cc_library_conversion_test.go +++ b/bp2build/cc_library_conversion_test.go @@ -1409,6 +1409,7 @@ func makeCcLibraryTargets(name string, attrs AttrNameToString) []string { "strip": true, "inject_bssl_hash": true, "has_stubs": true, + "stubs_symbol_file": true, "use_version_lib": true, } @@ -2710,7 +2711,8 @@ func TestCcLibraryStaticDisabledForSomeArch(t *testing.T) { func TestCcLibraryStubs(t *testing.T) { expectedBazelTargets := makeCcLibraryTargets("a", AttrNameToString{ - "has_stubs": `True`, + "has_stubs": `True`, + "stubs_symbol_file": `"a.map.txt"`, }) expectedBazelTargets = append(expectedBazelTargets, makeCcStubSuiteTargets("a", AttrNameToString{ "soname": `"a.so"`, @@ -3600,3 +3602,46 @@ cc_library_static { }, }) } + +func TestCcLibraryHeaderAbiChecker(t *testing.T) { + runCcLibraryTestCase(t, Bp2buildTestCase{ + Description: "cc_library with header abi checker", + ModuleTypeUnderTest: "cc_library", + ModuleTypeUnderTestFactory: cc.LibraryFactory, + Blueprint: `cc_library { + name: "foo", + header_abi_checker: { + enabled: true, + symbol_file: "a.map.txt", + exclude_symbol_versions: [ + "29", + "30", + ], + exclude_symbol_tags: [ + "tag1", + "tag2", + ], + check_all_apis: true, + diff_flags: ["-allow-adding-removing-weak-symbols"], + }, + include_build_directory: false, +}`, + ExpectedBazelTargets: []string{ + MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{}), + MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ + "abi_checker_enabled": `True`, + "abi_checker_symbol_file": `"a.map.txt"`, + "abi_checker_exclude_symbol_versions": `[ + "29", + "30", + ]`, + "abi_checker_exclude_symbol_tags": `[ + "tag1", + "tag2", + ]`, + "abi_checker_check_all_apis": `True`, + "abi_checker_diff_flags": `["-allow-adding-removing-weak-symbols"]`, + }), + }, + }) +} diff --git a/bp2build/cc_library_shared_conversion_test.go b/bp2build/cc_library_shared_conversion_test.go index b86f60778..7e1d1117d 100644 --- a/bp2build/cc_library_shared_conversion_test.go +++ b/bp2build/cc_library_shared_conversion_test.go @@ -543,7 +543,8 @@ cc_library_shared { ]`, }), MakeBazelTarget("cc_library_shared", "a", AttrNameToString{ - "has_stubs": `True`, + "has_stubs": `True`, + "stubs_symbol_file": `"a.map.txt"`, }), }, }) @@ -845,3 +846,43 @@ cc_library_shared { }, }) } + +func TestCcLibrarySharedHeaderAbiChecker(t *testing.T) { + runCcLibrarySharedTestCase(t, Bp2buildTestCase{ + Description: "cc_library_shared with header abi checker", + Blueprint: `cc_library_shared { + name: "foo", + header_abi_checker: { + enabled: true, + symbol_file: "a.map.txt", + exclude_symbol_versions: [ + "29", + "30", + ], + exclude_symbol_tags: [ + "tag1", + "tag2", + ], + check_all_apis: true, + diff_flags: ["-allow-adding-removing-weak-symbols"], + }, + include_build_directory: false, +}`, + ExpectedBazelTargets: []string{ + MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{ + "abi_checker_enabled": `True`, + "abi_checker_symbol_file": `"a.map.txt"`, + "abi_checker_exclude_symbol_versions": `[ + "29", + "30", + ]`, + "abi_checker_exclude_symbol_tags": `[ + "tag1", + "tag2", + ]`, + "abi_checker_check_all_apis": `True`, + "abi_checker_diff_flags": `["-allow-adding-removing-weak-symbols"]`, + }), + }, + }) +} diff --git a/cc/library.go b/cc/library.go index 0729ff4a5..673f1cadd 100644 --- a/cc/library.go +++ b/cc/library.go @@ -411,13 +411,15 @@ func libraryBp2Build(ctx android.TopDownMutatorContext, m *Module) { Additional_linker_inputs: linkerAttrs.additionalLinkerInputs, - Strip: stripAttrsFromLinkerAttrs(&linkerAttrs), - Features: baseAttributes.features, + Strip: stripAttrsFromLinkerAttrs(&linkerAttrs), + Features: baseAttributes.features, + bazelCcHeaderAbiCheckerAttributes: bp2buildParseAbiCheckerProps(ctx, m), } if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 { hasStubs := true sharedTargetAttrs.Has_stubs.SetValue(&hasStubs) + sharedTargetAttrs.Stubs_symbol_file = compilerAttrs.stubsSymbolFile } sharedTargetAttrs.Suffix = compilerAttrs.suffix @@ -1735,7 +1737,6 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...) objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...) - objs.sAbiDumpFiles = append(objs.sAbiDumpFiles, deps.StaticLibObjs.sAbiDumpFiles...) objs.sAbiDumpFiles = append(objs.sAbiDumpFiles, deps.WholeStaticLibObjs.sAbiDumpFiles...) @@ -2757,6 +2758,29 @@ func maybeInjectBoringSSLHash(ctx android.ModuleContext, outputFile android.Modu return outputFile } +func bp2buildParseAbiCheckerProps(ctx android.TopDownMutatorContext, module *Module) bazelCcHeaderAbiCheckerAttributes { + lib, ok := module.linker.(*libraryDecorator) + if !ok { + return bazelCcHeaderAbiCheckerAttributes{} + } + + abiChecker := lib.Properties.Header_abi_checker + + abiCheckerAttrs := bazelCcHeaderAbiCheckerAttributes{ + Abi_checker_enabled: abiChecker.Enabled, + Abi_checker_exclude_symbol_versions: abiChecker.Exclude_symbol_versions, + Abi_checker_exclude_symbol_tags: abiChecker.Exclude_symbol_tags, + Abi_checker_check_all_apis: abiChecker.Check_all_apis, + Abi_checker_diff_flags: abiChecker.Diff_flags, + } + if abiChecker.Symbol_file != nil { + symbolFile := android.BazelLabelForModuleSrcSingle(ctx, *abiChecker.Symbol_file) + abiCheckerAttrs.Abi_checker_symbol_file = &symbolFile + } + + return abiCheckerAttrs +} + func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Module, isStatic bool) { baseAttributes := bp2BuildParseBaseProps(ctx, module) compilerAttrs := baseAttributes.compilerAttributes @@ -2863,10 +2887,13 @@ func sharedOrStaticLibraryBp2Build(ctx android.TopDownMutatorContext, module *Mo Features: baseAttributes.features, Suffix: compilerAttrs.suffix, + + bazelCcHeaderAbiCheckerAttributes: bp2buildParseAbiCheckerProps(ctx, module), } if compilerAttrs.stubsSymbolFile != nil && len(compilerAttrs.stubsVersions.Value) > 0 { hasStubs := true sharedLibAttrs.Has_stubs.SetValue(&hasStubs) + sharedLibAttrs.Stubs_symbol_file = compilerAttrs.stubsSymbolFile } attrs = sharedLibAttrs } @@ -2943,11 +2970,14 @@ type bazelCcLibrarySharedAttributes struct { Features bazel.StringListAttribute - Has_stubs bazel.BoolAttribute + Has_stubs bazel.BoolAttribute + Stubs_symbol_file *string Inject_bssl_hash bazel.BoolAttribute Suffix bazel.StringAttribute + + bazelCcHeaderAbiCheckerAttributes } type bazelCcStubSuiteAttributes struct { @@ -2958,3 +2988,12 @@ type bazelCcStubSuiteAttributes struct { Soname *string Deps bazel.LabelListAttribute } + +type bazelCcHeaderAbiCheckerAttributes struct { + Abi_checker_enabled *bool + Abi_checker_symbol_file *bazel.Label + Abi_checker_exclude_symbol_versions []string + Abi_checker_exclude_symbol_tags []string + Abi_checker_check_all_apis *bool + Abi_checker_diff_flags []string +}