tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PRESUBMIT.py (2034B)


      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.
      4 
      5 PRESUBMIT_VERSION = '2.0.0'
      6 
      7 import textwrap
      8 
      9 
     10 def CheckNoBadDeps(input_api, output_api):
     11  """Prevent additions of bad dependencies from the //build prefix."""
     12  build_file_patterns = [
     13      r'(.+/)?BUILD\.gn',
     14      r'.+\.gni',
     15  ]
     16  exclude_file_patterns = [
     17      r'build/rust/tests',
     18  ]
     19  blocklist_pattern = input_api.re.compile(r'^[^#]*"//(?!build).+?/.*"')
     20  allowlist_pattern = input_api.re.compile(r'^[^#]*"//third_party/junit')
     21 
     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).:""")
     30 
     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)
     35 
     36  problems = []
     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()))
     43  if problems:
     44    return [output_api.PresubmitPromptOrNotify(warning_message, problems)]
     45  else:
     46    return []
     47 
     48 
     49 def CheckPythonTests(input_api, output_api):
     50  return input_api.RunTests(
     51      input_api.canned_checks.GetUnitTestsInDirectory(
     52          input_api,
     53          output_api,
     54          input_api.PresubmitLocalPath(),
     55          files_to_check=[r'.+_(?:unit)?test\.py$']))