xref: /aosp_15_r20/external/pdfium/fpdfsdk/PRESUBMIT.py (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1# Copyright 2019 The PDFium Authors
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
11USE_PYTHON3 = True
12
13
14def _CheckApiTestFile(input_api, output_api):
15  """Checks that the public headers match the API tests."""
16  api_test_file = input_api.os_path.normpath('fpdfsdk/fpdf_view_c_api_test.c')
17
18  def is_api_test_file(f):
19    return input_api.os_path.normpath(f.LocalPath()) == api_test_file
20
21  if all([not is_api_test_file(f) for f in input_api.AffectedSourceFiles([])]):
22    return []
23
24  src_path = input_api.os_path.dirname(input_api.PresubmitLocalPath())
25  check_script = input_api.os_path.join(
26      src_path, 'testing' , 'tools' , 'api_check.py')
27  cmd = [input_api.python3_executable, check_script]
28  try:
29    input_api.subprocess.check_output(cmd)
30    return []
31  except input_api.subprocess.CalledProcessError as error:
32    return [output_api.PresubmitError('api_check.py failed:',
33                                      long_text=error.output)]
34
35
36def CheckChangeOnUpload(input_api, output_api):
37  results = []
38  results.extend(_CheckApiTestFile(input_api, output_api))
39  return results
40
41
42def CheckChangeOnCommit(input_api, output_api):
43  results = []
44  results.extend(_CheckApiTestFile(input_api, output_api))
45  return results
46