From dcc6e73d4b720fa39061b317fb3b7017ffb33b49 Mon Sep 17 00:00:00 2001 From: Chao Sun Date: Thu, 11 Oct 2018 15:46:49 +0800 Subject: [PATCH] Fix build error when fetching git hash (#171) When the parquet-rs crate is used in a third-party library, the "git" command in the build.rs will fail. This fixes it by skipping the git hash and just use "parquet-rs version " as the CREATED_BY string. This should be OK since a crate version should always map to a unique git hash. --- build.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/build.rs b/build.rs index 1457678..246b7cd 100644 --- a/build.rs +++ b/build.rs @@ -20,10 +20,12 @@ use std::process::Command; fn main() { // Set Parquet version, build hash and "created by" string. let version = env!("CARGO_PKG_VERSION"); - let git_hash = run(Command::new("git").arg("rev-parse").arg("HEAD")).unwrap(); - let created_by = format!("parquet-rs version {} (build {})", version, git_hash); + let mut created_by = format!("parquet-rs version {}", version); + if let Ok(git_hash) = run(Command::new("git").arg("rev-parse").arg("HEAD")) { + created_by.push_str(format!(" (build {})", git_hash).as_str()); + println!("cargo:rustc-env=PARQUET_BUILD={}", git_hash); + } println!("cargo:rustc-env=PARQUET_VERSION={}", version); - println!("cargo:rustc-env=PARQUET_BUILD={}", git_hash); println!("cargo:rustc-env=PARQUET_CREATED_BY={}", created_by); }