Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fl_dynload] Allow overriding low-level module loader #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/README.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ configuration files, and library routines in detail.</p>
<title>List of Changes</title>
<ul>

<li>
<p><em>1.9.7:</em>: Allow overriding low-level module loader
in `Fl_dynload.load_packages`. This is very useful in JSOO
where we may want to implement a `.cma` -> `.js` cache instead
of calling `Dynlink.loadfile` dynamically. (Emilio J. Gallego
Arias).</p>
</li>

<li>
<p><em>1.9.6:</em>: Support for OCaml-5 (as far as foreseeable)
(David Allsopp).</p>
Expand Down
10 changes: 5 additions & 5 deletions src/findlib/fl_dynload.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

open Printf

let load_pkg ~debug pkg =
let load_pkg ~debug ~loadfile pkg =
if not (Findlib.is_recorded_package pkg) then (
if debug then
eprintf "[DEBUG] Fl_dynload: about to load: %s\n%!" pkg;
Expand Down Expand Up @@ -34,12 +34,12 @@ let load_pkg ~debug pkg =
let files = Fl_split.in_words archive in
if debug then
eprintf "[DEBUG] Fl_dynload: files=%S\n%!" archive;
List.iter
List.iter
(fun file ->
if debug then
eprintf "[DEBUG] Fl_dynload: loading %S\n%!" file;
let file = Findlib.resolve_path ~base:d file in
Dynlink.loadfile file
loadfile file
) files;
Findlib.record_package Findlib.Record_load pkg
)
Expand All @@ -48,8 +48,8 @@ let load_pkg ~debug pkg =
eprintf "[DEBUG] Fl_dynload: not loading: %s\n%!" pkg


let load_packages ?(debug=false) pkgs =
let load_packages ?(debug=false) ?(loadfile=Dynlink.loadfile) pkgs =
let preds = Findlib.recorded_predicates() in
let eff_pkglist =
Findlib.package_deep_ancestors preds pkgs in
List.iter (load_pkg ~debug) eff_pkglist
List.iter (load_pkg ~debug ~loadfile) eff_pkglist
2 changes: 1 addition & 1 deletion src/findlib/fl_dynload.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

(** Utilities for loading dynamically packages *)

val load_packages : ?debug:bool -> string list -> unit
val load_packages : ?debug:bool -> ?loadfile:(string -> unit) -> string list -> unit
(** Load the given packages and all their dependencies dynamically. Packages
already loaded or already in-core are not loaded again. The predicates
are taken from {!Findlib.recorded_predicates}, which are normally the
Expand Down