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
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8for more details about the presubmit API built into depot_tools.
9"""
10
11def _CheckApiTestFile(input_api, output_api):
12  """Checks that the public headers match the API tests."""
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([])]):
19    return []
20
21  src_path = input_api.os_path.dirname(input_api.PresubmitLocalPath())
22  check_script = input_api.os_path.join(
23      src_path, 'testing' , 'tools' , 'api_check.py')
24  cmd = [input_api.python_executable, check_script]
25  try:
26    input_api.subprocess.check_output(cmd)
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
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
43