Thanks to visit codestin.com
Credit goes to chromium.googlesource.com

blob: 9f27912aba84dc205ba4af86fb306d4db4b9efd7 [file] [log] [blame]
Avi Drissmand387f0922022-09-14 20:51:311# Copyright 2014 The Chromium Authors
[email protected]0227bae2014-08-07 07:28:112# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
jamesra03ae492014-10-03 04:26:485"""Presubmit script for mojo
[email protected]0227bae2014-08-07 07:28:116
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8for more details about the presubmit API built into depot_tools.
9"""
10
Fred Shih0292146f2025-01-28 02:20:5111from filecmp import dircmp
[email protected]0227bae2014-08-07 07:28:1112import os.path
Fred Shih0292146f2025-01-28 02:20:5113import subprocess
14import tempfile
[email protected]0227bae2014-08-07 07:28:1115
Bruce Dawsonb9b04012022-08-03 18:12:3716PRESUBMIT_VERSION = '2.0.0'
Josip Sokcevic1b130f392021-06-12 02:30:4117
Bruce Dawsonb9b04012022-08-03 18:12:3718def CheckChange(input_api, output_api):
[email protected]0227bae2014-08-07 07:28:1119 # Additional python module paths (we're in src/mojo/); not everyone needs
20 # them, but it's easiest to add them to everyone's path.
21 # For ply and jinja2:
22 third_party_path = os.path.join(
23 input_api.PresubmitLocalPath(), "..", "third_party")
24 # For the bindings generator:
25 mojo_public_bindings_pylib_path = os.path.join(
26 input_api.PresubmitLocalPath(), "public", "tools", "bindings", "pylib")
qsr42868762014-10-10 16:38:1127 # For the python bindings:
28 mojo_python_bindings_path = os.path.join(
29 input_api.PresubmitLocalPath(), "public", "python")
[email protected]0227bae2014-08-07 07:28:1130 # TODO(vtl): Don't lint these files until the (many) problems are fixed
31 # (possibly by deleting/rewriting some files).
James Cooke9bc2112020-07-27 20:55:5532 files_to_skip = input_api.DEFAULT_FILES_TO_SKIP + \
[email protected]0227bae2014-08-07 07:28:1133 (r".*\bpublic[\\\/]tools[\\\/]bindings[\\\/]pylib[\\\/]mojom[\\\/]"
34 r"generate[\\\/].+\.py$",
Alex Goughf0563ec2022-04-22 17:58:2035 r".*\bpublic[\\\/]tools[\\\/]bindings[\\\/]checks[\\\/].+\.py$",
[email protected]0227bae2014-08-07 07:28:1136 r".*\bpublic[\\\/]tools[\\\/]bindings[\\\/]generators[\\\/].+\.py$",
37 r".*\bspy[\\\/]ui[\\\/].+\.py$",
38 r".*\btools[\\\/]pylib[\\\/]transitive_hash\.py$",
39 r".*\btools[\\\/]test_runner\.py$")
40
41 results = []
qsr42868762014-10-10 16:38:1142 pylint_extra_paths = [
43 third_party_path,
44 mojo_public_bindings_pylib_path,
45 mojo_python_bindings_path,
qsr42868762014-10-10 16:38:1146 ]
[email protected]0227bae2014-08-07 07:28:1147 results += input_api.canned_checks.RunPylint(
48 input_api, output_api, extra_paths_list=pylint_extra_paths,
James Cooke9bc2112020-07-27 20:55:5549 files_to_skip=files_to_skip)
[email protected]0227bae2014-08-07 07:28:1150 return results
Fred Shih0292146f2025-01-28 02:20:5151
52def CheckGoldenFilesUpToDate(input_api, output_api):
53 generate_script = os.path.join(input_api.PresubmitLocalPath(),
54 'golden/generate.py')
55 generated_dir = os.path.join(input_api.PresubmitLocalPath(),
56 'golden/generated')
57 with tempfile.TemporaryDirectory() as tmp_dir:
58 subprocess.run(['python3', generate_script, '--output-dir', tmp_dir],
59 check=True)
Fred Shih4ff44412025-07-09 21:37:5260 diff_files = []
61 for _, dcmp in dircmp(tmp_dir, generated_dir).subdirs.items():
62 diff_files += dcmp.diff_files
63 if len(diff_files) == 0:
Fred Shih0292146f2025-01-28 02:20:5164 return []
65 return [output_api.PresubmitError(
66 'Bindings generated from mojo/golden/corpus differ from '
67 'golden files in mojo/golden/generated. Please regenerate '
68 'golden files by running: mojo/golden/generate.py',
Fred Shih4ff44412025-07-09 21:37:5269 items=diff_files)]