Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/icp-cli/src/commands/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ pub async fn exec(ctx: &Context, cmd: Cmd) -> Result<(), CommandError> {
for (i, step) in c.build.steps.iter().enumerate() {
// Indicate to user the current step being executed
let current_step = i + 1;
let pb_hdr = format!("\nBuilding: {step} {current_step} of {step_count}");
let pb_hdr =
format!("\nBuilding: step {current_step} of {step_count} {step}");
let tx = pb.begin_step(pb_hdr);

// Perform build step
Expand Down
79 changes: 68 additions & 11 deletions crates/icp-cli/tests/build_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,16 @@ fn build_adapter_display_failing_build_output() {
let expected_output = indoc! {r#"
Build output for canister my-canister:

Building: script (command: echo "success 1") 1 of 3
Building: step 1 of 3 (script)
echo "success 1"
success 1

Building: script (command: echo "success 2") 2 of 3
Building: step 2 of 3 (script)
echo "success 2"
success 2

Building: script (command: for i in $(seq 1 5); do echo "failing build step $i"; done; exit 1) 3 of 3
Building: step 3 of 3 (script)
for i in $(seq 1 5); do echo "failing build step $i"; done; exit 1
failing build step 1
failing build step 2
failing build step 3
Expand Down Expand Up @@ -175,10 +178,12 @@ fn build_adapter_display_failing_prebuilt_output() {
let expected_output = indoc! {r#"
Build output for canister my-canister:

Building: script (command: echo "initial step succeeded") 1 of 2
Building: step 1 of 2 (script)
echo "initial step succeeded"
initial step succeeded

Building: pre-built (path: /nonexistent/path/to/wasm.wasm, sha: invalid) 2 of 2
Building: step 2 of 2 (pre-built)
path: /nonexistent/path/to/wasm.wasm, sha: invalid
Reading local file: /nonexistent/path/to/wasm.wasm
"#};

Expand Down Expand Up @@ -220,10 +225,12 @@ fn build_adapter_display_failing_build_output_no_output() {
let expected_output = indoc! {r#"
Build output for canister my-canister:

Building: script (command: echo "step 1 succeeded") 1 of 2
Building: step 1 of 2 (script)
echo "step 1 succeeded"
step 1 succeeded

Building: script (command: exit 1) 2 of 2
Building: step 2 of 2 (script)
exit 1
<no output>
Failed to build canister: command 'exit 1' failed with status code 1
"#};
Expand Down Expand Up @@ -272,21 +279,25 @@ fn build_adapter_display_multiple_failing_canisters() {
let expected_output_one = indoc! {r#"
Build output for canister canister-one:

Building: script (command: echo "canister-one step 1") 1 of 2
Building: step 1 of 2 (script)
echo "canister-one step 1"
canister-one step 1

Building: script (command: echo "canister-one error"; exit 1) 2 of 2
Building: step 2 of 2 (script)
echo "canister-one error"; exit 1
canister-one error
Failed to build canister: command 'echo "canister-one error"; exit 1' failed with status code 1
"#};

let expected_output_two = indoc! {r#"
Build output for canister canister-two:

Building: script (command: echo "canister-two step 1") 1 of 2
Building: step 1 of 2 (script)
echo "canister-two step 1"
canister-two step 1

Building: script (command: echo "canister-two error"; exit 1) 2 of 2
Building: step 2 of 2 (script)
echo "canister-two error"; exit 1
canister-two error
Failed to build canister: command 'echo "canister-two error"; exit 1' failed with status code 1
"#};
Expand Down Expand Up @@ -340,3 +351,49 @@ fn build_adapter_script_with_explicit_sh_c() {
.expect("failed to read temporary file");
assert_eq!(contents, "nested shell\n");
}

#[test]
fn build_adapter_display_script_multiple_commands_output() {
let ctx = TestContext::new();

// Setup project
let project_dir = ctx.create_project_dir("icp");

// Project manifest with multiple commands
let pm = indoc! {r#"
canister:
name: my-canister
build:
steps:
- type: script
commands:
- echo "command 1"
- echo "command 2"
- echo "command 3"
"#};

write_string(
&project_dir.join("icp.yaml"), // path
pm, // contents
)
.expect("failed to write project manifest");

// Invoke build
let expected_output = indoc! {r#"
Building: step 1 of 1 (script)
echo "command 1"
echo "command 2"
echo "command 3"
command 1
command 2
command 3
Failed to build canister: build did not result in output
"#};

ctx.icp()
.current_dir(project_dir)
.args(["build"])
.assert()
.failure()
.stdout(contains(expected_output));
}
4 changes: 2 additions & 2 deletions crates/icp/src/canister/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ impl fmt::Display for Step {
f,
"{}",
match self {
Step::Script(v) => format!("script {v}"),
Step::Prebuilt(v) => format!("pre-built {v}"),
Step::Script(v) => format!("(script)\n{v}"),
Step::Prebuilt(v) => format!("(pre-built)\n{v}"),
}
)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/icp/src/manifest/adapter/prebuilt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl fmt::Display for Adapter {
None => "n/a",
};

write!(f, "({src}, sha: {sha})")
write!(f, "{src}, sha: {sha}")
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/icp/src/manifest/adapter/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ pub struct Adapter {
impl fmt::Display for Adapter {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let cmd = match &self.command {
CommandField::Command(c) => format!("command: {c}"),
CommandField::Commands(cs) => format!("{} commands", cs.len()),
CommandField::Command(c) => c,
CommandField::Commands(cs) => &cs.join("\n"),
};

write!(f, "({cmd})")
write!(f, "{cmd}")
}
}

Expand Down