blob: 17f7c6abc98123d147b403c9bea5f0161477fa89 [file] [log] [blame]
Lei Zhangac011992019-07-13 01:43:41 +00001# Copyright 2019 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.
4
5"""Presubmit script for pdfium.
6
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8for more details about the presubmit API built into depot_tools.
9"""
10
Lei Zhangac011992019-07-13 01:43:41 +000011def _CheckApiTestFile(input_api, output_api):
12 """Checks that the public headers match the API tests."""
Lei Zhang9f96a2d2019-07-17 17:33:58 +000013 api_test_file = input_api.os_path.normpath('fpdfsdk/fpdf_view_c_api_test.c')
14
15 def is_api_test_file(f):
16 return input_api.os_path.normpath(f.LocalPath()) == api_test_file
17
18 if all([not is_api_test_file(f) for f in input_api.AffectedSourceFiles([])]):
Lei Zhangac011992019-07-13 01:43:41 +000019 return []
20
Lei Zhang90ddbac2019-07-17 17:27:28 +000021 src_path = input_api.os_path.dirname(input_api.PresubmitLocalPath())
Lei Zhangac011992019-07-13 01:43:41 +000022 check_script = input_api.os_path.join(
23 src_path, 'testing' , 'tools' , 'api_check.py')
Lei Zhang90ddbac2019-07-17 17:27:28 +000024 cmd = [input_api.python_executable, check_script]
Lei Zhangac011992019-07-13 01:43:41 +000025 try:
Lei Zhang90ddbac2019-07-17 17:27:28 +000026 input_api.subprocess.check_output(cmd)
Lei Zhangac011992019-07-13 01:43:41 +000027 return []
28 except input_api.subprocess.CalledProcessError as error:
29 return [output_api.PresubmitError('api_check.py failed:',
30 long_text=error.output)]
31
32
33def CheckChangeOnUpload(input_api, output_api):
34 results = []
35 results += _CheckApiTestFile(input_api, output_api)
36 return results
37
38
39def CheckChangeOnCommit(input_api, output_api):
40 results = []
41 results += _CheckApiTestFile(input_api, output_api)
42 return results