Giter Club home page Giter Club logo

Comments (9)

cpsauer avatar cpsauer commented on June 2, 2024 2

Ran across this looking for the same thing. The code's handy--certainly looks like there's popular demand to me.

@laurentlb, would you be down to get your code in?

P.S. I just watched your immersion demo. It's super neat!

from bazel-skylib.

alexeagle avatar alexeagle commented on June 2, 2024 1

FWIW we now have this in https://github.com/aspect-build/bazel-lib/blob/main/lib/expand_make_vars.bzl
Since bazel-skylib wants to reduce scope, we're adding these helpers over there.

from bazel-skylib.

 avatar commented on June 2, 2024 1

We've used laurentlb's sketchup internally for a while now, so I look forward to vertexwahn's PR landing.

I'm currently tweaking our internal version, however, to additionally accept substitution information via a SubstitutionInfo provider. Would this be useful to Skylib?

Use cases:

  • Values of a string_dict aren't configurable. Suppose I have a template where I'm expanding 6 variable expressions, and assume 5 of those 6 are static, while the 6th varies by build configuration. If I have N configuration cases, I have to define N unique dictionaries with the common key-value items repeated. (I can reduce repetition w/ dicts.add, but it's still clumsy.)
  • I have a template file with two variables to expand. I can define one expansion via an expand_template rule in a BUILD file. However, the other expansion is performed by a rule class which examines a Java library's runtime classpath and generates its own ctx.expand_template action. To apply both substitutions today, I have to define a chain of expansions, where the output of one expansion rule is the input to another.

Sketchup of a BUILD file using a provider-aware expand_template:

expand_template_info(
    name = "foo_subinfo",
    substitutions = {"%FOO%": "foo"},
)

expand_template_info(
    name = "bar_subinfo",
    substitutions = select({
        "//condition_1": {"%BAR%": "bar1"},
        "//conditions:default": {"%BAR%": "bar"},
    }),
)

# Returns a `SubstitutionInfo` containing a dict of `"%RUNTIME_CLASSPATH%": ":".join([...])`.
java_runtime_classpath(
    name = "libfoo_classpath",
    runtime_deps = [":foo"],
    marker = "%RUNTIME_CLASSPATH%",
)

expand_template(
    name = "dummy_json",
    template = "dummy.tpl.json",
    deps = [
        ":foo_subinfo",
        ":bar_subinfo",  # Or I could `select` here between a static `bar1..N_subinfo`.
        ":libfoo_classpath",
    ],
)

from bazel-skylib.

alexeagle avatar alexeagle commented on June 2, 2024 1

@pauldraper sorry about that 😛

from bazel-skylib.

Vertexwahn avatar Vertexwahn commented on June 2, 2024 1

meanwhile, I updated my PR (#330). Would be nice if anyone could review it

from bazel-skylib.

ashi009 avatar ashi009 commented on June 2, 2024

We also have something similar internally and would like to have it in a shared lib.

The code is easy, but naming is hard. Having both expand_template and write_file in skylib for writing files could be confusing. How about generate_file or gen_file?

from bazel-skylib.

Vertexwahn avatar Vertexwahn commented on June 2, 2024

Would also be helpful for tensorflow, kythe, and OpenEXR

from bazel-skylib.

laurentlb avatar laurentlb commented on June 2, 2024

fyi, I'll let the code owners (@brandjon @tetromino) decide what to do here. Feel free to reuse my code sample in any way you want.

from bazel-skylib.

pauldraper avatar pauldraper commented on June 2, 2024

I was very sad to learn that https://github.com/bazel-contrib/rules-template was not this.

from bazel-skylib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.