Skip to content

Commit 04f908b

Browse files
committed
[libcxx][lit] Add support for custom ssh/scp flags in ssh.py
In our CHERI Jenkins CI we need to pass `-F <custom_config_file>` to each ssh/scp command to set various arguments such as the localhost port, usage of controlmaster, etc. to speed up connections to our emulated QEMU systems. For our specific use-case I could have also added a single --ssh-config-file argument that can be used for both the scp and ssh commands, but being able to pass arbitrary extra flags for both commands seems more flexible. Reviewed By: #libc, ldionne Differential Revision: https://reviews.llvm.org/D84097
1 parent f0a78bd commit 04f908b

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

libcxx/utils/ssh.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,41 @@
1717
import argparse
1818
import os
1919
import posixpath
20+
import shlex
2021
import subprocess
2122
import sys
2223
import tarfile
2324
import tempfile
2425

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+
2539

2640
def main():
2741
parser = argparse.ArgumentParser()
2842
parser.add_argument('--host', type=str, required=True)
2943
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)
3046
parser.add_argument('--codesign_identity', type=str, required=False, default=None)
3147
parser.add_argument('--env', type=str, nargs='*', required=False, default=dict())
3248
parser.add_argument("command", nargs=argparse.ONE_OR_MORE)
3349
args = parser.parse_args()
3450
commandLine = args.command
3551

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-
3952
# Create a temporary directory where the test will be run.
4053
# 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()
4255

4356
# HACK:
4457
# If an argument is a file that ends in `.tmp.exe`, assume it is the name
@@ -67,7 +80,7 @@ def main():
6780
# the temporary file while still open doesn't work on Windows.
6881
tmpTar.close()
6982
remoteTarball = pathOnRemote(tmpTar.name)
70-
subprocess.check_call(scp(tmpTar.name, remoteTarball))
83+
subprocess.check_call(scp(args, tmpTar.name, remoteTarball))
7184
finally:
7285
# Make sure we close the file in case an exception happens before
7386
# we've closed it above -- otherwise close() is idempotent.
@@ -97,12 +110,12 @@ def main():
97110
remoteCommands.append(subprocess.list2cmdline(commandLine))
98111

99112
# 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)))
101114
return rc
102115

103116
finally:
104117
# 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)))
106119

107120

108121
if __name__ == '__main__':

0 commit comments

Comments
 (0)