cargo icon indicating copy to clipboard operation
cargo copied to clipboard

Add a `--dry-run` flag to the `install` command

Open Flowrey opened this issue 1 year ago • 2 comments

What does this PR try to resolve?

This PR add the --dry-run flag to the cargo install command (see #11123). I've tried to do the bare minimal for this flag to work without changing anything in the output.

In my opinion, the --dry-run flag should mimic as close as possible the behavior of the normal command to avoid missing potential issue in the normal execution. ~~Currently we're missing information about where the binary will be installed.~~

Unlike #13598 this PR:

  • Include as much of the compilation process as possible without actually compiling
  • use the information provided by BuildContext instead of InstallablePackage::new
  • in the same way as unit_graph, it add a dry_run to the CompileOptions and return a Compilation::new from the function compile_ws without actually compiling.
  • keeps the output the same rather than adding status messages indicating which very broad actions would be performed
  • ~~remove some warning not relevant in the case of a --dry-run~~

Like #13598, the version check and crate downloads still occur.

How should we test and review this PR?

The first commit include a unit tests to ensure that no binary is actually installed after the dry run. There is also a snapshot test that show the diff output of the --help flag.

Additional information

Tests and documentation done in #13598, may be cherry picked into this PR if needed.

Flowrey avatar Jul 21 '24 09:07 Flowrey

r? @ehuss

rustbot has assigned @ehuss. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

rustbot avatar Jul 21 '24 09:07 rustbot

r? epage If you don't mind, feel free to reassign if you are too busy.

ehuss avatar Jul 25 '24 01:07 ehuss

Note: I tweaked the commits to make this easier to review.

epage avatar Aug 27 '24 20:08 epage

Note: I tweaked the commits to make this easier to review.

Thanks, sorry if i made a mess with the commits :sweat_smile:

Flowrey avatar Sep 01 '24 07:09 Flowrey

@bors r+

weihanglo avatar Sep 21 '24 00:09 weihanglo

:pushpin: Commit b0e08fcd3278b727a4492832316c39efd5433d77 has been approved by weihanglo

It is now in the queue for this repository.

bors avatar Sep 21 '24 00:09 bors

:hourglass: Testing commit b0e08fcd3278b727a4492832316c39efd5433d77 with merge d7bffc302ef83dd8a4bf06bd4fb7579e7988263e...

bors avatar Sep 21 '24 00:09 bors

:sunny: Test successful - checks-actions Approved by: weihanglo Pushing d7bffc302ef83dd8a4bf06bd4fb7579e7988263e to master...

bors avatar Sep 21 '24 01:09 bors