Reviewers: Jakob,

Description:
Add presubmit check for header inclusion violation.

This warns about include directives of inline headers within normal
header files. Note that this warning should not close the tree or
prevent the CQ from landing the patch.

[email protected]

Please review this at https://codereview.chromium.org/1293273005/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+35, -0 lines):
  M PRESUBMIT.py


Index: PRESUBMIT.py
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index b0b811dc41a82a74d099e7a1c5ce29f98630c28e..df1e44f8916c27d7f2e0a135e44f3588352b45b4 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -141,6 +141,39 @@ def _CheckUnwantedDependencies(input_api, output_api):
   return results


+def _CheckNoInlineHeaderIncludesInNormalHeaders(input_api, output_api):
+  """Attempts to prevent inclusion in inline headers into normal header
+  files. This tries to establish a layering where inline headers can be
+  included by other inline headers or compilation units only."""
+  file_inclusion_pattern = r'(?!.+-inl\.h).+\.h'
+  include_directive_pattern = input_api.re.compile(r'#include ".+-inl.h"')
+  include_warning = (
+    'You might be including an inline header (e.g. foo-inl.h) within a\n'
+    'normal header (e.g. bar.h) file.  Can you avoid introducing the\n'
+    '#include?  The commit queue will not block on this warning.')
+
+  def FilterFile(affected_file):
+    black_list = (_EXCLUDED_PATHS +
+                  input_api.DEFAULT_BLACK_LIST)
+    return input_api.FilterSourceFile(
+      affected_file,
+      white_list=(file_inclusion_pattern, ),
+      black_list=black_list)
+
+  problems = []
+  for f in input_api.AffectedSourceFiles(FilterFile):
+    local_path = f.LocalPath()
+    for line_number, line in f.ChangedContents():
+      if (include_directive_pattern.search(line)):
+        problems.append(
+          '%s:%d\n    %s' % (local_path, line_number, line.strip()))
+
+  if problems:
+    return [output_api.PresubmitPromptOrNotify(include_warning, problems)]
+  else:
+    return []
+
+
 def _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api):
   """Attempts to prevent use of functions intended only for testing in
   non-testing code. For now this is just a best-effort implementation
@@ -195,6 +228,8 @@ def _CommonChecks(input_api, output_api):
   results.extend(_CheckUnwantedDependencies(input_api, output_api))
   results.extend(
       _CheckNoProductionCodeUsingTestOnlyFunctions(input_api, output_api))
+  results.extend(
+      _CheckNoInlineHeaderIncludesInNormalHeaders(input_api, output_api))
   return results




--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to