Adds exported_by function to cc_shared_library
This function is meant to be used for the tag containing exported_by.
RELNOTES:none
PiperOrigin-RevId: 298568236
Change-Id: Ia7b039d1764a3b79a3a0cc3f7f68a8eb17e6f0d5
diff --git a/examples/experimental_cc_shared_library.bzl b/examples/experimental_cc_shared_library.bzl
index fedb4ca..dc63965 100644
--- a/examples/experimental_cc_shared_library.bzl
+++ b/examples/experimental_cc_shared_library.bzl
@@ -15,6 +15,14 @@
# used sparingly after making sure it's safe to use.
LINKABLE_MORE_THAN_ONCE = "LINKABLE_MORE_THAN_ONCE"
+_EXPORTED_BY_TAG_BEGINNING = "exported_by="
+
+def exported_by(labels):
+ str_builder = []
+ for label in labels:
+ str_builder.append(label)
+ return _EXPORTED_BY_TAG_BEGINNING + ",".join(str_builder)
+
GraphNodeInfo = provider(
fields = {
"children": "Other GraphNodeInfo from dependencies of this target",
@@ -346,8 +354,8 @@
linkable_more_than_once = False
if hasattr(ctx.rule.attr, "tags"):
for tag in ctx.rule.attr.tags:
- if tag.startswith("exported_by=") and len(tag) > 12:
- for target in tag[12:].split(","):
+ if tag.startswith(_EXPORTED_BY_TAG_BEGINNING) and len(tag) > len(_EXPORTED_BY_TAG_BEGINNING):
+ for target in tag[len(_EXPORTED_BY_TAG_BEGINNING):].split(","):
# Only absolute labels allowed. Targets in same package
# or subpackage can be exported anyway.
if not target.startswith("//") and not target.startswith("@"):
diff --git a/examples/test_cc_shared_library2/BUILD b/examples/test_cc_shared_library2/BUILD
index 1789a5f..9c07def 100644
--- a/examples/test_cc_shared_library2/BUILD
+++ b/examples/test_cc_shared_library2/BUILD
@@ -1,9 +1,10 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
+load("@rules_cc//examples:experimental_cc_shared_library.bzl", "exported_by")
cc_library(
name = "bar",
srcs = ["bar.cc"],
hdrs = ["bar.h"],
- tags = ["exported_by=@rules_cc//examples/test_cc_shared_library:bar_so"],
+ tags = [exported_by(["@rules_cc//examples/test_cc_shared_library:bar_so"])],
visibility = ["//visibility:public"],
)