From 114cd4deeea792912bf435e04d659fa5fbb9f2dc Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Sat, 10 May 2025 10:54:01 -0400 Subject: [PATCH] show_help: only parse specific trees for help files Change --root CLI param to --roots in order to accept a specific list of root directories to traverse to look for help files (rather than a single top-level root that contains all the directories that we want to traverse -- but which also contains directories that we *don't* want to traverse). Also, just for the heckuvit, parameterize the list of subdirectories to skip (via --skip-dirs). Using --roots prevents us from accidentally traversing into VPATH build directories, for example, and finding PMIx and/or PRTE help files. Signed-off-by: Jeff Squyres --- opal/util/Makefile.am | 8 +++-- opal/util/convert-help-files-to-c-code.py | 39 +++++++++++++---------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/opal/util/Makefile.am b/opal/util/Makefile.am index 03020fb31e9..afd657b5b09 100644 --- a/opal/util/Makefile.am +++ b/opal/util/Makefile.am @@ -128,8 +128,12 @@ libopalutil_core_la_SOURCES = \ uri.c show_help_content.c: convert-help-files-to-c-code.py - $(OMPI_V_GEN) $(PYTHON) $(abs_srcdir)/convert-help-files-to-c-code.py \ - --root $(abs_top_srcdir) \ + $(OMPI_V_GEN) subdirs=""; \ + for dir in $(MCA_PROJECT_SUBDIRS); do \ + subdirs="$(abs_top_srcdir)/$$dir $$subdirs"; \ + done; \ + $(PYTHON) $(abs_srcdir)/convert-help-files-to-c-code.py \ + --roots $$subdirs \ --out show_help_content.c if OPAL_COMPILE_TIMING diff --git a/opal/util/convert-help-files-to-c-code.py b/opal/util/convert-help-files-to-c-code.py index d8814d9fb1b..288b4772d35 100755 --- a/opal/util/convert-help-files-to-c-code.py +++ b/opal/util/convert-help-files-to-c-code.py @@ -12,22 +12,24 @@ import sys import argparse -def find_help_files(root, verbose=False): +def find_help_files(roots, skip_dirs, verbose=False): # Search for help-*.txt files across the source tree, skipping # some directories (e.g., 3rd-party) help_files = [] - skip_dirs = ['.git', '3rd-party'] - for root_dir, dirs, files in os.walk(root): - for sd in skip_dirs: - if sd in dirs: - dirs.remove(sd) - - for file in files: - if file.startswith("help-") and file.endswith(".txt"): - full_path = os.path.join(root_dir, file) - help_files.append(full_path) - if verbose: - print(f"Found: {full_path}") + for root in roots: + for root_dir, dirs, files in os.walk(root): + for sd in skip_dirs: + if sd in dirs: + print(f"Skipping additional dir: {root_dir}/{sd}") + dirs.remove(sd) + + for file in files: + if file.startswith("help-") and file.endswith(".txt"): + full_path = os.path.join(root_dir, file) + help_files.append(full_path) + if verbose: + print(f"Found: {full_path}") + return help_files def parse_ini_files(file_paths, verbose=False): @@ -162,9 +164,14 @@ def generate_c_code(parsed_data): def main(): parser = argparse.ArgumentParser(description="Generate C code from help text INI files.") - parser.add_argument("--root", + parser.add_argument("--roots", + nargs='+', required=True, - help="Root directory to search for help-*.txt files") + help="Space-delimited list of directories to search for help-*.txt files") + parser.add_argument("--skip-dirs", + nargs='*', + default=['.git', '3rd-party'], + help="Space-delimited list of directories to skip traversing") parser.add_argument("--out", required=True, help="Output C file") @@ -176,7 +183,7 @@ def main(): if args.verbose: print(f"Searching in: {args.root}") - file_paths = find_help_files(args.root, args.verbose) + file_paths = find_help_files(args.roots, args.skip_dirs, args.verbose) parsed_data = parse_ini_files(file_paths, args.verbose) c_code = generate_c_code(parsed_data)