1*3ac0a46fSAndroid Build Coastguard Worker# Copyright 2019 The PDFium Authors 2*3ac0a46fSAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be 3*3ac0a46fSAndroid Build Coastguard Worker# found in the LICENSE file. 4*3ac0a46fSAndroid Build Coastguard Worker 5*3ac0a46fSAndroid Build Coastguard Worker"""Presubmit script for pdfium. 6*3ac0a46fSAndroid Build Coastguard Worker 7*3ac0a46fSAndroid Build Coastguard WorkerSee http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 8*3ac0a46fSAndroid Build Coastguard Workerfor more details about the presubmit API built into depot_tools. 9*3ac0a46fSAndroid Build Coastguard Worker""" 10*3ac0a46fSAndroid Build Coastguard Worker 11*3ac0a46fSAndroid Build Coastguard WorkerUSE_PYTHON3 = True 12*3ac0a46fSAndroid Build Coastguard Worker 13*3ac0a46fSAndroid Build Coastguard Worker 14*3ac0a46fSAndroid Build Coastguard Workerdef _CheckApiTestFile(input_api, output_api): 15*3ac0a46fSAndroid Build Coastguard Worker """Checks that the public headers match the API tests.""" 16*3ac0a46fSAndroid Build Coastguard Worker api_test_file = input_api.os_path.normpath('fpdfsdk/fpdf_view_c_api_test.c') 17*3ac0a46fSAndroid Build Coastguard Worker 18*3ac0a46fSAndroid Build Coastguard Worker def is_api_test_file(f): 19*3ac0a46fSAndroid Build Coastguard Worker return input_api.os_path.normpath(f.LocalPath()) == api_test_file 20*3ac0a46fSAndroid Build Coastguard Worker 21*3ac0a46fSAndroid Build Coastguard Worker if all([not is_api_test_file(f) for f in input_api.AffectedSourceFiles([])]): 22*3ac0a46fSAndroid Build Coastguard Worker return [] 23*3ac0a46fSAndroid Build Coastguard Worker 24*3ac0a46fSAndroid Build Coastguard Worker src_path = input_api.os_path.dirname(input_api.PresubmitLocalPath()) 25*3ac0a46fSAndroid Build Coastguard Worker check_script = input_api.os_path.join( 26*3ac0a46fSAndroid Build Coastguard Worker src_path, 'testing' , 'tools' , 'api_check.py') 27*3ac0a46fSAndroid Build Coastguard Worker cmd = [input_api.python3_executable, check_script] 28*3ac0a46fSAndroid Build Coastguard Worker try: 29*3ac0a46fSAndroid Build Coastguard Worker input_api.subprocess.check_output(cmd) 30*3ac0a46fSAndroid Build Coastguard Worker return [] 31*3ac0a46fSAndroid Build Coastguard Worker except input_api.subprocess.CalledProcessError as error: 32*3ac0a46fSAndroid Build Coastguard Worker return [output_api.PresubmitError('api_check.py failed:', 33*3ac0a46fSAndroid Build Coastguard Worker long_text=error.output)] 34*3ac0a46fSAndroid Build Coastguard Worker 35*3ac0a46fSAndroid Build Coastguard Worker 36*3ac0a46fSAndroid Build Coastguard Workerdef CheckChangeOnUpload(input_api, output_api): 37*3ac0a46fSAndroid Build Coastguard Worker results = [] 38*3ac0a46fSAndroid Build Coastguard Worker results.extend(_CheckApiTestFile(input_api, output_api)) 39*3ac0a46fSAndroid Build Coastguard Worker return results 40*3ac0a46fSAndroid Build Coastguard Worker 41*3ac0a46fSAndroid Build Coastguard Worker 42*3ac0a46fSAndroid Build Coastguard Workerdef CheckChangeOnCommit(input_api, output_api): 43*3ac0a46fSAndroid Build Coastguard Worker results = [] 44*3ac0a46fSAndroid Build Coastguard Worker results.extend(_CheckApiTestFile(input_api, output_api)) 45*3ac0a46fSAndroid Build Coastguard Worker return results 46