Commit 225de05b authored by Sergio Villar Senin's avatar Sergio Villar Senin Committed by Commit Bot

Add a presubmit check for blink/public/web dependencies in chrome/browser

As part of crbug.com/1008303 we are removing all the blink/public/web
dependencies from chrome/browser. It would be nice to add a presubmit check so
that new dependencies are not added in the meantime.

Bug: 1008303
Change-Id: Id6aee21e4c64271b0c1e00cdffc848de88bb4629
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1879921
Commit-Queue: Sergio Villar <svillar@igalia.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713391}
parent 01969e7f
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
"""Presubmit script for Chromium browser code.""" """Presubmit script for Chromium browser code."""
import re
def _RunHistogramChecks(input_api, output_api, histogram_name): def _RunHistogramChecks(input_api, output_api, histogram_name):
try: try:
# Setup sys.path so that we can call histograms code. # Setup sys.path so that we can call histograms code.
...@@ -25,10 +27,32 @@ def _RunHistogramChecks(input_api, output_api, histogram_name): ...@@ -25,10 +27,32 @@ def _RunHistogramChecks(input_api, output_api, histogram_name):
finally: finally:
sys.path = original_sys_path sys.path = original_sys_path
def _CheckUnwantedDependencies(input_api, output_api):
problems = []
for f in input_api.AffectedFiles():
if not f.LocalPath().endswith('DEPS'):
continue
for line_num, line in f.ChangedContents():
if not line.strip().startswith('#'):
m = re.search(r".*\/blink\/public\/web.*", line)
if m:
problems.append(m.group(0))
if not problems:
return []
return [output_api.PresubmitPromptWarning(
'chrome/browser cannot depend on blink/public/web interfaces. ' +
'Use blink/public/common instead.',
items=problems)]
def _CommonChecks(input_api, output_api): def _CommonChecks(input_api, output_api):
"""Checks common to both upload and commit.""" """Checks common to both upload and commit."""
return _RunHistogramChecks(input_api, output_api, "BadMessageReasonChrome") results = []
results.extend(_CheckUnwantedDependencies(input_api, output_api))
results.extend(_RunHistogramChecks(input_api, output_api,
"BadMessageReasonChrome"))
return results
def CheckChangeOnUpload(input_api, output_api): def CheckChangeOnUpload(input_api, output_api):
......
#!/usr/bin/env python
# Copyright (c) 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os.path
import subprocess
import sys
import unittest
import PRESUBMIT
file_dir_path = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(file_dir_path, '..', '..'))
from PRESUBMIT_test_mocks import MockFile, MockAffectedFile
from PRESUBMIT_test_mocks import MockInputApi, MockOutputApi
_VALID_DEP = "+third_party/blink/public/platform/web_something.h,"
_INVALID_DEP = "+third_party/blink/public/web/web_something.h,"
_INVALID_DEP2 = "+third_party/blink/public/web/web_nothing.h,"
class BlinkPublicWebUnwantedDependenciesTest(unittest.TestCase):
def makeInputApi(self, files):
input_api = MockInputApi()
input_api.files = files
# Override os_path.exists because the presubmit uses the actual
# os.path.exists.
input_api.CreateMockFileInPath(
[x.LocalPath() for x in input_api.AffectedFiles(include_deletes=True)])
return input_api
INVALID_DEPS_MESSAGE = ('chrome/browser cannot depend on '
'blink/public/web interfaces. Use'
' blink/public/common instead.')
def testAdditionOfUnwantedDependency(self):
input_api = self.makeInputApi([
MockAffectedFile('DEPS', [_INVALID_DEP], [], action='M')])
warnings = PRESUBMIT._CheckUnwantedDependencies(input_api, MockOutputApi())
self.assertEqual(1, len(warnings))
self.assertEqual(self.INVALID_DEPS_MESSAGE, warnings[0].message)
self.assertEqual(1, len(warnings[0].items))
def testAdditionOfUnwantedDependencyInComment(self):
input_api = self.makeInputApi([
MockAffectedFile('DEPS', ["#" + _INVALID_DEP], [], action='M')])
warnings = PRESUBMIT._CheckUnwantedDependencies(input_api, MockOutputApi())
self.assertEqual([], warnings)
def testAdditionOfValidDependency(self):
input_api = self.makeInputApi([
MockAffectedFile('DEPS', [_VALID_DEP], [], action='M')])
warnings = PRESUBMIT._CheckUnwantedDependencies(input_api, MockOutputApi())
self.assertEqual([], warnings)
def testAdditionOfMultipleUnwantedDependency(self):
input_api = self.makeInputApi([
MockAffectedFile('DEPS', [_INVALID_DEP, _INVALID_DEP2], action='M')])
warnings = PRESUBMIT._CheckUnwantedDependencies(input_api, MockOutputApi())
self.assertEqual(1, len(warnings))
self.assertEqual(self.INVALID_DEPS_MESSAGE, warnings[0].message)
self.assertEqual(2, len(warnings[0].items))
input_api = self.makeInputApi([
MockAffectedFile('DEPS', [_INVALID_DEP, _VALID_DEP], [], action='M')])
warnings = PRESUBMIT._CheckUnwantedDependencies(input_api, MockOutputApi())
self.assertEqual(1, len(warnings))
self.assertEqual(self.INVALID_DEPS_MESSAGE, warnings[0].message)
self.assertEqual(1, len(warnings[0].items))
def testRemovalOfUnwantedDependency(self):
input_api = self.makeInputApi([
MockAffectedFile('DEPS', [], [_INVALID_DEP], action='M')])
warnings = PRESUBMIT._CheckUnwantedDependencies(input_api, MockOutputApi())
self.assertEqual([], warnings)
def testRemovalOfValidDependency(self):
input_api = self.makeInputApi([
MockAffectedFile('DEPS', [], [_VALID_DEP], action='M')])
warnings = PRESUBMIT._CheckUnwantedDependencies(input_api, MockOutputApi())
self.assertEqual([], warnings)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment