diff options
author | Sam Delmerico <delmerico@google.com> | 2023-03-16 09:45:51 -0400 |
---|---|---|
committer | Sam Delmerico <delmerico@google.com> | 2023-03-16 13:50:52 +0000 |
commit | 3a57120a52602a908ded0262b72f44fd2fc23f1a (patch) | |
tree | 3da81b6a89f2aeb338e632fc62b77f015df250b0 /rules/cc | |
parent | 7e1e104dea97949be4646d55d34c29c446435885 (diff) | |
download | bazel-3a57120a52602a908ded0262b72f44fd2fc23f1a.tar.gz |
remove stub dependency on source_library
Since the source_library attribute of _cc_stub_library_shared was a
label attribute, the source library was added as a dependency of the
stub which doesn't always make sense. E.g. it caused validation actions
for the source library to run even when we weren't building the source
library.
This change converts the label attriubte to a string attribute so that
we don't add the dependency.
Bug: 263390551
Test: WITH_TIDY=1 DISABLE_ARTIFACT_PATH_REQUIREMENTS=true b build //packages/modules/NeuralNetworks/apex:com.android.neuralnetworks --config=android
Test: b test //build/bazel/rules/... --config=android
Test: b test //build/bazel/rules/...
Change-Id: I8a238b6c220738a81a189966716fba8593cef965
Diffstat (limited to 'rules/cc')
-rw-r--r-- | rules/cc/cc_library_shared_test.bzl | 6 | ||||
-rw-r--r-- | rules/cc/cc_stub_library.bzl | 17 |
2 files changed, 12 insertions, 11 deletions
diff --git a/rules/cc/cc_library_shared_test.bzl b/rules/cc/cc_library_shared_test.bzl index 58a84630..09b5f8ab 100644 --- a/rules/cc/cc_library_shared_test.bzl +++ b/rules/cc/cc_library_shared_test.bzl @@ -707,7 +707,7 @@ def _cc_library_set_defines_for_stubs(): cc_stub_suite( name = name + "_libfoo_stub_libs", soname = name + "_libfoo.so", - source_library = ":" + name + "_libfoo", + source_library_label = ":" + name + "_libfoo", symbol_file = name + "_libfoo.map.txt", versions = ["30", "40"], ) @@ -723,7 +723,7 @@ def _cc_library_set_defines_for_stubs(): cc_stub_suite( name = name + "_libbar_stub_libs", soname = name + "_libbar.so", - source_library = ":" + name + "_libbar", + source_library_label = ":" + name + "_libbar", symbol_file = name + "_libbar.map.txt", versions = ["current"], ) @@ -739,7 +739,7 @@ def _cc_library_set_defines_for_stubs(): cc_stub_suite( name = name + "_libbaz_stub_libs", soname = name + "_libbaz.so", - source_library = ":" + name + "_libbaz", + source_library_label = ":" + name + "_libbaz", symbol_file = name + "_libbaz.map.txt", versions = ["30"], ) diff --git a/rules/cc/cc_stub_library.bzl b/rules/cc/cc_stub_library.bzl index 5e07f613..abcd28c8 100644 --- a/rules/cc/cc_stub_library.bzl +++ b/rules/cc/cc_stub_library.bzl @@ -92,7 +92,7 @@ cc_stub_gen = rule( CcStubLibrarySharedInfo = provider( fields = { - "source_library": "The source library label of the cc_stub_library_shared", + "source_library_label": "The source library label of the cc_stub_library_shared", }, ) @@ -100,7 +100,7 @@ CcStubLibrarySharedInfo = provider( # from a library's .map.txt files and ndkstubgen. The top level target returns the same # providers as a cc_library_shared, with the addition of a CcStubInfo # containing metadata files and versions of the stub library. -def cc_stub_library_shared(name, stubs_symbol_file, version, export_includes, soname, source_library, deps, target_compatible_with, features, tags): +def cc_stub_library_shared(name, stubs_symbol_file, version, export_includes, soname, source_library_label, deps, target_compatible_with, features, tags): # Call ndkstubgen to generate the stub.c source file from a .map.txt file. These # are accessible in the CcStubInfo provider of this target. cc_stub_gen( @@ -173,7 +173,7 @@ def cc_stub_library_shared(name, stubs_symbol_file, version, export_includes, so stub_target = name + "_files", library_target = name + "_so", deps = [name + "_root"], - source_library = source_library, + source_library_label = source_library_label, version = version, tags = tags, ) @@ -186,8 +186,9 @@ def _cc_stub_library_shared_impl(ctx): if len(ctx.attr.deps) != 1: fail("Exactly one 'deps' must be specified for cc_stub_library_shared") + source_library_label = Label(ctx.attr.source_library_label) api_level = str(api.parse_api_level_from_version(ctx.attr.version)) - version_macro_name = "__" + ctx.attr.source_library.label.name.upper() + "__API__=" + api_level + version_macro_name = "__" + source_library_label.name.upper() + "__API__=" + api_level compilation_context = cc_common.create_compilation_context( defines = depset([version_macro_name]), ) @@ -203,7 +204,7 @@ def _cc_stub_library_shared_impl(ctx): cc_info, CcStubLibrariesInfo(has_stubs = True), OutputGroupInfo(rule_impl_debug_files = depset()), - CcStubLibrarySharedInfo(source_library = ctx.attr.source_library), + CcStubLibrarySharedInfo(source_library_label = source_library_label), ] _cc_stub_library_shared = rule( @@ -218,7 +219,7 @@ _cc_stub_library_shared = rule( # "deps" should be a single element: the root target of the stub library. # See _cc_stub_library_shared_impl comment for explanation. "deps": attr.label_list(mandatory = True), - "source_library": attr.label(mandatory = True), + "source_library_label": attr.string(mandatory = True), "version": attr.string(mandatory = True), "_allowlist_function_transition": attr.label( default = "@bazel_tools//tools/allowlists/function_transition_allowlist", @@ -226,7 +227,7 @@ _cc_stub_library_shared = rule( }, ) -def cc_stub_suite(name, source_library, versions, symbol_file, export_includes = [], soname = "", deps = [], data = [], target_compatible_with = [], features = [], tags = ["manual"]): +def cc_stub_suite(name, source_library_label, versions, symbol_file, export_includes = [], soname = "", deps = [], data = [], target_compatible_with = [], features = [], tags = ["manual"]): # Implicitly add "current" to versions. This copies the behavior from Soong (aosp/1641782) if "current" not in versions: versions.append("current") @@ -239,7 +240,7 @@ def cc_stub_suite(name, source_library, versions, symbol_file, export_includes = stubs_symbol_file = symbol_file, export_includes = export_includes, soname = soname, - source_library = source_library, + source_library_label = str(native.package_relative_label(source_library_label)), deps = deps, target_compatible_with = target_compatible_with, features = features, |