11"""Rule/Macro pair to produce bazelrc preset file"""
22
3+ load ("@aspect_bazel_lib//lib:utils.bzl" , "propagate_common_rule_attributes" )
34load ("@aspect_bazel_lib//lib:write_source_files.bzl" , "write_source_file" )
45load ("@bazel_features_version//:version.bzl" , "version" )
56load ("@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 )
0 commit comments