[libcxx-commits] [libcxx] ba3bddb - [libcxx] [test] Prepend to PATH instead of overriding it
Martin Storsjö via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Apr 27 09:27:30 PDT 2023
Author: Martin Storsjö
Date: 2023-04-27T19:25:59+03:00
New Revision: ba3bddb6f4736b99437c069d61f4e558c6198e5a
URL: https://github.com/llvm/llvm-project/commit/ba3bddb6f4736b99437c069d61f4e558c6198e5a
DIFF: https://github.com/llvm/llvm-project/commit/ba3bddb6f4736b99437c069d61f4e558c6198e5a.diff
LOG: [libcxx] [test] Prepend to PATH instead of overriding it
On Windows, the PATH env variable is used for locating dynamically
linked librarys, akin to LD_LIBRARY_PATH on Linux.
The tests that run with a dynamically linked libc++ used "--env
PATH=%{lib}" in the test config. This had the unfortunate side effect
of making other tools from PATH unavailable during the runtime of the
tests; in particular, it caused the "executor-has-no-bash" flag to be
set for all those Windows test configs (with the clang-cl static config
being the only one lacking it).
Thus, this increases the number of tests actually included in the
clang-cl dll and all mingw test configs by 9 tests.
The clang-cl static test configuration has been executing those tests
since the "--env PATH=%{lib}" was removed from that test config in
e78223e79efc886ef6f0ea5413deab3737d6d63b. (For mingw we haven't had a
need to split the test config between shared and static, which means
that the mingw static test config previously ran with --env PATH
needlessly.)
This increases the test coverage for patches like D146398 which
can't be executed in the executor-has-no-bash configs.
Change the default value of the arg.env to an empty array; when we do
pass values to the option, they get passed as an array of strings,
so make sure the variable behaves consistently when no arguments
have been passed.
Differential Revision: https://reviews.llvm.org/D148324
Added:
Modified:
libcxx/test/configs/llvm-libc++-mingw.cfg.in
libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in
libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in
libcxx/utils/run.py
libcxx/utils/ssh.py
libcxxabi/test/configs/llvm-libc++abi-mingw.cfg.in
libcxxabi/test/configs/llvm-libc++abi-shared-clangcl.cfg.in
libcxxabi/test/configs/llvm-libc++abi-static-clangcl.cfg.in
libunwind/test/configs/llvm-libunwind-mingw.cfg.in
Removed:
################################################################################
diff --git a/libcxx/test/configs/llvm-libc++-mingw.cfg.in b/libcxx/test/configs/llvm-libc++-mingw.cfg.in
index 449b030dd3fc6..eb77f1142db61 100644
--- a/libcxx/test/configs/llvm-libc++-mingw.cfg.in
+++ b/libcxx/test/configs/llvm-libc++-mingw.cfg.in
@@ -11,7 +11,7 @@ config.substitutions.append(('%{link_flags}',
'-nostdlib++ -L %{lib} -lc++'
))
config.substitutions.append(('%{exec}',
- '%{executor} --execdir %T --env PATH=%{lib} -- '
+ '%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
))
import os, site
diff --git a/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in b/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in
index 3814bd4cfe22d..fe406044223f8 100644
--- a/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in
+++ b/libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in
@@ -11,7 +11,7 @@ config.substitutions.append(('%{link_flags}',
'-nostdlib -L %{lib} -lc++ -lmsvcrt -lmsvcprt -loldnames'
))
config.substitutions.append(('%{exec}',
- '%{executor} --execdir %T --env PATH=%{lib} -- '
+ '%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
))
import os, site
diff --git a/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in b/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in
index bdaa834477507..a3ef060f28ba5 100644
--- a/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in
+++ b/libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in
@@ -12,7 +12,7 @@ config.substitutions.append(('%{link_flags}',
'-nostdlib -L %{lib} -lc++ -lmsvcrt -lmsvcprt -loldnames'
))
config.substitutions.append(('%{exec}',
- '%{executor} --execdir %T --env PATH=%{lib} -- '
+ '%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
))
import os, site
diff --git a/libcxx/utils/run.py b/libcxx/utils/run.py
index bcb7b8412700c..347a013243c84 100755
--- a/libcxx/utils/run.py
+++ b/libcxx/utils/run.py
@@ -23,7 +23,8 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('--execdir', type=str, required=True)
parser.add_argument('--codesign_identity', type=str, required=False, default=None)
- parser.add_argument('--env', type=str, nargs='*', required=False, default=dict())
+ parser.add_argument('--env', type=str, nargs='*', required=False, default=[])
+ parser.add_argument('--prepend_env', type=str, nargs='*', required=False, default=[])
parser.add_argument("command", nargs=argparse.ONE_OR_MORE)
args = parser.parse_args()
commandLine = args.command
@@ -43,6 +44,14 @@ def main():
# Extract environment variables into a dictionary
env = {k : v for (k, v) in map(lambda s: s.split('=', 1), args.env)}
+
+ # Set environment variables where we prepend the given value to the
+ # existing environment variable.
+ for (k, v) in map(lambda s: s.split('=', 1), args.prepend_env):
+ if k in os.environ:
+ v = v + os.pathsep + os.environ[k]
+ env[k] = v
+
if platform.system() == 'Windows':
# Pass some extra variables through on Windows:
# COMSPEC is needed for running subprocesses via std::system().
diff --git a/libcxx/utils/ssh.py b/libcxx/utils/ssh.py
index 281ff10b52bc6..a5f17d6ecd598 100755
--- a/libcxx/utils/ssh.py
+++ b/libcxx/utils/ssh.py
@@ -47,7 +47,8 @@ def main():
parser.add_argument('--extra-ssh-args', type=str, required=False)
parser.add_argument('--extra-scp-args', type=str, required=False)
parser.add_argument('--codesign_identity', type=str, required=False, default=None)
- parser.add_argument('--env', type=str, nargs='*', required=False, default=dict())
+ parser.add_argument('--env', type=str, nargs='*', required=False, default=[])
+ parser.add_argument('--prepend_env', type=str, nargs='*', required=False, default=[])
parser.add_argument("command", nargs=argparse.ONE_OR_MORE)
args = parser.parse_args()
commandLine = args.command
@@ -108,6 +109,12 @@ def main():
# temporary directory on the remote host.
commandLine = (pathOnRemote(x) if isTestExe(x) else x for x in commandLine)
remoteCommands.append('cd {}'.format(tmp))
+
+ if args.prepend_env:
+ # We can't sensibly know the original value of the env vars
+ # in order to prepend to them, so just overwrite these variables.
+ args.env.extend(args.prepend_env)
+
if args.env:
env = list(map(cmd_quote, args.env))
remoteCommands.append('export {}'.format(' '.join(args.env)))
diff --git a/libcxxabi/test/configs/llvm-libc++abi-mingw.cfg.in b/libcxxabi/test/configs/llvm-libc++abi-mingw.cfg.in
index 6f88304fb0c52..1e9f202e8dd8a 100644
--- a/libcxxabi/test/configs/llvm-libc++abi-mingw.cfg.in
+++ b/libcxxabi/test/configs/llvm-libc++abi-mingw.cfg.in
@@ -11,7 +11,7 @@ config.substitutions.append(('%{link_flags}',
'-nostdlib++ -L %{lib} -lc++'
))
config.substitutions.append(('%{exec}',
- '%{executor} --execdir %T --env PATH=%{lib} -- '
+ '%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
))
import os, site
diff --git a/libcxxabi/test/configs/llvm-libc++abi-shared-clangcl.cfg.in b/libcxxabi/test/configs/llvm-libc++abi-shared-clangcl.cfg.in
index a375722ba7c2f..cfdfc0f86090c 100644
--- a/libcxxabi/test/configs/llvm-libc++abi-shared-clangcl.cfg.in
+++ b/libcxxabi/test/configs/llvm-libc++abi-shared-clangcl.cfg.in
@@ -11,7 +11,7 @@ config.substitutions.append(('%{link_flags}',
'-nostdlib -L %{lib} -lc++ -lc++abi -lmsvcrt -lmsvcprt -loldnames'
))
config.substitutions.append(('%{exec}',
- '%{executor} --execdir %T --env PATH=%{lib} -- '
+ '%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
))
import os, site
diff --git a/libcxxabi/test/configs/llvm-libc++abi-static-clangcl.cfg.in b/libcxxabi/test/configs/llvm-libc++abi-static-clangcl.cfg.in
index 445ee02b1a988..ba67c8b2b7653 100644
--- a/libcxxabi/test/configs/llvm-libc++abi-static-clangcl.cfg.in
+++ b/libcxxabi/test/configs/llvm-libc++abi-static-clangcl.cfg.in
@@ -11,7 +11,7 @@ config.substitutions.append(('%{link_flags}',
'-nostdlib -L %{lib} -llibc++ -llibc++abi -lmsvcrt -lmsvcprt -loldnames'
))
config.substitutions.append(('%{exec}',
- '%{executor} --execdir %T --env PATH=%{lib} -- '
+ '%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
))
import os, site
diff --git a/libunwind/test/configs/llvm-libunwind-mingw.cfg.in b/libunwind/test/configs/llvm-libunwind-mingw.cfg.in
index 99d0aac9015ca..33d061a3efc6f 100644
--- a/libunwind/test/configs/llvm-libunwind-mingw.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-mingw.cfg.in
@@ -11,7 +11,7 @@ config.substitutions.append(('%{link_flags}',
'-L %{lib} -lunwind'
))
config.substitutions.append(('%{exec}',
- '%{executor} --execdir %T --env PATH=%{lib} -- '
+ '%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
))
import os, site
More information about the libcxx-commits
mailing list