Interpolate bash variable into a genrule's string parameter macro
See original GitHub issueWe’d like to do something like
# foo/BUCK
for i in ['Linux', 'Darwin']:
genrule(
name = 'bar-' + i,
# blah
)
genrule(
name = 'bar',
cmd = 'cp $(location :bar-$(uname -s)) $OUT',
out = 'my-plat-bar'
)
where we want to let people refer to //foo:bar
that’s specific to their own system’s platform, but also allow them to refer to //foo:bar-Linux
and //foo:bar-Darwin
if they want to explicitly build the genrule for the other architecture.
Unfortunately, using bash interpolation within a string parameter macro like $(location {})
doesn’t work; it’d be nice if it did.
Maybe we just shouldn’t have the convenience of having a single build rule refer have different outputs depending on platform? Seems unfortunate, though 😦
(Context: we currently use import sys
, an unsafe import, to do this from python instead of inside the genrule itself.)
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Variable interpolation in the shell - bash - Stack Overflow
This is why export PATH=$PATH:$addpath works to add :$addpath (which would be subject to parameter expansion) to the PATH environment variable.
Read more >variable interpolation in shell script - Unix Stack Exchange
A very common mistake. This is missing curly braces: ERROR_FILE="$HOME/pg_bak/error_bak/$FILE_error.txt". and is fixed by:
Read more >General Rules | Bazel
The genrule command is executed by a Bash shell that is configured to fail when a command or a pipeline fails, using set...
Read more >Pass interpolating string to macro - Julia Discourse
I'm trying to define basic macro but fail: macro mydebug(s) :(println($s)) end function main() i = 42 @mydebug("$(i)") end. This one yield:
Read more >How to allow arbitrary expressions in format strings
If the format! macro interpolates only identifiers, then in my ... enough that named variables and string interpolation are required. At the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh, that helps! Thanks 😃
I’m not sure what are you using
sh_binary
for, since having a dependency on agenrule
is sufficient to create its output for the rule that depends on it. I think adding anexecutable = True
to yourgenrule
is all you need to use genrules directly.