Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix git revision reported by --version on nix build #610

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading