16 lines · plain
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 substitutions3# will be fully expanded when passed to the tests. For example, we want an4# %{exec} substitution that contains `--execdir %{temp}` to be passed as-is, without5# substituting the directory. This way, the test itself can populate %{temp} as it6# sees fit, and %{exec} will respect it.7#8# To solve this problem, we pickle the substitutions and base64 encode that9# to pass it to the test, and we decode and unpickle the substitutions from10# within the test.11import base64, lit.util, pickle12 13base64Encode = lambda s: base64.b64encode(s).decode("utf-8")14escapedSubstitutions = base64Encode(pickle.dumps(config.substitutions))15config.substitutions.append(("%{substitutions}", escapedSubstitutions))16