forked from crypto-org-chain/chain-main
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
157 lines (145 loc) · 4.61 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
{ system ? builtins.currentSystem, pkgs ? import ./nix { inherit system; }, commit ? "" }:
let
src_regexes = [
"^x$"
"^x/.*"
"^app$"
"^app/.*"
"^config$"
"^config/.*"
"^cmd$"
"^cmd/.*"
"^proto$"
"^proto/.*"
"^test$"
"^test/.*"
"^go.mod$"
"^go.sum$"
];
lib = pkgs.lib;
build-chain-maind = { ledger_zemu ? false, network ? "mainnet" }: pkgs.buildGoModule rec {
pname = "chain-maind";
version = "0.0.1";
src = lib.cleanSourceWith {
name = "src";
src = lib.sourceByRegex ./. src_regexes;
};
subPackages = [ "cmd/chain-maind" ];
vendorSha256 = sha256:0ivzdzn1kwzaa0zafmilf1pwqc5fb4rh7km5h3hv86r83gi4vflc;
runVend = true;
outputs = [
"out"
"instrumented"
];
buildTags = "cgo,ledger,!test_ledger_mock,!ledger_mock," +
(if ledger_zemu then "ledger_zemu" else "!ledger_zemu") +
(lib.optionalString (network == "testnet") ",testnet");
buildFlags = "-tags ${buildTags}";
buildFlagsArray = ''
-ldflags=
-X github.com/cosmos/cosmos-sdk/version.Name=crypto-com-chain
-X github.com/cosmos/cosmos-sdk/version.AppName=${pname}
-X github.com/cosmos/cosmos-sdk/version.Version=${version}
-X github.com/cosmos/cosmos-sdk/version.Commit=${commit}
-X github.com/cosmos/cosmos-sdk/version.BuildTags=${buildTags}
'';
instrumentedBinary = "chain-maind-inst";
# FIXME remove the "-w -s" ldflags, https://github.com/golang/go/issues/40974
postBuild = ''
echo "Build instrumented binary"
go test ./cmd/chain-maind $buildFlags",testbincover" "''${buildFlagsArray[@]} -w -s" -coverpkg=./...,github.com/cosmos/cosmos-sdk/x/... -c -o ${instrumentedBinary}
'';
postInstall = ''
mkdir -p $instrumented/bin
mv ./${instrumentedBinary} $instrumented/bin/
'';
preFixup = ''
find $instrumented/bin/ -type f 2>/dev/null | xargs -r remove-references-to -t ${pkgs.go} || true
'';
};
in
rec {
inherit (pkgs) relayer cosmovisor;
chain-maind = build-chain-maind { };
pystarport = import ./pystarport { inherit pkgs; chaind = "${chain-maind}/bin/chain-maind"; };
chain-maind-testnet = build-chain-maind { network = "testnet"; };
# for testing and dev
chain-maind-zemu = build-chain-maind { ledger_zemu = true; };
# one can set binary with environment variable CHAIN_MAIND, or it'll find chain-maind in PATH
pystarport-unbind = import ./pystarport { inherit pkgs; };
# python env for python linter tools and pytest
test-pyenv = pkgs.poetry2nix.mkPoetryEnv { projectDir = ./integration_tests; };
# lint tools
lint-env = pkgs.buildEnv {
name = "lint-env";
pathsToLink = [ "/bin" "/share" ];
paths = with pkgs; [
test-pyenv
nixpkgs-fmt
(pkgs.writeShellScriptBin "lint-ci" ''
EXIT_STATUS=0
go mod verify || EXIT_STATUS=$?
flake8 --show-source --count --statistics \
--format="::error file=%(path)s,line=%(row)d,col=%(col)d::%(path)s:%(row)d:%(col)d: %(code)s %(text)s" \
|| EXIT_STATUS=$?
find . -name "*.nix" -type f | xargs nixpkgs-fmt --check || EXIT_STATUS=$?
exit $EXIT_STATUS
'')
];
};
common-env = [
cosmovisor
relayer
];
# sources for integration tests
tests = pkgs.runCommandLocal "tests"
{
src = lib.sourceByRegex ./. [
"^integration_tests$"
"^integration_tests/.*\\.py$"
"^integration_tests/configs$"
"^integration_tests/configs/.*"
];
} ''
mkdir -p $out/share
ln -s $src/integration_tests $out/share/
'';
# an env which can run integration tests
ci-env-inner = pkgs.buildEnv {
name = "ci-env-inner";
pathsToLink = [ "/bin" "/share" ];
paths = with pkgs; [
lint-env
chain-maind-zemu
chain-maind-zemu.instrumented
tests
] ++ common-env;
};
# main entrypoint script to run integration tests
run-integration-tests = pkgs.writeShellScriptBin "run-integration-tests" ''
export PATH=${ci-env-inner}/bin:$PATH
export TESTS=${ci-env-inner}/share/integration_tests
pytest -v -n 7 -m 'not ledger' --dist loadscope $TESTS
pytest -v -m ledger $TESTS
'';
ci-env = pkgs.symlinkJoin {
name = "ci-env";
paths = [
ci-env-inner
run-integration-tests
];
};
# test in dev-shell will use the chain-maind in PATH
dev-shell = pkgs.mkShell {
buildInputs = with pkgs; [
lint-env
go
python3Packages.poetry
pystarport-unbind
] ++ common-env;
shellHook = ''
# prefer local pystarport directory for development
export PYTHONPATH=./pystarport:$PYTHONPATH
'';
};
}