Skip to content

Commit

Permalink
cargo-install: prefer building artifacts in the system temporary dire…
Browse files Browse the repository at this point in the history
…ctory

and each cargo-install instance creates and uses its own build directory. This
allows running several cargo-install instances in parallel.

If we fail to create a temporary directory for whatever reason fallback to
creating and using a target-install directory in the current directory.

closes #2606
  • Loading branch information
Jorge Aparicio committed Apr 22, 2016
1 parent 867627c commit 1a6bad8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ regex = "0.1"
rustc-serialize = "0.3"
semver = "0.2.2"
tar = "0.4"
tempdir = "0.3"
term = "0.4.4"
time = "0.1"
toml = "0.1"
url = "0.2"
winapi = "0.2"

[dev-dependencies]
tempdir = "0.3"
hamcrest = "0.1"
bufstream = "0.1"
filetime = "0.1"
Expand Down
1 change: 1 addition & 0 deletions src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern crate regex;
extern crate rustc_serialize;
extern crate semver;
extern crate tar;
extern crate tempdir;
extern crate term;
extern crate time;
extern crate toml;
Expand Down
15 changes: 14 additions & 1 deletion src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::io::prelude::*;
use std::io::SeekFrom;
use std::path::{Path, PathBuf};

use tempdir::TempDir;
use toml;

use core::{SourceId, Source, Package, Registry, Dependency, PackageIdSpec};
Expand Down Expand Up @@ -79,13 +80,25 @@ pub fn install(root: Option<&str>,
try!(check_overwrites(&dst, &pkg, &opts.filter, &list));
}

let mut td_opt = None;
let target_dir = if source_id.is_path() {
config.target_dir(&pkg)
} else {
Filesystem::new(config.cwd().join("target-install"))
if let Ok(td) = TempDir::new("cargo-install") {
let p = td.path().to_owned();
td_opt = Some(td);
Filesystem::new(p)
} else {
Filesystem::new(config.cwd().join("target-install"))
}
};
config.set_target_dir(target_dir.clone());
let compile = try!(ops::compile_pkg(&pkg, Some(source), opts).chain_error(|| {
if let Some(td) = td_opt.take() {
// preserve the temporary directory, so the user can inspect it
td.into_path();
}

human(format!("failed to compile `{}`, intermediate artifacts can be \
found at `{}`", pkg, target_dir.display()))
}));
Expand Down

0 comments on commit 1a6bad8

Please sign in to comment.