@@ -235,11 +235,12 @@ def quote_windows_command(seq):
235
235
236
236
return '' .join (result )
237
237
238
- # cmd is export or env
239
- def updateEnv (env , cmd ):
238
+ # args are from 'export' or 'env' command.
239
+ # Returns copy of args without those commands or their arguments.
240
+ def updateEnv (env , args ):
240
241
arg_idx = 1
241
242
unset_next_env_var = False
242
- for arg_idx , arg in enumerate (cmd . args [1 :]):
243
+ for arg_idx , arg in enumerate (args [1 :]):
243
244
# Support for the -u flag (unsetting) for env command
244
245
# e.g., env -u FOO -u BAR will remove both FOO and BAR
245
246
# from the environment.
@@ -258,7 +259,7 @@ def updateEnv(env, cmd):
258
259
if eq == '' :
259
260
break
260
261
env .env [key ] = val
261
- cmd . args = cmd . args [arg_idx + 1 :]
262
+ return args [arg_idx + 1 :]
262
263
263
264
def executeBuiltinEcho (cmd , shenv ):
264
265
"""Interpret a redirected echo command"""
@@ -825,7 +826,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
825
826
raise ValueError ("'export' cannot be part of a pipeline" )
826
827
if len (cmd .commands [0 ].args ) != 2 :
827
828
raise ValueError ("'export' supports only one argument" )
828
- updateEnv (shenv , cmd .commands [0 ])
829
+ updateEnv (shenv , cmd .commands [0 ]. args )
829
830
return 0
830
831
831
832
if cmd .commands [0 ].args [0 ] == 'mkdir' :
@@ -872,12 +873,13 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
872
873
for i ,j in enumerate (cmd .commands ):
873
874
# Reference the global environment by default.
874
875
cmd_shenv = shenv
876
+ args = list (j .args )
875
877
if j .args [0 ] == 'env' :
876
878
# Create a copy of the global environment and modify it for this one
877
879
# command. There might be multiple envs in a pipeline:
878
880
# env FOO=1 llc < %s | env BAR=2 llvm-mc | FileCheck %s
879
881
cmd_shenv = ShellEnvironment (shenv .cwd , shenv .env )
880
- updateEnv (cmd_shenv , j )
882
+ args = updateEnv (cmd_shenv , j . args )
881
883
882
884
stdin , stdout , stderr = processRedirects (j , default_stdin , cmd_shenv ,
883
885
opened_files )
@@ -899,7 +901,6 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
899
901
stderrTempFiles .append ((i , stderr ))
900
902
901
903
# Resolve the executable path ourselves.
902
- args = list (j .args )
903
904
executable = None
904
905
is_builtin_cmd = args [0 ] in builtin_commands ;
905
906
if not is_builtin_cmd :
@@ -911,7 +912,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
911
912
if not executable :
912
913
executable = lit .util .which (args [0 ], cmd_shenv .env ['PATH' ])
913
914
if not executable :
914
- raise InternalShellError (j , '%r: command not found' % j . args [0 ])
915
+ raise InternalShellError (j , '%r: command not found' % args [0 ])
915
916
916
917
# Replace uses of /dev/null with temporary files.
917
918
if kAvoidDevNull :
0 commit comments