Skip to content

Commit a9652c0

Browse files
borsehuss
authored andcommitted
Auto merge of rust-lang#9185 - horacimacias:master, r=ehuss
Do not exit prematurely if anything failed installing. rust-lang#9180
1 parent ad976d6 commit a9652c0

File tree

2 files changed

+68
-9
lines changed

2 files changed

+68
-9
lines changed

src/cargo/ops/cargo_install.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,15 @@ pub fn install(
119119
// able to run these commands.
120120
let dst = root.join("bin").into_path_unlocked();
121121
let path = env::var_os("PATH").unwrap_or_default();
122-
for path in env::split_paths(&path) {
123-
if path == dst {
124-
return Ok(());
125-
}
126-
}
122+
let dst_in_path = env::split_paths(&path).any(|path| path == dst);
127123

128-
config.shell().warn(&format!(
129-
"be sure to add `{}` to your PATH to be \
124+
if !dst_in_path {
125+
config.shell().warn(&format!(
126+
"be sure to add `{}` to your PATH to be \
130127
able to run the installed binaries",
131-
dst.display()
132-
))?;
128+
dst.display()
129+
))?;
130+
}
133131
}
134132

135133
if scheduled_error {

tests/testsuite/install.rs

+61
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ use cargo_test_support::install::{
1414
assert_has_installed_exe, assert_has_not_installed_exe, cargo_home,
1515
};
1616
use cargo_test_support::paths;
17+
use std::env;
18+
use std::path::PathBuf;
1719

1820
fn pkg(name: &str, vers: &str) {
1921
Package::new(name, vers)
@@ -129,6 +131,65 @@ fn multiple_pkgs() {
129131
assert_has_not_installed_exe(cargo_home(), "bar");
130132
}
131133

134+
fn path() -> Vec<PathBuf> {
135+
env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect()
136+
}
137+
138+
#[cargo_test]
139+
fn multiple_pkgs_path_set() {
140+
// confirm partial failure results in 101 status code and does not have the
141+
// '[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries'
142+
// even if CARGO_HOME/bin is in the PATH
143+
pkg("foo", "0.0.1");
144+
pkg("bar", "0.0.2");
145+
146+
// add CARGO_HOME/bin to path
147+
let mut path = path();
148+
path.push(cargo_home().join("bin"));
149+
let new_path = env::join_paths(path).unwrap();
150+
cargo_process("install foo bar baz")
151+
.env("PATH", new_path)
152+
.with_status(101)
153+
.with_stderr(
154+
"\
155+
[UPDATING] `[..]` index
156+
[DOWNLOADING] crates ...
157+
[DOWNLOADED] foo v0.0.1 (registry `[CWD]/registry`)
158+
[INSTALLING] foo v0.0.1
159+
[COMPILING] foo v0.0.1
160+
[FINISHED] release [optimized] target(s) in [..]
161+
[INSTALLING] [CWD]/home/.cargo/bin/foo[EXE]
162+
[INSTALLED] package `foo v0.0.1` (executable `foo[EXE]`)
163+
[DOWNLOADING] crates ...
164+
[DOWNLOADED] bar v0.0.2 (registry `[CWD]/registry`)
165+
[INSTALLING] bar v0.0.2
166+
[COMPILING] bar v0.0.2
167+
[FINISHED] release [optimized] target(s) in [..]
168+
[INSTALLING] [CWD]/home/.cargo/bin/bar[EXE]
169+
[INSTALLED] package `bar v0.0.2` (executable `bar[EXE]`)
170+
[ERROR] could not find `baz` in registry `[..]` with version `*`
171+
[SUMMARY] Successfully installed foo, bar! Failed to install baz (see error(s) above).
172+
[ERROR] some crates failed to install
173+
",
174+
)
175+
.run();
176+
assert_has_installed_exe(cargo_home(), "foo");
177+
assert_has_installed_exe(cargo_home(), "bar");
178+
179+
cargo_process("uninstall foo bar")
180+
.with_stderr(
181+
"\
182+
[REMOVING] [CWD]/home/.cargo/bin/foo[EXE]
183+
[REMOVING] [CWD]/home/.cargo/bin/bar[EXE]
184+
[SUMMARY] Successfully uninstalled foo, bar!
185+
",
186+
)
187+
.run();
188+
189+
assert_has_not_installed_exe(cargo_home(), "foo");
190+
assert_has_not_installed_exe(cargo_home(), "bar");
191+
}
192+
132193
#[cargo_test]
133194
fn pick_max_version() {
134195
pkg("foo", "0.1.0");

0 commit comments

Comments
 (0)