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

install_crate dependencies not installing if newer version is already installed #1062

Closed
wmmc88 opened this issue Apr 2, 2024 · 8 comments
Closed
Assignees
Labels

Comments

@wmmc88
Copy link
Contributor

wmmc88 commented Apr 2, 2024

Describe The Bug

When install_crate is declared with version, and a different version is present on the system, cargo-make will not install the specified version. This is contrary to what's state in the documentation.

To Reproduce

[tasks.abc]
# clear = true
install_crate = { crate_name = "cargo-expand", version = "1.0.80" }
cargo install cargo-expand --version 1.0.81
cargo make abc
cargo-make][1] INFO - Calling cargo metadata to extract project info
[cargo-make][1] INFO - Cargo metadata done
[cargo-make][1] INFO - Project: sample-kmdf-driver
[cargo-make][1] INFO - Build File: Makefile.toml
[cargo-make][1] INFO - Task: abc
[cargo-make][1] INFO - Profile: development
[cargo-make][1] INFO - Skipping Task: legacy-migration
[cargo-make][1] INFO - Running Task: abc
[cargo-make][1] INFO - Execute Command: "cargo" "install" "cargo-expand"
    Updating crates.io index
     Ignored package `cargo-expand v1.0.81` is already installed, use --force to override
@wmmc88
Copy link
Contributor Author

wmmc88 commented Apr 2, 2024

explicitly setting force = true in install_crate also doesn't add --force to the command. output is same as above.

@sagiegurari
Copy link
Owner

either do:

install_crate = { crate_name = "cargo-expand", min_version = "1.0.80" }

or:

install_crate = { crate_name = "cargo-expand", binary="cargo", test_arg="whatever...", version = "1.0.80" }

which are the currently supported formats. you can see the types.rs for what combinations are supported.

@sagiegurari
Copy link
Owner

also i do'nt think the doc link you gave shows combination as you suggested, maybe i'm wrong. but if something is not clear, would love you to help clear it up in the docs.

@wmmc88
Copy link
Contributor Author

wmmc88 commented Apr 5, 2024

@sagiegurari Even when I switch this to install_crate = { crate_name = "cargo-expand", binary="cargo", test_arg=["expand", "--version"], version = "1.0.80" }, it still doesn't force the install of an older version when a newer version is already installed. If version 1.0.81 is installed, but i explictly require version = "1.0.80" (**not min_version= "1.0.80" **), I expect cargo-make would try to run cargo install cargo-expand --version 1.0.80 --force

@sagiegurari
Copy link
Owner

@wmmc88

i ran:

cargo install cargo-expand

checked version manuallly:

gitpod /workspace/cargo-make (master) $ cargo expand --version
cargo-expand 1.0.81

created this makefile:

[config]
skip_core_tasks = true
skip_git_env_info = true
skip_rust_env_info = true
skip_crate_env_info = true

[tasks.default]
install_crate = { crate_name = "cargo-expand", binary="cargo", test_arg=["expand", "--version"], version = "1.0.80" }
script = '''
cargo expand --version
'''

ran it:

[cargo-make] INFO - cargo make 0.37.10
[cargo-make] INFO - Build File: ./target/Makefile.toml
[cargo-make] INFO - Task: default
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: default
[cargo-make] INFO - Execute Command: "cargo" "install" "--force" "--locked" "--version" "1.0.80" "cargo-expand"
    Updating crates.io index
  Installing cargo-expand v1.0.80
    Updating crates.io index
    Updating crates.io index
   Compiling proc-macro2 v1.0.79
   Compiling unicode-ident v1.0.12
   Compiling serde v1.0.197
   Compiling memchr v2.7.1
   Compiling regex-syntax v0.8.2
   Compiling cfg-if v1.0.0
   Compiling libc v0.2.153
   Compiling equivalent v1.0.1
   Compiling crc32fast v1.4.0
   Compiling hashbrown v0.14.3
   Compiling serde_json v1.0.114
   Compiling bit-vec v0.6.3
   Compiling semver v1.0.22
   Compiling adler v1.0.2
   Compiling itoa v1.0.10
   Compiling ryu v1.0.17
   Compiling thiserror v1.0.58
   Compiling utf8parse v0.2.1
   Compiling same-file v1.0.6
   Compiling anstyle-parse v0.2.3
   Compiling miniz_oxide v0.7.2
   Compiling walkdir v2.5.0
   Compiling bit-set v0.5.3
   Compiling prettyplease v0.2.17
   Compiling once_cell v1.19.0
   Compiling anstyle-query v1.0.2
   Compiling log v0.4.21
   Compiling anstyle v1.0.6
   Compiling bytemuck v1.15.0
   Compiling rustix v0.38.32
   Compiling colorchoice v1.0.0
   Compiling fnv v1.0.7
   Compiling rgb v0.8.37
   Compiling anstream v0.6.13
   Compiling lazy_static v1.4.0
   Compiling std_prelude v0.2.12
   Compiling linux-raw-sys v0.4.13
   Compiling unsafe-libyaml v0.2.11
   Compiling aho-corasick v1.1.3
   Compiling clap_lex v0.7.0
   Compiling quote v1.0.35
   Compiling indexmap v2.2.6
   Compiling syn v2.0.55
   Compiling flate2 v1.0.28
   Compiling strsim v0.11.0
   Compiling winnow v0.6.5
   Compiling heck v0.5.0
   Compiling unicode-width v0.1.11
   Compiling bat v0.24.0
   Compiling bitflags v2.5.0
   Compiling termcolor v1.4.1
   Compiling bitflags v1.3.2
   Compiling clap_builder v4.5.2
   Compiling console v0.15.8
   Compiling ansi_colours v1.2.2
   Compiling content_inspector v0.2.4
   Compiling path_abs v0.5.1
   Compiling encoding_rs v0.8.33
   Compiling home v0.5.9
   Compiling nu-ansi-term v0.49.0
   Compiling shell-words v1.1.0
   Compiling cargo-expand v1.0.80
   Compiling regex-automata v0.4.6
   Compiling fastrand v2.0.2
   Compiling bytesize v1.3.0
   Compiling cargo-subcommand-metadata v0.1.0
   Compiling tempfile v3.10.1
   Compiling serde_derive v1.0.197
   Compiling thiserror-impl v1.0.58
   Compiling clap_derive v4.5.3
   Compiling syn-select v0.3.0
   Compiling regex v1.10.4
   Compiling bstr v1.9.1
   Compiling fancy-regex v0.11.0
   Compiling toolchain_find v0.4.0
   Compiling globset v0.4.14
   Compiling clap v4.5.3
   Compiling grep-cli v0.1.10
   Compiling bincode v1.3.3
   Compiling toml_datetime v0.6.5
   Compiling serde_spanned v0.6.5
   Compiling serde_yaml v0.9.34+deprecated
   Compiling clircle v0.4.0
   Compiling toml_edit v0.22.9
   Compiling syntect v5.2.0
   Compiling toml v0.8.12
    Finished release [optimized] target(s) in 1m 11s
   Replacing /workspace/.cargo/bin/cargo-expand
    Replaced package `cargo-expand v1.0.81` with `cargo-expand v1.0.80` (executable `cargo-expand`)
