Skip to content

Commit

Permalink
Use non-ephemeral workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisduerr committed Jan 19, 2020
1 parent ae8dee5 commit e137ee6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ impl<'cfg> Workspace<'cfg> {
target_dir: Option<Filesystem>,
require_optional_deps: bool,
) -> CargoResult<Workspace<'cfg>> {
let manifest_path = package.manifest_path();
let mut ws = Workspace::new_default(manifest_path.to_path_buf(), config);
ws.root_manifest = ws.find_root(&manifest_path)?;
let mut ws = Workspace::new_default(package.manifest_path().to_path_buf(), config);
ws.is_ephemeral = true;
ws.require_optional_deps = require_optional_deps;
let key = ws.current_manifest.parent().unwrap();
Expand Down Expand Up @@ -831,6 +829,17 @@ impl<'cfg> Workspace<'cfg> {
}
Ok(())
}

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

// TODO: This seems like the wrong approach
pub fn set_package(&mut self, package: Package) {
let key = self.current_manifest.parent().unwrap();
let package = MaybePackage::Package(package);
self.packages.packages.insert(key.to_path_buf(), package);
}
}

impl<'cfg> Packages<'cfg> {
Expand Down
13 changes: 12 additions & 1 deletion src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ fn install_one(

let mut td_opt = None;
let mut needs_cleanup = false;
let overidden_target_dir = if source_id.is_path() {
let overidden_target_dir = if source_id.is_git() || source_id.is_path() {
None
} else if let Some(dir) = config.target_dir()? {
Some(dir)
Expand All @@ -220,6 +220,17 @@ fn install_one(
None => {
let mut ws = Workspace::new(pkg.manifest_path(), config)?;
ws.set_require_optional_deps(false);

// Use tempdir to build git depedencies to prevent bloat in cargo cache
if source_id.is_git() && config.target_dir()?.is_none() {
match TempFileBuilder::new().prefix("cargo-install").tempdir() {
Ok(td) => ws.set_target_dir(Filesystem::new(td.path().to_owned())),
// If tempfile creation fails, write to cargo cache but clean up afterwards
Err(_) => needs_cleanup = true,
}
}
ws.set_package(pkg);

ws
}
};
Expand Down

0 comments on commit e137ee6

Please sign in to comment.