[libc++] Use proper shell escaping in the executors

This was originally committed as f8452ddfcc33 and reverted in 7cb1aa9d9368.
The issue was that shell builtins were being escaped too, and apparently
Bash won't execute a builtin when it is quoted e.g. '!'. Instead, it
thinks it's a command and it can't find it.

Re-committing the change with that issue fixed.

Cr-Mirrored-From: https://chromium.googlesource.com/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 5eb8d45ab5b85cb3a2edfe995cbf1d4b1beae462
diff --git a/utils/run.py b/utils/run.py
index 7cdf652..0453e4a 100644
--- a/utils/run.py
+++ b/utils/run.py
@@ -30,11 +30,11 @@
     if len(remaining) < 2:
         sys.stderr.write('Missing actual commands to run')
         exit(1)
-    remaining = remaining[1:] # Skip the '--'
+    commandLine = remaining[1:] # Skip the '--'
 
     # Do any necessary codesigning.
     if args.codesign_identity:
-        exe = remaining[0]
+        exe = commandLine[0]
         rc = subprocess.call(['xcrun', 'codesign', '-f', '-s', args.codesign_identity, exe], env={})
         if rc != 0:
             sys.stderr.write('Failed to codesign: ' + exe)
@@ -57,8 +57,8 @@
             else:
                 shutil.copy2(dep, args.execdir)
 
-        # Run the executable with the given environment in the execution directory.
-        return subprocess.call(' '.join(remaining), cwd=args.execdir, env=env, shell=True)
+        # Run the command line with the given environment in the execution directory.
+        return subprocess.call(subprocess.list2cmdline(commandLine), cwd=args.execdir, env=env, shell=True)
     finally:
         shutil.rmtree(args.execdir)
 
diff --git a/utils/ssh.py b/utils/ssh.py
index c7d8c97..4bb983e 100644
--- a/utils/ssh.py
+++ b/utils/ssh.py
@@ -97,10 +97,11 @@
         # host by transforming the path of test-executables to their path in the
         # temporary directory, where we know they have been copied when we handled
         # test dependencies above.
+        commandLine = (pathOnRemote(x) if isTestExe(x) else x for x in commandLine)
         remoteCommands += [
             'cd {}'.format(tmp),
             'export {}'.format(' '.join(args.env)),
-            ' '.join(pathOnRemote(x) if isTestExe(x) else x for x in commandLine)
+            subprocess.list2cmdline(commandLine)
         ]
 
         # Finally, SSH to the remote host and execute all the commands.