-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix: display absolute path in the missing in PATH warning
#16125
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
Open
0xPoe
wants to merge
9
commits into
rust-lang:master
Choose a base branch
from
0xPoe:poe-patch-install.root
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+193
−18
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
feaa58b
refactor: inline GlobalContext::get_path
0xPoe 8a7929f
test: add a test case for the relative location
0xPoe e13f98f
test: add a case with trailing slash
0xPoe a23ce91
fix: always display the absolute path in the warning
0xPoe 064a7e3
feat: add the deprecation warning
0xPoe e543e22
test: add the CLI argument case
0xPoe 51e2e45
fix: check the absolute path
0xPoe 9bd2ca6
refactor: do not use two paths
0xPoe dc89d66
refactor: use annotate-snippets style report
0xPoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -317,6 +317,14 @@ impl<'gctx> InstallablePackage<'gctx> { | |
| self.gctx.shell().status("Installing", &self.pkg)?; | ||
|
|
||
| let dst = self.root.join("bin").into_path_unlocked(); | ||
| // `dst` is usually absolute; if not, make it absolute so messages are clearer. | ||
| // See: https://github.com/rust-lang/cargo/issues/16023 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two duplicate make-absolute code actually fix two different warnings, should we make one commit for each to make the intent more obvious? |
||
| let cwd = self.gctx.cwd(); | ||
| let dst_abs_root = if dst.is_absolute() { | ||
| paths::normalize_path(dst.as_path()) | ||
| } else { | ||
| paths::normalize_path(&cwd.join(&dst)) | ||
| }; | ||
|
|
||
| let mut td_opt = None; | ||
| let mut needs_cleanup = false; | ||
|
|
@@ -458,13 +466,18 @@ impl<'gctx> InstallablePackage<'gctx> { | |
| // Move the temporary copies into `dst` starting with new binaries. | ||
| for bin in to_install.iter() { | ||
| let src = staging_dir.path().join(bin); | ||
| let dst = dst.join(bin); | ||
| self.gctx.shell().status("Installing", dst.display())?; | ||
| let dst_rel = dst.join(bin); | ||
| let dst_abs = dst_abs_root.join(bin); | ||
| self.gctx.shell().status("Installing", dst_abs.display())?; | ||
| if !dry_run { | ||
| fs::rename(&src, &dst).with_context(|| { | ||
| format!("failed to move `{}` to `{}`", src.display(), dst.display()) | ||
| fs::rename(&src, &dst_rel).with_context(|| { | ||
| format!( | ||
| "failed to move `{}` to `{}`", | ||
| src.display(), | ||
| dst_abs.display() | ||
| ) | ||
| })?; | ||
| installed.bins.push(dst); | ||
| installed.bins.push(dst_rel); | ||
| successful_bins.insert(bin.to_string()); | ||
| } | ||
| } | ||
|
|
@@ -475,11 +488,16 @@ impl<'gctx> InstallablePackage<'gctx> { | |
| let mut try_install = || -> CargoResult<()> { | ||
| for &bin in to_replace.iter() { | ||
| let src = staging_dir.path().join(bin); | ||
| let dst = dst.join(bin); | ||
| self.gctx.shell().status("Replacing", dst.display())?; | ||
| let dst_rel = dst.join(bin); | ||
| let dst_abs = dst_abs_root.join(bin); | ||
| self.gctx.shell().status("Replacing", dst_abs.display())?; | ||
| if !dry_run { | ||
| fs::rename(&src, &dst).with_context(|| { | ||
| format!("failed to move `{}` to `{}`", src.display(), dst.display()) | ||
| fs::rename(&src, &dst_rel).with_context(|| { | ||
| format!( | ||
| "failed to move `{}` to `{}`", | ||
| src.display(), | ||
| dst_abs.display() | ||
| ) | ||
| })?; | ||
| successful_bins.insert(bin.to_string()); | ||
| } | ||
|
|
@@ -777,14 +795,22 @@ pub fn install( | |
| if installed_anything { | ||
| // Print a warning that if this directory isn't in PATH that they won't be | ||
| // able to run these commands. | ||
| // `dst` is usually absolute; if not, make it absolute so messages are clearer. | ||
| // See: https://github.com/rust-lang/cargo/issues/16023 | ||
| let cwd = gctx.cwd(); | ||
| let dst_abs = if dst.is_absolute() { | ||
| paths::normalize_path(dst.as_path()) | ||
| } else { | ||
| paths::normalize_path(&cwd.join(&dst)) | ||
| }; | ||
| let path = gctx.get_env_os("PATH").unwrap_or_default(); | ||
| let dst_in_path = env::split_paths(&path).any(|path| path == dst); | ||
|
|
||
| if !dst_in_path { | ||
| gctx.shell().warn(&format!( | ||
| "be sure to add `{}` to your PATH to be \ | ||
| able to run the installed binaries", | ||
| dst.display() | ||
| dst_abs.display() | ||
| ))?; | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.