1e5c31af7Sopenharmony_ci# -*- coding: utf-8 -*- 2e5c31af7Sopenharmony_ci 3e5c31af7Sopenharmony_ci#------------------------------------------------------------------------- 4e5c31af7Sopenharmony_ci# drawElements Quality Program utilities 5e5c31af7Sopenharmony_ci# -------------------------------------- 6e5c31af7Sopenharmony_ci# 7e5c31af7Sopenharmony_ci# Copyright 2015 The Android Open Source Project 8e5c31af7Sopenharmony_ci# 9e5c31af7Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); 10e5c31af7Sopenharmony_ci# you may not use this file except in compliance with the License. 11e5c31af7Sopenharmony_ci# You may obtain a copy of the License at 12e5c31af7Sopenharmony_ci# 13e5c31af7Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 14e5c31af7Sopenharmony_ci# 15e5c31af7Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 16e5c31af7Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, 17e5c31af7Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18e5c31af7Sopenharmony_ci# See the License for the specific language governing permissions and 19e5c31af7Sopenharmony_ci# limitations under the License. 20e5c31af7Sopenharmony_ci# 21e5c31af7Sopenharmony_ci#------------------------------------------------------------------------- 22e5c31af7Sopenharmony_ci 23e5c31af7Sopenharmony_ciimport sys 24e5c31af7Sopenharmony_cifrom argparse import ArgumentParser 25e5c31af7Sopenharmony_cifrom common import getChangedFiles, getAllProjectFiles 26e5c31af7Sopenharmony_cifrom check_include_guards import checkIncludeGuards 27e5c31af7Sopenharmony_cifrom check_encoding import checkEncoding 28e5c31af7Sopenharmony_cifrom check_whitespace import checkWhitespace 29e5c31af7Sopenharmony_cifrom check_license import checkLicense 30e5c31af7Sopenharmony_cifrom check_boms import checkBOMs 31e5c31af7Sopenharmony_cifrom check_file_size_limit import checkFilesSizeLimit 32e5c31af7Sopenharmony_ci 33e5c31af7Sopenharmony_ciif __name__ == "__main__": 34e5c31af7Sopenharmony_ci parser = ArgumentParser() 35e5c31af7Sopenharmony_ci parser.add_argument("-e", "--only-errors", action="store_true", dest="onlyErrors", default=False, help="Print only on error") 36e5c31af7Sopenharmony_ci parser.add_argument("-i", "--only-changed", action="store_true", dest="useGitIndex", default=False, help="Check only modified files. Uses git.") 37e5c31af7Sopenharmony_ci parser.add_argument("-b", "--fix-bom", action="store_true", dest="fixBOMs", default=False, help="Attempt to fix BOMs") 38e5c31af7Sopenharmony_ci 39e5c31af7Sopenharmony_ci args = parser.parse_args() 40e5c31af7Sopenharmony_ci 41e5c31af7Sopenharmony_ci if args.useGitIndex: 42e5c31af7Sopenharmony_ci files = getChangedFiles() 43e5c31af7Sopenharmony_ci else: 44e5c31af7Sopenharmony_ci files = getAllProjectFiles() 45e5c31af7Sopenharmony_ci 46e5c31af7Sopenharmony_ci # filter out original Vulkan header sources 47e5c31af7Sopenharmony_ci files = [f for f in files if "vulkancts/scripts/src" not in f.replace("\\", "/")] 48e5c31af7Sopenharmony_ci 49e5c31af7Sopenharmony_ci error = not all([ 50e5c31af7Sopenharmony_ci checkBOMs(files, args.fixBOMs), 51e5c31af7Sopenharmony_ci checkEncoding(files), 52e5c31af7Sopenharmony_ci checkWhitespace(files), 53e5c31af7Sopenharmony_ci checkIncludeGuards(files), 54e5c31af7Sopenharmony_ci checkLicense(files), 55e5c31af7Sopenharmony_ci checkFilesSizeLimit (files, 100 * 1024 * 1024), 56e5c31af7Sopenharmony_ci #todo checkRedundantIncludeGuards(files), 57e5c31af7Sopenharmony_ci ]) 58e5c31af7Sopenharmony_ci 59e5c31af7Sopenharmony_ci if error: 60e5c31af7Sopenharmony_ci print("One or more checks failed") 61e5c31af7Sopenharmony_ci sys.exit(1) 62e5c31af7Sopenharmony_ci if not args.onlyErrors: 63e5c31af7Sopenharmony_ci print("All checks passed") 64