cargo-expand 1.0.80
[cargo-make] INFO - Build Done in 71.51 seconds.

works fine.

@sagiegurari sagiegurari reopened this Apr 6, 2024
@wmmc88 wmmc88 changed the title install_crate dependencies not installing if older version is already installed install_crate dependencies not installing if newer version is already installed Apr 7, 2024
@wmmc88
Copy link
Contributor Author

wmmc88 commented Apr 7, 2024

@sagiegurari I am able to repro your behavior, but i still see other cases where this is not functioning.

Ex. If i enable core tasks and extend the test task like in #1063:

[config]
# skip_core_tasks = true
skip_git_env_info = true
skip_rust_env_info = true
skip_crate_env_info = true

[tasks.test]
install_crate = { crate_name = "cargo-expand", binary="cargo", test_arg=["expand", "--version"], version = "1.0.80" }

🪟 Windows 11 Enterprise(10.0.22631) (pwsh) make-test on  master [?] is 📦 v0.1.0 via 🦀 v1.77.1 took 3s
at 02:15:10 PM ❯ cargo clean
     Removed 19 files, 3.4MiB total

🪟 Windows 11 Enterprise(10.0.22631) (pwsh) make-test on  master [?] is 📦 v0.1.0 via 🦀 v1.77.1 
at 02:15:24 PM ❯ cargo expand --version
cargo-expand 1.0.82

🪟 Windows 11 Enterprise(10.0.22631) (pwsh) make-test on  master [?] is 📦 v0.1.0 via 🦀 v1.77.1 
at 02:15:31 PM ❯ cargo make test
[cargo-make] INFO - cargo make 0.37.11
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: test
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] INFO - Execute Command: "cargo" "test" "--all-features"
   Compiling make-test v0.1.0 (D:\make-test)
    Finished test [unoptimized + debuginfo] target(s) in 0.40s
     Running unittests src\main.rs (target\debug\deps\make_test-67937dc673a03896.exe)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

[cargo-make] INFO - Build Done in 2.11 seconds.

As you see above, when cargo-expand is already installed, it does not force the installation of the older version. But when uninstall cargo-expand and rerun the task, it works:

🪟 Windows 11 Enterprise(10.0.22631) (pwsh) make-test on  master [?] is 📦 v0.1.0 via 🦀 v1.77.1 took 2s
at 02:15:40 PM ❯ cargo uninstall cargo-expand
    Removing D:\.tools\.cargo\bin\cargo-expand.exe

🪟 Windows 11 Enterprise(10.0.22631) (pwsh) make-test on  master [?] is 📦 v0.1.0 via 🦀 v1.77.1 
at 02:16:45 PM ❯ cargo make test
[cargo-make] INFO - cargo make 0.37.11
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: test
[cargo-make] INFO - Profile: development
[cargo-make] INFO - Running Task: legacy-migration
[cargo-make] INFO - Execute Command: "cargo" "install" "--force" "--locked" "--version" "1.0.80" "cargo-expand"
    Updating crates.io index
  Installing cargo-expand v1.0.80
    Updating crates.io index
    Updating crates.io index

It seems like it is failing to respect version = 1.0.80 only when it is overriding the core test task

@sagiegurari
Copy link
Owner

@wmmc88 ok got it.
there is a small hint for it in the docs (could be MUCH improved):

This ensures we are using a crate version that supports the feature we require for the build.
Currently there are few limitations when defining min_version:

Specifying toolchain in the task or rustup_component_name in the install_crate structure, will make cargo-make ignore the min version value.

same goes for version, not just in version.
The 'test' task is defined as follows by default:

[tasks.test]
description = "Runs all available tests."
category = "Test"
install_crate = false
toolchain = "${CARGO_MAKE_RUST_DEFAULT_TOOLCHAIN}"
command = "cargo"
args = [
  "test",
  "@@remove-empty(CARGO_MAKE_CARGO_VERBOSE_FLAGS)",
  "@@split(CARGO_MAKE_CARGO_BUILD_TEST_FLAGS, )",
]

since toolchain is defined, you won't have support for min/version here.

options

  1. do clear=true but than you redefine everything
  2. add dependency to your task that installs whatever you want - best option

@sagiegurari
Copy link
Owner

@wmmc88 closing but reopen if you feel something is missing

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

No branches or pull requests

2 participants