Skip to content

Fix target_dir handling for RLS #5466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
@@ -131,7 +131,7 @@ impl<'cfg> Workspace<'cfg> {
/// root and all member packages. It will then validate the workspace
/// before returning it, so `Ok` is only returned for valid workspaces.
pub fn new(manifest_path: &Path, config: &'cfg Config) -> CargoResult<Workspace<'cfg>> {
let target_dir = config.target_dir();
let target_dir = config.target_dir()?;

let mut ws = Workspace {
config,
@@ -191,7 +191,7 @@ impl<'cfg> Workspace<'cfg> {
ws.target_dir = if let Some(dir) = target_dir {
Some(dir)
} else {
ws.config.target_dir()
ws.config.target_dir()?
};
ws.members.push(ws.current_manifest.clone());
ws.default_members.push(ws.current_manifest.clone());
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
@@ -213,7 +213,7 @@ fn install_one(
let mut needs_cleanup = false;
let overidden_target_dir = if source_id.is_path() {
None
} else if let Some(dir) = config.target_dir() {
} 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();
27 changes: 15 additions & 12 deletions src/cargo/util/config.rs
Original file line number Diff line number Diff line change
@@ -242,8 +242,17 @@ impl Config {
&self.cwd
}

pub fn target_dir(&self) -> Option<Filesystem> {
self.target_dir.clone()
pub fn target_dir(&self) -> CargoResult<Option<Filesystem>> {
if let Some(ref dir) = self.target_dir {
Ok(Some(dir.clone()))
} else if let Some(dir) = env::var_os("CARGO_TARGET_DIR") {
Ok(Some(Filesystem::new(self.cwd.join(dir))))
} else if let Some(val) = self.get_path("build.target-dir")? {
let val = self.cwd.join(val.val);
Ok(Some(Filesystem::new(val)))
} else {
Ok(None)
}
}

fn get(&self, key: &str) -> CargoResult<Option<ConfigValue>> {
@@ -491,23 +500,17 @@ impl Config {
| (None, None, None) => Verbosity::Normal,
};

let target_dir = if let Some(dir) = target_dir.as_ref() {
Some(Filesystem::new(self.cwd.join(dir)))
} else if let Some(dir) = env::var_os("CARGO_TARGET_DIR") {
Some(Filesystem::new(self.cwd.join(dir)))
} else if let Ok(Some(val)) = self.get_path("build.target-dir") {
let val = self.cwd.join(val.val);
Some(Filesystem::new(val))
} else {
None
let cli_target_dir = match target_dir.as_ref() {
Some(dir) => Some(Filesystem::new(dir.clone())),
None => None,
};

self.shell().set_verbosity(verbosity);
self.shell().set_color_choice(color.map(|s| &s[..]))?;
self.extra_verbose = extra_verbose;
self.frozen = frozen;
self.locked = locked;
self.target_dir = target_dir;
self.target_dir = cli_target_dir;
self.cli_flags.parse(unstable_flags)?;

Ok(())
5 changes: 1 addition & 4 deletions tests/testsuite/bad_config.rs
Original file line number Diff line number Diff line change
@@ -284,10 +284,7 @@ fn invalid_global_config() {
p.cargo("build").arg("-v"),
execs().with_status(101).with_stderr(
"\
error: failed to parse manifest at `[..]`
Caused by:
Couldn't load Cargo configuration
[ERROR] Couldn't load Cargo configuration
Caused by:
could not parse TOML configuration in `[..]`