2012-01-23 18:45:41 +01:00
|
|
|
# Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style license
|
|
|
|
# that can be found in the LICENSE file in the root of the source
|
|
|
|
# tree. An additional intellectual property rights grant can be found
|
|
|
|
# in the file PATENTS. All contributing project authors may
|
|
|
|
# be found in the AUTHORS file in the root of the source tree.
|
2011-05-30 13:51:34 +02:00
|
|
|
|
2013-10-22 18:47:40 +02:00
|
|
|
import re
|
2014-09-01 13:06:37 +02:00
|
|
|
import sys
|
2013-10-22 18:47:40 +02:00
|
|
|
|
|
|
|
|
2012-02-21 18:53:46 +01:00
|
|
|
def _CheckNoIOStreamInHeaders(input_api, output_api):
|
|
|
|
"""Checks to make sure no .h files include <iostream>."""
|
|
|
|
files = []
|
|
|
|
pattern = input_api.re.compile(r'^#include\s*<iostream>',
|
|
|
|
input_api.re.MULTILINE)
|
|
|
|
for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile):
|
|
|
|
if not f.LocalPath().endswith('.h'):
|
|
|
|
continue
|
|
|
|
contents = input_api.ReadFile(f)
|
|
|
|
if pattern.search(contents):
|
|
|
|
files.append(f)
|
|
|
|
|
|
|
|
if len(files):
|
|
|
|
return [ output_api.PresubmitError(
|
|
|
|
'Do not #include <iostream> in header files, since it inserts static ' +
|
|
|
|
'initialization into every file including the header. Instead, ' +
|
|
|
|
'#include <ostream>. See http://crbug.com/94794',
|
|
|
|
files) ]
|
|
|
|
return []
|
|
|
|
|
2014-08-06 11:11:18 +02:00
|
|
|
|
2012-02-21 18:53:46 +01:00
|
|
|
def _CheckNoFRIEND_TEST(input_api, output_api):
|
|
|
|
"""Make sure that gtest's FRIEND_TEST() macro is not used, the
|
|
|
|
FRIEND_TEST_ALL_PREFIXES() macro from testsupport/gtest_prod_util.h should be
|
|
|
|
used instead since that allows for FLAKY_, FAILS_ and DISABLED_ prefixes."""
|
|
|
|
problems = []
|
|
|
|
|
|
|
|
file_filter = lambda f: f.LocalPath().endswith(('.cc', '.h'))
|
|
|
|
for f in input_api.AffectedFiles(file_filter=file_filter):
|
|
|
|
for line_num, line in f.ChangedContents():
|
|
|
|
if 'FRIEND_TEST(' in line:
|
|
|
|
problems.append(' %s:%d' % (f.LocalPath(), line_num))
|
|
|
|
|
|
|
|
if not problems:
|
|
|
|
return []
|
|
|
|
return [output_api.PresubmitPromptWarning('WebRTC\'s code should not use '
|
|
|
|
'gtest\'s FRIEND_TEST() macro. Include testsupport/gtest_prod_util.h and '
|
|
|
|
'use FRIEND_TEST_ALL_PREFIXES() instead.\n' + '\n'.join(problems))]
|
|
|
|
|
2014-08-06 11:11:18 +02:00
|
|
|
|
2012-07-01 07:55:23 +02:00
|
|
|
def _CheckApprovedFilesLintClean(input_api, output_api,
|
|
|
|
source_file_filter=None):
|
|
|
|
"""Checks that all new or whitelisted .cc and .h files pass cpplint.py.
|
2012-02-21 18:53:46 +01:00
|
|
|
This check is based on _CheckChangeLintsClean in
|
|
|
|
depot_tools/presubmit_canned_checks.py but has less filters and only checks
|
|
|
|
added files."""
|
|
|
|
result = []
|
|
|
|
|
|
|
|
# Initialize cpplint.
|
|
|
|
import cpplint
|
|
|
|
# Access to a protected member _XX of a client class
|
|
|
|
# pylint: disable=W0212
|
|
|
|
cpplint._cpplint_state.ResetErrorCounts()
|
|
|
|
|
|
|
|
# Justifications for each filter:
|
|
|
|
#
|
|
|
|
# - build/header_guard : WebRTC coding style says they should be prefixed
|
|
|
|
# with WEBRTC_, which is not possible to configure in
|
|
|
|
# cpplint.py.
|
|
|
|
cpplint._SetFilters('-build/header_guard')
|
|
|
|
|
|
|
|
# Use the strictest verbosity level for cpplint.py (level 1) which is the
|
|
|
|
# default when running cpplint.py from command line.
|
|
|
|
# To make it possible to work with not-yet-converted code, we're only applying
|
2012-07-01 07:55:23 +02:00
|
|
|
# it to new (or moved/renamed) files and files listed in LINT_FOLDERS.
|
2012-02-21 18:53:46 +01:00
|
|
|
verbosity_level = 1
|
|
|
|
files = []
|
|
|
|
for f in input_api.AffectedSourceFiles(source_file_filter):
|
|
|
|
# Note that moved/renamed files also count as added for svn.
|
2013-03-07 10:59:43 +01:00
|
|
|
if (f.Action() == 'A'):
|
2012-02-21 18:53:46 +01:00
|
|
|
files.append(f.AbsoluteLocalPath())
|
2012-07-01 07:55:23 +02:00
|
|
|
|
2012-02-21 18:53:46 +01:00
|
|
|
for file_name in files:
|
|
|
|
cpplint.ProcessFile(file_name, verbosity_level)
|
|
|
|
|
|
|
|
if cpplint._cpplint_state.error_count > 0:
|
|
|
|
if input_api.is_committing:
|
|
|
|
# TODO(kjellander): Change back to PresubmitError below when we're
|
|
|
|
# confident with the lint settings.
|
|
|
|
res_type = output_api.PresubmitPromptWarning
|
|
|
|
else:
|
|
|
|
res_type = output_api.PresubmitPromptWarning
|
|
|
|
result = [res_type('Changelist failed cpplint.py check.')]
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2014-08-06 11:11:18 +02:00
|
|
|
|
|
|
|
def _CheckGypChanges(input_api, output_api):
|
|
|
|
source_file_filter = lambda x: input_api.FilterSourceFile(
|
|
|
|
x, white_list=(r'.+\.(gyp|gypi)$',))
|
|
|
|
|
|
|
|
gyp_files = []
|
|
|
|
for f in input_api.AffectedSourceFiles(source_file_filter):
|
|
|
|
gyp_files.append(f.LocalPath())
|
|
|
|
|
|
|
|
result = []
|
|
|
|
if gyp_files:
|
|
|
|
result.append(output_api.PresubmitNotifyResult(
|
|
|
|
'As you\'re changing GYP files: please make sure corresponding '
|
|
|
|
'BUILD.gn files are also updated.\nChanged GYP files:',
|
|
|
|
items=gyp_files))
|
|
|
|
return result
|
|
|
|
|
2014-09-01 13:06:37 +02:00
|
|
|
def _CheckUnwantedDependencies(input_api, output_api):
|
|
|
|
"""Runs checkdeps on #include statements added in this
|
|
|
|
change. Breaking - rules is an error, breaking ! rules is a
|
|
|
|
warning.
|
|
|
|
"""
|
|
|
|
# Copied from Chromium's src/PRESUBMIT.py.
|
|
|
|
|
|
|
|
# We need to wait until we have an input_api object and use this
|
|
|
|
# roundabout construct to import checkdeps because this file is
|
|
|
|
# eval-ed and thus doesn't have __file__.
|
|
|
|
original_sys_path = sys.path
|
|
|
|
try:
|
|
|
|
sys.path = sys.path + [input_api.os_path.join(
|
|
|
|
input_api.PresubmitLocalPath(), 'buildtools', 'checkdeps')]
|
|
|
|
import checkdeps
|
|
|
|
from cpp_checker import CppChecker
|
|
|
|
from rules import Rule
|
|
|
|
finally:
|
|
|
|
# Restore sys.path to what it was before.
|
|
|
|
sys.path = original_sys_path
|
|
|
|
|
|
|
|
added_includes = []
|
|
|
|
for f in input_api.AffectedFiles():
|
|
|
|
if not CppChecker.IsCppFile(f.LocalPath()):
|
|
|
|
continue
|
|
|
|
|
|
|
|
changed_lines = [line for _line_num, line in f.ChangedContents()]
|
|
|
|
added_includes.append([f.LocalPath(), changed_lines])
|
|
|
|
|
|
|
|
deps_checker = checkdeps.DepsChecker(input_api.PresubmitLocalPath())
|
|
|
|
|
|
|
|
error_descriptions = []
|
|
|
|
warning_descriptions = []
|
|
|
|
for path, rule_type, rule_description in deps_checker.CheckAddedCppIncludes(
|
|
|
|
added_includes):
|
|
|
|
description_with_path = '%s\n %s' % (path, rule_description)
|
|
|
|
if rule_type == Rule.DISALLOW:
|
|
|
|
error_descriptions.append(description_with_path)
|
|
|
|
else:
|
|
|
|
warning_descriptions.append(description_with_path)
|
|
|
|
|
|
|
|
results = []
|
|
|
|
if error_descriptions:
|
|
|
|
results.append(output_api.PresubmitError(
|
|
|
|
'You added one or more #includes that violate checkdeps rules.',
|
|
|
|
error_descriptions))
|
|
|
|
if warning_descriptions:
|
|
|
|
results.append(output_api.PresubmitPromptOrNotify(
|
|
|
|
'You added one or more #includes of files that are temporarily\n'
|
|
|
|
'allowed but being removed. Can you avoid introducing the\n'
|
|
|
|
'#include? See relevant DEPS file(s) for details and contacts.',
|
|
|
|
warning_descriptions))
|
|
|
|
return results
|
|
|
|
|
2014-08-06 11:11:18 +02:00
|
|
|
|
2012-01-26 22:24:23 +01:00
|
|
|
def _CommonChecks(input_api, output_api):
|
|
|
|
"""Checks common to both upload and commit."""
|
2012-02-21 18:53:46 +01:00
|
|
|
# TODO(kjellander): Use presubmit_canned_checks.PanProjectChecks too.
|
2011-05-30 13:51:34 +02:00
|
|
|
results = []
|
2013-03-07 10:59:43 +01:00
|
|
|
results.extend(input_api.canned_checks.RunPylint(input_api, output_api,
|
|
|
|
black_list=(r'^.*gviz_api\.py$',
|
|
|
|
r'^.*gaeunit\.py$',
|
2013-07-25 18:43:30 +02:00
|
|
|
# Embedded shell-script fakes out pylint.
|
2014-08-06 11:11:18 +02:00
|
|
|
r'^build/.*\.py$',
|
|
|
|
r'^buildtools/.*\.py$',
|
2014-08-20 14:10:11 +02:00
|
|
|
r'^chromium/.*\.py$',
|
2014-08-06 11:11:18 +02:00
|
|
|
r'^out.*/.*\.py$',
|
2013-07-25 18:43:30 +02:00
|
|
|
r'^talk/site_scons/site_tools/talk_linux.py$',
|
2013-03-07 10:59:43 +01:00
|
|
|
r'^testing/.*\.py$',
|
2014-08-06 11:11:18 +02:00
|
|
|
r'^third_party/.*\.py$',
|
2014-04-03 22:19:36 +02:00
|
|
|
r'^tools/clang/.*\.py$',
|
2014-08-06 11:11:18 +02:00
|
|
|
r'^tools/gn/.*\.py$',
|
2013-03-07 10:59:43 +01:00
|
|
|
r'^tools/gyp/.*\.py$',
|
|
|
|
r'^tools/perf_expectations/.*\.py$',
|
2013-05-14 11:42:39 +02:00
|
|
|
r'^tools/protoc_wrapper/.*\.py$',
|
2013-03-07 10:59:43 +01:00
|
|
|
r'^tools/python/.*\.py$',
|
|
|
|
r'^tools/python_charts/data/.*\.py$',
|
2013-08-22 09:57:00 +02:00
|
|
|
r'^tools/refactoring/.*\.py$',
|
2013-12-11 14:37:12 +01:00
|
|
|
r'^tools/swarming_client/.*\.py$',
|
2013-03-07 10:59:43 +01:00
|
|
|
# TODO(phoglund): should arguably be checked.
|
|
|
|
r'^tools/valgrind-webrtc/.*\.py$',
|
|
|
|
r'^tools/valgrind/.*\.py$',
|
|
|
|
# TODO(phoglund): should arguably be checked.
|
|
|
|
r'^webrtc/build/.*\.py$',
|
2014-08-06 11:11:18 +02:00
|
|
|
r'^xcodebuild.*/.*\.py$',),
|
|
|
|
|
2013-03-07 10:59:43 +01:00
|
|
|
disabled_warnings=['F0401', # Failed to import x
|
|
|
|
'E0611', # No package y in x
|
|
|
|
'W0232', # Class has no __init__ method
|
|
|
|
]))
|
2012-01-23 18:45:41 +01:00
|
|
|
results.extend(input_api.canned_checks.CheckLongLines(
|
2013-04-08 17:46:07 +02:00
|
|
|
input_api, output_api, maxlen=80))
|
2012-01-23 18:45:41 +01:00
|
|
|
results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
|
|
|
|
input_api, output_api))
|
2012-01-26 22:24:23 +01:00
|
|
|
results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
|
|
|
|
input_api, output_api))
|
|
|
|
results.extend(input_api.canned_checks.CheckChangeTodoHasOwner(
|
|
|
|
input_api, output_api))
|
2012-07-01 07:55:23 +02:00
|
|
|
results.extend(_CheckApprovedFilesLintClean(input_api, output_api))
|
2012-02-21 18:53:46 +01:00
|
|
|
results.extend(_CheckNoIOStreamInHeaders(input_api, output_api))
|
|
|
|
results.extend(_CheckNoFRIEND_TEST(input_api, output_api))
|
2014-08-06 11:11:18 +02:00
|
|
|
results.extend(_CheckGypChanges(input_api, output_api))
|
2014-09-01 13:06:37 +02:00
|
|
|
results.extend(_CheckUnwantedDependencies(input_api, output_api))
|
2012-01-26 22:24:23 +01:00
|
|
|
return results
|
2011-05-30 13:51:34 +02:00
|
|
|
|
2014-08-06 11:11:18 +02:00
|
|
|
|
2012-01-26 22:24:23 +01:00
|
|
|
def CheckChangeOnUpload(input_api, output_api):
|
|
|
|
results = []
|
|
|
|
results.extend(_CommonChecks(input_api, output_api))
|
2012-01-23 18:45:41 +01:00
|
|
|
return results
|
2011-05-30 13:51:34 +02:00
|
|
|
|
2014-08-06 11:11:18 +02:00
|
|
|
|
2012-01-23 18:45:41 +01:00
|
|
|
def CheckChangeOnCommit(input_api, output_api):
|
2011-06-09 09:07:24 +02:00
|
|
|
results = []
|
2012-01-26 22:24:23 +01:00
|
|
|
results.extend(_CommonChecks(input_api, output_api))
|
2011-06-09 09:07:24 +02:00
|
|
|
results.extend(input_api.canned_checks.CheckOwners(input_api, output_api))
|
2012-01-26 22:24:23 +01:00
|
|
|
results.extend(input_api.canned_checks.CheckChangeWasUploaded(
|
|
|
|
input_api, output_api))
|
|
|
|
results.extend(input_api.canned_checks.CheckChangeHasDescription(
|
|
|
|
input_api, output_api))
|
2012-02-21 18:53:46 +01:00
|
|
|
results.extend(input_api.canned_checks.CheckChangeHasBugField(
|
|
|
|
input_api, output_api))
|
|
|
|
results.extend(input_api.canned_checks.CheckChangeHasTestField(
|
|
|
|
input_api, output_api))
|
2014-02-13 12:53:43 +01:00
|
|
|
results.extend(input_api.canned_checks.CheckTreeIsOpen(
|
|
|
|
input_api, output_api,
|
|
|
|
json_url='http://webrtc-status.appspot.com/current?format=json'))
|
2011-06-09 09:07:24 +02:00
|
|
|
return results
|
2013-10-22 18:47:40 +02:00
|
|
|
|
2014-08-06 11:11:18 +02:00
|
|
|
|
2014-04-03 22:19:36 +02:00
|
|
|
def GetDefaultTryConfigs(bots=None):
|
|
|
|
"""Returns a list of ('bot', set(['tests']), optionally filtered by [bots].
|
|
|
|
|
|
|
|
For WebRTC purposes, we always return an empty list of tests, since we want
|
|
|
|
to run all tests by default on all our trybots.
|
|
|
|
"""
|
|
|
|
return { 'tryserver.webrtc': dict((bot, []) for bot in bots)}
|
|
|
|
|
2014-08-06 11:11:18 +02:00
|
|
|
|
2013-10-22 18:47:40 +02:00
|
|
|
# pylint: disable=W0613
|
2014-04-03 22:19:36 +02:00
|
|
|
def GetPreferredTryMasters(project, change):
|
2013-10-22 18:47:40 +02:00
|
|
|
files = change.LocalPaths()
|
|
|
|
|
2014-08-06 11:11:18 +02:00
|
|
|
android_gn_bots = [
|
|
|
|
'android_gn',
|
|
|
|
'android_gn_rel',
|
|
|
|
]
|
2013-12-20 22:20:42 +01:00
|
|
|
android_bots = [
|
|
|
|
'android',
|
2014-06-08 19:55:51 +02:00
|
|
|
'android_arm64',
|
2013-12-20 22:20:42 +01:00
|
|
|
'android_rel',
|
|
|
|
'android_clang',
|
2014-08-06 11:11:18 +02:00
|
|
|
] + android_gn_bots
|
2013-10-22 18:47:40 +02:00
|
|
|
ios_bots = [
|
|
|
|
'ios',
|
|
|
|
'ios_rel',
|
|
|
|
]
|
2014-08-06 11:11:18 +02:00
|
|
|
linux_gn_bots = [
|
|
|
|
'linux_gn',
|
|
|
|
'linux_gn_rel',
|
|
|
|
]
|
2013-10-22 18:47:40 +02:00
|
|
|
linux_bots = [
|
|
|
|
'linux',
|
|
|
|
'linux_asan',
|
2014-01-22 20:00:01 +01:00
|
|
|
'linux_baremetal',
|
2013-10-22 18:47:40 +02:00
|
|
|
'linux_rel',
|
2014-04-03 22:19:36 +02:00
|
|
|
'linux_tsan2',
|
2014-08-06 11:11:18 +02:00
|
|
|
] + linux_gn_bots
|
2013-10-22 18:47:40 +02:00
|
|
|
mac_bots = [
|
|
|
|
'mac',
|
|
|
|
'mac_asan',
|
2014-01-22 20:00:01 +01:00
|
|
|
'mac_baremetal',
|
2013-10-22 18:47:40 +02:00
|
|
|
'mac_rel',
|
|
|
|
'mac_x64_rel',
|
|
|
|
]
|
|
|
|
win_bots = [
|
|
|
|
'win',
|
2014-04-03 22:19:36 +02:00
|
|
|
'win_asan',
|
2014-01-22 20:00:01 +01:00
|
|
|
'win_baremetal',
|
2014-04-14 10:38:27 +02:00
|
|
|
'win_drmemory_light',
|
2013-10-22 18:47:40 +02:00
|
|
|
'win_rel',
|
|
|
|
'win_x64_rel',
|
|
|
|
]
|
|
|
|
if not files or all(re.search(r'[\\/]OWNERS$', f) for f in files):
|
2014-04-03 22:19:36 +02:00
|
|
|
return {}
|
2014-08-06 11:11:18 +02:00
|
|
|
if all(re.search(r'[\\/]BUILD.gn$', f) for f in files):
|
|
|
|
return GetDefaultTryConfigs(android_gn_bots + linux_gn_bots)
|
2013-10-22 18:47:40 +02:00
|
|
|
if all(re.search('\.(m|mm)$|(^|[/_])mac[/_.]', f) for f in files):
|
2014-04-03 22:19:36 +02:00
|
|
|
return GetDefaultTryConfigs(mac_bots)
|
2013-10-22 18:47:40 +02:00
|
|
|
if all(re.search('(^|[/_])win[/_.]', f) for f in files):
|
2014-04-03 22:19:36 +02:00
|
|
|
return GetDefaultTryConfigs(win_bots)
|
|
|
|
if all(re.search('(^|[/_])android[/_.]', f) for f in files):
|
|
|
|
return GetDefaultTryConfigs(android_bots)
|
|
|
|
if all(re.search('[/_]ios[/_.]', f) for f in files):
|
|
|
|
return GetDefaultTryConfigs(ios_bots)
|
2013-10-22 18:47:40 +02:00
|
|
|
|
2014-04-03 22:19:36 +02:00
|
|
|
return GetDefaultTryConfigs(android_bots + ios_bots + linux_bots + mac_bots +
|
|
|
|
win_bots)
|