utils.py (1179B)
1 # Lint as: python3 2 # Copyright 2021 The Chromium Authors 3 # Use of this source code is governed by a BSD-style license that can be 4 # found in the LICENSE file. 5 6 import logging 7 import os 8 import pathlib 9 import subprocess 10 11 # These paths should be relative to repository root. 12 _BAD_FILES = [ 13 # Malformed BUILD.gn file, remove this entry once it is fixed. 14 "third_party/swiftshader/tests/VulkanUnitTests/BUILD.gn", 15 ] 16 17 18 def is_bad_gn_file(filepath: str, root: pathlib.Path) -> bool: 19 relpath = os.path.relpath(filepath, root) 20 for bad_filepath in _BAD_FILES: 21 if relpath == bad_filepath: 22 logging.info(f'Skipping {relpath}: found in _BAD_FILES list.') 23 return True 24 if not os.access(filepath, os.R_OK | os.W_OK): 25 logging.info(f'Skipping {relpath}: Cannot read and write to it.') 26 return True 27 return False 28 29 30 def is_git_ignored(root: pathlib.Path, filepath: str) -> bool: 31 # The command git check-ignore exits with 0 if the path is ignored, 1 if it 32 # is not ignored. 33 exit_code = subprocess.run(['git', 'check-ignore', '-q', filepath], 34 cwd=root).returncode 35 return exit_code == 0