thought-machine / please

High-performance extensible build system for reproducible multi-language builds.
https://please.build
Apache License 2.0
2.46k stars 205 forks source link

Add support for text templating #2807

Open izissise opened 1 year ago

izissise commented 1 year ago

Hello, I would be nice for please to support templating text files. It is especially useful to render config files using information from the build system. the user could choose what templating engine they want to use.

The interface could look like this:

config = template(
    name = "render_config",
    source = "config.txt.j2",
    vars = {
        "a": 54,
        "b": ["a", "b", "c"],
        "c": "hello",
    },
    engine = "jinja2",
    out = "config.txt",
)

It could support all the major templating engines jinja2 mustache twig ...

To achieve this, a potential implementation approach similar to how 'arcat' is used could be adopted. This entails introducing a pre-build binary that takes an input file, along with the required variables, and renders the output file. If the binary is not already available, it should be downloaded as necessary.

Tatskaari commented 1 year ago

This would be a great example of something that can be implemented as a plugin! I'm very keen to have some external contributors over on the please-build org that own these sorts of things if you're interested. I'll be writing up a codelab on the plugin API soon (tm), but there are quire a few examples of this on that org already.

Some considerations:

  1. Do we want to support using build labels for values - "version": "//service:version", where //service:version
  2. How are we going to serialise the config options? We can probably use the json() builtin.
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had any recent activity in the past 90 days. It will be closed if no further activity occurs. If you require additional support, please reply to this message. Thank you for your contributions.