install the crate in the current directory. That is, `install` is equivalent to
the more explicit `install --path .`.
+If the source is crates.io or `--git` then by default the crate will be built
+in a temporary target directory. To avoid this, the target directory can be
+specified by setting the `CARGO_TARGET_DIR` environment variable to a relative
+path. In particular, this can be useful for caching build artifacts on
+continuous integration systems.
+
The `--list` option will list all installed packages (and their versions).
";
};
let mut td_opt = None;
+ let mut needs_cleanup = false;
let overidden_target_dir = if source_id.is_path() {
None
+ } else if let Some(dir) = config.target_dir()? {
+ Some(dir)
} else if let Ok(td) = TempDir::new("cargo-install") {
let p = td.path().to_owned();
td_opt = Some(td);
Some(Filesystem::new(p))
} else {
+ needs_cleanup = true;
Some(Filesystem::new(config.cwd().join("target-install")))
};
// Reaching here means all actions have succeeded. Clean up.
installed.success();
- if !source_id.is_path() {
+ if needs_cleanup {
// Don't bother grabbing a lock as we're going to blow it all away
// anyway.
let target_dir = ws.target_dir().into_path_unlocked();
That is, \f[I]install\f[] is equivalent to the more explicit "install
\-\-path .".
.PP
+If the source is crates.io or \f[B]\-\-git\f[] then by default the crate will be built in a temporary target directory.
+To avoid this, the target directory can be specified by setting the \f[B]CARGO_TARGET_DIR\f[] environment variable to a relative path.
+In particular, this can be useful for caching build artifacts on continuous integration systems.
+.PP
The \f[B]\-\-list\f[] option will list all installed packages (and their
versions).
.SH OPTIONS
use cargotest::support::paths;
use cargotest::support::registry::Package;
use cargotest::support::{project, execs};
-use hamcrest::{assert_that, is_not};
+use hamcrest::{assert_that, existing_dir, is_not};
fn cargo_process(s: &str) -> ProcessBuilder {
let mut p = cargotest::cargo_process();
assert_that(cargo_home(), is_not(has_installed_exe("foo")));
assert_that(cargo_home(), is_not(has_installed_exe("bar")));
}
+
+#[test]
+fn custom_target_dir_for_git_source() {
+ let p = git::repo(&paths::root().join("foo"))
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ authors = []
+ "#)
+ .file("src/main.rs", "fn main() {}")
+ .build();
+
+ assert_that(cargo_process("install")
+ .arg("--git").arg(p.url().to_string()),
+ execs().with_status(0));
+ assert_that(&paths::root().join("target/release"),
+ is_not(existing_dir()));
+
+ assert_that(cargo_process("install").arg("--force")
+ .arg("--git").arg(p.url().to_string())
+ .env("CARGO_TARGET_DIR", "target"),
+ execs().with_status(0));
+ assert_that(&paths::root().join("target/release"),
+ existing_dir());
+}