From 342d7b4fd180be2e823c34a20111bd32d37cba7e Mon Sep 17 00:00:00 2001 From: Luca Colagrande Date: Thu, 8 May 2025 20:37:21 +0200 Subject: [PATCH] Report all errors on `stderr` --- list-make-prerequisites.py | 46 +++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/list-make-prerequisites.py b/list-make-prerequisites.py index 650c249..a6ecabd 100755 --- a/list-make-prerequisites.py +++ b/list-make-prerequisites.py @@ -38,35 +38,30 @@ def parse_args(): # Function to parse all rules from 'make -pq' output def _parse_makefile(): - try: - # Run 'make -pq' and capture its output - result = subprocess.run( - ['make', '-pq'], - capture_output=True, - text=True) + # Run 'make -pq' and capture its output + result = subprocess.run( + ['make', '-pq'], + capture_output=True, + text=True) - # Initialize an empty dictionary to store the targets and their prerequisites - targets = {} + # Initialize an empty dictionary to store the targets and their prerequisites + targets = {} - # Split the output by lines - make_output = result.stdout.splitlines() + # Split the output by lines + make_output = result.stdout.splitlines() - # Regex to capture target and its prerequisites - target_pattern = re.compile(r'^([^\s]+)\s*:\s*([^\|]*)') + # Regex to capture target and its prerequisites + target_pattern = re.compile(r'^([^\s]+)\s*:\s*([^\|]*)') - # Parse the make output - for line in make_output: - match = target_pattern.match(line) - if match: - target = match.group(1) - prerequisites = match.group(2).split() - targets[target] = prerequisites + # Parse the make output + for line in make_output: + match = target_pattern.match(line) + if match: + target = match.group(1) + prerequisites = match.group(2).split() + targets[target] = prerequisites - return targets - - except Exception as e: - print(f"An error occurred: {e}") - sys.exit(1) + return targets # Internal function used for recursion. Takes additional arguments to keep track of state. @@ -130,8 +125,7 @@ def list_prerequisites(target, recursive=False, debug=False): return leaf_prerequisites else: - print(f"Target '{args.target}' not found in the Makefile.") - sys.exit(1) + raise Exception(f"Target '{args.target}' not found in the Makefile.") def hash_files(file_list):