[M85 Dev][EFL] Fix crashes at webview launch
[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 def _CheckNoInterfacesInBase(input_api, output_api):
12   """Checks to make sure no files in libbase.a have |@interface|."""
13   pattern = input_api.re.compile(r'^\s*@interface', input_api.re.MULTILINE)
14   files = []
15   for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
16     if (f.LocalPath().startswith('base/') and
17         not "/ios/" in f.LocalPath() and
18         not "/test/" in f.LocalPath() and
19         not f.LocalPath().endswith('.java') and
20         not f.LocalPath().endswith('_unittest.mm') and
21         not f.LocalPath().endswith('mac/sdk_forward_declarations.h')):
22       contents = input_api.ReadFile(f)
23       if pattern.search(contents):
24         files.append(f)
25
26   if len(files):
27     return [ output_api.PresubmitError(
28         'Objective-C interfaces or categories are forbidden in libbase. ' +
29         'See http://groups.google.com/a/chromium.org/group/chromium-dev/' +
30         'browse_thread/thread/efb28c10435987fd',
31         files) ]
32   return []
33
34
35 def _CheckNoTraceEventInclude(input_api, output_api):
36   """Verify that //base includes base_tracing.h instead of trace event headers.
37
38   Checks that files outside trace event implementation include the
39   base_tracing.h header instead of specific trace event implementation headers
40   to maintain compatibility with the gn flag "enable_base_tracing = false".
41   """
42   discouraged_includes = [
43     r'^#include "base/trace_event/blame_context.h"$',
44     r'^#include "base/trace_event/memory_allocator_dump_guid.h"$',
45     r'^#include "base/trace_event/memory_dump_provider.h"$',
46     r'^#include "base/trace_event/trace_event.h"$',
47     r'^#include "base/trace_event/traced_value.h"$',
48   ]
49
50   white_list = [
51     r".*\.(h|cc|mm)$",
52   ]
53   black_list = [
54     r".*[\\/]trace_event[\\/].*",
55     r".*[\\/]tracing[\\/].*",
56   ]
57
58   def FilterFile(affected_file):
59     return input_api.FilterSourceFile(
60       affected_file,
61       white_list=white_list,
62       black_list=black_list)
63
64   locations = []
65   for f in input_api.AffectedSourceFiles(FilterFile):
66     for line_num, line in f.ChangedContents():
67       for include in discouraged_includes:
68         if input_api.re.search(include, line):
69           locations.append("    %s:%d" % (f.LocalPath(), line_num))
70           break
71
72   if locations:
73     return [ output_api.PresubmitPromptWarning(
74         'Consider replacing includes to trace_event implementation headers\n' +
75         'in //base with "base/trace_event/base_tracing.h" and/or verify\n' +
76         'that base_unittests still passes with gn arg\n' +
77         'enable_base_tracing = false.\n' + '\n'.join(locations)) ]
78   return []
79
80
81 def _CommonChecks(input_api, output_api):
82   """Checks common to both upload and commit."""
83   results = []
84   results.extend(_CheckNoInterfacesInBase(input_api, output_api))
85   results.extend(_CheckNoTraceEventInclude(input_api, output_api))
86   return results
87
88
89 def CheckChangeOnUpload(input_api, output_api):
90   results = []
91   results.extend(_CommonChecks(input_api, output_api))
92   return results
93
94
95 def CheckChangeOnCommit(input_api, output_api):
96   results = []
97   results.extend(_CommonChecks(input_api, output_api))
98   return results