My aggregated monorepo of OCaml code, automaintained
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Replace jtw_container_script with jtw opam invocation in day10

- Add findlib_names_of_installed_libs to extract findlib package names
from installed_libs paths by finding directories containing META files
- Replace hand-rolled js_of_ocaml compile commands in jtw_container_script
with a single `jtw opam` call that handles .cmi copying, .cma -> .cma.js
compilation, dynamic_cmis.json, and findlib_index.json generation
- Delete unused jsoo_compile_command helper function

This eliminates code duplication between jtw.ml (opam mode) and
jtw_gen.ml (day10 mode), letting day10 reuse jtw opam's per-package
artifact generation logic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+26 -32
+26 -32
day10/bin/jtw_gen.ml
··· 1 - (** JTW generation logic: compile .cma to .cma.js, extract .cmi, META, 2 - generate dynamic_cmis.json, assemble universe output directories. *) 1 + (** JTW generation logic: prepare container scripts for jtw opam, 2 + assemble universe output directories with content-hashed paths. *) 3 3 4 4 (** Compute hash for a jtw layer. 5 5 Depends on the build hash and jtw-tools layer hash. *) ··· 115 115 let hash = Digest.to_hex (Digest.string (Buffer.contents buf)) in 116 116 String.sub hash 0 16 117 117 118 - (** The shell command to compile a .cma to .cma.js inside a container. 119 - Returns a command string suitable for bash -c. *) 120 - let jsoo_compile_command ~cma_path ~output_path ~js_stubs = 121 - let stubs = String.concat " " (List.map Filename.quote js_stubs) in 122 - Printf.sprintf "js_of_ocaml compile --toplevel --include-runtime --effects=disabled %s %s -o %s" 123 - stubs (Filename.quote cma_path) (Filename.quote output_path) 118 + (** Extract top-level findlib package names from installed lib file paths. 119 + Each path is relative to lib/ (e.g., "hmap/hmap.cmi", "hmap/META"). 120 + A findlib package is identified by the presence of a META file. 121 + Returns deduplicated, sorted list of findlib directory names containing META. *) 122 + let findlib_names_of_installed_libs installed_libs = 123 + List.filter_map (fun rel_path -> 124 + if Filename.basename rel_path = "META" then 125 + Some (Filename.dirname rel_path) 126 + else None 127 + ) installed_libs 128 + |> List.sort_uniq String.compare 124 129 125 130 (** Build the shell script to run inside the container for jtw generation. 126 - This compiles all .cma files found in the package's lib directory. *) 131 + Calls `jtw opam` to handle all per-package artifact generation: 132 + .cmi copying, .cma -> .cma.js compilation, dynamic_cmis.json, findlib_index.json. *) 127 133 let jtw_container_script ~pkg ~installed_libs = 128 134 let pkg_name = OpamPackage.name_to_string pkg in 129 - let lib_base = "/home/opam/.opam/default/lib" in 130 - (* Find .cma files from installed_libs *) 131 - let cma_files = List.filter (fun f -> Filename.check_suffix f ".cma") installed_libs in 132 - if cma_files = [] then 133 - (* No .cma files - just exit success, we'll still copy .cmi and META *) 135 + let findlib_names = findlib_names_of_installed_libs installed_libs in 136 + if findlib_names = [] then 134 137 "true" 135 - else begin 136 - let compile_cmds = List.map (fun cma_rel -> 137 - let cma_path = lib_base ^ "/" ^ cma_rel in 138 - let js_output = "/home/opam/jtw-output/lib/" ^ cma_rel ^ ".js" in 139 - let js_dir = Filename.dirname js_output in 140 - (* Look for jsoo runtime stubs in the same directory as the .cma *) 141 - let cma_dir = Filename.dirname cma_path in 142 - Printf.sprintf "mkdir -p %s && js_stubs=$(find %s -name '*.js' -not -name '*.cma.js' 2>/dev/null | sort | tr '\\n' ' ') && js_of_ocaml compile --toplevel --include-runtime --effects=disabled $js_stubs %s -o %s" 143 - (Filename.quote js_dir) (Filename.quote cma_dir) (Filename.quote cma_path) (Filename.quote js_output) 144 - ) cma_files in 145 - let script = String.concat " && " ( 146 - ["eval $(opam env)"; 147 - Printf.sprintf "echo 'JTW: Compiling %s (%d archives)'" pkg_name (List.length cma_files)] 148 - @ compile_cmds 149 - @ ["echo 'JTW: Done'"] 150 - ) in 151 - script 152 - end 138 + else 139 + let libs = String.concat " " (List.map Filename.quote findlib_names) in 140 + String.concat " && " [ 141 + "eval $(opam env)"; 142 + Printf.sprintf "echo 'JTW: Building %s via jtw opam (%d findlib packages)'" pkg_name (List.length findlib_names); 143 + Printf.sprintf "jtw opam --path %s --no-worker -o /home/opam/jtw-output %s" 144 + (Filename.quote pkg_name) libs; 145 + "echo 'JTW: Done'"; 146 + ] 153 147 154 148 (** Assemble the jtw output directory structure from completed jtw layers. 155 149