Avi Drissman | d387f092 | 2022-09-14 20:51:31 | [diff] [blame] | 1 | # Copyright 2014 The Chromium Authors |
viettrungluu@chromium.org | 0227bae | 2014-08-07 07:28:11 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
jamesr | a03ae49 | 2014-10-03 04:26:48 | [diff] [blame] | 5 | """Presubmit script for mojo |
viettrungluu@chromium.org | 0227bae | 2014-08-07 07:28:11 | [diff] [blame] | 6 | |
| 7 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 8 | for more details about the presubmit API built into depot_tools. |
| 9 | """ |
| 10 | |
Fred Shih | 0292146f | 2025-01-28 02:20:51 | [diff] [blame] | 11 | from filecmpimport dircmp |
viettrungluu@chromium.org | 0227bae | 2014-08-07 07:28:11 | [diff] [blame] | 12 | import os.path |
Fred Shih | 0292146f | 2025-01-28 02:20:51 | [diff] [blame] | 13 | import subprocess |
| 14 | import tempfile |
viettrungluu@chromium.org | 0227bae | 2014-08-07 07:28:11 | [diff] [blame] | 15 | |
Bruce Dawson | b9b0401 | 2022-08-03 18:12:37 | [diff] [blame] | 16 | PRESUBMIT_VERSION='2.0.0' |
Josip Sokcevic | 1b130f39 | 2021-06-12 02:30:41 | [diff] [blame] | 17 | |
Bruce Dawson | b9b0401 | 2022-08-03 18:12:37 | [diff] [blame] | 18 | defCheckChange(input_api, output_api): |
viettrungluu@chromium.org | 0227bae | 2014-08-07 07:28:11 | [diff] [blame] | 19 | # 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") |
qsr | 4286876 | 2014-10-10 16:38:11 | [diff] [blame] | 27 | # For the python bindings: |
| 28 | mojo_python_bindings_path= os.path.join( |
| 29 | input_api.PresubmitLocalPath(),"public","python") |
viettrungluu@chromium.org | 0227bae | 2014-08-07 07:28:11 | [diff] [blame] | 30 | # TODO(vtl): Don't lint these files until the (many) problems are fixed |
| 31 | # (possibly by deleting/rewriting some files). |
James Cook | e9bc211 | 2020-07-27 20:55:55 | [diff] [blame] | 32 | files_to_skip= input_api.DEFAULT_FILES_TO_SKIP+ \ |
viettrungluu@chromium.org | 0227bae | 2014-08-07 07:28:11 | [diff] [blame] | 33 | (r".*\bpublic[\\\/]tools[\\\/]bindings[\\\/]pylib[\\\/]mojom[\\\/]" |
| 34 | r"generate[\\\/].+\.py$", |
Alex Gough | f0563ec | 2022-04-22 17:58:20 | [diff] [blame] | 35 | r".*\bpublic[\\\/]tools[\\\/]bindings[\\\/]checks[\\\/].+\.py$", |
viettrungluu@chromium.org | 0227bae | 2014-08-07 07:28:11 | [diff] [blame] | 36 | 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=[] |
qsr | 4286876 | 2014-10-10 16:38:11 | [diff] [blame] | 42 | pylint_extra_paths=[ |
| 43 | third_party_path, |
| 44 | mojo_public_bindings_pylib_path, |
| 45 | mojo_python_bindings_path, |
qsr | 4286876 | 2014-10-10 16:38:11 | [diff] [blame] | 46 | ] |
viettrungluu@chromium.org | 0227bae | 2014-08-07 07:28:11 | [diff] [blame] | 47 | results+= input_api.canned_checks.RunPylint( |
| 48 | input_api, output_api, extra_paths_list=pylint_extra_paths, |
James Cook | e9bc211 | 2020-07-27 20:55:55 | [diff] [blame] | 49 | files_to_skip=files_to_skip) |
viettrungluu@chromium.org | 0227bae | 2014-08-07 07:28:11 | [diff] [blame] | 50 | return results |
Fred Shih | 0292146f | 2025-01-28 02:20:51 | [diff] [blame] | 51 | |
| 52 | defCheckGoldenFilesUpToDate(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 Shih | 4ff4441 | 2025-07-09 21:37:52 | [diff] [blame] | 60 | diff_files=[] |
| 61 | for _, dcmpin dircmp(tmp_dir, generated_dir).subdirs.items(): |
| 62 | diff_files+= dcmp.diff_files |
| 63 | if len(diff_files)==0: |
Fred Shih | 0292146f | 2025-01-28 02:20:51 | [diff] [blame] | 64 | 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 Shih | 4ff4441 | 2025-07-09 21:37:52 | [diff] [blame] | 69 | items=diff_files)] |