Skip to content

Commit 67554d1

Browse files
authored
Make the Git revision available to pir/uplc/plc programs (#6949)
1 parent 006c46e commit 67554d1

File tree

13 files changed

+336
-117
lines changed

13 files changed

+336
-117
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,4 @@ plutus-pab/test-node/alonzo-purple/db
113113
*.stacks
114114
.nvimrc
115115
release-*
116+
.worktrees

nix/outputs.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let
3636
{ inherit self pkgs; };
3737

3838
project = import ./project.nix
39-
{ inherit inputs pkgs lib agda-with-stdlib r-with-packages; };
39+
{ inherit inputs pkgs lib agda-with-stdlib r-with-packages utils; };
4040

4141
mkShell = project: import ./shell.nix
4242
{ inherit inputs pkgs lib project agda-with-stdlib r-with-packages; };
@@ -122,6 +122,7 @@ let
122122
hydraJobs = ciJobs;
123123

124124
__internal = {
125+
inherit self;
125126
inherit pkgs;
126127
inherit project;
127128
inherit agda-with-stdlib;

nix/project.nix

Lines changed: 119 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,126 @@
11
# editorconfig-checker-disable-file
2-
{ inputs, pkgs, lib, agda-with-stdlib, r-with-packages }:
2+
{ inputs, pkgs, lib, agda-with-stdlib, r-with-packages, utils }:
33

44
let
5-
cabalProject = pkgs.haskell-nix.cabalProject' ({ config, pkgs, ... }: {
6-
name = "plutus";
7-
8-
# We need the mkDefault here since compiler-nix-name will be overridden
9-
# in the flake variants.
10-
compiler-nix-name = lib.mkDefault "ghc96";
11-
12-
src = ../.;
13-
14-
flake.variants = {
15-
ghc96 = { }; # Alias for the default project
16-
profiled.modules = [{
17-
enableProfiling = true;
18-
enableLibraryProfiling = true;
19-
}];
20-
ghc810.compiler-nix-name = "ghc810";
21-
ghc98.compiler-nix-name = "ghc98";
22-
ghc910.compiler-nix-name = "ghc910";
23-
};
24-
25-
inputMap = { "https://chap.intersectmbo.org/" = inputs.CHaP; };
26-
27-
sha256map = {
28-
"https://github.com/jaccokrijnen/plutus-cert"."e814b9171398cbdfecdc6823067156a7e9fc76a3" =
29-
"0srqvx0b819b5crrbsa9hz2fnr50ahqizvvm0wdmyq2bbpk2rka7";
30-
};
31-
32-
modules = [
33-
# Common
34-
{
35-
packages = {
36-
# plutus-metatheory needs agda with the stdlib around for the custom setup
37-
# I can't figure out a way to apply this as a blanket change for all the
38-
# components in the package, oh well
39-
plutus-metatheory.components.library.build-tools =
40-
[ agda-with-stdlib ];
41-
plutus-metatheory.components.exes.plc-agda.build-tools =
42-
[ agda-with-stdlib ];
43-
plutus-metatheory.components.tests.test-NEAT.build-tools =
44-
[ agda-with-stdlib ];
45-
46-
plutus-executables.components.exes.uplc.build-tools =
47-
[ agda-with-stdlib ];
48-
49-
plutus-executables.components.tests.test-simple.build-tools =
50-
[ agda-with-stdlib ];
51-
plutus-executables.components.tests.test-detailed.build-tools =
52-
[ agda-with-stdlib ];
53-
54-
plutus-core.components.benchmarks.update-cost-model = {
55-
build-tools = [ r-with-packages ];
56-
};
57-
58-
plutus-core.components.benchmarks.cost-model-test = {
59-
build-tools = [ r-with-packages ];
60-
};
61-
62-
plutus-cert.components.library.build-tools =
63-
# Needs to build both itself and its bundled deps.
64-
# This needs both coq and ocaml packages, and only
65-
# works with particular versions. Fortunately
66-
# they're in nixpkgs.
67-
let
68-
ocamlPkgs = pkgs.ocaml-ng.ocamlPackages_4_10;
69-
coqPkgs = pkgs.coqPackages_8_13;
70-
in
71-
with ocamlPkgs;
72-
with coqPkgs; [
5+
cabalProject = pkgs.haskell-nix.cabalProject' ({ config, pkgs, ... }:
6+
let
7+
ghc-options-for-static-exe =
8+
lib.optionals pkgs.stdenv.hostPlatform.isMusl [ "-fexternal-interpreter" ];
9+
in
10+
{
11+
name = "plutus";
12+
13+
# We need the mkDefault here since compiler-nix-name will be overridden
14+
# in flake.variants.
15+
compiler-nix-name = lib.mkDefault "ghc96";
16+
17+
src = ../.;
18+
19+
flake.variants = {
20+
ghc96 = { }; # Alias for the default project
21+
profiled.modules = [{
22+
enableProfiling = true;
23+
enableLibraryProfiling = true;
24+
}];
25+
ghc810.compiler-nix-name = "ghc810";
26+
ghc98.compiler-nix-name = "ghc98";
27+
ghc910.compiler-nix-name = "ghc910";
28+
};
29+
30+
inputMap = { "https://chap.intersectmbo.org/" = inputs.CHaP; };
31+
32+
sha256map = {
33+
"https://github.com/jaccokrijnen/plutus-cert"."e814b9171398cbdfecdc6823067156a7e9fc76a3" =
34+
"0srqvx0b819b5crrbsa9hz2fnr50ahqizvvm0wdmyq2bbpk2rka7";
35+
};
36+
37+
modules = [
38+
{
39+
packages = {
40+
41+
plutus-metatheory.components.library.build-tools =
42+
[ agda-with-stdlib ];
43+
44+
plutus-metatheory.components.exes.plc-agda.build-tools =
45+
[ agda-with-stdlib ];
46+
47+
plutus-metatheory.components.tests.test-NEAT.build-tools =
48+
[ agda-with-stdlib ];
49+
50+
plutus-executables.components.exes.pir = {
51+
preBuild = utils.exportGitHashAndGitCommitDateEnvVars inputs.self;
52+
ghcOptions = ghc-options-for-static-exe;
53+
};
54+
55+
plutus-executables.components.exes.plc = {
56+
preBuild = utils.exportGitHashAndGitCommitDateEnvVars inputs.self;
57+
ghcOptions = ghc-options-for-static-exe;
58+
};
59+
60+
plutus-executables.components.exes.uplc = {
61+
preBuild = utils.exportGitHashAndGitCommitDateEnvVars inputs.self;
62+
ghcOptions = ghc-options-for-static-exe;
63+
build-tools = [ agda-with-stdlib ];
64+
};
65+
66+
plutus-executables.components.tests.test-simple.build-tools =
67+
[ agda-with-stdlib ];
68+
69+
plutus-executables.components.tests.test-detailed.build-tools =
70+
[ agda-with-stdlib ];
71+
72+
plutus-core.components.benchmarks.update-cost-model.build-tools =
73+
[ r-with-packages ];
74+
75+
plutus-core.components.benchmarks.cost-model-test.build-tools =
76+
[ r-with-packages ];
77+
78+
plutus-core.components.tests.plutus-core-test.postInstall = ''
79+
wrapProgram $out/bin/plutus-core-test --set PATH ${
80+
lib.makeBinPath [ pkgs.diffutils ]
81+
}
82+
'';
83+
84+
plutus-core.components.tests.plutus-ir-test.postInstall = ''
85+
wrapProgram $out/bin/plutus-ir-test --set PATH ${
86+
lib.makeBinPath [ pkgs.diffutils ]
87+
}
88+
'';
89+
90+
plutus-core.components.exes.plutus = {
91+
preBuild = utils.exportGitHashAndGitCommitDateEnvVars inputs.self;
92+
ghcOptions = ghc-options-for-static-exe;
93+
};
94+
95+
plutus-cert.components.library.build-tools = [
7396
pkgs.perl
74-
ocaml
75-
ocamlbuild
76-
findlib
77-
coq
78-
mathcomp
79-
coq-ext-lib
80-
ssreflect
81-
equations
97+
pkgs.ocaml-ng.ocamlPackages_4_10.ocaml
98+
pkgs.ocaml-ng.ocamlPackages_4_10.ocamlbuild
99+
pkgs.ocaml-ng.ocamlPackages_4_10.findlib
100+
pkgs.coqPackages_8_13.coq
101+
pkgs.coqPackages_8_13.mathcomp
102+
pkgs.coqPackages_8_13.coq-ext-lib
103+
pkgs.coqPackages_8_13.ssreflect
104+
pkgs.coqPackages_8_13.equations
82105
];
83-
84-
plutus-core.components.tests.plutus-core-test.postInstall = ''
85-
wrapProgram $out/bin/plutus-core-test --set PATH ${
86-
lib.makeBinPath [ pkgs.diffutils ]
87-
}
88-
'';
89-
90-
plutus-core.components.tests.plutus-ir-test.postInstall = ''
91-
wrapProgram $out/bin/plutus-ir-test --set PATH ${
92-
lib.makeBinPath [ pkgs.diffutils ]
93-
}
94-
'';
95-
};
96-
}
97-
98-
{
99-
packages = {
100-
cardano-constitution.ghcOptions = [ "-Werror" ];
101-
plutus-benchmark.ghcOptions = [ "-Werror" ];
102-
plutus-conformance.ghcOptions = [ "-Werror" ];
103-
plutus-core.ghcOptions = [ "-Werror" ];
104-
plutus-executables.ghcOptions = [ "-Werror" ];
105-
plutus-ledger-api.ghcOptions = [ "-Werror" ];
106-
plutus-metatheory.ghcOptions = [ "-Werror" ];
107-
plutus-tx.ghcOptions = [ "-Werror" ];
108-
plutus-tx-plugin.ghcOptions = [ "-Werror" ];
109-
plutus-tx-test-util.ghcOptions = [ "-Werror" ];
110-
};
111-
}
112-
];
113-
});
114-
106+
};
107+
}
108+
109+
{
110+
packages = {
111+
cardano-constitution.ghcOptions = [ "-Werror" ];
112+
plutus-benchmark.ghcOptions = [ "-Werror" ];
113+
plutus-conformance.ghcOptions = [ "-Werror" ];
114+
plutus-core.ghcOptions = [ "-Werror" ];
115+
plutus-executables.ghcOptions = [ "-Werror" ];
116+
plutus-ledger-api.ghcOptions = [ "-Werror" ];
117+
plutus-metatheory.ghcOptions = [ "-Werror" ];
118+
plutus-tx.ghcOptions = [ "-Werror" ];
119+
plutus-tx-plugin.ghcOptions = [ "-Werror" ];
120+
plutus-tx-test-util.ghcOptions = [ "-Werror" ];
121+
};
122+
}
123+
];
124+
});
115125
in
116126
cabalProject

