From f8b585df39630b63cdc0de44056621eb65372291 Mon Sep 17 00:00:00 2001 From: neodiX42 Date: Thu, 4 May 2023 08:49:43 -0500 Subject: [PATCH] Fix missing git revision when built with Nix. (#680) --- flake.nix | 3 +++ git_watcher.cmake | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/flake.nix b/flake.nix index e7b0422e..d3fca85c 100644 --- a/flake.nix +++ b/flake.nix @@ -50,6 +50,9 @@ "-static-libstdc++" ]); + GIT_REVISION = if self ? rev then self.rev else "dirty"; + GIT_REVISION_DATE = (builtins.concatStringsSep "-" (builtins.match "(.{4})(.{2})(.{2}).*" self.lastModifiedDate)) + " " + (builtins.concatStringsSep ":" (builtins.match "^........(.{2})(.{2})(.{2}).*" self.lastModifiedDate)); + postInstall = '' moveToOutput bin "$bin" ''; diff --git a/git_watcher.cmake b/git_watcher.cmake index ab135e80..78e57ba1 100644 --- a/git_watcher.cmake +++ b/git_watcher.cmake @@ -139,6 +139,8 @@ function(GetGitState _working_dir) RunGitCommand(show -s "--format=%H" ${object}) if(exit_code EQUAL 0) set(ENV{GIT_HEAD_SHA1} ${output}) + else() + set(ENV{GIT_HEAD_SHA1} "$ENV{GIT_REVISION}") endif() RunGitCommand(show -s "--format=%an" ${object}) @@ -154,6 +156,8 @@ function(GetGitState _working_dir) RunGitCommand(show -s "--format=%ci" ${object}) if(exit_code EQUAL 0) set(ENV{GIT_COMMIT_DATE_ISO8601} "${output}") + else() + set(ENV{GIT_COMMIT_DATE_ISO8601} "$ENV{GIT_REVISION_DATE}") endif() RunGitCommand(show -s "--format=%s" ${object})