rules_jsonnet
rules_jsonnet copied to clipboard
Support user definitions in substrings
I'm using jsonnet to generate docker-compose configs. I'd like to pass bazel defines/vars into the generated files.
Maybe something like this:
ext_strs = {
"foo_cmd": " ".join([
"--key0=val0",
"--key1=val1",
"--mode=$(foo_mode)",
]),
"bar_cmd": " ".join([
"--key2=val2",
"--key3=val3",
"--mode=$(bar_mode)",
]),
},
Unfortunately, jsonnet.bzl
only does substitution if the $(...)
is the entire string.
https://github.com/bazelbuild/rules_jsonnet/blob/12979862ab51358a8a5753f5a4aa0658fec9d4af/jsonnet/jsonnet.bzl#L128
I was thinking of using a select
statement, but that's broken inside dicts:
https://github.com/bazelbuild/bazel/issues/3902
I can promote variables to top-level:
ext_strs = {
"foo_cmd": " ".join([
"--key0=val0",
"--key1=val1",
]),
"foo_mode": "$(foo_mode)",
"bar_cmd": " ".join([
"--key2=val2",
"--key3=val3",
]),
"bar_mode": "$(bar_mode)",
},
But this makes "foo_mode" and "bar_mode" required, since jsonnet doesn't support default values for extVar: https://github.com/google/go-jsonnet/issues/247
This is unpleasant, since we have several jsonnet_to_json
rules, reusing the same foo.jsonnet
, enabling & disabling various containers. I'd like to avoid enumerating all custom args for containers that have been explicitly disabled.
The request I'll make here is to add support for $(...)
within larger strings.