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.
This commit is contained in:
Adam Felizzi
2018-08-21 17:48:42 +10:00
parent 880686dd22
commit 2bf255c8a3
2 changed files with 16 additions and 9 deletions

View File

@@ -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
)

View File

@@ -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))