From 20476935ffafda62767de08a4ff1edb0add8fd8e Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Wed, 28 Jun 2023 10:24:55 -0700 Subject: [PATCH] Enable building Spin outside of Git worktree Removes requirement for Git information to be available during builds. Sets default values for any unavailable git information. Signed-off-by: Kate Goldenring --- build.rs | 4 +++- sdk/rust/build.rs | 13 +++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/build.rs b/build.rs index 5ab623f4b..e0b6db636 100644 --- a/build.rs +++ b/build.rs @@ -14,6 +14,9 @@ const RUST_OUTBOUND_REDIS_INTEGRATION_TEST: &str = "tests/outbound-redis/http-ru const TIMER_TRIGGER_INTEGRATION_TEST: &str = "examples/spin-timer/app-example"; fn main() { + // Extract environment information to be passed to plugins. + // Git information will be set to defaults if Spin is not + // built within a Git worktree. vergen::EmitBuilder::builder() .build_date() .build_timestamp() @@ -23,7 +26,6 @@ fn main() { .git_commit_date() .git_commit_timestamp() .git_sha(true) - .fail_on_error() .emit() .expect("failed to extract build information"); diff --git a/sdk/rust/build.rs b/sdk/rust/build.rs index c0159d23d..5e27b420e 100644 --- a/sdk/rust/build.rs +++ b/sdk/rust/build.rs @@ -8,17 +8,14 @@ fn main() { format!("-{pre}") }; - let output = Command::new("git") + let commit = Command::new("git") .arg("rev-parse") .arg("HEAD") .output() - .expect("failed to execute `git`"); - - let commit = if output.status.success() { - String::from_utf8(output.stdout).unwrap() - } else { - panic!("`git` failed: {}", String::from_utf8_lossy(&output.stderr)); - }; + .ok() + .filter(|o| o.status.success()) + .map(|o| String::from_utf8_lossy(&o.stdout).to_string()) + .unwrap_or(String::from("unknown")); let commit = commit.trim();