Reland: Add presubmit check for changes in 3pp

Reland of CL https://webrtc-review.googlesource.com/c/src/+/77421

Copied description:
--
Add presubmit check for changes in 3pp

Presubmit check will test will new changes be overriden by autoroll
or not. In more details presubmit will check:
1. Each dependency in third_party have to be specified in one of:
   a. THIRD_PARTY_CHROMIUM_DEPS.json
   b. THIRD_PARTY_WEBRTC_DEPS.json
2. Each dependency not specified in both files from #1
3. Changes won't be overriden by chromium third_party deps autoroll:
   a. Changes were made in WebRTC owned dependency
   b. Changes were addition of new Chromium owned dependency
--
Also if commit message contains tag NO_AUTOIMPORT_DEPS_CHECK equal
to True, than changes in chromium specific deps will be permitted.
It is required for autoroller to be able to commit its changes and
not to fail on presubmit check.

Bug: webrtc:8366
Change-Id: I545a4778445855cf3db7cf257ca0cb63753aac06
Reviewed-on: https://webrtc-review.googlesource.com/78042
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23348}
This commit is contained in:
Artem Titov
2018-05-22 10:21:27 +02:00
committed by Commit Bot
parent c7f09ad2e0
commit e92675b5c4
9 changed files with 388 additions and 11 deletions

View File

