add a use_alsa gyp setting
[chromium-blink-merge.git] / cc / PRESUBMIT.py
blob319d3b5234469fda2acd4114ac8b5bc7905f9913
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 """Top-level presubmit script for cc.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
8 details on the presubmit API built into gcl.
9 """
11 import re
13 CC_SOURCE_FILES=(r'^cc/.*\.(cc|h)$',)
14 CC_PERF_TEST =(r'^.*_perftest.*\.(cc|h)$',)
16 def CheckAsserts(input_api, output_api, white_list=CC_SOURCE_FILES, black_list=None):
17 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)
18 source_file_filter = lambda x: input_api.FilterSourceFile(x, white_list, black_list)
20 assert_files = []
21 notreached_files = []
23 for f in input_api.AffectedSourceFiles(source_file_filter):
24 contents = input_api.ReadFile(f, 'rb')
25 # WebKit ASSERT() is not allowed.
26 if re.search(r"\bASSERT\(", contents):
27 assert_files.append(f.LocalPath())
28 # WebKit ASSERT_NOT_REACHED() is not allowed.
29 if re.search(r"ASSERT_NOT_REACHED\(", contents):
30 notreached_files.append(f.LocalPath())
32 if assert_files:
33 return [output_api.PresubmitError(
34 'These files use ASSERT instead of using DCHECK:',
35 items=assert_files)]
36 if notreached_files:
37 return [output_api.PresubmitError(
38 'These files use ASSERT_NOT_REACHED instead of using NOTREACHED:',
39 items=notreached_files)]
40 return []
42 def CheckSpamLogging(input_api, output_api, white_list=CC_SOURCE_FILES, black_list=None):
43 black_list = tuple(black_list or input_api.DEFAULT_BLACK_LIST)
44 source_file_filter = lambda x: input_api.FilterSourceFile(x, white_list, black_list)
46 log_info = []
47 printf = []
49 for f in input_api.AffectedSourceFiles(source_file_filter):
50 contents = input_api.ReadFile(f, 'rb')
51 if re.search(r"\bD?LOG\s*\(\s*INFO\s*\)", contents):
52 log_info.append(f.LocalPath())
53 if re.search(r"\bf?printf\(", contents):
54 printf.append(f.LocalPath())
56 if log_info:
57 return [output_api.PresubmitError(
58 'These files spam the console log with LOG(INFO):',
59 items=log_info)]
60 if printf:
61 return [output_api.PresubmitError(
62 'These files spam the console log with printf/fprintf:',
63 items=printf)]
64 return []
67 def CheckChangeOnUpload(input_api, output_api):
68 results = []
69 results += CheckAsserts(input_api, output_api)
70 results += CheckSpamLogging(input_api, output_api, black_list=CC_PERF_TEST)
71 return results
73 def GetPreferredTrySlaves(project, change):
74 return [
75 'linux_layout_rel',