Comments (9)
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.
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.
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 ownctx.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.
@pauldraper sorry about that 😛
from bazel-skylib.
meanwhile, I updated my PR (#330). Would be nice if anyone could review it
from bazel-skylib.
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.
Would also be helpful for tensorflow, kythe, and OpenEXR
from bazel-skylib.
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.
I was very sad to learn that https://github.com/bazel-contrib/rules-template was not this.
from bazel-skylib.
Related Issues (20)
- Expand make variables in write_file content and expand_template substitutions HOT 4
- Bazel skylib fails on Bazel@HEAD in downstream CI HOT 2
- zlib not found HOT 2
- [feature] Add repository rule for translation of "properties" file into a .bzl HOT 3
- Gazelle plugin just deleting `srcs` from some libraries HOT 7
- analysis_test_e2e_test is failing with Bazel@HEAD HOT 7
- bazel-skylib is failing at BAZEL@HEAD HOT 2
- Search runfiles in `select_file` rule HOT 1
- Error in rule: Use of Starlark transition without allowlist attribute '_allowlist_function_transition' with Bazel@HEAD HOT 3
- Version 1.4.2 is broken in bzlmod HOT 2
- Requesting New Release/Tag
- Set up publish-to-bcr for skylib HOT 2
- Brings in very old version of rules_cc: Eliminate or update? HOT 2
- ERROR: no such package '@@rules_java~7.1.0~toolchains~remote_java_tools with BAZEL@HEAD HOT 2
- RELEASE NOTES TYPO FOR 1.5.0: Missing comma for WORKSPACE sha256
- `build_test` shows test as cached even if the build was not up-to-date HOT 1
- `diff_test` relies on a `diff` binary being installed on the host
- paths method performance
- NullPointerException with bazel@HEAD in CI HOT 11
- Feature: allow custom mnemonic for copy_file HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bazel-skylib.