nix/shell.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ let
122122
quick-shell = project.shellFor {
123123
name = "plutus-shell-${project.args.compiler-nix-name}";
124124
tools = { cabal = "latest"; };
125+
shellHook = ''
126+
${locale-archive-hook}
127+
export PS1="\n\[\033[1;32m\][nix-shell:\w]\$\[\033[0m\] "
128+
echo -e "\n🤟 Welcome to Plutus 🤟"
129+
'';
125130
};
126131

127132

nix/utils.nix

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{ lib }:
2-
{
2+
3+
rec {
4+
35
flattenDerivationTree = separator: set:
46
let
57
recurse = name: name':
@@ -26,4 +28,23 @@
2628
meta.description = "All jobs required to pass CI";
2729
constituents = lib.collect lib.isDerivation clean-jobs;
2830
};
31+
32+
33+
exportGitHashAndGitCommitDateEnvVars = self:
34+
''
35+
export GIT_HASH=${self.sourceInfo.rev or "unknown"}
36+
export GIT_COMMIT_DATE=${date_YYYYMMDDHHmmSS_ToIso8601 self.sourceInfo.lastModifiedDate}
37+
'';
38+
39+
40+
date_YYYYMMDDHHmmSS_ToIso8601 = ts:
41+
let
42+
year = lib.substring 0 4 ts;
43+
month = lib.substring 4 2 ts;
44+
day = lib.substring 6 2 ts;
45+
hour = lib.substring 8 2 ts;
46+
minute = lib.substring 10 2 ts;
47+
second = lib.substring 12 2 ts;
48+
in
49+
"${year}-${month}-${day}T${hour}:${minute}:${second}Z";
2950
}

plutus-core/executables/plutus/Mode/HelpVersion.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
13
module Mode.HelpVersion
24
( runHelp
35
, runVersion
46
) where
57

8+
import Data.Version.Extras (gitAwareVersionInfo)
69
import GetOpt
10+
import Paths_plutus_core qualified as Paths
711

812
runHelp :: IO ()
913
runHelp = do
@@ -13,4 +17,4 @@ usageHeader :: String
1317
usageHeader = "USAGE: plutus [--compile|--run|--bench|--debug] FILES..."
1418

1519
runVersion :: IO ()
16-
runVersion = putStrLn "Version 0"
20+
runVersion = putStrLn $(gitAwareVersionInfo Paths.version)

plutus-core/plutus-core.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ library
8888
Data.Either.Extras
8989
Data.List.Extras
9090
Data.MultiSet.Lens
91+
Data.Version.Extras
92+
Development.GitRev.Extras
9193
PlutusCore
9294
PlutusCore.Analysis.Definitions
9395
PlutusCore.Annotation
@@ -311,6 +313,7 @@ library
311313
, flat ^>=0.6
312314
, free
313315
, ghc-prim
316+
, gitrev
314317
, hashable >=1.4
315318
, hedgehog >=1.0
316319
, index-envs
@@ -678,6 +681,7 @@ executable plutus
678681
Mode.ListExamples
679682
Mode.PrintBuiltins
680683
Mode.PrintCostModel
684+
Paths_plutus_core
681685
Types
682686

683687
build-depends:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
3+
module Data.Version.Extras
4+
( gitAwareVersionInfo
5+
) where
6+
7+
8+
import Data.Version qualified as Data.Version
9+
import Development.GitRev.Extras qualified as GitRev
10+
import Language.Haskell.TH qualified as TH
11+
12+
13+
gitAwareVersionInfo
14+
:: Data.Version.Version -- | The version, usually coming from Paths_<pkg>.version
15+
-> TH.ExpQ -- | A string that includes, if available, the git hash and the git commit date
16+
gitAwareVersionInfo version = [| version' <> gitHash <> gitCommitDate |]
17+
where
18+
version' = Data.Version.showVersion version
19+
20+
gitCommitDate = do
21+
let commitDate = $(GitRev.gitCommitDate)
22+
if null commitDate then "" else " - " <> commitDate
23+
24+
gitHash = do
25+
let hash = $(GitRev.gitHash)
26+
if null hash then "" else " - git rev " <> hash

0 commit comments

Comments
 (0)