@ -13,7 +13,6 @@ import sys
from collections import defaultdict
from contextlib import contextmanager
# Files and directories that are *skipped* by cpplint in the presubmit script.
CPPLINT_BLACKLIST = [
'api/video_codecs/video_decoder.h',
@ -140,6 +139,7 @@ def VerifyNativeApiHeadersListIsValid(input_api, output_api):
non_existing_paths)]
return []
API_CHANGE_MSG = """
You seem to be changing native API header files. Please make sure that you:
1. Make compatible changes that don't break existing clients. Usually
@ -159,6 +159,7 @@ You seem to be changing native API header files. Please make sure that you:
Related files:
"""
def CheckNativeApiHeaderChanges(input_api, output_api):
"""Checks to remind proper changing of native APIs."""
files = []
@ -288,7 +289,7 @@ def CheckApprovedFilesLintClean(input_api, output_api,
for f in input_api.AffectedSourceFiles(source_file_filter):
# Note that moved/renamed files also count as added.
if f.Action() == 'A' or not IsLintBlacklisted(blacklist_paths,
f.LocalPath()):
f.LocalPath()):
files.append(f.AbsoluteLocalPath())
for file_name in files:
@ -303,6 +304,7 @@ def CheckApprovedFilesLintClean(input_api, output_api,
return result
def CheckNoSourcesAbove(input_api, gn_files, output_api):
# Disallow referencing source files with paths above the GN file location.
source_pattern = input_api.re.compile(r' +sources \+?= \[(.*?)\]',
@ -331,11 +333,13 @@ def CheckNoSourcesAbove(input_api, gn_files, output_api):
items=violating_gn_files)]
return []
def CheckNoMixingSources(input_api, gn_files, output_api):
"""Disallow mixing C, C++ and Obj-C/Obj-C++ in the same target.
See bugs.webrtc.org/7743 for more context.
"""
def _MoreThanOneSourceUsed(*sources_lists):
sources_used = 0
for source_list in sources_lists:
@ -397,6 +401,7 @@ def CheckNoMixingSources(input_api, gn_files, output_api):
'\n'.join(errors.keys())))]
return []
def CheckNoPackageBoundaryViolations(input_api, gn_files, output_api):
cwd = input_api.PresubmitLocalPath()
with _AddToPath(input_api.os_path.join(
@ -456,6 +461,7 @@ def CheckNoStreamUsageIsAdded(input_api, output_api,
return [output_api.PresubmitError(error_msg, errors)]
return []
def CheckPublicDepsIsNotUsed(gn_files, input_api, output_api):
"""Checks that public_deps is not used without a good reason."""
result = []
@ -477,6 +483,7 @@ def CheckPublicDepsIsNotUsed(gn_files, input_api, output_api):
line_number)))
return result
def CheckCheckIncludesIsNotUsed(gn_files, output_api):
result = []
error_msg = ('check_includes overrides are not allowed since it can cause '
@ -494,6 +501,7 @@ def CheckCheckIncludesIsNotUsed(gn_files, output_api):
line_number)))
return result
def CheckGnChanges(input_api, output_api, source_file_filter):
file_filter = lambda x: (input_api.FilterSourceFile(
x, white_list=(r'.+\.(gn|gni)$',),
@ -514,6 +522,7 @@ def CheckGnChanges(input_api, output_api, source_file_filter):
result.extend(CheckCheckIncludesIsNotUsed(gn_files, output_api))
return result
def CheckGnGen(input_api, output_api):
"""Runs `gn gen --check` with default args to detect mismatches between
#includes and dependencies in the BUILD.gn files, as well as general build
@ -530,6 +539,7 @@ def CheckGnGen(input_api, output_api):
long_text='\n\n'.join(errors))]
return []
def CheckUnwantedDependencies(input_api, output_api, source_file_filter):
"""Runs checkdeps on #include statements added in this
change. Breaking - rules is an error, breaking ! rules is a
@ -589,6 +599,7 @@ def CheckUnwantedDependencies(input_api, output_api, source_file_filter):
warning_descriptions))
return results
def CheckCommitMessageBugEntry(input_api, output_api):
"""Check that bug entries are well-formed in commit message."""
bogus_bug_msg = (
@ -614,6 +625,7 @@ def CheckCommitMessageBugEntry(input_api, output_api):
results.append(bogus_bug_msg % bug)
return [output_api.PresubmitError(r) for r in results]
def CheckChangeHasBugField(input_api, output_api):
"""Requires that the changelist is associated with a bug.
@ -633,6 +645,7 @@ def CheckChangeHasBugField(input_api, output_api):
' * https://bugs.webrtc.org - reference it using Bug: webrtc:XXXX\n'
' * https://crbug.com - reference it using Bug: chromium:XXXXXX')]
def CheckJSONParseErrors(input_api, output_api, source_file_filter):
"""Check that JSON files do not contain syntax errors."""
@ -655,7 +668,8 @@ def CheckJSONParseErrors(input_api, output_api, source_file_filter):
affected_file.AbsoluteLocalPath())
if parse_error:
results.append(output_api.PresubmitError('%s could not be parsed: %s' %
(affected_file.LocalPath(), parse_error)))
(affected_file.LocalPath(),
parse_error)))
return results
@ -778,14 +792,14 @@ def CommonChecks(input_api, output_api):
third_party_filter_list)
hundred_char_sources = lambda x: input_api.FilterSourceFile(x,
white_list=objc_filter_list)
non_third_party_sources = lambda x: input_api.FilterSourceFile(x,
black_list=third_party_filter_list)
results.extend(input_api.canned_checks.CheckLongLines(
input_api, output_api, maxlen=80, source_file_filter=eighty_char_sources))
results.extend(input_api.canned_checks.CheckLongLines(
input_api, output_api, maxlen=100,
source_file_filter=hundred_char_sources))
non_third_party_sources = lambda x: input_api.FilterSourceFile(x,
black_list=third_party_filter_list)
results.extend(input_api.canned_checks.CheckChangeHasNoTabs(
input_api, output_api, source_file_filter=non_third_party_sources))
results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace(
@ -816,9 +830,17 @@ def CommonChecks(input_api, output_api):
input_api, output_api, source_file_filter=non_third_party_sources))
results.extend(CheckNoStreamUsageIsAdded(
input_api, output_api, non_third_party_sources))
results.extend(CheckThirdPartyChanges(input_api, output_api))
return results
def CheckThirdPartyChanges(input_api, output_api):
with _AddToPath(input_api.os_path.join(
input_api.PresubmitLocalPath(), 'tools_webrtc', 'presubmit_checks_lib')):
from check_3pp import CheckThirdPartyDirectory
return CheckThirdPartyDirectory(input_api, output_api)
def CheckChangeOnUpload(input_api, output_api):
results = []
results.extend(CommonChecks(input_api, output_api))
@ -874,8 +896,7 @@ def CheckOrphanHeaders(input_api, output_api, source_file_filter):
return results
def CheckNewlineAtTheEndOfProtoFiles(input_api, output_api,
source_file_filter):
def CheckNewlineAtTheEndOfProtoFiles(input_api, output_api, source_file_filter):
"""Checks that all .proto files are terminated with a newline."""
error_msg = 'File {} must end with exactly one newline.'
results = []