Skip to content

Commit

Permalink
Auto merge of #7768 - chrisduerr:install-workspaces-from-git, r=ehuss
Browse files Browse the repository at this point in the history
Search for root manifest with ephemeral workspaces

Fixes #5495.

This seems like it's too simple to just work like this, but after trying a few different things, this was the only solution which worked reliably for me.

I've verified that no `/target` is present in the actual checkout location, the target directory used is actually the one created in `/tmp`.

I've also verified that both workspaces and "normal" packages still install through git and that a normal `cargo install --path` works too (though that doesn't use ephemeral workspaces anyways).
  • Loading branch information
bors committed Jan 27, 2020
2 parents 9d32b7b + 601d04c commit 328b7d6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 26 deletions.
4 changes: 4 additions & 0 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,10 @@ impl<'cfg> Workspace<'cfg> {
}
Ok(())
}

pub fn set_target_dir(&mut self, target_dir: Filesystem) {
self.target_dir = Some(target_dir);
}
}

impl<'cfg> Packages<'cfg> {
Expand Down
48 changes: 26 additions & 22 deletions src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,31 +200,35 @@ fn install_one(
)?
};

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) = TempFileBuilder::new().prefix("cargo-install").tempdir() {
let p = td.path().to_owned();
td_opt = Some(td);
Some(Filesystem::new(p))
let (mut ws, git_package) = if source_id.is_git() {
// Don't use ws.current() in order to keep the package source as a git source so that
// install tracking uses the correct source.
(Workspace::new(pkg.manifest_path(), config)?, Some(&pkg))
} else if source_id.is_path() {
(Workspace::new(pkg.manifest_path(), config)?, None)
} else {
needs_cleanup = true;
Some(Filesystem::new(config.cwd().join("target-install")))
};

let mut ws = match overidden_target_dir {
Some(dir) => Workspace::ephemeral(pkg, config, Some(dir), false)?,
None => {
let mut ws = Workspace::new(pkg.manifest_path(), config)?;
ws.set_require_optional_deps(false);
ws
}
(Workspace::ephemeral(pkg, config, None, false)?, None)
};
ws.set_ignore_lock(config.lock_update_allowed());
let pkg = ws.current()?;
ws.set_require_optional_deps(false);

let mut td_opt = None;
let mut needs_cleanup = false;
if !source_id.is_path() {
let target_dir = if let Some(dir) = config.target_dir()? {
dir
} else if let Ok(td) = TempFileBuilder::new().prefix("cargo-install").tempdir() {
let p = td.path().to_owned();
td_opt = Some(td);
Filesystem::new(p)
} else {
needs_cleanup = true;
Filesystem::new(config.cwd().join("target-install"))
};
ws.set_target_dir(target_dir);
}

let pkg = git_package.map_or_else(|| ws.current(), |pkg| Ok(pkg))?;

if from_cwd {
if pkg.manifest().edition() == Edition::Edition2015 {
Expand Down
34 changes: 30 additions & 4 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ fn multiple_crates_git_all() {
let p = git::repo(&paths::root().join("foo"))
.file(
"Cargo.toml",
r#"\
[workspace]
members = ["bin1", "bin2"]
"#,
r#"
[workspace]
members = ["bin1", "bin2"]
"#,
)
.file("bin1/Cargo.toml", &basic_manifest("bin1", "0.1.0"))
.file("bin2/Cargo.toml", &basic_manifest("bin2", "0.1.0"))
Expand Down Expand Up @@ -1422,3 +1422,29 @@ fn install_version_req() {
.with_stderr_contains("[INSTALLING] foo v0.0.3")
.run();
}

#[cargo_test]
fn git_install_reads_workspace_manifest() {
let p = git::repo(&paths::root().join("foo"))
.file(
"Cargo.toml",
r#"
[workspace]
members = ["bin1"]
[profile.release]
incremental = 3
"#,
)
.file("bin1/Cargo.toml", &basic_manifest("bin1", "0.1.0"))
.file(
"bin1/src/main.rs",
r#"fn main() { println!("Hello, world!"); }"#,
)
.build();

cargo_process(&format!("install --git {}", p.url().to_string()))
.with_status(101)
.with_stderr_contains(" invalid type: integer `3`[..]")
.run();
}

0 comments on commit 328b7d6

Please sign in to comment.