1# Since we try to pass substitutions as-is to some tests, we must "escape" 2# them in case they contain other substitutions. Otherwise, the substitutions 3# will be fully expanded when passed to the tests. For example, we want an 4# %{exec} substitution that contains `--execdir %T` to be passed as-is, without 5# substituting the directory. This way, the test itself can populate %T as it 6# sees fit, and %{exec} will respect it. 7# 8# To solve this problem, we pickle the substitutions and base64 encode that 9# to pass it to the test, and we decode and unpickle the substitutions from 10# within the test. 11import base64, lit.util, pickle 12 13base64Encode = lambda s: lit.util.to_string(base64.b64encode(lit.util.to_bytes(s))) 14escapedSubstitutions = base64Encode(pickle.dumps(config.substitutions)) 15config.substitutions.append(("%{substitutions}", escapedSubstitutions)) 16