From 2bf255c8a3ed5f8151e554b94ad7de03517425be Mon Sep 17 00:00:00 2001 From: Adam Felizzi Date: Tue, 21 Aug 2018 17:48:42 +1000 Subject: [PATCH] tools: Ignore option for circular_includes script Added an "ignore" argument to the circular_includes script. This allows the caller to specify files for the script to ignore when it parses the source file. Rather than creating a special ignore case for "kernel_all.c" in the script itself, the user parses the file as an argument (plus others if needed). Updated the kernels cmake file to reflect the change. --- CMakeLists.txt | 2 +- tools/circular_includes.py | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7dfea9631..3435e8309 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -380,7 +380,7 @@ CPPFile("${linker_lds_path}" linker_ld_wrapper "${linker_source}" ) add_custom_command(OUTPUT circular_includes_valid - COMMAND ${CIRCULAR_INCLUDES} < kernel_all.i + COMMAND ${CIRCULAR_INCLUDES} --ignore kernel_all.c < kernel_all.i COMMAND touch circular_includes_valid DEPENDS kernel_i_wrapper kernel_all.i ) diff --git a/tools/circular_includes.py b/tools/circular_includes.py index 825a44a5e..ffe1829b5 100755 --- a/tools/circular_includes.py +++ b/tools/circular_includes.py @@ -18,22 +18,29 @@ prints circular dependency and exits with a status of -1. import sys import re +import argparse -def main(): +def main(parse_args): """ Reads pre-processed sel4 source from standard input. If a circular dependency is found, the chain of includes resulting in the loop is printed out. """ - kernel_all_re = re.compile(r'^# 1 ".*kernel_all\.c"') + ignore_re = None + ignore_args = parse_args.ignore + if ignore_args and len(ignore_args): + ignore_args = [re.escape(ignore) for ignore in ignore_args] + ignore_re_string = '(' + '|'.join(ignore_args) + ')' + ignore_re = re.compile(r'^# 1 ".*' + ignore_re_string + '"') + header_re = re.compile(r'^# (\d+) "(.*\..)"') file_stack = [] for line in sys.stdin: - if kernel_all_re.match(line): + if ignore_re and ignore_re.match(line): continue match = header_re.match(line) @@ -62,9 +69,9 @@ def main(): if __name__ == "__main__": - if len(sys.argv) != 1: - print("Usage: %s < path/to/kernel_all.c_pp" % sys.argv[0]) - print(__doc__) - sys.exit(-1) + parser = argparse.ArgumentParser() + parser.add_argument('--ignore', nargs='+', + help="Files to ignore when parsing the sel4 source") + args = parser.parse_args() - sys.exit(main()) + sys.exit(main(args))