Skip to content

Commit 9712070

Browse files
committed
Adds a dune wrapper to check current switch consistency opam.export #10982
1 parent 2c37a84 commit 9712070

File tree

6 files changed

+141
-31
lines changed

6 files changed

+141
-31
lines changed

Makefile

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ ifeq ($(DUNE_PROFILE),)
1212
DUNE_PROFILE := dev
1313
endif
1414

15+
# Dune
16+
DUNE = scripts/dune_wrapper
17+
18+
1519
# Temp directory
1620
TMPDIR ?= /tmp
1721

@@ -77,64 +81,64 @@ libp2p_helper:
7781

7882
genesis_ledger: ocaml_checks
7983
$(info Building runtime_genesis_ledger)
80-
ulimit -s 65532 && (ulimit -n 10240 || true) && env MINA_COMMIT_SHA1=$(GITLONGHASH) dune exec --profile=$(DUNE_PROFILE) src/app/runtime_genesis_ledger/runtime_genesis_ledger.exe -- --genesis-dir $(GENESIS_DIR)
84+
ulimit -s 65532 && (ulimit -n 10240 || true) && env MINA_COMMIT_SHA1=$(GITLONGHASH) $(DUNE) exec --profile=$(DUNE_PROFILE) src/app/runtime_genesis_ledger/runtime_genesis_ledger.exe -- --genesis-dir $(GENESIS_DIR)
8185
$(info Genesis ledger and genesis proof generated)
8286

8387
build: ocaml_checks git_hooks reformat-diff libp2p_helper
8488
$(info Starting Build)
85-
ulimit -s 65532 && (ulimit -n 10240 || true) && env MINA_COMMIT_SHA1=$(GITLONGHASH) dune build src/app/logproc/logproc.exe src/app/cli/src/mina.exe --profile=$(DUNE_PROFILE)
89+
ulimit -s 65532 && (ulimit -n 10240 || true) && env MINA_COMMIT_SHA1=$(GITLONGHASH) $(DUNE) build src/app/logproc/logproc.exe src/app/cli/src/mina.exe --profile=$(DUNE_PROFILE)
8690
$(info Build complete)
8791

8892
build_all_sigs: ocaml_checks git_hooks reformat-diff libp2p_helper
8993
$(info Starting Build)
90-
ulimit -s 65532 && (ulimit -n 10240 || true) && env MINA_COMMIT_SHA1=$(GITLONGHASH) dune build src/app/logproc/logproc.exe src/app/cli/src/mina.exe src/app/cli/src/mina_testnet_signatures.exe src/app/cli/src/mina_mainnet_signatures.exe --profile=$(DUNE_PROFILE)
94+
ulimit -s 65532 && (ulimit -n 10240 || true) && env MINA_COMMIT_SHA1=$(GITLONGHASH) $(DUNE) build src/app/logproc/logproc.exe src/app/cli/src/mina.exe src/app/cli/src/mina_testnet_signatures.exe src/app/cli/src/mina_mainnet_signatures.exe --profile=$(DUNE_PROFILE)
9195
$(info Build complete)
9296

9397
build_archive: ocaml_checks git_hooks reformat-diff
9498
$(info Starting Build)
95-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/app/archive/archive.exe --profile=$(DUNE_PROFILE)
99+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/app/archive/archive.exe --profile=$(DUNE_PROFILE)
96100
$(info Build complete)
97101

98102
build_archive_all_sigs: ocaml_checks git_hooks reformat-diff
99103
$(info Starting Build)
100-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/app/archive/archive.exe src/app/archive/archive_testnet_signatures.exe src/app/archive/archive_mainnet_signatures.exe --profile=$(DUNE_PROFILE)
104+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/app/archive/archive.exe src/app/archive/archive_testnet_signatures.exe src/app/archive/archive_mainnet_signatures.exe --profile=$(DUNE_PROFILE)
101105
$(info Build complete)
102106

