Skip to content

Support user definitions in substrings #126

Description

@lshamis

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions