[M94 Dev][Tizen] Fix for errors for generating ninja files
[platform/framework/web/chromium-efl.git] / base / PRESUBMIT.py
1 # Copyright (c) 2012 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 """Chromium presubmit script for src/base.
6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details on the presubmit API built into depot_tools.
9 """
10
11
12 USE_PYTHON3 = True
13
14
15 def _CheckNoInterfacesInBase(input_api, output_api):
16   """Checks to make sure no files in libbase.a have |@interface|."""
17   pattern = input_api.re.compile(r'^\s*@interface', input_api.re.MULTILINE)
18   files = []
19   for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
20     if (f.LocalPath().startswith('base/') and
21         not "/ios/" in f.LocalPath() and
22         not "/test/" in f.LocalPath() and
23         not f.LocalPath().endswith('.java') and
24         not f.LocalPath().endswith('_unittest.mm') and
25         not f.LocalPath().endswith('mac/sdk_forward_declarations.h')):
26       contents = input_api.ReadFile(f)
27       if pattern.search(contents):
28         files.append(f)
29
30   if len(files):
31     return [ output_api.PresubmitError(
32         'Objective-C interfaces or categories are forbidden in libbase. ' +
33         'See http://groups.google.com/a/chromium.org/group/chromium-dev/' +
34         'browse_thread/thread/efb28c10435987fd',
35         files) ]
36   return []
37
38
39 def _FindLocations(input_api, search_regexes, files_to_check, files_to_skip):
40   """Returns locations matching one of the search_regexes."""
41   def FilterFile(affected_file):
42     return input_api.FilterSourceFile(
43       affected_file,
44       files_to_check=files_to_check,
45       files_to_skip=files_to_skip)
46
47   no_presubmit = r"// no-presubmit-check"
48   locations = []
49   for f in input_api.AffectedSourceFiles(FilterFile):
50     for line_num, line in f.ChangedContents():
51       for search_regex in search_regexes:
52         if (input_api.re.search(search_regex, line) and
53             not input_api.re.search(no_presubmit, line)):
54           locations.append("    %s:%d" % (f.LocalPath(), line_num))
55           break
56   return locations
57
58
59 def _CheckNoTraceEventInclude(input_api, output_api):
60   """Verify that //base includes base_tracing.h instead of trace event headers.
61
62   Checks that files outside trace event implementation include the
63   base_tracing.h header instead of specific trace event implementation headers
64   to maintain compatibility with the gn flag "enable_base_tracing = false".
65   """
66   discouraged_includes = [
67     r'^#include "base/trace_event/(?!base_tracing\.h|base_tracing_forward\.h)',
68     r'^#include "third_party/perfetto/include/',
69   ]
70
71   files_to_check = [
72     r".*\.(h|cc|mm)$",
73   ]
74   files_to_skip = [
75     r".*[\\/]test[\\/].*",
76     r".*[\\/]trace_event[\\/].*",
77     r".*[\\/]tracing[\\/].*",
78   ]
79
80   locations = _FindLocations(input_api, discouraged_includes, files_to_check,
81                              files_to_skip)
82   if locations:
83     return [ output_api.PresubmitError(
84         'Base code should include "base/trace_event/base_tracing.h" instead\n' +
85         'of trace_event implementation headers. If you need to include an\n' +
86         'implementation header, verify that "gn check" and base_unittests\n' +
87         'still pass with gn arg "enable_base_tracing = false" and add\n' +
88         '"// no-presubmit-check" after the include. \n' +
89         '\n'.join(locations)) ]
90   return []
91
92
93 def _WarnPbzeroIncludes(input_api, output_api):
94   """Warn to check enable_base_tracing=false when including a pbzero header.
95
96   Emits a warning when including a perfetto pbzero header, encouraging the
97   user to verify that //base still builds with enable_base_tracing=false.
98   """
99   warn_includes = [
100     r'^#include "third_party/perfetto/protos/',
101     r'^#include "base/tracing/protos/',
102   ]
103
104   files_to_check = [
105     r".*\.(h|cc|mm)$",
106   ]
107   files_to_skip = [
108     r".*[\\/]test[\\/].*",
109     r".*[\\/]trace_event[\\/].*",
110     r".*[\\/]tracing[\\/].*",
111   ]
112
113   locations = _FindLocations(input_api, warn_includes, files_to_check,
114                              files_to_skip)
115   if locations:
116     return [ output_api.PresubmitPromptWarning(
117         'Please verify that "gn check" and base_unittests still pass with\n' +
118         'gn arg "enable_base_tracing = false" when adding typed trace\n' +
119         'events to //base. You can use "#if BUILDFLAG(ENABLE_BASE_TRACING)"\n' +
120         'to exclude pbzero headers and anything not supported by\n' +
121         '//base/trace_event/trace_event_stub.h.\n' +
122         '\n'.join(locations)) ]
123   return []
124
125
126 def _CommonChecks(input_api, output_api):
127   """Checks common to both upload and commit."""
128   results = []
129   results.extend(_CheckNoInterfacesInBase(input_api, output_api))
130   results.extend(_CheckNoTraceEventInclude(input_api, output_api))
131   results.extend(_WarnPbzeroIncludes(input_api, output_api))
132   return results
133
134
135 def CheckChangeOnUpload(input_api, output_api):
136   results = []
137   results.extend(_CommonChecks(input_api, output_api))
138   return results
139
140
141 def CheckChangeOnCommit(input_api, output_api):
142   results = []
143   results.extend(_CommonChecks(input_api, output_api))
144   return results