Hi rafael,

This revision has a couple of small changes to make check_cfc.py made so it 
works better with build systems.

gcc/clang options which output dependency files instead of object files (e.g. 
-M, -MM) are identified and checks are not performed in these cases.

When reporting a check failure, the input file name is reported which can help 
to identify where the problem was in large build logs, particularly with 
parallel builds.

Please let me know if okay to commit?

http://reviews.llvm.org/D10183

Files:
  utils/check_cfc/check_cfc.py
  utils/check_cfc/test_check_cfc.py

Index: utils/check_cfc/check_cfc.py
===================================================================
--- utils/check_cfc/check_cfc.py
+++ utils/check_cfc/check_cfc.py
@@ -213,16 +213,18 @@
 
 def is_normal_compile(args):
     """Check if this is a normal compile which will output an object file 
rather
-    than a preprocess or link."""
+    than a preprocess or link. args is a list of command line arguments."""
     compile_step = '-c' in args
     # Bitcode cannot be disassembled in the same way
     bitcode = '-flto' in args or '-emit-llvm' in args
     # Version and help are queries of the compiler and override -c if specified
     query = '--version' in args or '--help' in args
+    # Options to output dependency files for make
+    dependency = '-M' in args or '-MM' in args
     # Check if the input is recognised as a source file (this may be too
     # strong a restriction)
     input_is_valid = bool(get_input_file(args))
-    return compile_step and not bitcode and not query and input_is_valid
+    return compile_step and not bitcode and not query and not dependency and 
input_is_valid
 
 def run_step(command, my_env, error_on_failure):
     """Runs a step of the compilation. Reports failure as exception."""
@@ -367,7 +369,7 @@
                 checker.perform_check(arguments_a, my_env)
             except WrapperCheckException as e:
                 # Check failure
-                print(e.msg, file=sys.stderr)
+                print("{} {}".format(get_input_file(arguments_a), e.msg), 
file=sys.stderr)
 
                 # Remove file to comply with build system expectations (no
                 # output file if failed)
Index: utils/check_cfc/test_check_cfc.py
===================================================================
--- utils/check_cfc/test_check_cfc.py
+++ utils/check_cfc/test_check_cfc.py
@@ -103,6 +103,16 @@
             check_cfc.is_normal_compile(['clang', '-c', 'test.cpp', 
'--version']))
         self.assertFalse(
             check_cfc.is_normal_compile(['clang', '-c', 'test.cpp', '--help']))
+        # Outputting dependency files is not a normal compile
+        self.assertFalse(
+            check_cfc.is_normal_compile(['clang', '-c', '-M', 'test.cpp']))
+        self.assertFalse(
+            check_cfc.is_normal_compile(['clang', '-c', '-MM', 'test.cpp']))
+        # Creating a dependency file as a side effect still outputs an object 
file
+        self.assertTrue(
+            check_cfc.is_normal_compile(['clang', '-c', '-MD', 'test.cpp']))
+        self.assertTrue(
+            check_cfc.is_normal_compile(['clang', '-c', '-MMD', 'test.cpp']))
 
     def test_replace_output_file(self):
         self.assertEqual(check_cfc.replace_output_file(

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: utils/check_cfc/check_cfc.py
===================================================================
--- utils/check_cfc/check_cfc.py
+++ utils/check_cfc/check_cfc.py
@@ -213,16 +213,18 @@
 
 def is_normal_compile(args):
     """Check if this is a normal compile which will output an object file rather
-    than a preprocess or link."""
+    than a preprocess or link. args is a list of command line arguments."""
     compile_step = '-c' in args
     # Bitcode cannot be disassembled in the same way
     bitcode = '-flto' in args or '-emit-llvm' in args
     # Version and help are queries of the compiler and override -c if specified
     query = '--version' in args or '--help' in args
+    # Options to output dependency files for make
+    dependency = '-M' in args or '-MM' in args
     # Check if the input is recognised as a source file (this may be too
     # strong a restriction)
     input_is_valid = bool(get_input_file(args))
-    return compile_step and not bitcode and not query and input_is_valid
+    return compile_step and not bitcode and not query and not dependency and input_is_valid
 
 def run_step(command, my_env, error_on_failure):
     """Runs a step of the compilation. Reports failure as exception."""
@@ -367,7 +369,7 @@
                 checker.perform_check(arguments_a, my_env)
             except WrapperCheckException as e:
                 # Check failure
-                print(e.msg, file=sys.stderr)
+                print("{} {}".format(get_input_file(arguments_a), e.msg), file=sys.stderr)
 
                 # Remove file to comply with build system expectations (no
                 # output file if failed)
Index: utils/check_cfc/test_check_cfc.py
===================================================================
--- utils/check_cfc/test_check_cfc.py
+++ utils/check_cfc/test_check_cfc.py
@@ -103,6 +103,16 @@
             check_cfc.is_normal_compile(['clang', '-c', 'test.cpp', '--version']))
         self.assertFalse(
             check_cfc.is_normal_compile(['clang', '-c', 'test.cpp', '--help']))
+        # Outputting dependency files is not a normal compile
+        self.assertFalse(
+            check_cfc.is_normal_compile(['clang', '-c', '-M', 'test.cpp']))
+        self.assertFalse(
+            check_cfc.is_normal_compile(['clang', '-c', '-MM', 'test.cpp']))
+        # Creating a dependency file as a side effect still outputs an object file
+        self.assertTrue(
+            check_cfc.is_normal_compile(['clang', '-c', '-MD', 'test.cpp']))
+        self.assertTrue(
+            check_cfc.is_normal_compile(['clang', '-c', '-MMD', 'test.cpp']))
 
     def test_replace_output_file(self):
         self.assertEqual(check_cfc.replace_output_file(
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to