103107
build_rosetta: ocaml_checks
104108
$(info Starting Build)
105-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/app/archive/archive.exe src/app/rosetta/rosetta.exe src/app/rosetta/ocaml-signer/signer.exe --profile=$(DUNE_PROFILE)
109+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/app/archive/archive.exe src/app/rosetta/rosetta.exe src/app/rosetta/ocaml-signer/signer.exe --profile=$(DUNE_PROFILE)
106110
$(info Build complete)
107111

108112
build_rosetta_all_sigs: ocaml_checks
109113
$(info Starting Build)
110-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/app/archive/archive.exe src/app/archive/archive_testnet_signatures.exe src/app/archive/archive_mainnet_signatures.exe src/app/rosetta/rosetta.exe src/app/rosetta/rosetta_testnet_signatures.exe src/app/rosetta/rosetta_mainnet_signatures.exe src/app/rosetta/ocaml-signer/signer.exe src/app/rosetta/ocaml-signer/signer_testnet_signatures.exe src/app/rosetta/ocaml-signer/signer_mainnet_signatures.exe --profile=$(DUNE_PROFILE)
114+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/app/archive/archive.exe src/app/archive/archive_testnet_signatures.exe src/app/archive/archive_mainnet_signatures.exe src/app/rosetta/rosetta.exe src/app/rosetta/rosetta_testnet_signatures.exe src/app/rosetta/rosetta_mainnet_signatures.exe src/app/rosetta/ocaml-signer/signer.exe src/app/rosetta/ocaml-signer/signer_testnet_signatures.exe src/app/rosetta/ocaml-signer/signer_mainnet_signatures.exe --profile=$(DUNE_PROFILE)
111115
$(info Build complete)
112116

113117
build_intgtest: ocaml_checks
114118
$(info Starting Build)
115-
dune build --profile=$(DUNE_PROFILE) src/app/test_executive/test_executive.exe src/app/logproc/logproc.exe
119+
$(DUNE) build --profile=$(DUNE_PROFILE) src/app/test_executive/test_executive.exe src/app/logproc/logproc.exe
116120
$(info Build complete)
117121

118122
client_sdk: ocaml_checks
119123
$(info Starting Build)
120-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune b src/lib/crypto/kimchi_bindings/js/node_js && dune b src/app/client_sdk/client_sdk.bc.js
124+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) b src/lib/crypto/kimchi_bindings/js/node_js && $(DUNE) b src/app/client_sdk/client_sdk.bc.js
121125
$(info Build complete)
122126

123127
client_sdk_test_sigs: ocaml_checks
124128
$(info Starting Build)
125-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/app/client_sdk/tests/test_signatures.exe --profile=mainnet
129+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/app/client_sdk/tests/test_signatures.exe --profile=mainnet
126130
$(info Build complete)
127131

128132
client_sdk_test_sigs_nonconsensus: ocaml_checks
129133
$(info Starting Build)
130-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/app/client_sdk/tests/test_signatures_nonconsensus.exe --profile=nonconsensus_mainnet
134+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/app/client_sdk/tests/test_signatures_nonconsensus.exe --profile=nonconsensus_mainnet
131135
$(info Build complete)
132136

133137
mina_signer: ocaml_checks
134138
$(info Starting Build)
135139
ulimit -s 65532 && (ulimit -n 10240 || true) \
136-
&& dune b src/lib/crypto/kimchi_bindings/js/node_js \
137-
&& dune b src/app/client_sdk/client_sdk.bc.js \
140+
&& $(DUNE) b src/lib/crypto/kimchi_bindings/js/node_js \
141+
&& $(DUNE) b src/app/client_sdk/client_sdk.bc.js \
138142
&& (cd frontend/mina-signer; \
139143
([ -d node_modules ] || npm i) && npm run copy-jsoo && npm run copy-wasm && npm run build; \
140144
cd ../..)
@@ -148,57 +152,57 @@ snarkyjs: ocaml_checks
148152

149153
rosetta_lib_encodings: ocaml_checks
150154
$(info Starting Build)
151-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/lib/rosetta_lib/test/test_encodings.exe --profile=mainnet
155+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/lib/rosetta_lib/test/test_encodings.exe --profile=mainnet
152156
$(info Build complete)
153157

