diff --git a/Makefile b/Makefile index 5358bcf538eb5c931f38ac58fd844a2cc4ab1d16..5c47f867f37fe3d53ed7b77acd129b84b5b23908 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 9610310571adf99e18aaf47849309f14523c60fe..de0419c557623618f8a4ee9cb3b65b47ae2fb22e 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/dune-project b/dune-project index bd3122e6c9f25bb757a68665adabe721142760cc..777758aa0a14503b1b757774534effe27759ff31 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 a04eac2ade62119f2966a78d0e1034c56232405e..56e4536e73ace7893573ccd897f45ca43d42bcfa 100644 --- a/dune-workspace +++ b/dune-workspace @@ -1,6 +1,16 @@ -(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)) + (js_of_ocaml + (runtest_alias runtest_js))) + (release + (ocamlopt_flags (:standard -O3)) + (js_of_ocaml + (runtest_alias runtest_js))) + (_ + (js_of_ocaml + (runtest_alias runtest_js))) ) diff --git a/src/bin_client/dune b/src/bin_client/dune index b3f70c874088ba0b37b85c9e65f9b17a86907630..4c58a6494d4923ecc67a9131bc809e46d254665a 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 6dd8f266d59f1081bf65f79df6d8e16c8028cf47..0225cd065b5a1d56d4fd3acc5b16df276321ecfd 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 cd167568c56f20e9254d5411faa8ffe6808cf11f..c920d46da3c5ba57e789da1241613226c31c70f1 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 f1ab498d79e0bf341e6c18953bb248382e77429d..32b9c63b761cfee36fc3e4c836e84c4793144110 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 a0a483a00d235c27fc02028c666aa84fddccef1f..0279287fae4d2b58320eaae0f9c7916206666528 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 f737757bb0aba4890bbecb606de56a3d16f8a5d3..d6c927a2ae756504764b04ae369e07d2535127c0 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 a009f02889ac80e379555252cc309e15c9aab42c..b4513b2dbcf9bb69c3e64d3c800543d145e673f7 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_error_monad/dune-project b/src/lib_error_monad/dune-project index afdc7450b7927a1dcc19814c5e5b8b68bfdfb663..38969c1edda4d47f1a3e375ee01769e22f38f097 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 f7e1ac8c51a672aa64a497bc47b56bcf643590a2..6f07988740cfed8d43c2b7ddc26a76753bec30d3 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 b/src/lib_micheline/dune index e14ce2900185a431bd40aea4399a5c93ef083c45..e51eb0ce8c2d4e10c0185fd50b9ced82df8cba8b 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_micheline/dune-project b/src/lib_micheline/dune-project index 9741b44e56d3069e43d17abbea86dae3c9febe1f..9034b8ef1171e5a6c3c85d418c7c7fbb6eab2834 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 edf28f436aef4693c5aa0e1618602d0b942e0463..4a2bf9a2cdd572a57ae29e7365827e43115ef770 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 39791b1965ddc4a6405fc4350bb532125d81ba86..2fd0d61e1df9ae479464c393ddc6d9cd3991ad19 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_protocol_compiler/bin/dune b/src/lib_protocol_compiler/bin/dune index 3543c8535eb3d5124c509fe427761df7d6b6f847..5e45fc73b5cb9ec5768908f023d3923491abc3fd 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 881e2df6d87a30db8cd0178aa3138dffadecb751..8538502bc9a0a4e9a9d78979a8be60adabd124e6 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/lib_stdlib/dune b/src/lib_stdlib/dune index 22eb92bb69ec78ca757abb35825815ebc6ceeb78..05665be2e4847b60883d61b9ba65121447b29552 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/lib_stdlib/dune-project b/src/lib_stdlib/dune-project index 90953e71deb35c28dd73792b62d9408f1c258b19..14c7b4f4ed092d2c64aba03821c6f5c3c15a8ef6 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 498db102508b7e9481a5821868a411e1a8a95fad..673e160a8d5988b9ced557e5909f16a9bd3a67ef 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 3c4b238e0f12bd2d64396731291a13ca3ea2de87..65a6236d37cbe9182b7d955f6c76e3a0f68c0bce 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) diff --git a/src/proto_008_PtEdo2Zk/parameters/dune b/src/proto_008_PtEdo2Zk/parameters/dune index f9a324da0bf80e418148a8238d6afc03516da3b5..ed909e037d6641cf8417f2e4c074eb4217c64bfb 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 f9a324da0bf80e418148a8238d6afc03516da3b5..ed909e037d6641cf8417f2e4c074eb4217c64bfb 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 f9a324da0bf80e418148a8238d6afc03516da3b5..ed909e037d6641cf8417f2e4c074eb4217c64bfb 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 f4f72161b26f4886ce1d92550e2f14d48b3ce4ec..4da07709ec31625b9d0de671164baf38f0e539c9 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 cad6ae39df90bb1523a71fb542ae2ec1a9528c0d..ab47c01e7136741a0b5ad1097cd66580f1d79588 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 d4b3e36c3136c8fde8f4f135c365b08739e943a6..7322c53f61a9adb89509cdf26549a4da53a444a8 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 f9a324da0bf80e418148a8238d6afc03516da3b5..ed909e037d6641cf8417f2e4c074eb4217c64bfb 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 2c93b1f051a20be652b947e0f9b96243b79358b8..d8905e15e6e0877a1396b4b7caff6a693e022a47 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 9c8f57185f45182450c88d463c978a3bae94ea73..4a59e2f3e1b12b720f7ed8aa58edbf0f960c83a8 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 f9a324da0bf80e418148a8238d6afc03516da3b5..ed909e037d6641cf8417f2e4c074eb4217c64bfb 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 fdccc1691e5ea4a09cb459bcba8312bf55c7e76d..3e2b9843d51350b057e7e6b9af0fe9232f339e73 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 51b3365bf832e37b8ca9ef180e547845e9998314..fa76e1ae0220df3955bdb8c8e487e9a8b6551a9b 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 f9a324da0bf80e418148a8238d6afc03516da3b5..ed909e037d6641cf8417f2e4c074eb4217c64bfb 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 diff --git a/src/tooling/dune b/src/tooling/dune index d99f2a0af58829ef9349a350f209dbde1dbb1874..ec412f4f479725ca6e66b1659ee34ab00eba39df 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 fe567acc297065f75ad69f315a488c6a77c542ac..0000000000000000000000000000000000000000 --- 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