Skip to content

Commit 8f6d07f

Browse files
authored
Fix detect_compiler_family.c not being created (#1072)
1 parent 61b81c8 commit 8f6d07f

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/tool.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,28 @@ impl Tool {
110110
cargo_output: &CargoOutput,
111111
out_dir: Option<&Path>,
112112
) -> Result<ToolFamily, Error> {
113-
let tmp = NamedTempfile::new(
114-
&out_dir
115-
.map(Cow::Borrowed)
116-
.unwrap_or_else(|| Cow::Owned(env::temp_dir())),
117-
"detect_compiler_family.c",
118-
)?;
113+
let out_dir = out_dir
114+
.map(Cow::Borrowed)
115+
.unwrap_or_else(|| Cow::Owned(env::temp_dir()));
116+
117+
// Ensure all the parent directories exist otherwise temp file creation
118+
// will fail
119+
std::fs::create_dir_all(&out_dir).map_err(|err| Error {
120+
kind: ErrorKind::IOError,
121+
message: format!("failed to create OUT_DIR '{}': {}", out_dir.display(), err)
122+
.into(),
123+
})?;
124+
125+
let tmp =
126+
NamedTempfile::new(&out_dir, "detect_compiler_family.c").map_err(|err| Error {
127+
kind: ErrorKind::IOError,
128+
message: format!(
129+
"failed to create detect_compiler_family.c temp file in '{}': {}",
130+
out_dir.display(),
131+
err
132+
)
133+
.into(),
134+
})?;
119135
tmp.file()
120136
.write_all(include_bytes!("detect_compiler_family.c"))?;
121137

0 commit comments

Comments
 (0)