Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selectively skipping task #538

Closed
orenbenkiki opened this issue Mar 31, 2021 · 10 comments
Closed

Selectively skipping task #538

orenbenkiki opened this issue Mar 31, 2021 · 10 comments
Assignees
Milestone

Comments

@orenbenkiki
Copy link

Feature Description

Allow cargo make some-goal --skip some-task to skip a specific named some-task while building some-goal. Allow --skip to be repeated.

Ideally, --skip would accept a pattern rather than an exact name. For simplicity, specifying it takes a substring of the skipped task would be sufficient (similar to how cargo test works).

This is a natural extension of --skip-init-end-tasks, which would be equivalent to writing --skip 'pre-*' --skip 'post-*' (or --skip pre- --skip post- if --skip takes a simple substring of the skipped goals).

The specific reason I'd like this is to disable the rustfmt related tasks while building in nightly, without having to duplicate all the high-level flows.

@sagiegurari
Copy link
Owner

why not add condition for rsut stable + beta for that specific task instead?
i use conditions a lot in the default makefiles.

@orenbenkiki
Copy link
Author

Because "it depends". When I'm running on a nightly toolchain on my local machine, I do want to have the rustfmt tasks, especially when I do the full CI build before pushing a new version. On the other hand, in the CI build itself, I don't want it to use rustfmt as it is not necessarily available in the bleeding-edge nightly, and I know that the stable build (which happens in parallel) will deal with the rustfmt issues. The whole rustfmt is not always available issue is a PITA...

Regardless of the rustfmt issue, the concept --skip makes sense in general as it witnessed by the existing special case of --skip-init-end-tasks. If --skip existed, there would have been no need for that special case flag.

@sagiegurari
Copy link
Owner

sagiegurari commented Mar 31, 2021

i'll ask few more questions about conditions, but i am not sure it doesn't solve the general issue and i'll use your rustfmt example.
what about something like this:

[tasks.rustfmt-conditional]
run_task = [
  { name = "rustfmt", condition = { channels = ["stable", "beta"] } },
  { name = "rustfmt", condition = { env_false = ["CARGO_MAKE_CI"] } },
]

this is kinda of doing an OR between conditions (currently condition is AND for all) so this is a wrapper above that.
it would save you from typing stuff like --skip xyz when invoking things.

another way to make a simple condition like:
condition = { env_true = ["run_fmt"] }
is maybe to use profiles, so you can set that run_fmt=true in the env block and than have a profile that disables it.
than you can run with --profile nofmt which sets that. for example:

[env]
run_fmt = true
run_clippy = true

[env.notooling]
run_fmt = false
run_clippy = false

[tasks.fmt]
condition = { env_true = ["run_fmt"] }
# ....

having skip globally could be very tricky to understand.
what if i run a child cargo-make process, will it impact? for example when using the 'fork' attribute or just having a task calling cargo make somewhere else.
if the skipped task has dependencies, should they be skipped?
what if task is invoked directly from embedded duckscript cm_run_task command?

@orenbenkiki
Copy link
Author

orenbenkiki commented Mar 31, 2021

I understand the alternatives but they suffer from a common downside, the all require modification of the flow in advance, or at minimum duplicate an existing task just to add a condition to it. If one is using canned flows (e.g. from cargo make itself), then this isn't convenient and also will prevent the modified (duplicated) task from benefiting from future bug fixes or improvements in the original canned flow. Edit: Is there a way to say in my Makefile.toml "Just add a condition to an existing task w/o modifying it in any other way"?

As for semantics in edge cases (recursive cargo-make, dependencies, direct invocation, or other such issues) I'd say that the answer is "keep the same behavior as --skip-init-end-tasks today", that is, --skip-init-end-tasks would be just a shorthand for --skip pre- --skip post-.

@sagiegurari
Copy link
Owner

Is there a way to say in my Makefile.toml "Just add a condition to an existing task w/o modifying it in any other way"?

you can redefine the task in your makefile and just add the condition. the rest will be taken from the core makefile.

[tasks.mytask]
condition = { env_true = ["abc"] }

so in this case, if mytask is defined in a core makefile (or any extended makefile), the rest of the attributes are taken from there, and only the condition is added on top.

keep the same behavior as --skip-init-end-tasks today

got it. i'll check it out later this week and think about it.

@orenbenkiki
Copy link
Author

Good to know about being able to add a condition in this way - that provides a workaround, though IMVHO being able to simply --skip would be preferable.

@sagiegurari
Copy link
Owner

@orenbenkiki this is now available in the 0.32.16 dev branch. tell me if it works well for you.

@sagiegurari sagiegurari added this to the 0.32.16 milestone Apr 2, 2021
@orenbenkiki
Copy link
Author

Wow, that was fast.

Yes, this seems to work well. I note that one can't repeat --skip pattern1 --skip pattern2 and instead one has to specify --skip 'pattern1|pattern2'. That might be worth a note in the help message, or maybe just change the value_name to SKIP_TASK_PATTERN|PATTERN|... as a hint in this direction.

Thanks!

@sagiegurari
Copy link
Owner

ya, will add a bit more to the cli doc.

@sagiegurari
Copy link
Owner

released :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants