Skip to content

Commit

Permalink
[lib/prep.sh] Limit calls to cargo install --list for plugins.
Browse files Browse the repository at this point in the history
When checking for an installing plugins, there isn't a need to call
cargo for each plugin to check. While this is just-as-good as previous
behavior, it also limits any issues when calling a Cargo subcommand that
might fail.

Presently, there are times where a race exists and either `STDOUT` or
`STDERR` might disppear when Rustup (or potentially Cargo) is used in a
shell pipeline, leading to a program panic with `failed printing to
stdout: Broken pipe (os error 32)`. This change tries to minimize the
probability that this occurs until a more robust upstream fix has
landed.

References: rust-lang/rustup#1730
References: rust-lang/rustup#1765

Signed-off-by: Fletcher Nichol <fnichol@nichol.ca>
  • Loading branch information
fnichol committed Apr 23, 2019
1 parent b312a46 commit e87ff18
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ install_rust() {
local rustc="$HOME/.cargo/bin/rustc"
local cargo="$HOME/.cargo/bin/cargo"
local rustup="$HOME/.cargo/bin/rustup"
local installed_plugins

header "Setting up Rust"

Expand All @@ -482,8 +483,9 @@ install_rust() {
"$rustup" component add rust-src | indent
"$rustup" component add rustfmt | indent

installed_plugins="$("$cargo" install --list | grep ':$' | cut -d ' ' -f 1)"
for plugin in cargo-watch cargo-edit cargo-outdated; do
if ! "$cargo" install --list | grep -q "$plugin"; then
if ! echo "$installed_plugins" | grep -q "^$plugin\$"; then
info "Installing $plugin"
"$cargo" install "$plugin" 2>&1 | indent
fi
Expand Down

0 comments on commit e87ff18

Please sign in to comment.