Lei Zhang | 91d07df | 2017-03-30 23:14:16 -0700 | [diff] [blame] | 1 | # Copyright 2017 The PDFium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
Lei Zhang | 91d07df | 2017-03-30 23:14:16 -0700 | [diff] [blame] | 4 | """Presubmit script for PDFium testing corpus. |
| 5 | |
| 6 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts |
| 7 | for more details about the presubmit API built into depot_tools. |
| 8 | """ |
| 9 | |
K. Moon | 3f50daa | 2022-12-21 20:12:57 +0000 | [diff] [blame] | 10 | PRESUBMIT_VERSION = '2.0.0' |
| 11 | |
| 12 | USE_PYTHON3 = True |
| 13 | |
Nicolas Pena | 128b91c | 2017-06-26 17:11:15 -0400 | [diff] [blame] | 14 | def _CheckNoIn(input_api, output_api): |
| 15 | """Checks that corpus tests don't contain .in files. Corpus tests should be |
| 16 | .pdf files, having both can cause race conditions on the bots, which run the |
| 17 | tests in parallel. |
| 18 | """ |
| 19 | results = [] |
| 20 | for f in input_api.AffectedFiles(include_deletes=False): |
| 21 | if f.LocalPath().endswith('.in'): |
| 22 | results.append(output_api.PresubmitError( |
K. Moon | 3f50daa | 2022-12-21 20:12:57 +0000 | [diff] [blame] | 23 | f'Remove {f.LocalPath()} since corpus tests should not use .in files' |
| 24 | )) |
Nicolas Pena | 128b91c | 2017-06-26 17:11:15 -0400 | [diff] [blame] | 25 | return results |
| 26 | |
Lei Zhang | 91d07df | 2017-03-30 23:14:16 -0700 | [diff] [blame] | 27 | def _CheckPngNames(input_api, output_api): |
Hui Yingst | 3c4d506 | 2021-10-01 16:49:54 +0000 | [diff] [blame] | 28 | """Checks that .png files have the right file name format, which must be in |
| 29 | the form of |
| 30 | NAME_expected(_(skia|skiapaths))?(_(win|mac|linux))?.pdf.#.png. This format |
| 31 | must be the same as the one used in PDFium's PRESUBMIT.py's |
| 32 | _CheckPNGFormat(). |
| 33 | """ |
| 34 | png_regex = input_api.re.compile( |
| 35 | r'.+_expected(_(skia|skiapaths))?(_(win|mac|linux))?\.pdf\.\d+.png') |
Lei Zhang | 91d07df | 2017-03-30 23:14:16 -0700 | [diff] [blame] | 36 | warnings = [] |
Lei Zhang | bf5149b | 2017-04-04 01:42:53 -0700 | [diff] [blame] | 37 | for f in input_api.AffectedFiles(include_deletes=False): |
Lei Zhang | 91d07df | 2017-03-30 23:14:16 -0700 | [diff] [blame] | 38 | local_path = f.LocalPath() |
| 39 | if local_path.endswith('.png'): |
| 40 | if not png_regex.match(local_path): |
| 41 | warnings.append(local_path) |
| 42 | |
| 43 | results = [] |
| 44 | if warnings: |
| 45 | results.append(output_api.PresubmitPromptOrNotify( |
| 46 | 'The following PNG files have the wrong file name format:\n', |
| 47 | warnings)) |
| 48 | return results |
| 49 | |
K. Moon | 3f50daa | 2022-12-21 20:12:57 +0000 | [diff] [blame] | 50 | def ChecksCommon(input_api, output_api): |
| 51 | results = [] |
| 52 | |
| 53 | results.extend( |
| 54 | input_api.canned_checks.PanProjectChecks( |
| 55 | input_api, output_api, project_name='PDFium')) |
| 56 | |
| 57 | return results |
| 58 | |
Lei Zhang | 91d07df | 2017-03-30 23:14:16 -0700 | [diff] [blame] | 59 | def CheckChangeOnUpload(input_api, output_api): |
| 60 | results = [] |
| 61 | results += _CheckPngNames(input_api, output_api) |
Nicolas Pena | 128b91c | 2017-06-26 17:11:15 -0400 | [diff] [blame] | 62 | results += _CheckNoIn(input_api, output_api) |
Lei Zhang | 91d07df | 2017-03-30 23:14:16 -0700 | [diff] [blame] | 63 | return results |