Open SanjayVas opened 1 year ago
This is a reasonable request, but note that we'd need an ergonomic way to specify how to map from variable names to substitution keys (e.g. are you using $var
or {{var}}
or $(var)
or ...)
Strong vote for ${var}
.
$
is widely used in scripting languages as a variable reference. It is universally familiar.$var
is insufficient because you you can't parse where var
ends.$(var)
is very Makefile
centric. While the Bazel engineers know that from history, it is not actually a widely used style anywhere else.{{var}}
is also not commonly used.%var%
is widely known in the windows world, but no where else.As an alternative, {var}
is sort of OK.
This is a reasonable request, but note that we'd need an ergonomic way to specify how to map from variable names to substitution keys (e.g. are you using
$var
or{{var}}
or$(var)
or ...)
To clarify, this is about substitution of Make Variables. There's no need to specify any kind of mapping here, as that's already defined. The rule implementation just needs to call ctx.expand_make_variables
(ignore the deprecation warning on that function, as a suitable replacement does not actually exist).
I think the appropriate solution to this issue would be such a suitable replacement. With sufficient flexibility to support ${var}
, $(var)
, or any other reasonable syntax. I don't see any particular reason why it's impossible; just some ugly string munging. (We can add some better APIs to a future version of Bazel to make the string munging less ugly, a real regex module exposed to Starlark for example would help massively, but skylib unfortunately needs to work with the current stable version of Bazel too.)
If a user wants make variable substitution, they need to either write their own versions of these rules or else fall back to genrule.
I assume a boolean attribute would need to be added to toggle this behavior as it wouldn't be backwards-compatible.