[libcxx-commits] [libcxx] 3980e89 - [libcxx][lit] Simplify parsing of trailing executor arguments
Alex Richardson via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 21 01:04:16 PDT 2020
Author: Alex Richardson
Date: 2020-07-21T09:03:45+01:00
New Revision: 3980e8956b68f229a79194fbd46e4a91abf3aa2e
URL: https://github.com/llvm/llvm-project/commit/3980e8956b68f229a79194fbd46e4a91abf3aa2e
DIFF: https://github.com/llvm/llvm-project/commit/3980e8956b68f229a79194fbd46e4a91abf3aa2e.diff
LOG: [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
Added:
Modified:
libcxx/utils/run.py
libcxx/utils/ssh.py
Removed:
################################################################################
diff --git a/libcxx/utils/run.py b/libcxx/utils/run.py
index e88fff128248..cdfa2387b22d 100755
--- a/libcxx/utils/run.py
+++ b/libcxx/utils/run.py
@@ -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:
diff --git a/libcxx/utils/ssh.py b/libcxx/utils/ssh.py
index f74ed785bbbf..876e35460dc7 100755
--- a/libcxx/utils/ssh.py
+++ b/libcxx/utils/ssh.py
@@ -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)]
More information about the libcxx-commits
mailing list