Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba3bddb

Browse files
committed
[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 e78223e. (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
1 parent eb5f9a5 commit ba3bddb

9 files changed

Lines changed: 25 additions & 9 deletions

libcxx/test/configs/llvm-libc++-mingw.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ config.substitutions.append(('%{link_flags}',
1111
'-nostdlib++ -L %{lib} -lc++'
1212
))
1313
config.substitutions.append(('%{exec}',
14-
'%{executor} --execdir %T --env PATH=%{lib} -- '
14+
'%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
1515
))
1616

1717
import os, site

libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ config.substitutions.append(('%{link_flags}',
1111
'-nostdlib -L %{lib} -lc++ -lmsvcrt -lmsvcprt -loldnames'
1212
))
1313
config.substitutions.append(('%{exec}',
14-
'%{executor} --execdir %T --env PATH=%{lib} -- '
14+
'%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
1515
))
1616

1717
import os, site

libcxx/test/configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ config.substitutions.append(('%{link_flags}',
1212
'-nostdlib -L %{lib} -lc++ -lmsvcrt -lmsvcprt -loldnames'
1313
))
1414
config.substitutions.append(('%{exec}',
15-
'%{executor} --execdir %T --env PATH=%{lib} -- '
15+
'%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
1616
))
1717

1818
import os, site

libcxx/utils/run.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def main():
2323
parser = argparse.ArgumentParser()
2424
parser.add_argument('--execdir', type=str, required=True)
2525
parser.add_argument('--codesign_identity', type=str, required=False, default=None)
26-
parser.add_argument('--env', type=str, nargs='*', required=False, default=dict())
26+
parser.add_argument('--env', type=str, nargs='*', required=False, default=[])
27+
parser.add_argument('--prepend_env', type=str, nargs='*', required=False, default=[])
2728
parser.add_argument("command", nargs=argparse.ONE_OR_MORE)
2829
args = parser.parse_args()
2930
commandLine = args.command
@@ -43,6 +44,14 @@ def main():
4344

4445
# Extract environment variables into a dictionary
4546
env = {k : v for (k, v) in map(lambda s: s.split('=', 1), args.env)}
47+
48+
# Set environment variables where we prepend the given value to the
49+
# existing environment variable.
50+
for (k, v) in map(lambda s: s.split('=', 1), args.prepend_env):
51+
if k in os.environ:
52+
v = v + os.pathsep + os.environ[k]
53+
env[k] = v
54+
4655
if platform.system() == 'Windows':
4756
# Pass some extra variables through on Windows:
4857
# COMSPEC is needed for running subprocesses via std::system().

libcxx/utils/ssh.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def main():
4747
parser.add_argument('--extra-ssh-args', type=str, required=False)
4848
parser.add_argument('--extra-scp-args', type=str, required=False)
4949
parser.add_argument('--codesign_identity', type=str, required=False, default=None)
50-
parser.add_argument('--env', type=str, nargs='*', required=False, default=dict())
50+
parser.add_argument('--env', type=str, nargs='*', required=False, default=[])
51+
parser.add_argument('--prepend_env', type=str, nargs='*', required=False, default=[])
5152
parser.add_argument("command", nargs=argparse.ONE_OR_MORE)
5253
args = parser.parse_args()
5354
commandLine = args.command
@@ -108,6 +109,12 @@ def main():
108109
# temporary directory on the remote host.
109110
commandLine = (pathOnRemote(x) if isTestExe(x) else x for x in commandLine)
110111
remoteCommands.append('cd {}'.format(tmp))
112+
113+
if args.prepend_env:
114+
# We can't sensibly know the original value of the env vars
115+
# in order to prepend to them, so just overwrite these variables.
116+
args.env.extend(args.prepend_env)
117+
111118
if args.env:
112119
env = list(map(cmd_quote, args.env))
113120
remoteCommands.append('export {}'.format(' '.join(args.env)))

libcxxabi/test/configs/llvm-libc++abi-mingw.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ config.substitutions.append(('%{link_flags}',
1111
'-nostdlib++ -L %{lib} -lc++'
1212
))
1313
config.substitutions.append(('%{exec}',
14-
'%{executor} --execdir %T --env PATH=%{lib} -- '
14+
'%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
1515
))
1616

1717
import os, site

libcxxabi/test/configs/llvm-libc++abi-shared-clangcl.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ config.substitutions.append(('%{link_flags}',
1111
'-nostdlib -L %{lib} -lc++ -lc++abi -lmsvcrt -lmsvcprt -loldnames'
1212
))
1313
config.substitutions.append(('%{exec}',
14-
'%{executor} --execdir %T --env PATH=%{lib} -- '
14+
'%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
1515
))
1616

1717
import os, site

libcxxabi/test/configs/llvm-libc++abi-static-clangcl.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ config.substitutions.append(('%{link_flags}',
1111
'-nostdlib -L %{lib} -llibc++ -llibc++abi -lmsvcrt -lmsvcprt -loldnames'
1212
))
1313
config.substitutions.append(('%{exec}',
14-
'%{executor} --execdir %T --env PATH=%{lib} -- '
14+
'%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
1515
))
1616

1717
import os, site

libunwind/test/configs/llvm-libunwind-mingw.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ config.substitutions.append(('%{link_flags}',
1111
'-L %{lib} -lunwind'
1212
))
1313
config.substitutions.append(('%{exec}',
14-
'%{executor} --execdir %T --env PATH=%{lib} -- '
14+
'%{executor} --execdir %T --prepend_env PATH=%{lib} -- '
1515
))
1616

1717
import os, site

0 commit comments

Comments
 (0)