diff --git a/libcxx/test/libcxx/selftest/dsl/dsl.sh.py b/libcxx/test/libcxx/selftest/dsl/dsl.sh.py --- a/libcxx/test/libcxx/selftest/dsl/dsl.sh.py +++ b/libcxx/test/libcxx/selftest/dsl/dsl.sh.py @@ -10,18 +10,12 @@ # Note: We prepend arguments with 'x' to avoid thinking there are too few # arguments in case an argument is an empty string. -# RUN: %{python} %s x%S \ -# RUN: x%T \ -# RUN: x%{escaped_exec} \ -# RUN: x%{escaped_cxx} \ -# RUN: x%{escaped_flags} \ -# RUN: x%{escaped_compile_flags} \ -# RUN: x%{escaped_link_flags} -# END. +# RUN: %{python} %s x%S x%T x%{substitutions} import base64 import copy import os +import pickle import platform import subprocess import sys @@ -40,9 +34,14 @@ # Steal some parameters from the config running this test so that we can # bootstrap our own TestingConfig. args = list(map(lambda s: s[1:], sys.argv[1:8])) # Remove the leading 'x' -SOURCE_ROOT, EXEC_PATH, EXEC, CXX, FLAGS, COMPILE_FLAGS, LINK_FLAGS = args +SOURCE_ROOT, EXEC_PATH, SUBSTITUTIONS = args sys.argv[1:8] = [] +# Decode the substitutions. +SUBSTITUTIONS = pickle.loads(base64.b64decode(SUBSTITUTIONS)) +for s, sub in SUBSTITUTIONS: + print("Substitution '{}' is '{}'".format(s, sub)) + class SetupConfigs(unittest.TestCase): """ Base class for the tests below -- it creates a fake TestingConfig. @@ -69,14 +68,7 @@ self.config.test_source_root = SOURCE_ROOT self.config.test_exec_root = EXEC_PATH self.config.recursiveExpansionLimit = 10 - base64Decode = lambda s: lit.util.to_string(base64.b64decode(s)) - self.config.substitutions = [ - ('%{cxx}', base64Decode(CXX)), - ('%{flags}', base64Decode(FLAGS)), - ('%{compile_flags}', base64Decode(COMPILE_FLAGS)), - ('%{link_flags}', base64Decode(LINK_FLAGS)), - ('%{exec}', base64Decode(EXEC)) - ] + self.config.substitutions = copy.deepcopy(SUBSTITUTIONS) def getSubstitution(self, substitution): """ diff --git a/libcxx/test/libcxx/selftest/dsl/lit.local.cfg b/libcxx/test/libcxx/selftest/dsl/lit.local.cfg --- a/libcxx/test/libcxx/selftest/dsl/lit.local.cfg +++ b/libcxx/test/libcxx/selftest/dsl/lit.local.cfg @@ -5,16 +5,14 @@ # 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 add base64 encoded versions of substitutions just -# in this directory. We then base64-decode them from the tests when we need to. -# Another option would be to have a way to prevent expansion in Lit itself. -import base64 -import lit.util +# 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))) -escaped = [(k.replace('%{', '%{escaped_'), base64Encode(v)) for (k, v) in config.substitutions] -config.substitutions.extend(escaped) +escapedSubstitutions = base64Encode(pickle.dumps(config.substitutions)) +config.substitutions.append(('%{substitutions}', escapedSubstitutions)) # The tests in this directory need to run Python -import pipes -import sys +import pipes, sys config.substitutions.append(('%{python}', pipes.quote(sys.executable)))