From 28b8fa6277defccb5ba7a3d754fcf2832a72a7a6 Mon Sep 17 00:00:00 2001 From: Alexander Esgen Date: Fri, 15 Mar 2024 11:01:55 +0100 Subject: [PATCH 1/3] cardano-git-rev: use just one CPP clause This helps in a follow-up commit. --- cardano-git-rev/src/Cardano/Git/Rev.hs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cardano-git-rev/src/Cardano/Git/Rev.hs b/cardano-git-rev/src/Cardano/Git/Rev.hs index 2e69c1501..5b73e163d 100644 --- a/cardano-git-rev/src/Cardano/Git/Rev.hs +++ b/cardano-git-rev/src/Cardano/Git/Rev.hs @@ -35,12 +35,7 @@ gitRev :: Q Exp gitRev | gitRevEmbed /= zeroRev = textE gitRevEmbed | otherwise = -#if defined(arm_HOST_ARCH) - -- cross compiling to arm fails; due to a linker bug - textE zeroRev -#else textE =<< TH.runIO runGitRevParse -#endif -- Git revision embedded after compilation using -- Data.FileEmbed.injectWith. If nothing has been injected, @@ -48,8 +43,11 @@ gitRev gitRevEmbed :: Text gitRevEmbed = Text.pack $ drop 28 $ unsafeDupablePerformIO (peekCStringLen utf8 (c_gitrev, 68)) -#if !defined(arm_HOST_ARCH) runGitRevParse :: IO Text +#if defined(arm_HOST_ARCH) +-- cross compiling to arm fails; due to a linker bug +runGitRevParse = pure zeroRev +#else runGitRevParse = do (exitCode, output, errorMessage) <- readProcessWithExitCode_ "git" ["rev-parse", "--verify", "HEAD"] "" case exitCode of From 314f6182c721ba5cc518396b2603d317d6ffb23c Mon Sep 17 00:00:00 2001 From: Alexander Esgen Date: Fri, 15 Mar 2024 11:03:50 +0100 Subject: [PATCH 2/3] Perform check for embedded git rev at run time Previously, it was performed at compile time, where it will always be false as no rev has been embedded yet. --- cardano-git-rev/src/Cardano/Git/Rev.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cardano-git-rev/src/Cardano/Git/Rev.hs b/cardano-git-rev/src/Cardano/Git/Rev.hs index 5b73e163d..51b065c57 100644 --- a/cardano-git-rev/src/Cardano/Git/Rev.hs +++ b/cardano-git-rev/src/Cardano/Git/Rev.hs @@ -32,10 +32,11 @@ foreign import ccall "&_cardano_git_rev" c_gitrev :: CString -- This must be a TH splice to ensure the git commit is captured at build time. -- ie called as `$(gitRev)`. gitRev :: Q Exp -gitRev - | gitRevEmbed /= zeroRev = textE gitRevEmbed - | otherwise = - textE =<< TH.runIO runGitRevParse +gitRev = + [| if + | gitRevEmbed /= zeroRev -> gitRevEmbed + | otherwise -> $(textE =<< TH.runIO runGitRevParse) + |] -- Git revision embedded after compilation using -- Data.FileEmbed.injectWith. If nothing has been injected, From 792ff3d96b892617ab29ec46152d36c470be2f7a Mon Sep 17 00:00:00 2001 From: Alexander Esgen Date: Mon, 18 Mar 2024 11:25:47 +0100 Subject: [PATCH 3/3] cardano-git-rev: only use `TemplateHaskellQuotes` We don't want to splice something at the top-level in cardano-git-rev, but rather just provide expressions such users can do that in their projects. --- cardano-git-rev/src/Cardano/Git/Rev.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cardano-git-rev/src/Cardano/Git/Rev.hs b/cardano-git-rev/src/Cardano/Git/Rev.hs index 51b065c57..f87a24110 100644 --- a/cardano-git-rev/src/Cardano/Git/Rev.hs +++ b/cardano-git-rev/src/Cardano/Git/Rev.hs @@ -1,9 +1,15 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE MultiWayIf #-} {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE ForeignFunctionInterface #-} +#if __GLASGOW_HASKELL__ >= 900 +{-# LANGUAGE TemplateHaskellQuotes #-} +#else +-- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/2288 +{-# LANGUAGE TemplateHaskell #-} +#endif + module Cardano.Git.Rev ( gitRev ) where