From cbb303986abd7ed38cd2a80816f9193626ceef03 Mon Sep 17 00:00:00 2001 From: jakub-nt <175944085+jakub-nt@users.noreply.github.com> Date: Thu, 25 Jul 2024 15:27:26 +0200 Subject: [PATCH] Building with invalid build steps now fails before executing any build steps, with an error message instead of a traceback Ticket: ENT-11207 Signed-off-by: jakub-nt <175944085+jakub-nt@users.noreply.github.com> --- cfbs/build.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/cfbs/build.py b/cfbs/build.py index fc55ae9..3c6ba6e 100644 --- a/cfbs/build.py +++ b/cfbs/build.py @@ -4,6 +4,7 @@ canonify, cp, find, + is_valid_arg_count, merge_json, mkdir, pad_right, @@ -222,14 +223,41 @@ def _perform_build_step(module, step, max_length): merged = merge_json(original, augment) if original else augment log.debug("Merged def.json: %s", pretty(merged)) write_json(path, merged) - else: - user_error("Unknown build step operation: %s" % operation) def perform_build_steps(config) -> int: if not config.get("build"): user_error("No 'build' key found in the configuration") - return 1 + + # mini-validation + for module in config.get("build", []): + for step in module["steps"]: + operation, args = split_command(step) + + if step.split() != [operation] + args: + user_error( + "Incorrect whitespace in the `%s` build step - singular spaces are required" + % step + ) + + if operation not in AVAILABLE_BUILD_STEPS: + user_error("Unknown build step operation: %s" % operation) + + expected = AVAILABLE_BUILD_STEPS[operation] + actual = len(args) + if not is_valid_arg_count(args, expected): + if type(expected) is int: + user_error( + "The `%s` build step expects %d arguments, %d were given" + % (step, expected, actual) + ) + else: + expected = int(expected[0:-1]) + user_error( + "The `%s` build step expects %d or more arguments, %d were given" + % (step, expected, actual) + ) + print("\nSteps:") module_name_length = config.longest_module_name() for module in config.get("build", []):