[libcxx][lit] Simplify parsing of trailing executor arguments

Adding a positional argparse.ONE_OR_MORE arguments will correctly remove
the "--" separator after --env and parse only the command. This also has
the advantage that misspelled flags raise an argparse error rather than
silently being added to the command to be executed.

I discovered this while adding a new commandline option to ssh.py to allow
passing additional arguments to the scp/ssh commands since this is required
for our CHERI CI where 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.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D84096
This commit is contained in:
Alex Richardson 2020-07-21 08:35:47 +01:00
parent aa84e6e579
commit 3980e8956b
2 changed files with 6 additions and 13 deletions

View File

@ -23,12 +23,9 @@ def main():
parser.add_argument('--execdir', type=str, required=True)
parser.add_argument('--codesign_identity', type=str, required=False, default=None)
parser.add_argument('--env', type=str, nargs='*', required=False, default=dict())
(args, remaining) = parser.parse_known_args(sys.argv[1:])
if len(remaining) < 2:
sys.stderr.write('Missing actual commands to run')
exit(1)
commandLine = remaining[1:] # Skip the '--'
parser.add_argument("command", nargs=argparse.ONE_OR_MORE)
args = parser.parse_args()
commandLine = args.command
# Do any necessary codesigning.
if args.codesign_identity:

View File

@ -29,13 +29,9 @@ def main():
parser.add_argument('--execdir', type=str, required=True)
parser.add_argument('--codesign_identity', type=str, required=False, default=None)
parser.add_argument('--env', type=str, nargs='*', required=False, default=dict())
(args, remaining) = parser.parse_known_args(sys.argv[1:])
if len(remaining) < 2:
sys.stderr.write('Missing actual commands to run')
return 1
commandLine = remaining[1:] # Skip the '--'
parser.add_argument("command", nargs=argparse.ONE_OR_MORE)
args = parser.parse_args()
commandLine = args.command
ssh = lambda command: ['ssh', '-oBatchMode=yes', args.host, command]
scp = lambda src, dst: ['scp', '-q', '-oBatchMode=yes', src, '{}:{}'.format(args.host, dst)]