From 903869718389be7a80da9a1ea5d6835a68cda655 Mon Sep 17 00:00:00 2001 From: thread-liu Date: Wed, 7 Apr 2021 11:50:47 +0800 Subject: [PATCH] [update] support bsp .ignore_format.yml. --- .ignore_format.yml | 9 +++++++ ignore_format.yml | 22 ---------------- tools/file_check.py | 62 +++++++++++++++++++++++++++++++-------------- 3 files changed, 52 insertions(+), 41 deletions(-) create mode 100644 .ignore_format.yml delete mode 100644 ignore_format.yml diff --git a/.ignore_format.yml b/.ignore_format.yml new file mode 100644 index 0000000000..4a0e8bbec7 --- /dev/null +++ b/.ignore_format.yml @@ -0,0 +1,9 @@ +# files format check exclude path, please follow the instructions below to modify; +# If you need to exclude an entire folder, add the folder path in dir_path; +# If you need to exclude a file, add the path to the file in file_path. + +file_path: +- bsp/allwinner_tina/libcpu/cpu.c + +dir_path: +- tools \ No newline at end of file diff --git a/ignore_format.yml b/ignore_format.yml deleted file mode 100644 index 17614c0b8e..0000000000 --- a/ignore_format.yml +++ /dev/null @@ -1,22 +0,0 @@ -# files format check exclude path, please follow the instructions below to modify; -# If you need to exclude an entire folder, add the folder path in dir_path; -# If you need to exclude a file, add the path to the file in file_path. - -file_path: -- bsp/stm32/stm32f072-st-nucleo/board/CubeMX_Config/Src/main.c - -dir_path: -- bsp/stm32/libraries/STM32F0xx_HAL -- bsp/stm32/libraries/STM32F1xx_HAL -- bsp/stm32/libraries/STM32F2xx_HAL -- bsp/stm32/libraries/STM32F4xx_HAL -- bsp/stm32/libraries/STM32F7xx_HAL -- bsp/stm32/libraries/STM32G0xx_HAL -- bsp/stm32/libraries/STM32G4xx_HAL -- bsp/stm32/libraries/STM32H7xx_HAL -- bsp/stm32/libraries/STM32L0xx_HAL -- bsp/stm32/libraries/STM32L1xx_HAL -- bsp/stm32/libraries/STM32L4xx_HAL -- bsp/stm32/libraries/STM32MPxx_HAL -- bsp/stm32/libraries/STM32WBxx_HAL -- bsp/stm32/libraries/STM32WLxx_HAL diff --git a/tools/file_check.py b/tools/file_check.py index f53edb53e6..d4095f55e4 100644 --- a/tools/file_check.py +++ b/tools/file_check.py @@ -34,22 +34,46 @@ class CheckOut: self.rtt_branch = rtt_branch def __exclude_file(self, file_path): - ignore_file_path = os.path.join(self.root, 'ignore_format.yml') - try: - with open(ignore_file_path) as f: - ignore_config = yaml.safe_load(f.read()) - file_ignore = ignore_config.get("file_path", []) - dir_ignore = ignore_config.get("dir_path", []) - except Exception as e: - logging.error(e) - return 1 + dir_number = file_path.split('/') + ignore_path = file_path - if file_path in file_ignore: - return 0 - - file_dir_path = os.path.dirname(file_path) - if file_dir_path in dir_ignore: - return 0 + # gets the file path depth. + for i in dir_number: + # current directory. + dir_name = os.path.dirname(ignore_path) + ignore_path = dir_name + # judge the ignore file exists in the current directory. + ignore_file_path = os.path.join(dir_name, ".ignore_format.yml") + if not os.path.exists(ignore_file_path): + continue + try: + with open(ignore_file_path) as f: + ignore_config = yaml.safe_load(f.read()) + file_ignore = ignore_config.get("file_path", []) + dir_ignore = ignore_config.get("dir_path", []) + except Exception as e: + logging.error(e) + continue + + try: + # judge file_path in the ignore file. + for file in file_ignore: + if file is not None: + file_real_path = os.path.join(dir_name, file) + if file_real_path == file_path: + logging.info("ignore file path: {}".format(file_real_path)) + return 0 + + file_dir_path = os.path.dirname(file_path) + for _dir in dir_ignore: + if _dir is not None: + dir_real_path = os.path.join(dir_name, _dir) + if dir_real_path == file_dir_path: + logging.info("ignore dir path: {}".format(dir_real_path)) + return 0 + except Exception as e: + logging.error(e) + continue return 1 @@ -93,7 +117,7 @@ class FormatCheck: def __init__(self, file_list): self.file_list = file_list - def __check_file(self, file_lines): + def __check_file(self, file_lines, file_path): line_num = 1 check_result = False for line in file_lines: @@ -101,12 +125,12 @@ class FormatCheck: line_start = line.replace(' ', '') # find tab if line_start.startswith('\t'): - logging.error("line[{}]: please use space replace tab at the start of this line.".format(line_num)) + logging.error("{} line[{}]: please use space replace tab at the start of this line.".format(file_path, line_num)) check_result = False # check line end lin_end = line.split('\n')[0] if lin_end.endswith(' ') or lin_end.endswith('\t'): - logging.error("line[{}]: please delete extra space at the end of this line.".format(line_num)) + logging.error("{} line[{}]: please delete extra space at the end of this line.".format(file_path, line_num)) check_result = False line_num += 1 @@ -140,7 +164,7 @@ class FormatCheck: with open(file_path, 'r') as f: file_lines = f.readlines() - format_check_result = self.__check_file(file_lines) + format_check_result = self.__check_file(file_lines, file_path) if not encoding_check_result or not format_check_result: logging.error("files format check fail.")