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

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rGd51f57c23ca9: [libc++] Pickle substitutions to pass them to dsl.sh.py (authored by ldionne).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111179/new/

https://reviews.llvm.org/D111179

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


Index: libcxx/test/libcxx/selftest/dsl/lit.local.cfg
===================================================================
--- libcxx/test/libcxx/selftest/dsl/lit.local.cfg
+++ 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)))
Index: libcxx/test/libcxx/selftest/dsl/dsl.sh.py
===================================================================
--- libcxx/test/libcxx/selftest/dsl/dsl.sh.py
+++ 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):
         """


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111179.377390.patch
Type: text/x-patch
Size: 3493 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211005/301f2147/attachment.bin>


More information about the libcxx-commits mailing list