Update code documentation for enum in EWK headers
[platform/framework/web/chromium-efl.git] / chrome / PRESUBMIT.py
1 # Copyright 2011 The Chromium Authors
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
12 import re
13
14 INCLUDE_CPP_FILES_ONLY = (
15   r'.*\.(cc|h)$',
16 )
17
18 INCLUDE_SOURCE_FILES_ONLY = (
19   r'.*\.(c|cc|cpp|h|m|mm)$',
20 )
21
22 EXCLUDE = (
23   # Objective C confuses everything.
24   r'.*cocoa.*',
25   r'.*_mac\.(cc|h)$',
26   r'.*_mac_.*',
27   # All the messages files do weird multiple include trickery
28   r'.*_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   files_to_skip = input_api.DEFAULT_FILES_TO_SKIP + EXCLUDE
40   sources = lambda x: input_api.FilterSourceFile(
41     x, files_to_check=INCLUDE_CPP_FILES_ONLY, files_to_skip=files_to_skip)
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 _CheckNoIsAppleBuildFlagsInChromeFile(input_api, f):
67   """Check for IS_APPLE in a given file in chrome/."""
68   preprocessor_statement = input_api.re.compile(r'^\s*#')
69   apple_buildflag = input_api.re.compile(r'BUILDFLAG\(IS_APPLE\)')
70   results = []
71   for lnum, line in f.ChangedContents():
72     if preprocessor_statement.search(line) and apple_buildflag.search(line):
73       results.append('    %s:%d' % (f.LocalPath(), lnum))
74
75   return results
76
77
78 def _CheckNoIsAppleBuildFlagsInChrome(input_api, output_api):
79   """Check for IS_APPLE which isn't used in chrome/."""
80   apple_buildflags = []
81   def SourceFilter(affected_file):
82     return input_api.FilterSourceFile(affected_file, INCLUDE_SOURCE_FILES_ONLY,
83                                       input_api.DEFAULT_FILES_TO_SKIP)
84   for f in input_api.AffectedSourceFiles(SourceFilter):
85     apple_buildflags.extend(_CheckNoIsAppleBuildFlagsInChromeFile(input_api, f))
86
87   if not apple_buildflags:
88     return []
89
90   return [output_api.PresubmitError(
91       'IS_APPLE is not used in chrome/ but found in:\n', apple_buildflags)]
92
93
94 def _CheckNoIsIOSBuildFlagsInChromeFile(input_api, f):
95   """Check for IS_IOS in a given file in chrome/."""
96   preprocessor_statement = input_api.re.compile(r'^\s*#')
97   ios_buildflag = input_api.re.compile(r'BUILDFLAG\(IS_IOS\)')
98   results = []
99   for lnum, line in f.ChangedContents():
100     if preprocessor_statement.search(line) and ios_buildflag.search(line):
101       results.append('    %s:%d' % (f.LocalPath(), lnum))
102
103   return results
104
105
106 def _CheckNoIsIOSBuildFlagsInChrome(input_api, output_api):
107   """Check for IS_IOS which isn't used in chrome/."""
108   ios_buildflags = []
109   def SourceFilter(affected_file):
110     return input_api.FilterSourceFile(affected_file, INCLUDE_SOURCE_FILES_ONLY,
111                                       input_api.DEFAULT_FILES_TO_SKIP)
112   for f in input_api.AffectedSourceFiles(SourceFilter):
113     ios_buildflags.extend(_CheckNoIsIOSBuildFlagsInChromeFile(input_api, f))
114
115   if not ios_buildflags:
116     return []
117
118   return [output_api.PresubmitError(
119       'IS_IOS is not used in chrome/ but found in:\n', ios_buildflags)]
120
121
122 def _CheckBreakingInstallerVersionBumpNeeded(input_api, output_api):
123   files = []
124   breaking_version_installer_updated = False
125
126   def _FilterFile(affected_file):
127     return input_api.FilterSourceFile(
128         affected_file,
129         files_to_check=input_api.DEFAULT_FILES_TO_CHECK + (r'.*\.release',))
130   for f in input_api.AffectedSourceFiles(_FilterFile):
131     # Normalize the local path to Linux-style path separators so that the path
132     # comparisons work on Windows as well.
133     local_path = f.LocalPath().replace('\\', '/')
134     breaking_version_installer_updated |= (local_path ==
135     'chrome/installer/setup/last_breaking_installer_version.cc')
136     if (local_path == 'chrome/installer/mini_installer/chrome.release' or
137         local_path.startswith('chrome/test/mini_installer')):
138       files.append(local_path)
139
140   if files and not breaking_version_installer_updated:
141     return [output_api.PresubmitPromptWarning('''
142 Update chrome/installer/setup/last_breaking_installer_version.cc if the changes
143 found in the following files might break make downgrades not possible beyond
144 this browser's version.''', items=files)]
145
146   if not files and breaking_version_installer_updated:
147     return [output_api.PresubmitPromptWarning('''
148 No installer breaking changes detected but
149 chrome/installer/setup/last_breaking_installer_version.cc was updated. Please
150 update chrome/installer/PRESUBMIT.py if more files need to be watched for
151 breaking installer changes.''')]
152
153   return []
154
155
156 def _CommonChecks(input_api, output_api):
157   """Checks common to both upload and commit."""
158   results = []
159   results.extend(_CheckNoContentUnitTestsInChrome(input_api, output_api))
160   results.extend(_CheckNoIsAppleBuildFlagsInChrome(input_api, output_api))
161   results.extend(_CheckNoIsIOSBuildFlagsInChrome(input_api, output_api))
162   results.extend(_CheckBreakingInstallerVersionBumpNeeded(input_api,
163                  output_api))
164   return results
165
166
167 def CheckChangeOnUpload(input_api, output_api):
168   results = []
169   results.extend(_CommonChecks(input_api, output_api))
170   results.extend(_CheckChangeLintsClean(input_api, output_api))
171   return results
172
173
174 def CheckChangeOnCommit(input_api, output_api):
175   results = []
176   results.extend(_CommonChecks(input_api, output_api))
177   return results