154158
rosetta_lib_encodings_nonconsensus: ocaml_checks
155159
$(info Starting Build)
156-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/nonconsensus/rosetta_lib/test/test_encodings.exe --profile=nonconsensus_mainnet
160+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/nonconsensus/rosetta_lib/test/test_encodings.exe --profile=nonconsensus_mainnet
157161
$(info Build complete)
158162

159163
dhall_types: ocaml_checks
160164
$(info Starting Build)
161-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/app/dhall_types/dump_dhall_types.exe --profile=dev
165+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/app/dhall_types/dump_dhall_types.exe --profile=dev
162166
$(info Build complete)
163167

164168
replayer: ocaml_checks
165169
$(info Starting Build)
166-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/app/replayer/replayer.exe --profile=testnet_postake_medium_curves
170+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/app/replayer/replayer.exe --profile=testnet_postake_medium_curves
167171
$(info Build complete)
168172

169173
delegation_compliance: ocaml_checks
170174
$(info Starting Build)
171-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/app/delegation_compliance/delegation_compliance.exe --profile=testnet_postake_medium_curves
175+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/app/delegation_compliance/delegation_compliance.exe --profile=testnet_postake_medium_curves
172176
$(info Build complete)
173177

174178
missing_blocks_auditor: ocaml_checks
175179
$(info Starting Build)
176-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/app/missing_blocks_auditor/missing_blocks_auditor.exe --profile=testnet_postake_medium_curves
180+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/app/missing_blocks_auditor/missing_blocks_auditor.exe --profile=testnet_postake_medium_curves
177181
$(info Build complete)
178182

179183
extract_blocks: ocaml_checks
180184
$(info Starting Build)
181-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/app/extract_blocks/extract_blocks.exe --profile=testnet_postake_medium_curves
185+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/app/extract_blocks/extract_blocks.exe --profile=testnet_postake_medium_curves
182186
$(info Build complete)
183187

184188
archive_blocks: ocaml_checks
185189
$(info Starting Build)
186-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/app/archive_blocks/archive_blocks.exe --profile=testnet_postake_medium_curves
190+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/app/archive_blocks/archive_blocks.exe --profile=testnet_postake_medium_curves
187191
$(info Build complete)
188192

189193
patch_archive_test: ocaml_checks
190194
$(info Starting Build)
191-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/app/patch_archive_test/patch_archive_test.exe --profile=testnet_postake_medium_curves
195+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/app/patch_archive_test/patch_archive_test.exe --profile=testnet_postake_medium_curves
192196
$(info Build complete)
193197

194198
genesis_ledger_from_tsv: ocaml_checks
195199
$(info Starting Build)
196-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/app/genesis_ledger_from_tsv/genesis_ledger_from_tsv.exe --profile=testnet_postake_medium_curves
200+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/app/genesis_ledger_from_tsv/genesis_ledger_from_tsv.exe --profile=testnet_postake_medium_curves
197201
$(info Build complete)
198202

199203
swap_bad_balances: ocaml_checks
200204
$(info Starting Build)
201-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build src/app/swap_bad_balances/swap_bad_balances.exe --profile=testnet_postake_medium_curves
205+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build src/app/swap_bad_balances/swap_bad_balances.exe --profile=testnet_postake_medium_curves
202206
$(info Build complete)
203207

204208
dev: build
@@ -212,19 +216,19 @@ macos-portable:
212216
@echo Find coda-daemon-macos.zip inside _build/
213217

214218
update-graphql:
215-
ulimit -s 65532 && (ulimit -n 10240 || true) && dune build --profile=$(DUNE_PROFILE) graphql_schema.json
219+
ulimit -s 65532 && (ulimit -n 10240 || true) && $(DUNE) build --profile=$(DUNE_PROFILE) graphql_schema.json
216220

217221
########################################
218222
## Lint
219223

220224
reformat: ocaml_checks git_hooks
221-
dune exec --profile=$(DUNE_PROFILE) src/app/reformat/reformat.exe -- -path .
225+
$(DUNE) exec --profile=$(DUNE_PROFILE) src/app/reformat/reformat.exe -- -path .
222226

