Lei Zhang | ac01199 | 2019-07-13 01:43:41 +0000 | [diff] [blame] | 1 | # 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 | |
| 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 | |
Lei Zhang | ac01199 | 2019-07-13 01:43:41 +0000 | [diff] [blame] | 11 | def _CheckApiTestFile(input_api, output_api): |
| 12 | """Checks that the public headers match the API tests.""" |
Lei Zhang | 9f96a2d | 2019-07-17 17:33:58 +0000 | [diff] [blame] | 13 | 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 Zhang | ac01199 | 2019-07-13 01:43:41 +0000 | [diff] [blame] | 19 | return [] |
| 20 | |
Lei Zhang | 90ddbac | 2019-07-17 17:27:28 +0000 | [diff] [blame] | 21 | src_path = input_api.os_path.dirname(input_api.PresubmitLocalPath()) |
Lei Zhang | ac01199 | 2019-07-13 01:43:41 +0000 | [diff] [blame] | 22 | check_script = input_api.os_path.join( |
| 23 | src_path, 'testing' , 'tools' , 'api_check.py') |
Lei Zhang | 90ddbac | 2019-07-17 17:27:28 +0000 | [diff] [blame] | 24 | cmd = [input_api.python_executable, check_script] |
Lei Zhang | ac01199 | 2019-07-13 01:43:41 +0000 | [diff] [blame] | 25 | try: |
Lei Zhang | 90ddbac | 2019-07-17 17:27:28 +0000 | [diff] [blame] | 26 | input_api.subprocess.check_output(cmd) |
Lei Zhang | ac01199 | 2019-07-13 01:43:41 +0000 | [diff] [blame] | 27 | 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 | |
| 33 | def CheckChangeOnUpload(input_api, output_api): |
| 34 | results = [] |
| 35 | results += _CheckApiTestFile(input_api, output_api) |
| 36 | return results |
| 37 | |
| 38 | |
| 39 | def CheckChangeOnCommit(input_api, output_api): |
| 40 | results = [] |
| 41 | results += _CheckApiTestFile(input_api, output_api) |
| 42 | return results |