@@ -53,6 +53,9 @@ def _verify_command_overrides(meta):
5353 if sets .length (unique_commands ) != len (meta ):
5454 fail ("Multiple flag overrides use the same command. Make sure flag overrides use different command." )
5555
56+ def _get_flags_from_extra_presets (extra_presets_json ):
57+ return {key : struct (** value ) for key , value in json .decode (extra_presets_json ).items ()}
58+
5659def _generate_preset (ctx ):
5760 content = ctx .actions .args ().set_param_file_format ("multiline" )
5861 content .add_all ([
@@ -61,7 +64,7 @@ def _generate_preset(ctx):
6164 " bazel run {}.update" .format (ctx .label ),
6265 ], format_each = "# %s" )
6366
64- flags = FLAGS | (MIGRATIONS if ctx .attr .strict else {})
67+ flags = FLAGS | (MIGRATIONS if ctx .attr .strict else {}) | _get_flags_from_extra_presets ( ctx . attr . extra_presets )
6568 for flag , meta in flags .items ():
6669 # Syntax sugar: allow a struct to stand in for a singleton list
6770 if type (meta ) != type ([]):
@@ -77,6 +80,11 @@ def _generate_preset(ctx):
7780generate_preset = rule (
7881 implementation = _generate_preset ,
7982 attrs = {
83+ "extra_presets" : attr .string (
84+ doc = """\
85+ A json encoded string of presets to add to the preset generation matching the format of the FLAGS dictionary.
86+ """ ,
87+ ),
8088 "out" : attr .output (),
8189 "strict" : attr .bool (
8290 default = False ,
@@ -110,6 +118,7 @@ def bazelrc_preset(name, out_file = None, **kwargs):
110118 Label ("//:strict.true" ): True ,
111119 "//conditions:default" : False ,
112120 })),
121+ extra_presets = json .encode (kwargs .pop ("extra_presets" , {})),
113122 ** kwargs
114123 )
115124 if not out_file :
0 commit comments