How do you use environment variables in Tup startup statements?

I am trying to run a file given an environment variable to generate some environment rules.

However, Tup does not allow environment variables to be used directly in Tupfiles (you can send them to child processes using a keyword export

, but you cannot use them in statements run

).

How can I use an environment variable in a statement run

?

+3


source to share


1 answer


You can achieve this by using a keyword export

to pass the environment variable through the child process (bash in this case) and then using the child process's ability to access environment variables to then run the script you want.

To do this, create a helper script:

#!/bin/bash
# bootstrap-script.sh
"${!1}/$2"

      



which takes the first argument passed to it, resolves it as a variable name, and then performs the substitution (where, since the second argument is a direct substitute), then runs it from your Tupfile using:

# Tupfile
export SCRIPT_DIR
run ./bootstrap-script.sh SCRIPT_DIR my_script.py

      

The above procedure goes through SCRIPT_DIR

to the previously mentioned bootstrap script as well as the target script or program to run (to generate rules using the Tup keyword run

).

+1


source







All Articles