223227
reformat-diff:
224228
@ocamlformat --doc-comments=before --inplace $(shell git status -s | cut -c 4- | grep '\.mli\?$$' | while IFS= read -r f; do stat "$$f" >/dev/null 2>&1 && echo "$$f"; done) || true
225229

226230
check-format: ocaml_checks
227-
dune exec --profile=$(DUNE_PROFILE) src/app/reformat/reformat.exe -- -path . -check
231+
$(DUNE) exec --profile=$(DUNE_PROFILE) src/app/reformat/reformat.exe -- -path . -check
228232

229233
check-snarky-submodule:
230234
./scripts/check-snarky-submodule.sh
@@ -255,12 +259,12 @@ deb_optimized:
255259

256260
build_pv_keys: ocaml_checks
257261
$(info Building keys)
258-
ulimit -s 65532 && (ulimit -n 10240 || true) && env MINA_COMMIT_SHA1=$(GITLONGHASH) dune exec --profile=$(DUNE_PROFILE) src/lib/snark_keys/gen_keys/gen_keys.exe -- --generate-keys-only
262+
ulimit -s 65532 && (ulimit -n 10240 || true) && env MINA_COMMIT_SHA1=$(GITLONGHASH) $(DUNE) exec --profile=$(DUNE_PROFILE) src/lib/snark_keys/gen_keys/gen_keys.exe -- --generate-keys-only
259263
$(info Keys built)
260264

261265
build_or_download_pv_keys: ocaml_checks
262266
$(info Building keys)
263-
ulimit -s 65532 && (ulimit -n 10240 || true) && env MINA_COMMIT_SHA1=$(GITLONGHASH) dune exec --profile=$(DUNE_PROFILE) src/lib/snark_keys/gen_keys/gen_keys.exe -- --generate-keys-only
267+
ulimit -s 65532 && (ulimit -n 10240 || true) && env MINA_COMMIT_SHA1=$(GITLONGHASH) $(DUNE) exec --profile=$(DUNE_PROFILE) src/lib/snark_keys/gen_keys/gen_keys.exe -- --generate-keys-only
264268
$(info Keys built)
265269

266270
publish_deb:
@@ -293,7 +297,7 @@ web:
293297
## Benchmarks
294298

295299
benchmarks: ocaml_checks
296-
dune build src/app/benchmarks/main.exe
300+
$(DUNE) build src/app/benchmarks/main.exe
297301

298302
########################################
299303
# Coverage testing and output
@@ -341,7 +345,7 @@ doc_diagrams: $(addsuffix .png,$(wildcard $(doc_diagram_sources)))
341345
# Generate odoc documentation
342346

343347
ml-docs: ocaml_checks
344-
dune build --profile=$(DUNE_PROFILE) @doc
348+
$(DUNE) build --profile=$(DUNE_PROFILE) @doc
345349

