Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support user definitions in substrings #126

Open
lshamis opened this issue Jan 22, 2020 · 0 comments
Open

Support user definitions in substrings #126

lshamis opened this issue Jan 22, 2020 · 0 comments

Comments

@lshamis
Copy link

lshamis commented Jan 22, 2020

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:
bazelbuild/bazel#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: google/go-jsonnet#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant