From d8df2ee1894e0ec0c8e1e631e4051c26896a8a3d Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Fri, 17 May 2024 17:45:11 +0200 Subject: [PATCH 1/4] Fix detect_compiler_family.c not being created --- src/tool.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/tool.rs b/src/tool.rs index 850065800..dfa25e506 100644 --- a/src/tool.rs +++ b/src/tool.rs @@ -110,12 +110,26 @@ impl Tool { cargo_output: &CargoOutput, out_dir: Option<&Path>, ) -> Result { - let tmp = NamedTempfile::new( - &out_dir - .map(Cow::Borrowed) - .unwrap_or_else(|| Cow::Owned(env::temp_dir())), - "detect_compiler_family.c", - )?; + let out_dir = out_dir + .map(Cow::Borrowed) + .unwrap_or_else(|| Cow::Owned(env::temp_dir())); + + // Ensure all the parent directories exist otherwise temp file creation + // will fail + std::fs::create_dir_all(&out_dir).map_err(|err| Error { + kind: ErrorKind::IOError, + message: format!("failed to create OUT_DIR '{:?}': {}", out_dir, err).into(), + })?; + + let tmp = + NamedTempfile::new(&out_dir, "detect_compiler_family.c").map_err(|err| Error { + kind: ErrorKind::IOError, + message: format!( + "failed to create detect_compiler_family.c temp file in '{:?}': {}", + out_dir, err + ) + .into(), + })?; tmp.file() .write_all(include_bytes!("detect_compiler_family.c"))?; From bcbc5f6d1cf711a16179a7eafa17f1ccad52a370 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Sat, 18 May 2024 11:16:38 +0200 Subject: [PATCH 2/4] Fix quotes Co-authored-by: Jiahao XU --- src/tool.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tool.rs b/src/tool.rs index dfa25e506..04a3523d5 100644 --- a/src/tool.rs +++ b/src/tool.rs @@ -118,7 +118,7 @@ impl Tool { // will fail std::fs::create_dir_all(&out_dir).map_err(|err| Error { kind: ErrorKind::IOError, - message: format!("failed to create OUT_DIR '{:?}': {}", out_dir, err).into(), + message: format!("failed to create OUT_DIR '{}': {}", out_dir.display(), err).into(), })?; let tmp = From 9459cf177d2db230bdbbdb27bf042a3ee457e43a Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Sat, 18 May 2024 11:16:47 +0200 Subject: [PATCH 3/4] Fix quotes Co-authored-by: Jiahao XU --- src/tool.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tool.rs b/src/tool.rs index 04a3523d5..74f5c67ff 100644 --- a/src/tool.rs +++ b/src/tool.rs @@ -125,8 +125,8 @@ impl Tool { NamedTempfile::new(&out_dir, "detect_compiler_family.c").map_err(|err| Error { kind: ErrorKind::IOError, message: format!( - "failed to create detect_compiler_family.c temp file in '{:?}': {}", - out_dir, err + "failed to create detect_compiler_family.c temp file in '{}': {}", + out_dir.display(), err ) .into(), })?; From 05081b9ca08039c24524d47439fb3d349e60529d Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Sun, 19 May 2024 09:54:16 +0200 Subject: [PATCH 4/4] Format --- src/tool.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/tool.rs b/src/tool.rs index 74f5c67ff..ea0f36fad 100644 --- a/src/tool.rs +++ b/src/tool.rs @@ -118,7 +118,8 @@ impl Tool { // will fail std::fs::create_dir_all(&out_dir).map_err(|err| Error { kind: ErrorKind::IOError, - message: format!("failed to create OUT_DIR '{}': {}", out_dir.display(), err).into(), + message: format!("failed to create OUT_DIR '{}': {}", out_dir.display(), err) + .into(), })?; let tmp = @@ -126,7 +127,8 @@ impl Tool { kind: ErrorKind::IOError, message: format!( "failed to create detect_compiler_family.c temp file in '{}': {}", - out_dir.display(), err + out_dir.display(), + err ) .into(), })?;