@@ -719,6 +719,20 @@ def processRedirects(cmd, stdin_source, cmd_shenv, opened_files):
719
719
720
720
return std_fds
721
721
722
+ def _expandLateSubstitutions (arguments , cwd ):
723
+ for i , arg in enumerate (arguments ):
724
+ if not isinstance (arg , str ):
725
+ continue
726
+ def _replaceReadFile (match ):
727
+ filePath = match .group (1 )
728
+ if not os .path .isabs (filePath ):
729
+ filePath = os .path .join (cwd , filePath )
730
+ with open (filePath ) as fileHandle :
731
+ return fileHandle .read ()
732
+
733
+ arguments [i ] = re .sub (r"%{readfile:([^}]*)}" , _replaceReadFile , arg )
734
+
735
+ return arguments
722
736
723
737
def _executeShCmd (cmd , shenv , results , timeoutHelper ):
724
738
if timeoutHelper .timeoutReached ():
@@ -834,6 +848,9 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
834
848
# Ensure args[0] is hashable.
835
849
args [0 ] = expand_glob (args [0 ], cmd_shenv .cwd )[0 ]
836
850
851
+ # Expand all late substitutions
852
+ args = _expandLateSubstitutions (args , cmd_shenv .cwd )
853
+
837
854
inproc_builtin = inproc_builtins .get (args [0 ], None )
838
855
if inproc_builtin and (args [0 ] != "echo" or len (cmd .commands ) == 1 ):
839
856
# env calling an in-process builtin is useless, so we take the safe
0 commit comments