| # Since we try to pass substitutions as-is to some tests, we must "escape" |
| # them in case they contain other substitutions. Otherwise, the substitutions |
| # will be fully expanded when passed to the tests. For example, we want an |
| # %{exec} substitution that contains `--execdir %T` to be passed as-is, without |
| # substituting the directory. This way, the test itself can populate %T as it |
| # sees fit, and %{exec} will respect it. |
| # |
| # To solve this problem, we pickle the substitutions and base64 encode that |
| # to pass it to the test, and we decode and unpickle the substitutions from |
| # within the test. |
| import base64, lit.util, pickle |
| base64Encode = lambda s: lit.util.to_string(base64.b64encode(lit.util.to_bytes(s))) |
| escapedSubstitutions = base64Encode(pickle.dumps(config.substitutions)) |
| config.substitutions.append(('%{substitutions}', escapedSubstitutions)) |
| |
| # The tests in this directory need to run Python |
| import pipes, sys |
| config.substitutions.append(('%{python}', pipes.quote(sys.executable))) |