From 6c04a4d21e31d5c4fbca371297d31ada78de600d Mon Sep 17 00:00:00 2001 From: Emilio Jesus Gallego Arias Date: Sat, 28 Sep 2024 14:45:16 +0200 Subject: [PATCH 1/3] [compiler] Print backtraces on `Failure` too. We keep the case as to not to disturbe the printing, but not sure it is worth it. --- compiler/bin-js_of_ocaml/js_of_ocaml.ml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/bin-js_of_ocaml/js_of_ocaml.ml b/compiler/bin-js_of_ocaml/js_of_ocaml.ml index 144543663c..a80b6ce41d 100644 --- a/compiler/bin-js_of_ocaml/js_of_ocaml.ml +++ b/compiler/bin-js_of_ocaml/js_of_ocaml.ml @@ -109,7 +109,9 @@ let () = comp; exit 1 | Failure s -> + let backtrace = Printexc.get_backtrace () in Format.eprintf "%s: Error: %s@." Sys.argv.(0) s; + prerr_string backtrace; exit 1 | exc -> let backtrace = Printexc.get_backtrace () in From 69bb02549979741831c50381656094ca4e598527 Mon Sep 17 00:00:00 2001 From: Emilio Jesus Gallego Arias Date: Sat, 28 Sep 2024 14:52:43 +0200 Subject: [PATCH 2/3] [compiler] [build-fs] Fix `target not set error` Regression from #1655 . Not sure if `Config.target` should be better handled as a parameter? --- compiler/bin-js_of_ocaml/build_fs.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/bin-js_of_ocaml/build_fs.ml b/compiler/bin-js_of_ocaml/build_fs.ml index 16ac22a23d..3d20db9454 100644 --- a/compiler/bin-js_of_ocaml/build_fs.ml +++ b/compiler/bin-js_of_ocaml/build_fs.ml @@ -61,6 +61,7 @@ function jsoo_create_file_extern(name,content){ } |} in + Config.set_target `JavaScript; let fragments = Linker.Fragment.parse_string code in Linker.load_fragments ~target_env:Isomorphic ~filename:"" fragments; Linker.check_deps (); From 10847ff43a1a6e8a38da74af4bd23b2a04c5dd08 Mon Sep 17 00:00:00 2001 From: Emilio Jesus Gallego Arias Date: Sat, 28 Sep 2024 18:00:11 +0200 Subject: [PATCH 3/3] [compiler] [build-fs] Test for #1694 --- compiler/tests-full/dune | 17 ++++++++++++++++ compiler/tests-full/file1 | 1 + compiler/tests-full/file2 | 1 + compiler/tests-full/fs.expected.js | 31 ++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 compiler/tests-full/file1 create mode 100644 compiler/tests-full/file2 create mode 100644 compiler/tests-full/fs.expected.js diff --git a/compiler/tests-full/dune b/compiler/tests-full/dune index 802b8da1db..5effacad3b 100644 --- a/compiler/tests-full/dune +++ b/compiler/tests-full/dune @@ -26,3 +26,20 @@ (= %{ocaml_version} "5.2.0")) (action (diff stdlib.cma.expected.js stdlib.cma.output.js))) + +(rule + (targets fs.output.js) + (deps file1 file2) + (action + (run + %{bin:js_of_ocaml} + build-fs + -o + %{targets} + file1:/static/file1 + file2:/static/dir/file2))) + +(rule + (alias runtest) + (action + (diff fs.expected.js fs.output.js))) diff --git a/compiler/tests-full/file1 b/compiler/tests-full/file1 new file mode 100644 index 0000000000..28bf5b1fb9 --- /dev/null +++ b/compiler/tests-full/file1 @@ -0,0 +1 @@ +This is file 1 \ No newline at end of file diff --git a/compiler/tests-full/file2 b/compiler/tests-full/file2 new file mode 100644 index 0000000000..4419d52b7a --- /dev/null +++ b/compiler/tests-full/file2 @@ -0,0 +1 @@ +This is file 2 \ No newline at end of file diff --git a/compiler/tests-full/fs.expected.js b/compiler/tests-full/fs.expected.js new file mode 100644 index 0000000000..82bf5656ea --- /dev/null +++ b/compiler/tests-full/fs.expected.js @@ -0,0 +1,31 @@ +(function(a){ + typeof globalThis !== "object" + && + (this + ? b() + : (a.defineProperty + (a.prototype, "_T_", {configurable: true, get: b}), + _T_)); + function b(){ + var b = this || self; + b.globalThis = b; + delete a.prototype._T_; + } + } + (Object)); +(function(c){ + "use strict"; + function a(a, b){ + if(c.jsoo_create_file) + c.jsoo_create_file(a, b); + else{ + if(! c.caml_fs_tmp) c.caml_fs_tmp = []; + c.caml_fs_tmp.push({name: a, content: b}); + } + return 0; + } + a("/static/file1", "This is file 1"); + a("/static/dir/file2", "This is file 2"); + return; + } + (globalThis));