Skip to content

Commit 82d730a

Browse files
committed
fix: check the absolute path
1 parent 1cb8b4d commit 82d730a

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/cargo/ops/cargo_install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ pub fn install(
804804
paths::normalize_path(&cwd.join(&dst))
805805
};
806806
let path = gctx.get_env_os("PATH").unwrap_or_default();
807-
let dst_in_path = env::split_paths(&path).any(|path| path == dst);
807+
let dst_in_path = env::split_paths(&path).any(|path| path == dst_abs);
808808

809809
if !dst_in_path {
810810
gctx.shell().warn(&format!(

tests/testsuite/install.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,48 @@ fn relative_install_location_with_trailing_slash() {
593593
assert_has_not_installed_exe(&project_t1, "foo");
594594
}
595595

596+
#[cargo_test]
597+
fn relative_install_location_with_path_set() {
598+
// Test that when the absolute install path is in PATH, no warning is shown
599+
let p = project().file("src/main.rs", "fn main() {}").build();
600+
601+
let root = paths::root();
602+
let p_path = p.root().to_path_buf();
603+
let project_t1 = p_path.join("t1");
604+
605+
fs::create_dir(root.join(".cargo")).unwrap();
606+
fs::write(
607+
root.join(".cargo/config.toml"),
608+
r#"
609+
[install]
610+
root = "t1"
611+
"#,
612+
)
613+
.unwrap();
614+
615+
// Add the absolute path to PATH environment variable
616+
let install_bin_path = project_t1.join("bin");
617+
let mut path = path();
618+
path.push(install_bin_path);
619+
let new_path = env::join_paths(path).unwrap();
620+
621+
let mut cmd = cargo_process("install --path .");
622+
cmd.cwd(p.root());
623+
cmd.env("PATH", new_path);
624+
cmd.with_stderr_data(str![[r#"
625+
[WARNING] the `install.root` value `t1` defined in [ROOT]/.cargo/config.toml without a trailing slash is deprecated; a future version of Cargo will treat it as relative to the configuration directory. Add a trailing slash (`t1/`) to adopt the correct behavior and silence this warning. See more at https://doc.rust-lang.org/cargo/reference/config.html#config-relative-paths
626+
[INSTALLING] foo v0.0.1 ([ROOT]/foo)
627+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
628+
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s
629+
[INSTALLING] [ROOT]/foo/t1/bin/foo[EXE]
630+
[INSTALLED] package `foo v0.0.1 ([ROOT]/foo)` (executable `foo[EXE]`)
631+
632+
"#]])
633+
.run();
634+
635+
assert_has_installed_exe(&project_t1, "foo");
636+
}
637+
596638
#[cargo_test]
597639
fn install_path() {
598640
let p = project().file("src/main.rs", "fn main() {}").build();

0 commit comments

Comments
 (0)