[UpdateTestChecks] Update tests option

Summary:
Port of new feature introduced https://reviews.llvm.org/D65610 to other update scripts.

- update_*_checks.py: add an alias -u for --update-only
- port --update-only to other update_*_test_checks.py scripts
- update script aborts if the test file was generated by another update_*_test_checks.py utility

Reviewers: lebedev.ri, RKSimon, MaskRay, reames, gbedwell

Reviewed By: MaskRay

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D65793

llvm-svn: 368174
diff --git a/llvm/utils/update_test_checks.py b/llvm/utils/update_test_checks.py
index 0783a650..fa8e1d4 100755
--- a/llvm/utils/update_test_checks.py
+++ b/llvm/utils/update_test_checks.py
@@ -62,23 +62,24 @@
                       help='The opt binary used to generate the test case')
   parser.add_argument(
       '--function', help='The function in the test file to update')
-  parser.add_argument('--update-only', action='store_true',
+  parser.add_argument('-u', '--update-only', action='store_true',
                       help='Only update test if it was already autogened')
   parser.add_argument('tests', nargs='+')
   args = parser.parse_args()
 
-  autogenerated_note = (ADVERT + 'utils/' + os.path.basename(__file__))
+  script_name = os.path.basename(__file__)
+  autogenerated_note = (ADVERT + 'utils/' + script_name)
 
   opt_basename = os.path.basename(args.opt_binary)
   if not re.match(r'^opt(-\d+)?$', opt_basename):
-    print('ERROR: Unexpected opt name: ' + opt_basename, file=sys.stderr)
+    common.error('Unexpected opt name: ' + opt_basename)
     sys.exit(1)
   opt_basename = 'opt'
 
   test_paths = []
   for test in args.tests:
     if not glob.glob(test):
-      print("WARNING: Test file '%s' was not found. Ignoring it." % (test,), file=sys.stderr)
+      common.warn("Test file '%s' was not found. Ignoring it." % (test,))
       continue
     test_paths.append(test)
 
@@ -88,9 +89,14 @@
     with open(test) as f:
       input_lines = [l.rstrip() for l in f]
 
+    first_line = input_lines[0] if input_lines else ""
+    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 args.update_only:
-      if len(input_lines) == 0 or 'autogenerated' not in input_lines[0]:
-        print("Skipping test which isn't autogenerated: " + test, file=sys.stderr)
+      if not first_line or 'autogenerated' not in first_line:
+        common.warn("Skipping test which isn't autogenerated: " + test)
         continue
 
     raw_lines = [m.group(1)
@@ -110,17 +116,17 @@
     prefix_list = []
     for l in run_lines:
       if '|' not in l:
-        print('WARNING: Skipping unparseable RUN line: ' + l, file=sys.stderr)
+        common.warn('Skipping unparseable RUN line: ' + l)
         continue
 
       (tool_cmd, filecheck_cmd) = tuple([cmd.strip() for cmd in l.split('|', 1)])
       common.verify_filecheck_prefixes(filecheck_cmd)
       if not tool_cmd.startswith(opt_basename + ' '):
-        print('WARNING: Skipping non-%s RUN line: %s' % (opt_basename, l), file=sys.stderr)
+        common.warn('Skipping non-%s RUN line: %s' % (opt_basename, l))
         continue
 
       if not filecheck_cmd.startswith('FileCheck '):
-        print('WARNING: Skipping non-FileChecked RUN line: ' + l, file=sys.stderr)
+        common.warn('Skipping non-FileChecked RUN line: ' + l)
         continue
 
       tool_cmd_args = tool_cmd[len(opt_basename):].strip()