[M67 Dev][Tizen] Integrate GN and set up build environment
[platform/framework/web/chromium-efl.git] / chrome / PRESUBMIT.py
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Presubmit script for changes affecting chrome/
6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools.
9 """
10
11 import re
12
13 INCLUDE_CPP_FILES_ONLY = (
14   r'.*\.(cc|h)$',
15 )
16
17 INCLUDE_SOURCE_FILES_ONLY = (
18   r'.*\.(c|cc|cpp|h|m|mm)$',
19 )
20
21 EXCLUDE = (
22   # Objective C confuses everything.
23   r'.*cocoa.*',
24   r'.*_mac\.(cc|h)$',
25   r'.*_mac_.*',
26   # All the messages files do weird multiple include trickery
27   r'.*_messages.*\.h$',
28   r'render_messages.h$',
29   # Autogenerated window resources files are off limits
30   r'.*resource.h$',
31   # Header trickery
32   r'.*-inl\.h$',
33   # Has safe printf usage that cpplint complains about
34   r'safe_browsing_util\.cc$',
35 )
36
37 def _CheckChangeLintsClean(input_api, output_api):
38   """Makes sure that the chrome/ code is cpplint clean."""
39   black_list = input_api.DEFAULT_BLACK_LIST + EXCLUDE
40   sources = lambda x: input_api.FilterSourceFile(
41     x, white_list=INCLUDE_CPP_FILES_ONLY, black_list=black_list)
42   return input_api.canned_checks.CheckChangeLintsClean(
43       input_api, output_api, sources)
44
45
46 def _CheckNoContentUnitTestsInChrome(input_api, output_api):
47   """Makes sure that no unit tests from content/ are included in unit_tests."""
48   problems = []
49   for f in input_api.AffectedFiles():
50     if not f.LocalPath().endswith('BUILD.gn'):
51       continue
52
53     for line_num, line in f.ChangedContents():
54       m = re.search(r"'(.*\/content\/.*unittest.*)'", line)
55       if m:
56         problems.append(m.group(1))
57
58   if not problems:
59     return []
60   return [output_api.PresubmitPromptWarning(
61       'Unit tests located in content/ should be added to the ' +
62       'content_unittests target.',
63       items=problems)]
64
65
66 def _CheckNoOSIOSMacrosInChromeFile(input_api, f):
67   """Check for OS_IOS in a given file in chrome/."""
68   preprocessor_statement = input_api.re.compile(r'^\s*#')
69   ios_macro = input_api.re.compile(r'defined\(OS_IOS\)')
70   results = []
71   for lnum, line in f.ChangedContents():
72     if preprocessor_statement.search(line) and ios_macro.search(line):
73       results.append('    %s:%d' % (f.LocalPath(), lnum))
74
75   return results
76
77
78 def _CheckNoOSIOSMacrosInChrome(input_api, output_api):
79   """Check for OS_IOS which isn't used in chrome/."""
80   ios_macros = []
81   def SourceFilter(affected_file):
82     return input_api.FilterSourceFile(affected_file, INCLUDE_SOURCE_FILES_ONLY,
83                                       input_api.DEFAULT_BLACK_LIST)
84   for f in input_api.AffectedSourceFiles(SourceFilter):
85     ios_macros.extend(_CheckNoOSIOSMacrosInChromeFile(input_api, f))
86
87   if not ios_macros:
88     return []
89
90   return [output_api.PresubmitError(
91       'OS_IOS is not used in chrome/ but found in:\n', ios_macros)]
92
93
94 def _CommonChecks(input_api, output_api):
95   """Checks common to both upload and commit."""
96   results = []
97   results.extend(_CheckNoContentUnitTestsInChrome(input_api, output_api))
98   results.extend(_CheckNoOSIOSMacrosInChrome(input_api, output_api))
99   return results
100
101
102 def CheckChangeOnUpload(input_api, output_api):
103   results = []
104   results.extend(_CommonChecks(input_api, output_api))
105   results.extend(_CheckChangeLintsClean(input_api, output_api))
106   return results
107
108
109 def CheckChangeOnCommit(input_api, output_api):
110   results = []
111   results.extend(_CommonChecks(input_api, output_api))
112   return results