[libcxx-commits] [PATCH] D84096: [libcxx][lit] Simplify parsing of trailing executor arguments

Alexander Richardson via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jul 18 05:52:51 PDT 2020


arichardson created this revision.
arichardson added reviewers: libc++, ldionne.
Herald added subscribers: libcxx-commits, dexonsmith.
Herald added a project: libc++.
Herald added 1 blocking reviewer(s): libc++.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84096

Files:
  libcxx/utils/run.py
  libcxx/utils/ssh.py


Index: libcxx/utils/ssh.py
===================================================================
--- libcxx/utils/ssh.py
+++ libcxx/utils/ssh.py
@@ -29,13 +29,14 @@
     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:])
+    parser.add_argument("command", nargs=argparse.ONE_OR_MORE)
+    args = parser.parse_args()
 
-    if len(remaining) < 2:
+    commandLine = args.command  # argparse will strip the initial '--'
+    if len(commandLine) < 1:
         sys.stderr.write('Missing actual commands to run')
         return 1
 
-    commandLine = remaining[1:] # Skip the '--'
 
     ssh = lambda command: ['ssh', '-oBatchMode=yes', args.host, command]
     scp = lambda src, dst: ['scp', '-q', '-oBatchMode=yes', src, '{}:{}'.format(args.host, dst)]
Index: libcxx/utils/run.py
===================================================================
--- libcxx/utils/run.py
+++ libcxx/utils/run.py
@@ -23,12 +23,13 @@
     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:])
+    parser.add_argument("command", nargs=argparse.ONE_OR_MORE)
+    args = parser.parse_args()
 
-    if len(remaining) < 2:
+    commandLine = args.command  # argparse will strip the initial '--'
+    if len(commandLine) < 1:
         sys.stderr.write('Missing actual commands to run')
         exit(1)
-    commandLine = remaining[1:] # Skip the '--'
 
     # Do any necessary codesigning.
     if args.codesign_identity:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84096.278992.patch
Type: text/x-patch
Size: 1884 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200718/d7bd5087/attachment.bin>


More information about the libcxx-commits mailing list