-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Basic implementation for cargo install --dry-run
#13598
Conversation
Signed-off-by: Paul Mabileau <[email protected]>
Signed-off-by: Paul Mabileau <[email protected]>
Signed-off-by: Paul Mabileau <[email protected]>
Signed-off-by: Paul Mabileau <[email protected]>
Signed-off-by: Paul Mabileau <[email protected]>
r? @weihanglo since you kindly wrote the mentor notes. |
&[krate.map_or_else( | ||
|| -> CargoResult<&str> { | ||
// `krate` is `None` usually for a Git source at | ||
// this point. Select the package again in order to | ||
// be able to retrieve its name. | ||
if let SourceKind::Git(_) = source_id.kind() { | ||
Ok(select_pkg( | ||
&mut GitSource::new(source_id, gctx)?, | ||
None, | ||
|git_src| git_src.read_packages(), | ||
gctx, | ||
current_rust_version.as_ref(), | ||
)? | ||
.name() | ||
.as_str()) | ||
} else { | ||
Ok("") | ||
} | ||
}, | ||
|kr| Ok(kr), | ||
)?], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels hackish to me, but I couldn't find a better way. If you have one, I would be glad to integrate it instead.
I also don't know exactly what to do about |
.arg( | ||
flag( | ||
"dry-run", | ||
"Display what would be installed without actually performing anything (unstable)", | ||
) | ||
.short('n'), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI
cargo/src/cargo/util/command_prelude.rs
Lines 350 to 352 in 6972630
fn arg_dry_run(self, dry_run: &'static str) -> Self { | |
self._arg(flag("dry-run", dry_run).short('n')) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, didn't see that one, thanks!
@@ -201,6 +208,9 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult { | |||
if args.flag("list") { | |||
ops::install_list(root, gctx)?; | |||
} else { | |||
if args.flag("dry-run") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI
cargo/src/cargo/util/command_prelude.rs
Lines 529 to 531 in 6972630
fn dry_run(&self) -> bool { | |
self.flag("dry-run") | |
} |
@@ -2623,3 +2623,598 @@ fn uninstall_running_binary() { | |||
) | |||
.run(); | |||
} | |||
|
|||
#[cargo_test(nightly, reason = "--dry-run is unstable")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These do not need nightly, only to masquerade as nightly
@@ -2623,3 +2623,598 @@ fn uninstall_running_binary() { | |||
) | |||
.run(); | |||
} | |||
|
|||
#[cargo_test(nightly, reason = "--dry-run is unstable")] | |||
fn dry_run_freshinstall_one() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add these tests in their own commit at the start, without the dry-run flag, so we can compare what the dry-run flag does to the output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be clear, you want a copy of each test where only the flag is removed and the output adapted in consequence, right? Also, when you say "add these tests in their own commit at the start", are you referring to the already-written tests, the "copies" that need writing or all of them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each test that exists in this PR should be added in their own commit, the first one. The --dry-run
flag would be missing. These tests would pass.
The next commit in the PR would update the tests to add --dry-run
and update the output accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I see.
@@ -2623,3 +2623,598 @@ fn uninstall_running_binary() { | |||
) | |||
.run(); | |||
} | |||
|
|||
#[cargo_test(nightly, reason = "--dry-run is unstable")] | |||
fn dry_run_freshinstall_one() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
freshinstall
is two words
@@ -222,6 +222,12 @@ fn substitute_macros(input: &str) -> String { | |||
("[REPLACING]", " Replacing"), | |||
("[UNPACKING]", " Unpacking"), | |||
("[SUMMARY]", " Summary"), | |||
("[DESTINATION]", " Destination"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add these in the commit where they are used
("[INSTALL]", " Install"), | ||
("[UPGRADE]", " Upgrade"), | ||
("[DOWNGRADE]", " Downgrade"), | ||
("[UPTODATE]", " Up-to-date"), | ||
("[REINSTALL]", " Re-install"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo the dry-run should generally match the regular behavior.
If we want to improve the cargo install
output, that is a change on its own to be evaluated.
if dry_run { | ||
match installable_pkg { | ||
Some(installable_pkg) => dry_run_report( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #11123 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is indeed required, I'll see what I can do to rework this and go into the more fine-grained compilation steps to have a proper dry-run. It might take some time though, as it is almost starting from scratch.
@rustbot author
☔ The latest upstream changes (presumably #13602) made this pull request unmergeable. Please resolve the merge conflicts. |
Add a `--dry-run` flag to the `install` command ### 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.
What does this PR try to resolve?
This is an attempt at providing a starting implementation for
cargo install --dry-run
discussed in #11123. The precise objective is more to have something that works now rather than a much more complete version requiring time and complexity-facing skills I don't currently have.Indeed, #11123 (comment) suggested to descend into
InstallablePackage::install_one
and its inner guts. That would enable getting much more accurate information relatively to the usual non-dry-run operation. However, it looked a bit too complicated for a reviewable first step and also not too orthogonal with thebuild-plan
andunit-graph
features. The plan I adopted in this attempt is therefore to:cargo_install::install
;InstallablePackage::new
and other easily-retrievable ones;As a quick preview:
How should we test and review this PR?
Several tests have been added in order to check that the usual combinations of the flag with
--git
,--path
and installation states behave as expected and print the desired outputs. See the end oftests/testsuite/install.rs
for more details about this.Review should be made easier using the few provided commits:
In particular, I might not be too fond of the wording I chose here and there. The way the information is displayed in a split manner using several new status kinds might not be the best either considering the rest of Cargo's output. Feel free to correct me on any of this.
Additional information
This is very much a first implementation that could evolve in the near future depending on the precision of the emulation that is desirable. As-is, most of the operation is entirely avoided and only informational messages are printed instead. This feels to me enough for a first step. Being more precise would require emulating the compilation jobs or even their inner operations, at the cost of additional complexity.
Obviously, any feedback is welcome, especially if it is about the next steps potentially requiring the mentioned accuracy or if these should be done now instead.