@@ -2,6 +2,9 @@ load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
22load ("@score_baselibs//score/flatbuffers/bazel:tools.bzl" , "serialize_buffer" )
33
44def _lm_config_splitter_impl (ctx ):
5+ """Run a script to convert from the new config structure to the old, this
6+ creates 3 seperate configs.
7+ """
58 script = ctx .executable .script
69 config = ctx .file .config
710 schema = ctx .file .schema
@@ -24,6 +27,7 @@ def _lm_config_splitter_impl(ctx):
2427
2528lm_config_splitter = rule (
2629 implementation = _lm_config_splitter_impl ,
30+ doc = "Splits the new configuration format int othe old 3 formats." ,
2731 attrs = {
2832 "config" : attr .label (
2933 allow_single_file = [".json" ],
@@ -49,6 +53,53 @@ lm_config_splitter = rule(
4953 },
5054)
5155
56+ def _lm_config_combiner_impl (ctx ):
57+ """Declare a single directory that all three serialized buffers get copied
58+ into. Consumers receive this one directory instead of three individual
59+ files.
60+ """
61+ etc_dir = ctx .actions .declare_directory (ctx .attr .dir_name )
62+
63+ srcs = [ctx .file .lm_config , ctx .file .hm_config , ctx .file .hm_core_config ]
64+
65+ args = ctx .actions .args ()
66+ args .add (etc_dir .path )
67+ args .add_all ([f .path for f in srcs ])
68+
69+ ctx .actions .run_shell (
70+ inputs = srcs ,
71+ outputs = [etc_dir ],
72+ arguments = [args ],
73+ command = 'dest="$1"; shift; mkdir -p "$dest"; for f in "$@"; do cp "$f" "$dest/"; done' ,
74+ mnemonic = "LmConfigCombine" ,
75+ progress_message = "Combining launch manager configs into {}" .format (etc_dir .short_path ),
76+ )
77+
78+ return [DefaultInfo (files = depset ([etc_dir ]))]
79+
80+ lm_config_combiner = rule (
81+ implementation = _lm_config_combiner_impl ,
82+ doc = "Combines the generated .bin files into a single etc directory." ,
83+ attrs = {
84+ "lm_config" : attr .label (
85+ allow_single_file = [".bin" ],
86+ mandatory = True ,
87+ ),
88+ "hm_config" : attr .label (
89+ allow_single_file = [".bin" ],
90+ mandatory = True ,
91+ ),
92+ "hm_core_config" : attr .label (
93+ allow_single_file = [".bin" ],
94+ mandatory = True ,
95+ ),
96+ "dir_name" : attr .string (
97+ default = "etc" ,
98+ doc = "Name of the directory to place the combined config files into." ,
99+ ),
100+ },
101+ )
102+
52103def launch_manager_config (
53104 name ,
54105 config ,
@@ -61,6 +112,8 @@ def launch_manager_config(
61112 ** kwargs ):
62113 split_name = name + "_split"
63114
115+ # note that the splitting and combining is a workaround as we have to return
116+ # the etc directory where all the .bin files are for backwards compatibility.
64117 lm_config_splitter (
65118 name = split_name ,
66119 config = config ,
@@ -81,25 +134,15 @@ def launch_manager_config(
81134 name = name + suffix ,
82135 data = json_prefix + stem + ".json" ,
83136 schema = schema_file ,
84- output = flatbuffer_out_dir + "/" + stem + ".bin" ,
137+ output = name + "_serialized /" + stem + ".bin" ,
85138 ** kwargs
86139 )
87140
88- # native.filegroup(
89- # name = name,
90- # srcs = [
91- # ":" + name + "_lm_bin",
92- # ":" + name + "_hm_bin",
93- # ":" + name + "_hmcore_bin",
94- # ],
95-
96- pkg_files (
141+ lm_config_combiner (
97142 name = name ,
98- srcs = [
99- ":" + name + "_lm_bin" ,
100- ":" + name + "_hm_bin" ,
101- ":" + name + "_hmcore_bin" ,
102- ],
103- prefix = "/etc" ,
143+ lm_config = ":" + name + "_lm_bin" ,
144+ hm_config = ":" + name + "_hm_bin" ,
145+ hm_core_config = ":" + name + "_hmcore_bin" ,
146+ dir_name = flatbuffer_out_dir ,
147+ ** kwargs
104148 )
105- # **kwargs
0 commit comments