blob: 3b9c3d186292a23e09c2891ad2ce81fbfde804f8 [file] [log] [blame]
Lei Zhang91d07df2017-03-30 23:14:16 -07001# 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 Zhang91d07df2017-03-30 23:14:16 -07004"""Presubmit script for PDFium testing corpus.
5
6See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
7for more details about the presubmit API built into depot_tools.
8"""
9
K. Moon3f50daa2022-12-21 20:12:57 +000010PRESUBMIT_VERSION = '2.0.0'
11
12USE_PYTHON3 = True
13
Nicolas Pena128b91c2017-06-26 17:11:15 -040014def _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. Moon3f50daa2022-12-21 20:12:57 +000023 f'Remove {f.LocalPath()} since corpus tests should not use .in files'
24 ))
Nicolas Pena128b91c2017-06-26 17:11:15 -040025 return results
26
Lei Zhang91d07df2017-03-30 23:14:16 -070027def _CheckPngNames(input_api, output_api):
Hui Yingst3c4d5062021-10-01 16:49:54 +000028 """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 Zhang91d07df2017-03-30 23:14:16 -070036 warnings = []
Lei Zhangbf5149b2017-04-04 01:42:53 -070037 for f in input_api.AffectedFiles(include_deletes=False):
Lei Zhang91d07df2017-03-30 23:14:16 -070038 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. Moon3f50daa2022-12-21 20:12:57 +000050def 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 Zhang91d07df2017-03-30 23:14:16 -070059def CheckChangeOnUpload(input_api, output_api):
60 results = []
61 results += _CheckPngNames(input_api, output_api)
Nicolas Pena128b91c2017-06-26 17:11:15 -040062 results += _CheckNoIn(input_api, output_api)
Lei Zhang91d07df2017-03-30 23:14:16 -070063 return results