From f15d0953b76f8e63afb0f5fac11ad22a9373c1ab Mon Sep 17 00:00:00 2001 From: Ali Caglayan Date: Sat, 28 Sep 2024 21:04:50 +0100 Subject: [PATCH 1/7] reproduce bug in #10674 with empty .opam version field Signed-off-by: Ali Caglayan --- .../package-version-empty.t/dune-project | 1 + .../package-version-empty.t/foo.opam | 2 + .../test-cases/package-version-empty.t/run.t | 50 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 test/blackbox-tests/test-cases/package-version-empty.t/dune-project create mode 100644 test/blackbox-tests/test-cases/package-version-empty.t/foo.opam create mode 100644 test/blackbox-tests/test-cases/package-version-empty.t/run.t diff --git a/test/blackbox-tests/test-cases/package-version-empty.t/dune-project b/test/blackbox-tests/test-cases/package-version-empty.t/dune-project new file mode 100644 index 00000000000..ddef0c5dd50 --- /dev/null +++ b/test/blackbox-tests/test-cases/package-version-empty.t/dune-project @@ -0,0 +1 @@ +(lang dune 3.16) diff --git a/test/blackbox-tests/test-cases/package-version-empty.t/foo.opam b/test/blackbox-tests/test-cases/package-version-empty.t/foo.opam new file mode 100644 index 00000000000..19f54b31342 --- /dev/null +++ b/test/blackbox-tests/test-cases/package-version-empty.t/foo.opam @@ -0,0 +1,2 @@ +opam-version: "2.0" +version: "" diff --git a/test/blackbox-tests/test-cases/package-version-empty.t/run.t b/test/blackbox-tests/test-cases/package-version-empty.t/run.t new file mode 100644 index 00000000000..966189bfba9 --- /dev/null +++ b/test/blackbox-tests/test-cases/package-version-empty.t/run.t @@ -0,0 +1,50 @@ +Testing dune #10674 where an empty version in an opam file caused a code error +in dune. We should make sure that this case is handled gracefully. + + $ dune build + Internal error, please report upstream including the contents of _build/log. + Description: + ("Invalid Package_version.t", { s = "" }) + Raised at Stdune__Code_error.raise in file + "otherlibs/stdune/src/code_error.ml", line 10, characters 30-62 + Called from Stdune__Option.O.(>>|) in file "otherlibs/stdune/src/option.ml", + line 9, characters 21-26 + Called from Dune_pkg__Opam_file.load_opam_file_with_contents in file + "src/dune_pkg/opam_file.ml" (inlined), line 273, characters 35-74 + Called from Dune_pkg__Opam_file.load_opam_file_with_contents in file + "src/dune_pkg/opam_file.ml", line 273, characters 13-75 + Called from Fiber__Core.O.(>>|).(fun) in file "vendor/fiber/src/core.ml", + line 253, characters 36-41 + Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml", + line 76, characters 8-11 + Re-raised at Stdune__Exn.raise_with_backtrace in file + "otherlibs/stdune/src/exn.ml", line 38, characters 27-56 + Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml", + line 76, characters 8-11 + Re-raised at Stdune__Exn.raise_with_backtrace in file + "otherlibs/stdune/src/exn.ml", line 38, characters 27-56 + Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml", + line 76, characters 8-11 + Re-raised at Stdune__Exn.raise_with_backtrace in file + "otherlibs/stdune/src/exn.ml", line 38, characters 27-56 + Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml", + line 76, characters 8-11 + Re-raised at Stdune__Exn.raise_with_backtrace in file + "otherlibs/stdune/src/exn.ml", line 38, characters 27-56 + Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml", + line 76, characters 8-11 + Re-raised at Stdune__Exn.raise_with_backtrace in file + "otherlibs/stdune/src/exn.ml", line 38, characters 27-56 + Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml", + line 76, characters 8-11 + -> required by ("find-dir-raw", In_source_tree ".") + -> required by ("dune_load", ()) + -> required by ("Super_context.all", ()) + -> required by ("toplevel", ()) + + I must not crash. Uncertainty is the mind-killer. Exceptions are the + little-death that brings total obliteration. I will fully express my cases. + Execution will pass over me and through me. And when it has gone past, I + will unwind the stack along its path. Where the cases are handled there will + be nothing. Only I will remain. + [1] From 3729396651000de2962c6554f958e4cf68622dab Mon Sep 17 00:00:00 2001 From: Ali Caglayan Date: Sat, 28 Sep 2024 21:25:59 +0100 Subject: [PATCH 2/7] fix #10674 Signed-off-by: Ali Caglayan --- src/dune_lang/package_version.mli | 1 + src/dune_pkg/opam_file.ml | 20 +++++--- src/dune_pkg/package_version.mli | 1 + .../test-cases/package-version-empty.t/run.t | 49 ++----------------- 4 files changed, 19 insertions(+), 52 deletions(-) diff --git a/src/dune_lang/package_version.mli b/src/dune_lang/package_version.mli index 186931ed2a0..31c51d13cbb 100644 --- a/src/dune_lang/package_version.mli +++ b/src/dune_lang/package_version.mli @@ -4,6 +4,7 @@ type t val of_string : string -> t val of_string_opt : string -> t option +val of_string_user_error : Loc.t * string -> (t, User_message.t) result val to_string : t -> string val equal : t -> t -> bool val to_dyn : t -> Dyn.t diff --git a/src/dune_pkg/opam_file.ml b/src/dune_pkg/opam_file.ml index cec17d64e9c..c28ec969749 100644 --- a/src/dune_pkg/opam_file.ml +++ b/src/dune_pkg/opam_file.ml @@ -57,13 +57,15 @@ let parse = let parse_value = parse_gen OpamBaseParser.value -let get_field t name = +let get_field_with_pos t name = List.find_map t.file_contents ~f:(fun value -> match value.pelem with - | Variable (var, value) when var.pelem = name -> Some value + | Variable (var, value) when var.pelem = name -> Some (value, var.pos) | _ -> None) ;; +let get_field t name = get_field_with_pos t name |> Option.map ~f:fst + let absolutify_positions ~file_contents t = let bols = ref [ 0 ] in String.iteri file_contents ~f:(fun i ch -> if ch = '\n' then bols := (i + 1) :: !bols); @@ -225,15 +227,16 @@ let load_opam_file_with_contents ~contents:opam_file_string file name = None in let open Option.O in - let get_one name = - let* value = + let get_one_with_loc name = + let* value, pos = let* opam = opam in - get_field opam name + get_field_with_pos opam name in match value.pelem with - | String s -> Some s + | String s -> Some (loc_of_opam_pos pos, s) | _ -> None in + let get_one name = get_one_with_loc name >>| snd in let get_many name = let* value = let* opam = opam in @@ -270,7 +273,10 @@ let load_opam_file_with_contents ~contents:opam_file_string file name = ~name ~dir ~loc - ~version:(get_one "version" |> Option.map ~f:Package_version.of_string) + ~version: + (get_one_with_loc "version" + |> Option.map ~f:Package_version.of_string_user_error + >>| User_error.ok_exn) ~conflicts:[] ~depends:[] ~depopts:[] diff --git a/src/dune_pkg/package_version.mli b/src/dune_pkg/package_version.mli index 723bdafaf3a..a95cf9fbf3d 100644 --- a/src/dune_pkg/package_version.mli +++ b/src/dune_pkg/package_version.mli @@ -3,6 +3,7 @@ open! Stdune type t = Dune_lang.Package_version.t val of_string : string -> t +val of_string_user_error : Loc.t * string -> (t, User_message.t) result val to_string : t -> string val equal : t -> t -> bool val to_dyn : t -> Dyn.t diff --git a/test/blackbox-tests/test-cases/package-version-empty.t/run.t b/test/blackbox-tests/test-cases/package-version-empty.t/run.t index 966189bfba9..c0df696fbdd 100644 --- a/test/blackbox-tests/test-cases/package-version-empty.t/run.t +++ b/test/blackbox-tests/test-cases/package-version-empty.t/run.t @@ -2,49 +2,8 @@ Testing dune #10674 where an empty version in an opam file caused a code error in dune. We should make sure that this case is handled gracefully. $ dune build - Internal error, please report upstream including the contents of _build/log. - Description: - ("Invalid Package_version.t", { s = "" }) - Raised at Stdune__Code_error.raise in file - "otherlibs/stdune/src/code_error.ml", line 10, characters 30-62 - Called from Stdune__Option.O.(>>|) in file "otherlibs/stdune/src/option.ml", - line 9, characters 21-26 - Called from Dune_pkg__Opam_file.load_opam_file_with_contents in file - "src/dune_pkg/opam_file.ml" (inlined), line 273, characters 35-74 - Called from Dune_pkg__Opam_file.load_opam_file_with_contents in file - "src/dune_pkg/opam_file.ml", line 273, characters 13-75 - Called from Fiber__Core.O.(>>|).(fun) in file "vendor/fiber/src/core.ml", - line 253, characters 36-41 - Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml", - line 76, characters 8-11 - Re-raised at Stdune__Exn.raise_with_backtrace in file - "otherlibs/stdune/src/exn.ml", line 38, characters 27-56 - Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml", - line 76, characters 8-11 - Re-raised at Stdune__Exn.raise_with_backtrace in file - "otherlibs/stdune/src/exn.ml", line 38, characters 27-56 - Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml", - line 76, characters 8-11 - Re-raised at Stdune__Exn.raise_with_backtrace in file - "otherlibs/stdune/src/exn.ml", line 38, characters 27-56 - Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml", - line 76, characters 8-11 - Re-raised at Stdune__Exn.raise_with_backtrace in file - "otherlibs/stdune/src/exn.ml", line 38, characters 27-56 - Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml", - line 76, characters 8-11 - Re-raised at Stdune__Exn.raise_with_backtrace in file - "otherlibs/stdune/src/exn.ml", line 38, characters 27-56 - Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml", - line 76, characters 8-11 - -> required by ("find-dir-raw", In_source_tree ".") - -> required by ("dune_load", ()) - -> required by ("Super_context.all", ()) - -> required by ("toplevel", ()) - - I must not crash. Uncertainty is the mind-killer. Exceptions are the - little-death that brings total obliteration. I will fully express my cases. - Execution will pass over me and through me. And when it has gone past, I - will unwind the stack along its path. Where the cases are handled there will - be nothing. Only I will remain. + File "foo.opam", line 2, characters 0-7: + 2 | version: "" + ^^^^^^^ + Error: "" is an invalid package version. [1] From c26080287e21b250ba5f06db0e89d9f7c23e880a Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sat, 28 Sep 2024 22:42:53 +0100 Subject: [PATCH 3/7] test: add missing dep to fswatch_win tests (#10966) Signed-off-by: Rudi Grinberg --- test/unit-tests/fswatch_win/dune | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit-tests/fswatch_win/dune b/test/unit-tests/fswatch_win/dune index 28fdea3af73..247fce6d959 100644 --- a/test/unit-tests/fswatch_win/dune +++ b/test/unit-tests/fswatch_win/dune @@ -1,6 +1,6 @@ (executable (name fswatch_win_tests) - (libraries fswatch_win stdune)) + (libraries fswatch_win unix stdune)) (rule (alias fswatch_win_tests) From 71db2d47fad82865c8035ef3553e0136cb08e337 Mon Sep 17 00:00:00 2001 From: hhugo Date: Sat, 28 Sep 2024 23:51:21 +0200 Subject: [PATCH 4/7] Pass the linkall flag to jsoo in whole program compilation as well (#10935) Signed-off-by: Hugo Heuzard --- doc/changes/10935.md | 1 + src/dune_rules/jsoo/jsoo_rules.ml | 20 +++++++++++++++++-- .../test-cases/jsoo/inline-tests.t/run.t | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 doc/changes/10935.md diff --git a/doc/changes/10935.md b/doc/changes/10935.md new file mode 100644 index 00000000000..d6b1a2bf0f8 --- /dev/null +++ b/doc/changes/10935.md @@ -0,0 +1 @@ +- Forward the linkall flag to jsoo in whole program compilation as well (#10935, @hhugo) \ No newline at end of file diff --git a/src/dune_rules/jsoo/jsoo_rules.ml b/src/dune_rules/jsoo/jsoo_rules.ml index 52f7941c75f..148479f7c78 100644 --- a/src/dune_rules/jsoo/jsoo_rules.ml +++ b/src/dune_rules/jsoo/jsoo_rules.ml @@ -291,10 +291,25 @@ let standalone_runtime_rule cc ~javascript_files ~target ~flags = ~config:(Some config) ;; -let exe_rule cc ~javascript_files ~src ~target ~flags = +let exe_rule cc ~linkall ~javascript_files ~src ~target ~flags = let dir = Compilation_context.dir cc in let sctx = Compilation_context.super_context cc in let libs = Compilation_context.requires_link cc in + let linkall = + let open Action_builder.O in + let+ linkall = linkall + and+ jsoo_version = + let* jsoo = jsoo ~dir sctx in + Action_builder.of_memo @@ Version.jsoo_version jsoo + in + Command.Args.As + (match jsoo_version, linkall with + | Some version, true -> + (match Version.compare version (5, 1) with + | Lt -> [] + | Gt | Eq -> [ "--linkall" ]) + | None, _ | _, false -> []) + in let spec = Command.Args.S [ Resolve.Memo.args @@ -303,6 +318,7 @@ let exe_rule cc ~javascript_files ~src ~target ~flags = Command.Args.Deps (jsoo_runtime_files libs)) ; Deps (List.map ~f:Path.build javascript_files) ; Dep (Path.build src) + ; Dyn linkall ] in js_of_ocaml_rule sctx ~sub_command:Compile ~dir ~spec ~target ~flags ~config:None @@ -549,7 +565,7 @@ let build_exe in () | Whole_program -> - exe_rule cc ~javascript_files ~src ~target ~flags ~sourcemap + exe_rule cc ~linkall ~javascript_files ~src ~target ~flags ~sourcemap |> Super_context.add_rule sctx ~loc ~dir ~mode ;; diff --git a/test/blackbox-tests/test-cases/jsoo/inline-tests.t/run.t b/test/blackbox-tests/test-cases/jsoo/inline-tests.t/run.t index fba35fdc48e..87386212671 100644 --- a/test/blackbox-tests/test-cases/jsoo/inline-tests.t/run.t +++ b/test/blackbox-tests/test-cases/jsoo/inline-tests.t/run.t @@ -16,6 +16,7 @@ Run inline tests using node js inline tests (JS) $ dune runtest --profile release + Warning: your program contains effect handlers; you should probably run js_of_ocaml with option '--enable=effects' inline tests (JS) inline tests (JS) inline tests (Native) From cc415a0615af2a7da6ef3f36100f5be50c49098c Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 29 Sep 2024 13:40:12 +0100 Subject: [PATCH 5/7] test: add more missing unix deps (#10967) Signed-off-by: Rudi Grinberg --- bench/micro/dune | 2 +- test/expect-tests/dune_file_watcher/dune | 1 + test/expect-tests/fsevents/dune | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/bench/micro/dune b/bench/micro/dune index f19e6da16ec..e66f2bb7369 100644 --- a/bench/micro/dune +++ b/bench/micro/dune @@ -29,7 +29,7 @@ (library_flags -linkall) (preprocess (pps ppx_bench)) - (libraries dune_thread_pool threads.posix core_bench.inline_benchmarks)) + (libraries dune_thread_pool unix threads.posix core_bench.inline_benchmarks)) (executable (name thread_pool_bench_main) diff --git a/test/expect-tests/dune_file_watcher/dune b/test/expect-tests/dune_file_watcher/dune index 47e7b7d3b5c..4971217ff88 100644 --- a/test/expect-tests/dune_file_watcher/dune +++ b/test/expect-tests/dune_file_watcher/dune @@ -14,6 +14,7 @@ (deps (sandbox always))) (libraries + unix dune_file_watcher dune_file_watcher_tests_lib ppx_expect.config diff --git a/test/expect-tests/fsevents/dune b/test/expect-tests/fsevents/dune index 27a004e9d93..00dcee57295 100644 --- a/test/expect-tests/fsevents/dune +++ b/test/expect-tests/fsevents/dune @@ -8,6 +8,7 @@ (deps (sandbox always))) (libraries + unix fsevents stdune threads.posix From 1861618e5577e20a073a20a73ed7f6436ffc5fcc Mon Sep 17 00:00:00 2001 From: Ali Caglayan Date: Sun, 29 Sep 2024 19:39:53 +0100 Subject: [PATCH 6/7] update nixpkgs in flake (#10969) Signed-off-by: Ali Caglayan --- flake.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index f9a4467cee6..00b118912a5 100644 --- a/flake.lock +++ b/flake.lock @@ -121,11 +121,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1726142289, - "narHash": "sha256-Jks8O42La+nm5AMTSq/PvM5O+fUAhIy0Ce1QYqLkyZ4=", + "lastModified": 1727524699, + "narHash": "sha256-k6YxGj08voz9NvuKExojiGXAVd69M8COtqWSKr6sQS4=", "owner": "nixos", "repo": "nixpkgs", - "rev": "280db3decab4cbeb22a4599bd472229ab74d25e1", + "rev": "b5b2fecd0cadd82ef107c9583018f381ae70f222", "type": "github" }, "original": { From 9f3cda70d29982105171e1435bf4caafce07866d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 29 Sep 2024 20:18:32 +0100 Subject: [PATCH 7/7] fix(stdune): ignore warning 53 for now (#10972) Signed-off-by: Rudi Grinberg --- otherlibs/stdune/src/stdune.ml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/otherlibs/stdune/src/stdune.ml b/otherlibs/stdune/src/stdune.ml index 37f7e7cdf26..1ea7da7ef61 100644 --- a/otherlibs/stdune/src/stdune.ml +++ b/otherlibs/stdune/src/stdune.ml @@ -1,5 +1,11 @@ -[@@@alert unstable "The API of this library is not stable and may change without notice."] -[@@@alert "-unstable"] +include struct + [@@@ocaml.warning "-53"] + + [@@@alert + unstable "The API of this library is not stable and may change without notice."] + + [@@@alert "-unstable"] +end module Appendable_list = Appendable_list module Nonempty_list = Nonempty_list