Skip to content

Commit c78180c

Browse files
bors[bot]matklad
andauthored
Merge #5152
5152: Don't crash on empty out_dirs with older cargos r=matklad a=matklad closes #5125 bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents bad0b9a + cec9240 commit c78180c

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

crates/ra_project_model/src/cargo_workspace.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//! FIXME: write short doc here
22
3-
use std::{ffi::OsStr, ops, path::Path, process::Command};
3+
use std::{
4+
ffi::OsStr,
5+
ops,
6+
path::{Path, PathBuf},
7+
process::Command,
8+
};
49

510
use anyhow::{Context, Result};
611
use cargo_metadata::{BuildScript, CargoOpt, Message, MetadataCommand, PackageId};
@@ -308,9 +313,13 @@ pub fn load_extern_resources(
308313
if let Ok(message) = message {
309314
match message {
310315
Message::BuildScriptExecuted(BuildScript { package_id, out_dir, cfgs, .. }) => {
311-
let out_dir = AbsPathBuf::assert(out_dir);
312-
res.out_dirs.insert(package_id.clone(), out_dir);
313-
res.cfgs.insert(package_id, cfgs);
316+
// cargo_metadata crate returns default (empty) path for
317+
// older cargos, which is not absolute, so work around that.
318+
if out_dir != PathBuf::default() {
319+
let out_dir = AbsPathBuf::assert(out_dir);
320+
res.out_dirs.insert(package_id.clone(), out_dir);
321+
res.cfgs.insert(package_id, cfgs);
322+
}
314323
}
315324
Message::CompilerArtifact(message) => {
316325
if message.target.kind.contains(&"proc-macro".to_string()) {

0 commit comments

Comments
 (0)