Skip to content

Commit ad9008b

Browse files
authored
fix: propagate tags to write_source_files (#51)
* fix: propagate tags to write_source_files Otherwise the macro had to be expanded in order to modify behavior * fix: code review comment * ci: account for new location
1 parent c020940 commit ad9008b

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

.github/workflows/delta.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
id: new
3535
run: |
3636
bazel build tests:preset
37-
cat bazel-bin/tests/preset.bazelrc | tee /tmp/new
37+
cat bazel-bin/tests/_preset.bazelrc | tee /tmp/new
3838
# Avoid problems with later bazel calls under --lockfile_mode=error
3939
git restore MODULE.bazel.lock
4040
env:
@@ -50,7 +50,7 @@ jobs:
5050
run: |
5151
git checkout ${{ github.event.pull_request.base.sha }}
5252
bazel build tests:preset
53-
cat bazel-bin/tests/preset.bazelrc | tee /tmp/old
53+
cat bazel-bin/tests/_preset.bazelrc | tee /tmp/old
5454
env:
5555
USE_BAZEL_VERSION: ${{ matrix.bazel_version }}
5656
- name: Show diff

bazelrc-preset.bzl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Rule/Macro pair to produce bazelrc preset file"""
22

3+
load("@aspect_bazel_lib//lib:utils.bzl", "propagate_common_rule_attributes")
34
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_file")
45
load("@bazel_features_version//:version.bzl", "version")
56
load("@bazel_skylib//lib:new_sets.bzl", "sets")
@@ -93,23 +94,29 @@ generate_preset = rule(
9394
},
9495
)
9596

96-
def bazelrc_preset(name, out_file = None):
97+
def bazelrc_preset(name, out_file = None, **kwargs):
9798
"""
9899
Creates a bazelrc preset file.
99100
100101
Args:
101102
name: The name of the preset.
102103
out_file: The file to write the preset to. If not provided, the preset will be written to `{name}.bazelrc`.
104+
**kwargs: Additional named arguments to pass to the `generate_preset` rule.
105+
Common attributes (those in https://bazel.build/reference/be/common-definitions#common-attributes)
106+
are propagated to the generated `write_source_file` rule as well.
103107
"""
104108
if lt("6.0.0"):
105109
fail("bazelrc_preset requires Bazel 6 or later. You are running Bazel {}".format(version))
110+
106111
generate_preset(
107112
name = name,
108113
out = "_{}.bazelrc".format(name),
109-
strict = select({
114+
# If strict was included in kwargs, use it. Otherwise, use the value from the flag.
115+
strict = kwargs.pop("strict", select({
110116
Label("//:strict.true"): True,
111117
"//conditions:default": False,
112-
}),
118+
})),
119+
**kwargs
113120
)
114121
if not out_file:
115122
out_file = "{}.bazelrc".format(name)
@@ -119,4 +126,5 @@ def bazelrc_preset(name, out_file = None):
119126
in_file = name,
120127
diff_test_failure_message = "The bazelrc preset has changed. Run 'bazel run {{TARGET}}' to update it.",
121128
file_missing_failure_message = "File %s is missing. Run 'bazel run {{TARGET}}' to create it." % out_file,
129+
**propagate_common_rule_attributes(kwargs)
122130
)

tests/BUILD

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
load("@bazel_skylib//rules:native_binary.bzl", "native_test")
2-
load("//:bazelrc-preset.bzl", "generate_preset")
2+
load("//:bazelrc-preset.bzl", "bazelrc_preset")
33

4-
generate_preset(
4+
bazelrc_preset(
55
name = "preset",
6-
out = "preset.bazelrc",
7-
strict = select({
8-
"//:strict.true": True,
9-
"//conditions:default": False,
10-
}),
6+
tags = ["manual"],
117
)
128

139
# To inspect the changes to presets when contributors send a PR

0 commit comments

Comments
 (0)