Jeremy Leconte | 1ab4e87 | 2022-08-29 21:14:15 +0200 | [diff] [blame] | 1 | #!/usr/bin/env vpython3 |
| 2 | |
Jeremy Leconte | 0c4059c | 2022-04-04 07:58:40 +0200 | [diff] [blame] | 3 | # Copyright (c) 2022 The WebRTC project authors. All Rights Reserved. |
| 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license |
| 6 | # that can be found in the LICENSE file in the root of the source |
| 7 | # tree. An additional intellectual property rights grant can be found |
| 8 | # in the file PATENTS. All contributing project authors may |
| 9 | # be found in the AUTHORS file in the root of the source tree. |
| 10 | |
Mirko Bonadei | 5c8993c | 2022-04-04 18:43:54 +0000 | [diff] [blame] | 11 | import os |
Byoungchan Lee | 7970f87 | 2022-12-06 21:34:35 +0900 | [diff] [blame] | 12 | import shlex |
Mirko Bonadei | 5c8993c | 2022-04-04 18:43:54 +0000 | [diff] [blame] | 13 | |
Jeremy Leconte | 1ab4e87 | 2022-08-29 21:14:15 +0200 | [diff] [blame] | 14 | # Runs PRESUBMIT.py in py3 mode by git cl presubmit. |
| 15 | USE_PYTHON3 = True |
| 16 | |
Jeremy Leconte | 0c4059c | 2022-04-04 07:58:40 +0200 | [diff] [blame] | 17 | |
| 18 | def _HasLocalChanges(input_api): |
| 19 | ret = input_api.subprocess.call(['git', 'diff', '--quiet']) |
| 20 | return ret != 0 |
| 21 | |
| 22 | |
| 23 | def CheckPatchFormatted(input_api, output_api): |
| 24 | results = [] |
| 25 | file_filter = lambda x: x.LocalPath().endswith('.pyl') |
| 26 | affected_files = input_api.AffectedFiles(include_deletes=False, |
| 27 | file_filter=file_filter) |
| 28 | |
| 29 | for f in affected_files: |
| 30 | cmd = ['yapf', '-i', f.AbsoluteLocalPath()] |
| 31 | if input_api.subprocess.call(cmd): |
Byoungchan Lee | 7970f87 | 2022-12-06 21:34:35 +0900 | [diff] [blame] | 32 | results.append( |
| 33 | output_api.PresubmitError('Error calling "' + shlex.join(cmd) + '"')) |
Jeremy Leconte | 0c4059c | 2022-04-04 07:58:40 +0200 | [diff] [blame] | 34 | |
| 35 | if _HasLocalChanges(input_api): |
| 36 | msg = ('Diff found after running "yapf -i" on modified .pyl files.\n' |
| 37 | 'Please commit or discard the new changes.') |
| 38 | results.append(output_api.PresubmitError(msg)) |
| 39 | |
| 40 | return results |
| 41 | |
| 42 | |
Mirko Bonadei | 5c8993c | 2022-04-04 18:43:54 +0000 | [diff] [blame] | 43 | def CheckSourceSideSpecs(input_api, output_api): |
| 44 | d = os.path.dirname |
Jeremy Leconte | 1ab4e87 | 2022-08-29 21:14:15 +0200 | [diff] [blame] | 45 | webrtc_root = d(d(input_api.PresubmitLocalPath())) |
| 46 | gen_script = os.path.join(webrtc_root, 'testing', 'buildbot', |
Mirko Bonadei | 5c8993c | 2022-04-04 18:43:54 +0000 | [diff] [blame] | 47 | 'generate_buildbot_json.py') |
| 48 | |
| 49 | commands = [ |
| 50 | input_api.Command(name='generate_buildbot_json', |
| 51 | cmd=[ |
Jeremy Leconte | 1ab4e87 | 2022-08-29 21:14:15 +0200 | [diff] [blame] | 52 | input_api.python3_executable, gen_script, '--check', |
Mirko Bonadei | 5c8993c | 2022-04-04 18:43:54 +0000 | [diff] [blame] | 53 | '--verbose', '--pyl-files-dir', |
| 54 | input_api.PresubmitLocalPath() |
| 55 | ], |
| 56 | kwargs={}, |
| 57 | message=output_api.PresubmitError), |
| 58 | ] |
| 59 | return input_api.RunTests(commands) |
| 60 | |
| 61 | |
Jeremy Leconte | 0c4059c | 2022-04-04 07:58:40 +0200 | [diff] [blame] | 62 | def CheckChangeOnUpload(input_api, output_api): |
| 63 | results = [] |
| 64 | results.extend(CheckPatchFormatted(input_api, output_api)) |
Mirko Bonadei | 5c8993c | 2022-04-04 18:43:54 +0000 | [diff] [blame] | 65 | results.extend(CheckSourceSideSpecs(input_api, output_api)) |
Jeremy Leconte | 0c4059c | 2022-04-04 07:58:40 +0200 | [diff] [blame] | 66 | return results |
| 67 | |
| 68 | |
| 69 | def CheckChangeOnCommit(input_api, output_api): |
| 70 | results = [] |
| 71 | results.extend(CheckPatchFormatted(input_api, output_api)) |
Mirko Bonadei | 5c8993c | 2022-04-04 18:43:54 +0000 | [diff] [blame] | 72 | results.extend(CheckSourceSideSpecs(input_api, output_api)) |
Jeremy Leconte | 0c4059c | 2022-04-04 07:58:40 +0200 | [diff] [blame] | 73 | return results |