|
17 | 17 | import argparse
|
18 | 18 | import os
|
19 | 19 | import posixpath
|
| 20 | +import shlex |
20 | 21 | import subprocess
|
21 | 22 | import sys
|
22 | 23 | import tarfile
|
23 | 24 | import tempfile
|
24 | 25 |
|
| 26 | +def ssh(args, command): |
| 27 | + cmd = ['ssh', '-oBatchMode=yes'] |
| 28 | + if args.extra_ssh_args is not None: |
| 29 | + cmd.extend(shlex.split(args.extra_ssh_args)) |
| 30 | + return cmd + [args.host, command] |
| 31 | + |
| 32 | + |
| 33 | +def scp(args, src, dst): |
| 34 | + cmd = ['scp', '-q', '-oBatchMode=yes'] |
| 35 | + if args.extra_scp_args is not None: |
| 36 | + cmd.extend(shlex.split(args.extra_scp_args)) |
| 37 | + return cmd + [src, '{}:{}'.format(args.host, dst)] |
| 38 | + |
25 | 39 |
|
26 | 40 | def main():
|
27 | 41 | parser = argparse.ArgumentParser()
|
28 | 42 | parser.add_argument('--host', type=str, required=True)
|
29 | 43 | parser.add_argument('--execdir', type=str, required=True)
|
| 44 | + parser.add_argument('--extra-ssh-args', type=str, required=False) |
| 45 | + parser.add_argument('--extra-scp-args', type=str, required=False) |
30 | 46 | parser.add_argument('--codesign_identity', type=str, required=False, default=None)
|
31 | 47 | parser.add_argument('--env', type=str, nargs='*', required=False, default=dict())
|
32 | 48 | parser.add_argument("command", nargs=argparse.ONE_OR_MORE)
|
33 | 49 | args = parser.parse_args()
|
34 | 50 | commandLine = args.command
|
35 | 51 |
|
36 |
| - ssh = lambda command: ['ssh', '-oBatchMode=yes', args.host, command] |
37 |
| - scp = lambda src, dst: ['scp', '-q', '-oBatchMode=yes', src, '{}:{}'.format(args.host, dst)] |
38 |
| - |
39 | 52 | # Create a temporary directory where the test will be run.
|
40 | 53 | # That is effectively the value of %T on the remote host.
|
41 |
| - tmp = subprocess.check_output(ssh('mktemp -d /tmp/libcxx.XXXXXXXXXX'), universal_newlines=True).strip() |
| 54 | + tmp = subprocess.check_output(ssh(args, 'mktemp -d /tmp/libcxx.XXXXXXXXXX'), universal_newlines=True).strip() |
42 | 55 |
|
43 | 56 | # HACK:
|
44 | 57 | # If an argument is a file that ends in `.tmp.exe`, assume it is the name
|
@@ -67,7 +80,7 @@ def main():
|
67 | 80 | # the temporary file while still open doesn't work on Windows.
|
68 | 81 | tmpTar.close()
|
69 | 82 | remoteTarball = pathOnRemote(tmpTar.name)
|
70 |
| - subprocess.check_call(scp(tmpTar.name, remoteTarball)) |
| 83 | + subprocess.check_call(scp(args, tmpTar.name, remoteTarball)) |
71 | 84 | finally:
|
72 | 85 | # Make sure we close the file in case an exception happens before
|
73 | 86 | # we've closed it above -- otherwise close() is idempotent.
|
@@ -97,12 +110,12 @@ def main():
|
97 | 110 | remoteCommands.append(subprocess.list2cmdline(commandLine))
|
98 | 111 |
|
99 | 112 | # Finally, SSH to the remote host and execute all the commands.
|
100 |
| - rc = subprocess.call(ssh(' && '.join(remoteCommands))) |
| 113 | + rc = subprocess.call(ssh(args, ' && '.join(remoteCommands))) |
101 | 114 | return rc
|
102 | 115 |
|
103 | 116 | finally:
|
104 | 117 | # Make sure the temporary directory is removed when we're done.
|
105 |
| - subprocess.check_call(ssh('rm -r {}'.format(tmp))) |
| 118 | + subprocess.check_call(ssh(args, 'rm -r {}'.format(tmp))) |
106 | 119 |
|
107 | 120 |
|
108 | 121 | if __name__ == '__main__':
|
|
0 commit comments