Skip to content

Commit 5af4753

Browse files
committed
Auto merge of #5466 - matklad:pr-5465, r=matklad
Fix target_dir handling for RLS Supersedes and closes #5465
2 parents 6cd841f + f1dabb7 commit 5af4753

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

src/cargo/core/workspace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'cfg> Workspace<'cfg> {
131131
/// root and all member packages. It will then validate the workspace
132132
/// before returning it, so `Ok` is only returned for valid workspaces.
133133
pub fn new(manifest_path: &Path, config: &'cfg Config) -> CargoResult<Workspace<'cfg>> {
134-
let target_dir = config.target_dir();
134+
let target_dir = config.target_dir()?;
135135

136136
let mut ws = Workspace {
137137
config,
@@ -191,7 +191,7 @@ impl<'cfg> Workspace<'cfg> {
191191
ws.target_dir = if let Some(dir) = target_dir {
192192
Some(dir)
193193
} else {
194-
ws.config.target_dir()
194+
ws.config.target_dir()?
195195
};
196196
ws.members.push(ws.current_manifest.clone());
197197
ws.default_members.push(ws.current_manifest.clone());

src/cargo/ops/cargo_install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ fn install_one(
213213
let mut needs_cleanup = false;
214214
let overidden_target_dir = if source_id.is_path() {
215215
None
216-
} else if let Some(dir) = config.target_dir() {
216+
} else if let Some(dir) = config.target_dir()? {
217217
Some(dir)
218218
} else if let Ok(td) = TempFileBuilder::new().prefix("cargo-install").tempdir() {
219219
let p = td.path().to_owned();

src/cargo/util/config.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,17 @@ impl Config {
242242
&self.cwd
243243
}
244244

245-
pub fn target_dir(&self) -> Option<Filesystem> {
246-
self.target_dir.clone()
245+
pub fn target_dir(&self) -> CargoResult<Option<Filesystem>> {
246+
if let Some(ref dir) = self.target_dir {
247+
Ok(Some(dir.clone()))
248+
} else if let Some(dir) = env::var_os("CARGO_TARGET_DIR") {
249+
Ok(Some(Filesystem::new(self.cwd.join(dir))))
250+
} else if let Some(val) = self.get_path("build.target-dir")? {
251+
let val = self.cwd.join(val.val);
252+
Ok(Some(Filesystem::new(val)))
253+
} else {
254+
Ok(None)
255+
}
247256
}
248257

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

494-
let target_dir = if let Some(dir) = target_dir.as_ref() {
495-
Some(Filesystem::new(self.cwd.join(dir)))
496-
} else if let Some(dir) = env::var_os("CARGO_TARGET_DIR") {
497-
Some(Filesystem::new(self.cwd.join(dir)))
498-
} else if let Ok(Some(val)) = self.get_path("build.target-dir") {
499-
let val = self.cwd.join(val.val);
500-
Some(Filesystem::new(val))
501-
} else {
502-
None
503+
let cli_target_dir = match target_dir.as_ref() {
504+
Some(dir) => Some(Filesystem::new(dir.clone())),
505+
None => None,
503506
};
504507

505508
self.shell().set_verbosity(verbosity);
506509
self.shell().set_color_choice(color.map(|s| &s[..]))?;
507510
self.extra_verbose = extra_verbose;
508511
self.frozen = frozen;
509512
self.locked = locked;
510-
self.target_dir = target_dir;
513+
self.target_dir = cli_target_dir;
511514
self.cli_flags.parse(unstable_flags)?;
512515

513516
Ok(())

tests/testsuite/bad_config.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,7 @@ fn invalid_global_config() {
284284
p.cargo("build").arg("-v"),
285285
execs().with_status(101).with_stderr(
286286
"\
287-
error: failed to parse manifest at `[..]`
288-
289-
Caused by:
290-
Couldn't load Cargo configuration
287+
[ERROR] Couldn't load Cargo configuration
291288
292289
Caused by:
293290
could not parse TOML configuration in `[..]`

0 commit comments

Comments
 (0)