Skip to content

Commit

Permalink
Switch from cfg! macro to cfg attribute for build.rs
Browse files Browse the repository at this point in the history
comptime `if cfg!(windows)` didn't eliminate erroneous `env!("ProgramFiles")` in CI 😢
  • Loading branch information
diogotito committed Aug 26, 2024
1 parent ab0cbcf commit 4ad4e9b
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions fpt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,30 @@ fn write_header(test_file: &mut File) {
write!(test_file, include_str!("./tests/templates/header")).unwrap();
}

const SH: &str = if cfg!(windows) {
// 💀 Assume a regular Git for Windows install
concat!(env!("ProgramFiles"), r#"\Git\bin\sh.exe"#)
} else {
#[cfg(target_os = "windows")]
fn get_sh() -> String {
std::env::var("ProgramFiles").unwrap_or(r#"C:\Program Files"#.to_string())
+ r#"\Git\bin\sh.exe"#
}

#[cfg(not(target_os = "windows"))]
fn get_sh() -> &'static str {
"sh"
};
}

fn run_cmd(cmd: &str) -> String {
let output = Command::new(SH)
let output = Command::new(get_sh())
.arg("-c")
.arg(cmd)
.output()
.unwrap_or_else(|e| panic!("failed to execute process: {:#?}: {:#?}", cmd, e));
.unwrap_or_else(|e| {
panic!(
"failed to execute process: {:#?} under {:#?}: {:#?}",
cmd,
get_sh(),
e
)
});
if !output.status.success() {
panic!("Command {} failed with exit code: {}", cmd, output.status);
}
Expand Down

0 comments on commit 4ad4e9b

Please sign in to comment.