[libcxx-commits] [libcxx] d51f57c - [libc++] Pickle substitutions to pass them to dsl.sh.py

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 5 16:51:33 PDT 2021


Author: Louis Dionne
Date: 2021-10-05T19:51:23-04:00
New Revision: d51f57c23ca95f4b9b383f0942fee2957d36fd4f

URL: https://github.com/llvm/llvm-project/commit/d51f57c23ca95f4b9b383f0942fee2957d36fd4f
DIFF: https://github.com/llvm/llvm-project/commit/d51f57c23ca95f4b9b383f0942fee2957d36fd4f.diff

LOG: [libc++] Pickle substitutions to pass them to dsl.sh.py

This is less brittle than hand-picking the substitutions that we
pass to the test, since a config could theorically use non-base
substitutions as well (such as defining %{flags} in terms of another
substitution like %{include}).

Also, print the decoded substitutions, which makes it much easier
to debug the test when it fails.

Differential Revision: https://reviews.llvm.org/D111179

Added: 
    

Modified: 
    libcxx/test/libcxx/selftest/dsl/dsl.sh.py
    libcxx/test/libcxx/selftest/dsl/lit.local.cfg

Removed: 
    


################################################################################
diff  --git a/libcxx/test/libcxx/selftest/dsl/dsl.sh.py b/libcxx/test/libcxx/selftest/dsl/dsl.sh.py
index 220bb4f9813bd..16435a073fcec 100644
--- 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 @@ def setUp(self):
         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
index 6613900fb5447..ccadd41765a7e 100644
--- 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)))


        


More information about the libcxx-commits mailing list