[PATCH] D69701: [Utils] Allow "on-the-fly" argument changes for update_test_check scripts

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 31 20:53:55 PDT 2019


jdoerfert created this revision.
jdoerfert added reviewers: lebedev.ri, greened, spatel, xbolva00, RKSimon, mehdi_amini, davezarzycki, arichardson, nikic.
Herald added a subscriber: bollu.
Herald added a project: LLVM.

Update test scripts were limited because they performed a single action
on the entire file and if that action was controlled by arguments, like
the one introduced in D68819 <https://reviews.llvm.org/D68819>, there was no record of it.

This patch introduces the capability of changing the arguments passed to
the script "on-the-fly" while processing a test file. In addition, an
"on/off" switch was added so that processing can be disabled for parts
of the file where the content is simply copied. The last extension is a
record of the invocation arguments in the auto generated NOTE. These
arguments are also picked up in a subsequent invocation, allowing
updates with special options enabled without user interaction.

To change the arguments the string `UTC_ARGS:` has to be present in a
line, followed by "additional command line arguments". That is
everything that follows `UTC_ARGS:` will be added to a growing list
of "command line arguments" which is reparsed after every update.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69701

Files:
  llvm/utils/UpdateTestChecks/common.py
  llvm/utils/update_test_checks.py


Index: llvm/utils/update_test_checks.py
===================================================================
--- llvm/utils/update_test_checks.py
+++ llvm/utils/update_test_checks.py
@@ -70,6 +70,8 @@
                       help='Keep function signature information around for the check line')
   parser.add_argument('--scrub-attributes', action='store_true',
                       help='Remove attribute annotations (#0) from the end of check line')
+  parser.add_argument('--turn', choices=['on', 'off'], default='on',
+                      help='Initial state, check lines are upded only in "on" state')
   parser.add_argument('tests', nargs='+')
   args = parser.parse_args()
 
@@ -94,6 +96,7 @@
   # On Windows we must expand the patterns ourselves.
   test_paths = [test for pattern in args.tests for test in glob.glob(pattern)]
   for test in test_paths:
+    argv = sys.argv[:]
     if args.verbose:
       print('Scanning for RUN lines in test file: ' + test, file=sys.stderr)
     with open(test) as f:
@@ -103,6 +106,9 @@
     if 'autogenerated' in first_line and script_name not in first_line:
       common.warn("Skipping test which wasn't autogenerated by " + script_name, test)
       continue
+    if first_line and 'autogenerated' in first_line:
+      args = common.check_for_command(first_line, parser, args, argv)
+    autogenerated_note += common.get_autogennote_suffix(parser, args)
 
     if args.update_only:
       if not first_line or 'autogenerated' not in first_line:
@@ -175,6 +181,14 @@
     output_lines.append(autogenerated_note)
 
     for input_line in input_lines:
+      # Discard any previous script advertising.
+      if input_line.startswith(ADVERT):
+        continue
+
+      args = common.check_for_command(input_line, parser, args, argv)
+      if args.turn == 'off':
+          output_lines.append(input_line)
+          continue
       if is_in_function_start:
         if input_line == '':
           continue
@@ -201,10 +215,6 @@
           is_in_function = False
         continue
 
-      # Discard any previous script advertising.
-      if input_line.startswith(ADVERT):
-        continue
-
       # If it's outside a function, it just gets copied to the output.
       output_lines.append(input_line)
 
Index: llvm/utils/UpdateTestChecks/common.py
===================================================================
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -49,6 +49,8 @@
 CHECK_PREFIX_RE = re.compile(r'--?check-prefix(?:es)?[= ](\S+)')
 PREFIX_RE = re.compile('^[a-zA-Z0-9_-]+$')
 CHECK_RE = re.compile(r'^\s*[;#]\s*([^:]+?)(?:-NEXT|-NOT|-DAG|-LABEL|-SAME)?:')
+UTC_ARGS_KEY = 'UTC_ARGS:'
+UTC_ARGS_CMD = re.compile(r'.*' + UTC_ARGS_KEY + '\s*(?P<cmd>.*)\s*$')
 
 OPT_FUNCTION_RE = re.compile(
     r'^\s*define\s+(?:internal\s+)?[^@]*@(?P<func>[\w-]+?)\s*'
@@ -357,3 +359,26 @@
         check_prefix(prefix)
         if prefixes.count(prefix) > 1:
           warn("Supplied prefix '%s' is not unique in the prefix list." % (prefix,))
+
+def get_autogennote_suffix(parser, args):
+    autogenerated_note_args = ''
+    for k, v in args._get_kwargs():
+        if parser.get_default(k) == v or k == 'tests':
+            continue
+        k = k.replace('_', '-')
+        if type(v) is bool:
+            autogenerated_note_args += '--%s' % (k)
+        else:
+            autogenerated_note_args += '--%s %s' % (k, v)
+    if autogenerated_note_args:
+        autogenerated_note_args = ' %s %s' % (UTC_ARGS_KEY, autogenerated_note_args)
+    return autogenerated_note_args
+
+
+def check_for_command(line, parser, args, argv):
+    cmd_m = UTC_ARGS_CMD.match(line)
+    if cmd_m:
+        cmd = cmd_m.group('cmd').strip().split(' ')
+        argv += cmd
+        args = parser.parse_args(argv)
+    return args


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69701.227395.patch
Type: text/x-patch
Size: 3813 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191101/1493a114/attachment-0001.bin>


More information about the llvm-commits mailing list