Skip to content

Commit 77d8ce5

Browse files
committed
[libc++] Add a --verbose option to ssh.py to help debug failures
1 parent ededcb0 commit 77d8ce5

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

libcxx/utils/ssh.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def scp(args, src, dst):
3939
cmd.extend(shlex.split(args.extra_scp_args))
4040
return cmd + [src, "{}:{}".format(args.host, dst)]
4141

42+
def runCommand(command, *args, **kwargs):
43+
return subprocess.run(command, *args, **kwargs)
4244

4345
def main():
4446
parser = argparse.ArgumentParser()
@@ -49,19 +51,25 @@ def main():
4951
parser.add_argument("--extra-scp-args", type=str, required=False)
5052
parser.add_argument("--codesign_identity", type=str, required=False, default=None)
5153
parser.add_argument("--env", type=str, nargs="*", required=False, default=[])
52-
parser.add_argument(
53-
"--prepend_env", type=str, nargs="*", required=False, default=[]
54-
)
54+
parser.add_argument("--prepend_env", type=str, nargs="*", required=False, default=[])
55+
parser.add_argument("-v", "--verbose", action='store_true')
5556
parser.add_argument("command", nargs=argparse.ONE_OR_MORE)
5657
args = parser.parse_args()
5758
commandLine = args.command
5859

60+
def runCommand(command, *args_, **kwargs):
61+
if args.verbose:
62+
print(f"$ {' '.join(command)}")
63+
return subprocess.run(command, *args_, **kwargs)
64+
5965
# Create a temporary directory where the test will be run.
6066
# That is effectively the value of %T on the remote host.
61-
tmp = subprocess.check_output(
67+
tmp = runCommand(
6268
ssh(args, "mktemp -d {}/libcxx.XXXXXXXXXX".format(args.tempdir)),
6369
universal_newlines=True,
64-
).strip()
70+
check=True,
71+
capture_output=True
72+
).stdout.strip()
6573

6674
# HACK:
6775
# If an argument is a file that ends in `.tmp.exe`, assume it is the name
@@ -77,10 +85,8 @@ def main():
7785
# Do any necessary codesigning of test-executables found in the command line.
7886
if args.codesign_identity:
7987
for exe in filter(isTestExe, commandLine):
80-
subprocess.check_call(
81-
["xcrun", "codesign", "-f", "-s", args.codesign_identity, exe],
82-
env={},
83-
)
88+
codesign = ["xcrun", "codesign", "-f", "-s", args.codesign_identity, exe]
89+
runCommand(codesign, env={}, check=True)
8490

8591
# tar up the execution directory (which contains everything that's needed
8692
# to run the test), and copy the tarball over to the remote host.
@@ -93,7 +99,7 @@ def main():
9399
# the temporary file while still open doesn't work on Windows.
94100
tmpTar.close()
95101
remoteTarball = pathOnRemote(tmpTar.name)
96-
subprocess.check_call(scp(args, tmpTar.name, remoteTarball))
102+
runCommand(scp(args, tmpTar.name, remoteTarball), check=True)
97103
finally:
98104
# Make sure we close the file in case an exception happens before
99105
# we've closed it above -- otherwise close() is idempotent.
@@ -130,12 +136,12 @@ def main():
130136
remoteCommands.append(subprocess.list2cmdline(commandLine))
131137

132138
# Finally, SSH to the remote host and execute all the commands.
133-
rc = subprocess.call(ssh(args, " && ".join(remoteCommands)))
139+
rc = runCommand(ssh(args, " && ".join(remoteCommands))).returncode
134140
return rc
135141

136142
finally:
137143
# Make sure the temporary directory is removed when we're done.
138-
subprocess.check_call(ssh(args, "rm -r {}".format(tmp)))
144+
runCommand(ssh(args, "rm -r {}".format(tmp)), check=True)
139145

140146

141147
if __name__ == "__main__":

0 commit comments

Comments
 (0)