aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJingwen Chen <jingwen@google.com>2023-05-04 13:46:04 +0000
committerJingwen Chen <jingwen@google.com>2023-05-04 23:56:39 +0000
commit774b5299ee260fdf3c2b99f775588ec40f95e1fe (patch)
tree44555b4c60232dabab67728a031cb2ffdd0f83bf
parenta4f9c6b0c0733777027c59e4108d6ba55550b8ea (diff)
downloadbazel_common_rules-774b5299ee260fdf3c2b99f775588ec40f95e1fe.tar.gz
Support disting testonly deps.
Setting testonly = True on a target requires all of its rdeps to also set testonly. This means that the rdeps dist targets also need to set distonly. Test: b build //build/bazel_common_rules/dist:all Change-Id: I20e5991cd07190d3a73d28e92ed83d31b19bec5d
-rw-r--r--dist/BUILD14
-rw-r--r--dist/dist.bzl8
2 files changed, 22 insertions, 0 deletions
diff --git a/dist/BUILD b/dist/BUILD
index e956a31..3f531ef 100644
--- a/dist/BUILD
+++ b/dist/BUILD
@@ -21,3 +21,17 @@ copy_to_dist_dir(
"//bionic/libdl",
],
)
+
+# For testing that `testonly` deps can be dist'd.
+genrule(
+ name = "testonly_sample",
+ testonly = True,
+ outs = ["testonly.txt"],
+ cmd = "touch $@",
+)
+
+copy_to_dist_dir(
+ name = "dist_testonly_sample",
+ testonly = True,
+ data = [":testonly_sample"],
+)
diff --git a/dist/dist.bzl b/dist/dist.bzl
index cb60d99..3d3ac66 100644
--- a/dist/dist.bzl
+++ b/dist/dist.bzl
@@ -69,6 +69,7 @@ def copy_to_dist_dir(
allow_duplicate_filenames = None,
mode_overrides = None,
log = None,
+ testonly = False,
**kwargs):
"""A dist rule to copy files out of Bazel's output directory into a custom location.
@@ -134,6 +135,10 @@ def copy_to_dist_dir(
log: If specified, `--log <log>` is provided to the script by default. This sets the
default log level of the script.
+ testonly: If enabled, testonly will also be set on the internal targets
+ for Bazel analysis to succeed due to the nature of testonly enforcement
+ on reverse dependencies.
+
See `dist.py` for allowed values and the default value.
kwargs: Additional attributes to the internal rule, e.g.
[`visibility`](https://docs.bazel.build/versions/main/visibility.html).
@@ -168,6 +173,7 @@ def copy_to_dist_dir(
name = name + "_dist_manifest",
data = data,
archives = archives,
+ testonly = testonly,
)
copy_file(
@@ -186,11 +192,13 @@ def copy_to_dist_dir(
python_version = "PY3",
visibility = ["//visibility:public"],
data = [name + "_dist_manifest"],
+ testonly = testonly,
args = default_args,
)
embedded_exec(
name = name,
actual = name + "_internal",
+ testonly = testonly,
**kwargs
)