I'm trying to run a file given an environment variable to generate some environment-specific rules.
However, Tup doesn't allow for environment variables to be used in Tupfiles directly (you can send them through to child processes using the export keyword but you can't use them in run statements).
How can I use an environment variable in a run statement?
You can achieve this by using the
exportkeyword to pass the environment variable through to a child process (bash, in this case), and then using the child process' ability to access environment variables to then run whatever script you want.To do this, create a helper script:
which takes the first argument passed to it, resolves it as a variable name, and then performs a replacement (where as the second argument is a direct replacement), and then run it from your Tupfile by using:
The above passes through
SCRIPT_DIRto the previously mentioned bootstrap script, along with a target script or program to run (in order to generate rules using Tup'srunkeyword).