Skip to content

Commit

Permalink
Merge pull request #610 from IntersectMBO/bug-all-zeros-git-revision
Browse files Browse the repository at this point in the history
Fix git revision reported by --version on nix build
  • Loading branch information
disassembler authored Feb 14, 2024
2 parents 646baf4 + d2994eb commit 7da4f5b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 12 additions & 4 deletions cardano-cli/src/Cardano/CLI/IO/GitRev.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ import Data.Text (Text)
import qualified Data.Text as T

import Cardano.Git.RevFromGit (gitRevFromGit)
import GHC.Foreign (peekCStringLen)
import GHC.Foreign (peekCStringLen)
import Foreign.C.String (CString)
import System.IO (utf8)
import System.IO.Unsafe (unsafeDupablePerformIO)

foreign import ccall "&_cardano_git_rev" c_gitrev :: CString

gitRev :: Text
gitRev | gitRevEmbed /= zeroRev = gitRevEmbed
| T.null fromGit = zeroRev
| otherwise = fromGit
gitRev | gitRevEmbed /= zeroRev = gitRevEmbed
| not (T.null fromGit) = fromGit
| not (T.null gitRevFromEnv) = gitRevFromEnv
| otherwise = zeroRev
where
-- Git revision embedded after compilation using
-- Data.FileEmbed.injectWith. If nothing has been injected,
Expand All @@ -38,5 +39,12 @@ gitRev | gitRevEmbed /= zeroRev = gitRevEmbed
fromGit = T.strip (T.pack $(gitRevFromGit))
#endif

gitRevFromEnv :: Text
#if defined(__GIT_REV__)
gitRevFromEnv = T.pack __GIT_REV__
#else
gitRevFromEnv = ""
#endif

zeroRev :: Text
zeroRev = "0000000000000000000000000000000000000000"
6 changes: 5 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
};
inherit (nixpkgs) lib;

gitRevFlag = if inputs.self ? rev
then [ ("--ghc-option=-D__GIT_REV__=\\\"" + inputs.self.rev + "\\\"") ]
else [];

# see flake `variants` below for alternative compilers
defaultCompiler = "ghc963";
# We use cabalProject' to ensure we don't build the plan for
Expand Down Expand Up @@ -85,7 +89,7 @@
# specific enough, or doesn't allow setting these.
modules = [
({pkgs, ...}: {
packages.cardano-cli.configureFlags = ["--ghc-option=-Werror"];
packages.cardano-cli.configureFlags = [ "--ghc-option=-Werror" ] ++ gitRevFlag;
packages.cardano-cli.components.tests.cardano-cli-test.build-tools =
with pkgs.buildPackages; [ jq coreutils shellcheck ];
packages.cardano-cli.components.tests.cardano-cli-golden.build-tools =
Expand Down

0 comments on commit 7da4f5b

Please sign in to comment.