diff --git a/scripts/mk_install_tactic_cpp.py b/scripts/mk_install_tactic_cpp.py new file mode 100755 index 000000000..f8323d731 --- /dev/null +++ b/scripts/mk_install_tactic_cpp.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python +""" +Determines the available tactics +in header files in the list of source directions +and generates a ``install_tactic.cpp`` file in +the destination directory that defines a function +``void install_tactics(tactic_manager& ctx)``. +""" +import mk_util +import argparse +import logging +import os +import sys + +def check_dir(path): + if not os.path.exists(path): + logging.error('"{}" does not exist'.format(path)) + return 1 + + if not os.path.isdir(path): + logging.error('"{}" is not a directory'.format(path)) + return 1 + + return 0 + + +def main(args): + logging.basicConfig(level=logging.INFO) + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("destination_dir", help="destination directory") + parser.add_argument("source_dirs", nargs="+", + help="One or more source directories to search") + pargs = parser.parse_args(args) + + if check_dir(pargs.destination_dir) != 0: + return 1 + + for source_dir in pargs.source_dirs: + if check_dir(source_dir) != 0: + return 1 + + mk_util.mk_install_tactic_cpp_internal(pargs.source_dirs, pargs.destination_dir) + return 0 + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) + diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 77a8df0e2..9060d37fc 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -2677,6 +2677,13 @@ def ADD_PROBE(name, descr, cmd): # It installs all tactics in the given component (name) list cnames # The procedure looks for ADD_TACTIC commands in the .h files of these components. def mk_install_tactic_cpp(cnames, path): + component_src_dirs = [] + for cname in cnames: + c = get_component(cname) + component_src_dirs.append(c.src_dir) + mk_install_tactic_cpp_internal(component_src_dirs, path) + +def mk_install_tactic_cpp_internal(component_src_dirs, path): global ADD_TACTIC_DATA, ADD_PROBE_DATA ADD_TACTIC_DATA = [] ADD_PROBE_DATA = [] @@ -2688,12 +2695,11 @@ def mk_install_tactic_cpp(cnames, path): fout.write('#include"cmd_context.h"\n') tactic_pat = re.compile('[ \t]*ADD_TACTIC\(.*\)') probe_pat = re.compile('[ \t]*ADD_PROBE\(.*\)') - for cname in cnames: - c = get_component(cname) - h_files = filter(lambda f: f.endswith('.h') or f.endswith('.hpp'), os.listdir(c.src_dir)) + for component_src_dir in component_src_dirs: + h_files = filter(lambda f: f.endswith('.h') or f.endswith('.hpp'), os.listdir(component_src_dir)) for h_file in h_files: added_include = False - fin = open(os.path.join(c.src_dir, h_file), 'r') + fin = open(os.path.join(component_src_dir, h_file), 'r') for line in fin: if tactic_pat.match(line): if not added_include: