sagiegurari / cargo-make

Rust task runner and build tool.
https://sagiegurari.github.io/cargo-make/
Apache License 2.0
2.46k stars 123 forks source link

`--skip-init-end-tasks` doesn't seem to work #1108

Closed 06393993 closed 2 days ago

06393993 commented 1 week ago

Describe The Bug

With tasks.init defined, even if we call cargo make --skip-init-end-tasks empty, the init task will be called.

I am not sure if I am understanding the --skip-init-end-tasks argument incorrectly, or there is a bug. If it's a misunderstanding, I believe we should change the documentation for the --skip-init-end-tasks argument: "If set, init and end tasks are skipped". If it's a bug, we need a fix.

To Reproduce

On Linux with bash:

cargo init hello-world && cd hello-world && echo "tasks.init.script = \"echo init\"" > Makefile.toml && cargo make --skip-init-end-tasks empty

The actual output is:

$ cargo init hello-world && cd hello-world && echo "tasks.init.script = \"echo init\"" > Makefile.toml && cargo make --skip-init-end-tasks empty
    Creating binary (application) package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[cargo-make] INFO - cargo make 0.37.13
[cargo-make] INFO - Calling cargo metadata to extract project info
[cargo-make] INFO - Cargo metadata done
[cargo-make] INFO - Project: hello-world
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: empty
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: init
init
[cargo-make] INFO - Build Done in 0.28 seconds.

I guess we are not supposed to see the "Running Task: init" log and the "init" echo?

Error Stack

N/A

Code Sample

tasks.init.script = "echo init"

This problem is important to me, as I plan to use the init task to add "-D warning" to the RUSTFLAGS environement variable for the CI environment. However, ff --skip-init-end-tasks doesn't work, the init task will be run another time when a new cargo-make process is forked due to tasks.<task_id>.run_task.fork being true. As a result, 2 duplicate "-D warnings" will be added to RUSTFLAGS, and cause recompilation.

EDIT: move the --skip-init-end-tasks argument before the empty target in To Reproduce section, and update the output.

sagiegurari commented 1 week ago

instead of cargo make empty --skip-init-end-tasks do cargo make --skip-init-end-tasks empty

06393993 commented 1 week ago

instead of cargo make empty --skip-init-end-tasks do cargo make --skip-init-end-tasks empty

The same:

$ cargo init hello-world && cd hello-world && echo "tasks.init.script = \"echo init\"" > Makefile.toml && cargo make --skip-init-end-tasks empty
    Creating binary (application) package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[cargo-make] INFO - cargo make 0.37.13
[cargo-make] INFO - Calling cargo metadata to extract project info
[cargo-make] INFO - Cargo metadata done
[cargo-make] INFO - Project: hello-world
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: empty
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: init
init
[cargo-make] INFO - Build Done in 0.28 seconds.
06393993 commented 1 week ago

A hacky patch works:

~/src/cargo-make$ git diff
diff --git a/src/lib/runner.rs b/src/lib/runner.rs
index c774314a..0f3d5d12 100755
--- a/src/lib/runner.rs
+++ b/src/lib/runner.rs
@@ -629,6 +629,14 @@ pub(crate) fn run(
         },
         None => None,
     };
+    let config = if cli_args.skip_init_end_tasks {
+        let mut config = config;
+        config.config.init_task = None;
+        config.config.end_task = None;
+        config
+    } else {
+        config
+    };

     let flow_info = FlowInfo {
         config,
~/src/cargo-make$ cargo run --bin makers -- --makefile /tmp/hello-world/Makefile.toml empty
   Compiling cargo-make v0.37.13 (/home/user/src/cargo-make)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.09s
     Running `target/debug/makers --makefile /tmp/hello-world/Makefile.toml empty`
[cargo-make] INFO - makers 0.37.13
[cargo-make] INFO - Calling cargo metadata to extract project info
[cargo-make] INFO - Cargo metadata done
[cargo-make] INFO - Project: cargo-make
[cargo-make] INFO - Build File: /tmp/hello-world/Makefile.toml
[cargo-make] INFO - Task: empty
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: init
init
[cargo-make] INFO - Build Done in 0.50 seconds.
~/src/cargo-make$ cargo run --bin makers -- --makefile /tmp/hello-world/Makefile.toml --skip-init-end-tasks empty
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.09s
     Running `target/debug/makers --makefile /tmp/hello-world/Makefile.toml --skip-init-end-tasks empty`
[cargo-make] INFO - makers 0.37.13
[cargo-make] INFO - Calling cargo metadata to extract project info
[cargo-make] INFO - Cargo metadata done
[cargo-make] INFO - Project: cargo-make
[cargo-make] INFO - Build File: /tmp/hello-world/Makefile.toml
[cargo-make] INFO - Task: empty
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Build Done in 0.57 seconds.
sagiegurari commented 1 week ago

hmmm... seems like a bug. i'll check it out.

06393993 commented 1 week ago

In case you miss it, I have uploaded a PR(#1109) to fix this issue. PTAL.

sagiegurari commented 3 days ago

thanks and sorry for the delay