1 # Copyright 2022 The Chromium Authors
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 PRESUBMIT_VERSION = '2.0.0'
10 def CheckNoBadDeps(input_api, output_api):
11 """Prevent additions of bad dependencies from the //build prefix."""
12 build_file_patterns = [
16 exclude_file_patterns = [
19 blocklist_pattern = input_api.re.compile(r'^[^#]*"//(?!build).+?/.*"')
20 allowlist_pattern = input_api.re.compile(r'^[^#]*"//third_party/junit')
22 warning_message = textwrap.dedent("""
23 The //build directory is meant to be as hermetic as possible so that
24 other projects (webrtc, v8, angle) can make use of it. If you are adding
25 a new dep from //build onto another directory, you should consider:
26 1) Can that dep live within //build?
27 2) Can the dep be guarded by "build_with_chromium"?
28 3) Have you made this new dep easy to pull in for other projects (ideally
29 a matter of adding a DEPS entry).:""")
31 def FilterFile(affected_file):
32 return input_api.FilterSourceFile(affected_file,
33 files_to_check=build_file_patterns,
34 files_to_skip=exclude_file_patterns)
37 for f in input_api.AffectedSourceFiles(FilterFile):
38 local_path = f.LocalPath()
39 for line_number, line in f.ChangedContents():
40 if blocklist_pattern.search(line) and not allowlist_pattern.search(line):
41 problems.append('%s:%d\n %s' %
42 (local_path, line_number, line.strip()))
44 return [output_api.PresubmitPromptOrNotify(warning_message, problems)]
49 def CheckPythonTests(input_api, output_api):
50 return input_api.RunTests(
51 input_api.canned_checks.GetUnitTestsInDirectory(
54 input_api.PresubmitLocalPath(),
55 files_to_check=[r'.+_(?:unit)?test\.py$']))