From dd4be587be696abbac5c9027d1895320b56bb316 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Tue, 21 Dec 2021 22:43:29 +0100 Subject: [PATCH 1/3] Build: cleanup after dune 3.0 --- dune-project | 2 +- dune-workspace | 9 ++++++--- src/bin_client/dune | 4 ---- src/bin_codec/dune | 4 ---- src/bin_node/dune | 3 --- src/bin_proxy_server/dune | 3 --- src/bin_signer/dune | 4 ---- src/bin_snoop/dune | 3 --- src/bin_validation/bin/dune | 2 -- src/lib_protocol_compiler/bin/dune | 2 -- src/lib_protocol_compiler/dune | 3 +-- src/proto_008_PtEdo2Zk/parameters/dune | 2 +- src/proto_009_PsFLoren/parameters/dune | 2 +- src/proto_010_PtGRANAD/parameters/dune | 2 +- src/proto_011_PtHangz2/bin_accuser/dune | 6 ------ src/proto_011_PtHangz2/bin_baker/dune | 6 ------ src/proto_011_PtHangz2/bin_endorser/dune | 6 ------ src/proto_011_PtHangz2/parameters/dune | 2 +- src/proto_012_PsiThaCa/bin_accuser/dune | 6 ------ src/proto_012_PsiThaCa/bin_baker/dune | 6 ------ src/proto_012_PsiThaCa/parameters/dune | 2 +- src/proto_alpha/bin_accuser/dune | 6 ------ src/proto_alpha/bin_baker/dune | 6 ------ src/proto_alpha/parameters/dune | 2 +- 24 files changed, 14 insertions(+), 79 deletions(-) diff --git a/dune-project b/dune-project index bd3122e6c9f2..777758aa0a14 100644 --- a/dune-project +++ b/dune-project @@ -1,4 +1,4 @@ -(lang dune 2.9) +(lang dune 3.0) (formatting (enabled_for ocaml)) ; dune-project files are automatically generated by dune but they are kept diff --git a/dune-workspace b/dune-workspace index a04eac2ade62..33c6574bb7a0 100644 --- a/dune-workspace +++ b/dune-workspace @@ -1,6 +1,9 @@ -(lang dune 2.9) +(lang dune 3.0) (env - (static (ocamlopt_flags (:standard -O3))) - (release (ocamlopt_flags (:standard -O3))) + (static + (ocamlopt_flags (:standard -O3)) + (link_flags (:standard -ccopt -static))) + (release + (ocamlopt_flags (:standard -O3))) ) diff --git a/src/bin_client/dune b/src/bin_client/dune index b3f70c874088..4c58a6494d49 100644 --- a/src/bin_client/dune +++ b/src/bin_client/dune @@ -2,10 +2,6 @@ ; the alternative dependency mechanism of dune to implement optional ; dependencies. -(env - (static - (flags (:standard -ccopt -static)))) - (executables (names main_client main_admin) (public_names tezos-client tezos-admin-client) diff --git a/src/bin_codec/dune b/src/bin_codec/dune index 6dd8f266d59f..0225cd065b5a 100644 --- a/src/bin_codec/dune +++ b/src/bin_codec/dune @@ -1,7 +1,3 @@ -(env - (static - (flags (:standard -ccopt -static)))) - (executable (name codec) (public_name tezos-codec) diff --git a/src/bin_node/dune b/src/bin_node/dune index cd167568c56f..c920d46da3c5 100644 --- a/src/bin_node/dune +++ b/src/bin_node/dune @@ -7,9 +7,6 @@ ; and copy always the same (generated itself) empty file ; "void_for_linking". -(env - (static (flags (:standard -ccopt -static)))) - (executable (name main) (public_name tezos-node) diff --git a/src/bin_proxy_server/dune b/src/bin_proxy_server/dune index f1ab498d79e0..32b9c63b761c 100644 --- a/src/bin_proxy_server/dune +++ b/src/bin_proxy_server/dune @@ -2,9 +2,6 @@ ; the alternative dependency mechanism of dune to implement optional ; dependencies. -(env - (static (flags (:standard -ccopt -static)))) - (executable (name main_proxy_server) (public_name tezos-proxy-server) diff --git a/src/bin_signer/dune b/src/bin_signer/dune index a0a483a00d23..0279287fae4d 100644 --- a/src/bin_signer/dune +++ b/src/bin_signer/dune @@ -1,7 +1,3 @@ -(env - (static - (flags (:standard -ccopt -static)))) - (executable (name main_signer) (public_name tezos-signer) diff --git a/src/bin_snoop/dune b/src/bin_snoop/dune index f737757bb0ab..d6c927a2ae75 100644 --- a/src/bin_snoop/dune +++ b/src/bin_snoop/dune @@ -1,6 +1,3 @@ -(env - (static (flags (:standard -ccopt -static)))) - (executable (name main_snoop) (public_name tezos-snoop) diff --git a/src/bin_validation/bin/dune b/src/bin_validation/bin/dune index a009f02889ac..b4513b2dbcf9 100644 --- a/src/bin_validation/bin/dune +++ b/src/bin_validation/bin/dune @@ -1,5 +1,3 @@ -(env (static (flags (:standard -ccopt -static)))) - (executable (name main_validator) (public_name tezos-validator) diff --git a/src/lib_protocol_compiler/bin/dune b/src/lib_protocol_compiler/bin/dune index 3543c8535eb3..5e45fc73b5cb 100644 --- a/src/lib_protocol_compiler/bin/dune +++ b/src/lib_protocol_compiler/bin/dune @@ -1,5 +1,3 @@ -(env (static (flags (:standard -ccopt -static)))) - (executable (name main_native) (public_name tezos-protocol-compiler) diff --git a/src/lib_protocol_compiler/dune b/src/lib_protocol_compiler/dune index 881e2df6d87a..8538502bc9a0 100644 --- a/src/lib_protocol_compiler/dune +++ b/src/lib_protocol_compiler/dune @@ -1,4 +1,3 @@ - (library (name tezos_protocol_registerer) (public_name tezos-protocol-compiler.registerer) @@ -6,7 +5,7 @@ (libraries tezos-base tezos-protocol-environment-sigs) - (flags (:standard -opaque -open Tezos_base__TzPervasives )) + (flags (:standard -opaque -open Tezos_base__TzPervasives)) (modules Registerer)) (rule diff --git a/src/proto_008_PtEdo2Zk/parameters/dune b/src/proto_008_PtEdo2Zk/parameters/dune index f9a324da0bf8..ed909e037d66 100644 --- a/src/proto_008_PtEdo2Zk/parameters/dune +++ b/src/proto_008_PtEdo2Zk/parameters/dune @@ -1,4 +1,4 @@ (copy_files (alias copy-parameters) - (mode promote-until-clean) + (mode (promote (until-clean))) (files ../lib_parameters/*.json)) \ No newline at end of file diff --git a/src/proto_009_PsFLoren/parameters/dune b/src/proto_009_PsFLoren/parameters/dune index f9a324da0bf8..ed909e037d66 100644 --- a/src/proto_009_PsFLoren/parameters/dune +++ b/src/proto_009_PsFLoren/parameters/dune @@ -1,4 +1,4 @@ (copy_files (alias copy-parameters) - (mode promote-until-clean) + (mode (promote (until-clean))) (files ../lib_parameters/*.json)) \ No newline at end of file diff --git a/src/proto_010_PtGRANAD/parameters/dune b/src/proto_010_PtGRANAD/parameters/dune index f9a324da0bf8..ed909e037d66 100644 --- a/src/proto_010_PtGRANAD/parameters/dune +++ b/src/proto_010_PtGRANAD/parameters/dune @@ -1,4 +1,4 @@ (copy_files (alias copy-parameters) - (mode promote-until-clean) + (mode (promote (until-clean))) (files ../lib_parameters/*.json)) \ No newline at end of file diff --git a/src/proto_011_PtHangz2/bin_accuser/dune b/src/proto_011_PtHangz2/bin_accuser/dune index f4f72161b26f..4da07709ec31 100644 --- a/src/proto_011_PtHangz2/bin_accuser/dune +++ b/src/proto_011_PtHangz2/bin_accuser/dune @@ -1,9 +1,3 @@ -; build static executable with --profile static -(env - (static - (flags (:standard - -ccopt -static)))) - (executable (name main_accuser_011_PtHangz2) (instrumentation (backend bisect_ppx)) diff --git a/src/proto_011_PtHangz2/bin_baker/dune b/src/proto_011_PtHangz2/bin_baker/dune index cad6ae39df90..ab47c01e7136 100644 --- a/src/proto_011_PtHangz2/bin_baker/dune +++ b/src/proto_011_PtHangz2/bin_baker/dune @@ -1,9 +1,3 @@ -; build static executable with --profile static -(env - (static - (flags (:standard - -ccopt -static)))) - (executable (name main_baker_011_PtHangz2) (instrumentation (backend bisect_ppx)) diff --git a/src/proto_011_PtHangz2/bin_endorser/dune b/src/proto_011_PtHangz2/bin_endorser/dune index d4b3e36c3136..7322c53f61a9 100644 --- a/src/proto_011_PtHangz2/bin_endorser/dune +++ b/src/proto_011_PtHangz2/bin_endorser/dune @@ -1,9 +1,3 @@ -; build static executable with --profile static -(env - (static - (flags (:standard - -ccopt -static)))) - (executable (name main_endorser_011_PtHangz2) (instrumentation (backend bisect_ppx)) diff --git a/src/proto_011_PtHangz2/parameters/dune b/src/proto_011_PtHangz2/parameters/dune index f9a324da0bf8..ed909e037d66 100644 --- a/src/proto_011_PtHangz2/parameters/dune +++ b/src/proto_011_PtHangz2/parameters/dune @@ -1,4 +1,4 @@ (copy_files (alias copy-parameters) - (mode promote-until-clean) + (mode (promote (until-clean))) (files ../lib_parameters/*.json)) \ No newline at end of file diff --git a/src/proto_012_PsiThaCa/bin_accuser/dune b/src/proto_012_PsiThaCa/bin_accuser/dune index 2c93b1f051a2..d8905e15e6e0 100644 --- a/src/proto_012_PsiThaCa/bin_accuser/dune +++ b/src/proto_012_PsiThaCa/bin_accuser/dune @@ -1,9 +1,3 @@ -; build static executable with --profile static -(env - (static - (flags (:standard - -ccopt -static)))) - (executable (name main_accuser_012_PsiThaCa) (instrumentation (backend bisect_ppx)) diff --git a/src/proto_012_PsiThaCa/bin_baker/dune b/src/proto_012_PsiThaCa/bin_baker/dune index 9c8f57185f45..4a59e2f3e1b1 100644 --- a/src/proto_012_PsiThaCa/bin_baker/dune +++ b/src/proto_012_PsiThaCa/bin_baker/dune @@ -1,9 +1,3 @@ -; build static executable with --profile static -(env - (static - (flags (:standard - -ccopt -static)))) - (executable (name main_baker_012_PsiThaCa) (instrumentation (backend bisect_ppx)) diff --git a/src/proto_012_PsiThaCa/parameters/dune b/src/proto_012_PsiThaCa/parameters/dune index f9a324da0bf8..ed909e037d66 100644 --- a/src/proto_012_PsiThaCa/parameters/dune +++ b/src/proto_012_PsiThaCa/parameters/dune @@ -1,4 +1,4 @@ (copy_files (alias copy-parameters) - (mode promote-until-clean) + (mode (promote (until-clean))) (files ../lib_parameters/*.json)) \ No newline at end of file diff --git a/src/proto_alpha/bin_accuser/dune b/src/proto_alpha/bin_accuser/dune index fdccc1691e5e..3e2b9843d513 100644 --- a/src/proto_alpha/bin_accuser/dune +++ b/src/proto_alpha/bin_accuser/dune @@ -1,9 +1,3 @@ -; build static executable with --profile static -(env - (static - (flags (:standard - -ccopt -static)))) - (executable (name main_accuser_alpha) (instrumentation (backend bisect_ppx)) diff --git a/src/proto_alpha/bin_baker/dune b/src/proto_alpha/bin_baker/dune index 51b3365bf832..fa76e1ae0220 100644 --- a/src/proto_alpha/bin_baker/dune +++ b/src/proto_alpha/bin_baker/dune @@ -1,9 +1,3 @@ -; build static executable with --profile static -(env - (static - (flags (:standard - -ccopt -static)))) - (executable (name main_baker_alpha) (instrumentation (backend bisect_ppx)) diff --git a/src/proto_alpha/parameters/dune b/src/proto_alpha/parameters/dune index f9a324da0bf8..ed909e037d66 100644 --- a/src/proto_alpha/parameters/dune +++ b/src/proto_alpha/parameters/dune @@ -1,4 +1,4 @@ (copy_files (alias copy-parameters) - (mode promote-until-clean) + (mode (promote (until-clean))) (files ../lib_parameters/*.json)) \ No newline at end of file -- GitLab From 7fc19c7afa25b157314e044c222aa4507d34ac02 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Tue, 21 Dec 2021 23:00:22 +0100 Subject: [PATCH 2/3] Cleanup jsoo wrt dune --- dune-workspace | 11 +++++++++-- src/lib_error_monad/dune-project | 2 +- src/lib_error_monad/test/dune | 5 ----- src/lib_micheline/dune-project | 2 +- src/lib_micheline/test/dune | 10 ---------- src/lib_micheline/test/test_diff.ml | 2 +- src/lib_stdlib/dune-project | 2 +- src/lib_stdlib/test/dune | 30 ----------------------------- src/lib_test/dune-project | 2 +- 9 files changed, 14 insertions(+), 52 deletions(-) diff --git a/dune-workspace b/dune-workspace index 33c6574bb7a0..56e4536e73ac 100644 --- a/dune-workspace +++ b/dune-workspace @@ -3,7 +3,14 @@ (env (static (ocamlopt_flags (:standard -O3)) - (link_flags (:standard -ccopt -static))) + (link_flags (:standard -ccopt -static)) + (js_of_ocaml + (runtest_alias runtest_js))) (release - (ocamlopt_flags (:standard -O3))) + (ocamlopt_flags (:standard -O3)) + (js_of_ocaml + (runtest_alias runtest_js))) + (_ + (js_of_ocaml + (runtest_alias runtest_js))) ) diff --git a/src/lib_error_monad/dune-project b/src/lib_error_monad/dune-project index afdc7450b792..38969c1edda4 100644 --- a/src/lib_error_monad/dune-project +++ b/src/lib_error_monad/dune-project @@ -1,3 +1,3 @@ -(lang dune 2.9) +(lang dune 3.0) (formatting (enabled_for ocaml)) (name tezos-error-monad) diff --git a/src/lib_error_monad/test/dune b/src/lib_error_monad/test/dune index f7e1ac8c51a6..6f07988740cf 100644 --- a/src/lib_error_monad/test/dune +++ b/src/lib_error_monad/test/dune @@ -7,8 +7,3 @@ data-encoding alcotest) (flags (:standard -open Tezos_error_monad))) - -(rule - (alias runtest_js) - (package tezos-error-monad) - (action (run node %{dep:./test_registration.bc.js}))) diff --git a/src/lib_micheline/dune-project b/src/lib_micheline/dune-project index 9741b44e56d3..9034b8ef1171 100644 --- a/src/lib_micheline/dune-project +++ b/src/lib_micheline/dune-project @@ -1,3 +1,3 @@ -(lang dune 2.9) +(lang dune 3.0) (formatting (enabled_for ocaml)) (name tezos-micheline) diff --git a/src/lib_micheline/test/dune b/src/lib_micheline/test/dune index edf28f436aef..4a2bf9a2cdd5 100644 --- a/src/lib_micheline/test/dune +++ b/src/lib_micheline/test/dune @@ -17,13 +17,3 @@ (modes native js) (modules Test_diff) (flags (:standard -open Tezos_micheline))) - -(rule - (alias runtest_js) - (package tezos-micheline) - (action (run node %{dep:./test_parser.bc.js}))) - -(rule - (alias runtest_js) - (package tezos-micheline) - (action (run node %{dep:./test_diff.bc.js}))) diff --git a/src/lib_micheline/test/test_diff.ml b/src/lib_micheline/test/test_diff.ml index 39791b1965dd..2fd0d61e1df9 100644 --- a/src/lib_micheline/test/test_diff.ml +++ b/src/lib_micheline/test/test_diff.ml @@ -64,7 +64,7 @@ let int i = Int ((), Z.of_int i) let str s = String ((), s) -let bytes bs = Bytes ((), bs) +let _bytes bs = Bytes ((), bs) let prim ?(args = []) ?(annots = []) p = Prim ((), p, args, annots) diff --git a/src/lib_stdlib/dune-project b/src/lib_stdlib/dune-project index 90953e71deb3..14c7b4f4ed09 100644 --- a/src/lib_stdlib/dune-project +++ b/src/lib_stdlib/dune-project @@ -1,3 +1,3 @@ -(lang dune 2.9) +(lang dune 3.0) (formatting (enabled_for ocaml)) (name tezos-stdlib) diff --git a/src/lib_stdlib/test/dune b/src/lib_stdlib/test/dune index 498db102508b..673e160a8d59 100644 --- a/src/lib_stdlib/test/dune +++ b/src/lib_stdlib/test/dune @@ -15,33 +15,3 @@ tezos-test-helpers qcheck-alcotest) (flags (:standard -open Tezos_stdlib))) - -(rule - (alias runtest_js) - (package tezos-stdlib) - (action (run node %{dep:./test_bits.bc.js}))) - -(rule - (alias runtest_js) - (package tezos-stdlib) - (action (run node %{dep:./test_tzList.bc.js}))) - -(rule - (alias runtest_js) - (package tezos-stdlib) - (action (run node %{dep:./test_bounded_heap.bc.js}))) - -(rule - (alias runtest_js) - (package tezos-stdlib) - (action (run node %{dep:./test_tzString.bc.js}))) - -(rule - (alias runtest_js) - (package tezos-stdlib) - (action (run node %{dep:./test_fallbackArray.bc.js}))) - -(rule - (alias runtest_js) - (package tezos-stdlib) - (action (run node %{dep:./test_functionalArray.bc.js}))) diff --git a/src/lib_test/dune-project b/src/lib_test/dune-project index 3c4b238e0f12..65a6236d37cb 100644 --- a/src/lib_test/dune-project +++ b/src/lib_test/dune-project @@ -1,3 +1,3 @@ -(lang dune 2.9) +(lang dune 3.0) (formatting (enabled_for ocaml)) (name tezos-test-helpers) -- GitLab From 108fd5cde5c420f5fa4b5575cbab1e107b12902c Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Tue, 21 Dec 2021 23:37:48 +0100 Subject: [PATCH 3/3] remove workaround for inline_test wrt jsoo --- Makefile | 1 - docs/developer/javascript.rst | 27 +---- src/lib_micheline/dune | 2 +- src/lib_stdlib/dune | 2 +- src/tooling/dune | 7 -- src/tooling/run_js_inline_tests.ml | 168 ----------------------------- 6 files changed, 5 insertions(+), 202 deletions(-) delete mode 100644 src/tooling/run_js_inline_tests.ml diff --git a/Makefile b/Makefile index 5358bcf538eb..5c47f867f37f 100644 --- a/Makefile +++ b/Makefile @@ -174,7 +174,6 @@ test-flextesa: .PHONY: test-js test-js: @dune build @runtest_js - @dune exec ./src/tooling/run_js_inline_tests.exe .PHONY: test-tezt test-tezt-i test-tezt-c test-tezt-v test-tezt: diff --git a/docs/developer/javascript.rst b/docs/developer/javascript.rst index 9610310571ad..de0419c55762 100644 --- a/docs/developer/javascript.rst +++ b/docs/developer/javascript.rst @@ -35,31 +35,12 @@ commands to install ``nvm`` and ``node``: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash scripts/install_builld_deps.js.sh - -Limitation with inline_tests ----------------------------- - -``Inline_tests`` (e.g. ``ppx_inline_test``) are compatible with -``js_of_ocaml``, but we currently can't configure the alias under which -they run. - -Because we don't want to force a ``nodejs`` dependency on everybody, we -can't have JavaScript test run under the ``runtest`` alias by default. - -To workaround this limitation, running -``dune exec ./src/tooling/run_js_inline_tests.exe`` will temporarily -patch dune files and run ``dune runtest`` for you. - Running tests ------------- One can run JavaScript tests with ``make test-js`` in the project root or directly using dune with ``dune builld @SOME-PATH/runtest_js``. -In addition, to run inline_tests, execute -``dune exec ./src/tooling/run_js_inline_tests.exe`` or -``dune exec ./src/tooling/run_js_inline_tests.exe SOME_PATH``. - Adding tests ------------ @@ -87,20 +68,18 @@ alcotest tests in JavaScript: Inline tests ~~~~~~~~~~~~ -Inline tests (e.g. ``ppx_inline_test``) are compatible with jsoo but do -not run by default (see limitation above). +Inline tests (e.g. ``ppx_inline_test``) are compatible with jsoo. In order to run inline_tests in javascript: -- make sure to have both ``(js_of_ocaml)`` and ``(inline_tests)`` in your library stanza. -- run ``dune exec ./src/tooling/run_js_inline_tests.exe`` +- make sure to have ``(inline_tests (modes js))`` in your library stanza. :: (library (name mylib) (js_of_ocaml) - (inline_tests) + (inline_tests (modes native js)) ) JavaScript test failures diff --git a/src/lib_micheline/dune b/src/lib_micheline/dune index e14ce2900185..e51eb0ce8c2d 100644 --- a/src/lib_micheline/dune +++ b/src/lib_micheline/dune @@ -9,7 +9,7 @@ tezos-stdlib tezos-error-monad data-encoding) - (inline_tests) + (inline_tests (modes js native)) (preprocess (pps ppx_inline_test)) (js_of_ocaml) (flags diff --git a/src/lib_stdlib/dune b/src/lib_stdlib/dune index 22eb92bb69ec..05665be2e484 100644 --- a/src/lib_stdlib/dune +++ b/src/lib_stdlib/dune @@ -7,6 +7,6 @@ zarith zarith_stubs_js lwt) - (inline_tests) + (inline_tests (modes native js)) (preprocess (pps ppx_inline_test)) (js_of_ocaml)) diff --git a/src/tooling/dune b/src/tooling/dune index d99f2a0af588..ec412f4f4797 100644 --- a/src/tooling/dune +++ b/src/tooling/dune @@ -9,13 +9,6 @@ (section libexec) (files (lint.sh as lint.sh))) -(executable - (name run_js_inline_tests) - (libraries - parsexp - unix) - (modules run_js_inline_tests)) - (executable (name node_wrapper) (libraries unix) diff --git a/src/tooling/run_js_inline_tests.ml b/src/tooling/run_js_inline_tests.ml deleted file mode 100644 index fe567acc2970..000000000000 --- a/src/tooling/run_js_inline_tests.ml +++ /dev/null @@ -1,168 +0,0 @@ -module Sexp = Sexplib0.Sexp - -let () = Sys.catch_break true - -let read_file file = - let ic = open_in_bin file in - let len = in_channel_length ic in - let content = really_input_string ic len in - close_in ic ; - content - -let write_file file ~content = - let oc = open_out_bin file in - output_string oc content ; - close_out oc - -let rec find_dune_files root acc = - let dune = Filename.concat root "dune" in - let acc = - try if Sys.file_exists dune then dune :: acc else acc with _ -> acc - in - let files = Array.to_list (Sys.readdir root) in - List.fold_left - (fun acc file -> - match file.[0] with - | '.' | '_' -> acc - | _ -> ( - let fullname = Filename.concat root file in - try - if Sys.is_directory fullname then find_dune_files fullname acc - else acc - with _ -> acc)) - acc - files - -let parse_file file = Parsexp.Many.parse_string_exn (read_file file) - -let has_inline_tests fields = - List.exists - (function Sexp.List (Sexp.Atom "inline_tests" :: _) -> true | _ -> false) - fields - -let has_jsoo fields = - List.exists - (function Sexp.List (Sexp.Atom "js_of_ocaml" :: _) -> true | _ -> false) - fields - -let add_inline_tests_mode_js fields = - List.map - (function - | Sexp.List (Sexp.Atom "inline_tests" :: p) -> - Sexp.List - (Sexp.Atom "inline_tests" - :: - Sexp.List [Sexp.Atom "modes"; Sexp.Atom "js"] - :: - List.filter - (function - | Sexp.List (Sexp.Atom "modes" :: _) -> false | _ -> true) - p) - | x -> x) - fields - -let patch_inline_tests_for_js (l : Sexp.t list) : Sexp.t list option = - let found = ref false in - let l = - List.map - (function - | Sexp.List (Sexp.Atom "library" :: fields) as x -> - if has_inline_tests fields && has_jsoo fields then ( - found := true ; - Sexp.List (Sexp.Atom "library" :: add_inline_tests_mode_js fields)) - else x - | x -> x) - l - in - if !found then Some l else None - -let restore l = - Printf.printf "\n" ; - List.iter - (fun (f, _, content) -> - Printf.printf "Restoring dune file: %s\n%!" f ; - write_file f ~content) - l - -let usage () = Printf.printf "%s [PATH1 [PATH2]]\n" Sys.executable_name - -let () = - let args = - match Array.to_list Sys.argv with [] | [_] -> ["./"] | _ :: l -> l - in - List.iter - (function - | "-help" | "--help" | "" -> - usage () ; - exit 0 - | x when x.[0] = '-' -> - usage () ; - exit 1 - | _ -> ()) - args ; - Printf.printf "Collect dune files\n" ; - let files = List.fold_left (fun acc x -> find_dune_files x acc) [] args in - let files = List.sort_uniq compare files in - let files = - List.filter_map - (fun filename -> - try - let dune = parse_file filename in - match patch_inline_tests_for_js dune with - | None -> None - | Some dune -> Some (filename, dune) - with _ -> - Printf.printf "Failed to parse %s, ignoring\n" filename ; - None) - files - in - (match files with - | [] -> - Printf.printf "nothing to run, exiting !\n" ; - exit 0 - | _ -> ()) ; - let files_with_backup = - List.map - (fun (filename, dune_patched) -> - (filename, dune_patched, read_file filename)) - files - in - at_exit (fun () -> restore files_with_backup) ; - List.iter - (fun (filename, dune_patched, backup) -> - let content = - String.concat "\n" (List.map Sexp.to_string_hum dune_patched) - in - let commented_backup = - String.split_on_char '\n' backup - |> List.map (fun x -> ";; " ^ x) - |> String.concat "\n" - in - let content = - Printf.sprintf - ";; TODO: REVERT CHANGES TO THIS FILE BEFORE COMMITING\n\ - ;; This dune file was temporarily modified by %s\n\ - ;; and will be restored once tests are done running.\n\n\ - %s\n\n\ - %s\n" - Sys.executable_name - content - commented_backup - in - Printf.printf "Patching %s\n%!" filename ; - write_file filename ~content) - files_with_backup ; - let cmd = - "dune build " - ^ String.concat - " " - (List.map - (fun (f, _) -> Printf.sprintf "@@%s/runtest" (Filename.dirname f)) - files) - in - Printf.printf "About to run: %s\n\n%!" cmd ; - flush_all () ; - match Unix.system cmd with - | WEXITED x -> exit x - | WSIGNALED _ -> exit 1 - | WSTOPPED _ -> exit 1 -- GitLab