346350
########################################
347351
# To avoid unintended conflicts with file names, always add new targets to .PHONY
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
(** This tool compares two opam.export files given as arguments (and is meant to be called via the [check_opam_switch.sh] script).
2+
It checks that the packages from the first one are installed in the second one (with the same version).*)
3+
4+
let error_message opam_export_filepath (print_error_message: unit -> unit)=
5+
Format.printf "Difference encountered while comparing the current opam switch and the %s file:\n" opam_export_filepath;
6+
print_error_message ();
7+
Format.printf "Current switch should be updated using 'opam switch import src/opam.export'\n";
8+
exit 1
9+
10+
let compare_packages opam_export_filepath installed_file installed_current =
11+
OpamPackage.Set.iter
12+
(fun p ->
13+
match OpamPackage.Set.find_opt ((=) p) installed_current with
14+
| Some _ -> ()
15+
| None ->
16+
error_message opam_export_filepath (fun () ->
17+
Format.printf "Could not find package %s in current switch\n" (OpamPackage.to_string p);
18+
)
19+
)
20+
installed_file
21+
22+
let check_overlays opam_export_filepath name (overlay_file:OpamFile.OPAM.t) (overlay_current: OpamFile.OPAM.t) =
23+
if overlay_file <> overlay_current then
24+
error_message opam_export_filepath (fun () ->
25+
Format.printf "Different overlays for package : %s\n" name;
26+
Format.printf "\nopam.export FILE:\n";
27+
Format.printf "-------------- BEGIN ----------------------\n";
28+
Format.printf "%s\n" (OpamFile.OPAM.write_to_string overlay_file);
29+
Format.printf "-------------- END ------------------------\n";
30+
Format.printf "\nCURRENT SWITCH:\n";
31+
Format.printf "-------------- BEGIN ----------------------\n";
32+
Format.printf "%s\n" (OpamFile.OPAM.write_to_string overlay_current);
33+
Format.printf "-------------- END ------------------------\n";
34+
)
35+
36+
let compare_overlays opam_export_filepath overlays_file overlays_current =
37+
OpamPackage.Name.Map.iter
38+
(fun name overlay_file ->
39+
match OpamPackage.Name.Map.find_opt name overlays_current with
40+
| None ->
41+
error_message opam_export_filepath (fun () ->
42+
Format.printf "Could not find overlay %s in current switch\n" (OpamPackage.Name.to_string name)
43+
)
44+
| Some overlay_current ->
45+
check_overlays opam_export_filepath (OpamPackage.Name.to_string name) overlay_file overlay_current
46+
)
47+
overlays_file
48+
49+
50+
let () =
51+
let opam_export_filepath = Sys.argv.(1) in
52+
let opam_export = OpamFilename.of_string opam_export_filepath
53+
|> OpamFile.make
54+
|> OpamFile.SwitchExport.read
55+
in
56+
let current = OpamFilename.of_string Sys.argv.(2)
57+
|> OpamFile.make
58+
|> OpamFile.SwitchExport.read
59+
in
60+
let () =
61+
compare_packages
62+
opam_export_filepath
63+
opam_export.selections.sel_installed
64+
current.selections.sel_installed
65+
in
66+
let () =
67+
compare_packages
68+
opam_export_filepath
69+
opam_export.selections.sel_compiler
70+
current.selections.sel_compiler
71+
in
72+
compare_overlays
73+
opam_export_filepath
74+
opam_export.overlays
75+
current.overlays
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
# This script checks that the ocaml packages specified in the
4+
# src/opam.export file are installed in the current switch.
5+
6+
set -e
7+
8+
CHECK_OPAM_DIR="$(dirname "$0")"
9+
10+
temp_file=$(mktemp /tmp/opam.export.XXXXXX)
11+
trap "rm -f $temp_file" 0 2 3 15
12+
13+
opam switch export "$temp_file"
14+
15+
pushd "$CHECK_OPAM_DIR"
16+
dune exec ./check_opam_switch.exe ../../src/opam.export "$temp_file"
17+
popd
18+

scripts/check_opam_switch/dune

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(executable
2+
(name check_opam_switch)
3+
(modes native)
4+
(libraries opam-format opam-file-format)
5+
(instrumentation (backend bisect_ppx))
6+
(preprocess (pps ppx_version)))

scripts/dune_wrapper

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
# This wrapper check that the current opam switch is consistent with the src/opam.export file before calling dune.
3+
"$(dirname "$0")/check_opam_switch/check_opam_switch.sh" && exec dune "$@"

src/opam.export

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ roots: [
2424
"ocamlgraph.1.8.8"
2525
"ocp-browser.1.3.3"
2626
"ocp-indent.1.7.0"
27+
"opam-file-format.2.1.4"
28+
"opam-format.2.1.2"
2729
"ppx_bitstring.4.1.0"
2830
"ppx_deriving.5.2.1"
2931
"ppx_deriving_yojson.3.6.1"
@@ -161,6 +163,8 @@ installed: [
161163
"octavius.1.2.2"
162164
"odoc-parser.1.0.0"
163165
"opam-depext.1.2.1"
166+
"opam-file-format.2.1.4"
167+
"opam-format.2.1.2"
164168
"parsexp.v0.14.2"
165169
"postgresql.5.0.0"
166170
"ppx_assert.v0.14.0"

0 commit comments

Comments
 (0)