Skip to content

Commit

Permalink
Building with invalid build steps now fails before executing any buil…
Browse files Browse the repository at this point in the history
…d steps, with an error message instead of a traceback

Ticket: ENT-11207
Signed-off-by: jakub-nt <[email protected]>
  • Loading branch information
jakub-nt committed Jul 25, 2024
1 parent b43266f commit cbb3039
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions cfbs/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
canonify,
cp,
find,
is_valid_arg_count,
merge_json,
mkdir,
pad_right,
Expand Down Expand Up @@ -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", []):
Expand Down

0 comments on commit cbb3039

Please sign in to comment.