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.
5 """Chromium presubmit script for src/base.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details on the presubmit API built into depot_tools.
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)
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):
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',
35 def _CheckNoTraceEventInclude(input_api, output_api):
36 """Verify that //base includes base_tracing.h instead of trace event headers.
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".
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"$',
54 r".*[\\/]trace_event[\\/].*",
55 r".*[\\/]tracing[\\/].*",
58 def FilterFile(affected_file):
59 return input_api.FilterSourceFile(
61 white_list=white_list,
62 black_list=black_list)
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))
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)) ]
81 def _CommonChecks(input_api, output_api):
82 """Checks common to both upload and commit."""
84 results.extend(_CheckNoInterfacesInBase(input_api, output_api))
85 results.extend(_CheckNoTraceEventInclude(input_api, output_api))
89 def CheckChangeOnUpload(input_api, output_api):
91 results.extend(_CommonChecks(input_api, output_api))
95 def CheckChangeOnCommit(input_api, output_api):
97 results.extend(_CommonChecks(input_api, output_api))