From 42abf64c628e779238efc8aefe406fc968291303 Mon Sep 17 00:00:00 2001 From: Alessandro Di Federico Date: Fri, 23 Jun 2023 17:55:38 +0200 Subject: [PATCH] revng.cli: ensure proper exit code propagation --- python/revng/cli/_commands/llvm_pipeline.py | 22 ++++++++++++++++---- python/revng/cli/_commands/pipeline_tools.py | 1 + python/revng/cli/support.py | 2 ++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/python/revng/cli/_commands/llvm_pipeline.py b/python/revng/cli/_commands/llvm_pipeline.py index 0752e4156..e1e677dda 100644 --- a/python/revng/cli/_commands/llvm_pipeline.py +++ b/python/revng/cli/_commands/llvm_pipeline.py @@ -48,7 +48,11 @@ class IRPipelineCommand(Command): saved_input_file.flush() # Extract model - run_revng_command(["model", "dump", saved_input_file.name, "-o", model.name], options) + result = run_revng_command( + ["model", "dump", saved_input_file.name, "-o", model.name], options + ) + if result != 0: + return result # Run revng-pipeline target = f"--produce={args.to}/module.ll/{args.target}" @@ -58,9 +62,14 @@ class IRPipelineCommand(Command): load_binary = [] if args.binary != "": from_step = args.__dict__["from"] - load_binary = ["-i", f"{args.binary}:{from_step}/input"] + load_binary = [ + "-i", + f"{args.binary}:{from_step}/input", + "-i", + f"{args.binary}:begin/input", + ] - run_revng_command( + result = run_revng_command( [ "pipeline", "-m", @@ -76,11 +85,16 @@ class IRPipelineCommand(Command): ], options, ) + if result != 0: + return result # Re-inject the model - run_revng_command( + result = run_revng_command( ["model", "inject", model.name, module.name, "-o", args.output], options ) + if result != 0: + return result + return 0 diff --git a/python/revng/cli/_commands/pipeline_tools.py b/python/revng/cli/_commands/pipeline_tools.py index 935a7323d..e870c1226 100644 --- a/python/revng/cli/_commands/pipeline_tools.py +++ b/python/revng/cli/_commands/pipeline_tools.py @@ -19,6 +19,7 @@ class PipelineToolCommand(Command): command = build_command_with_loads( f"revng-{self.name}", pipelines_args + options.remaining_args, options ) + return run(command, options) diff --git a/python/revng/cli/support.py b/python/revng/cli/support.py index e0a935293..8788575da 100644 --- a/python/revng/cli/support.py +++ b/python/revng/cli/support.py @@ -105,6 +105,8 @@ def run(command, options: Options, environment: OptionalEnv = None): if result != 0: sys.exit(result) + return result + def exec_run(command, options: Options, environment: OptionalEnv) -> Union[int, NoReturn]: command, environment = _run_common(command, options, environment)