| 1 |
(************************************************************************) |
| 2 |
(* * The Rocq Prover / The Rocq Development Team *) |
| 3 |
(* v * Copyright INRIA, CNRS and contributors *) |
| 4 |
(* <O___,, * (see version control and CREDITS file for authors & dates) *) |
| 5 |
(* \VV/ **************************************************************) |
| 6 |
(* // * This file is distributed under the terms of the *) |
| 7 |
(* * GNU Lesser General Public License Version 2.1 *) |
| 8 |
(* * (see LICENSE file for the text of the license) *) |
| 9 |
(************************************************************************) |
| 10 |
|
| 11 |
open File_util |
| 12 |
|
| 13 |
let coqc_predicates = ["native"] |
| 14 |
|
| 15 |
module Fl_internals = struct |
| 16 |
(** Functions not exported by findlib (XXX there is a copy in mltop, we should share them) *) |
| 17 |
|
| 18 |
(* Fl_split.in_words is not exported *) |
| 19 |
let fl_split_in_words s = |
| 20 |
(* splits s in words separated by commas and/or whitespace *) |
| 21 |
let l = String.length s in |
| 22 |
let rec split i j = |
| 23 |
if j < l then |
| 24 |
match s.[j] with |
| 25 |
| (' '|'\t'|'\n'|'\r'|',') -> |
| 26 |
if i<j then (String.sub s i (j-i)) :: (split (j+1) (j+1)) |
| 27 |
else split (j+1) (j+1) |
| 28 |
| _ -> |
| 29 |
split i (j+1) |
| 30 |
else |
| 31 |
if i<j then [ String.sub s i (j-i) ] else [] |
| 32 |
in |
| 33 |
split 0 0 |
| 34 |
|
| 35 |
(* simulate what fl_dynload does *) |
| 36 |
let fl_find_plugins lib = |
| 37 |
let base = Findlib.package_directory lib in |
| 38 |
let archive = try Findlib.package_property coqc_predicates lib "plugin" |
| 39 |
with Not_found -> |
| 40 |
try fst (Findlib.package_property_2 ("plugin"::coqc_predicates) lib "archive") |
| 41 |
with Not_found -> "" |
| 42 |
in |
| 43 |
fl_split_in_words archive |> List.map (Findlib.resolve_path ~base) |
| 44 |
|
| 45 |
(* first string is the v file which triggered the error, rest is Fl_package_base.No_such_package *) |
| 46 |
exception No_such_package of string * string * string |
| 47 |
|
| 48 |
let () = CErrors.register_handler Pp.(function |
| 49 |
| No_such_package(vfile,p,msg) -> |
| 50 |
let paths = Findlib.search_path () in |
| 51 |
Some (hov 0 (str "In file" ++ spc() ++ str vfile ++ spc() ++ |
| 52 |
str "findlib error: " ++ str p ++ str " not found in:" ++ cut () ++ |
| 53 |
v 0 (prlist_with_sep cut str paths) ++ fnl() ++ str msg)) |
| 54 |
| _ -> |
| 55 |
None |
| 56 |
) |
| 57 |
|
| 58 |
end |
| 59 |
|
| 60 |
let relative_if_dune path = |
| 61 |
(* relativize the path if inside the current dune workspace |
| 62 |
if we relativize paths outside the dune workspace it fails so make sure to avoid it *) |
| 63 |
match Sys.getenv_opt "DUNE_SOURCEROOT" with |
| 64 |
| Some dune when CString.is_prefix (Filename.concat dune "_build") path -> |
| 65 |
normalize_path (to_relative_path path) |
| 66 |
| _ -> normalize_path path |
| 67 |
|
| 68 |
let findlib_resolve ~package = |
| 69 |
let meta_file = Findlib.package_meta_file package in |
| 70 |
let cmxss = Fl_internals.fl_find_plugins package in |
| 71 |
let meta_file = relative_if_dune meta_file in |
| 72 |
let cmxs_file = List.map relative_if_dune cmxss in |
| 73 |
(meta_file, cmxs_file) |
| 74 |
|
| 75 |
let static_libs () = |
| 76 |
let packages = Findlib.package_deep_ancestors coqc_predicates ["rocq-runtime.toplevel"] in |
| 77 |
CString.Set.of_list packages |
| 78 |
|
| 79 |
let static_libs = Lazy.from_fun static_libs |
| 80 |
|
| 81 |
let findlib_deep_resolve ~package = |
| 82 |
let packages = Findlib.package_deep_ancestors coqc_predicates [package] in |
| 83 |
let packages = CList.filter (fun package -> |
| 84 |
not (CString.Set.mem package (Lazy.force static_libs))) |
| 85 |
packages |
| 86 |
in |
| 87 |
List.fold_left (fun (metas,cmxss) package -> |
| 88 |
let meta, cmxss' = findlib_resolve ~package in |
| 89 |
meta :: metas, cmxss' @ cmxss) |
| 90 |
([],[]) |
| 91 |
packages |
| 92 |
|
| 93 |
let findlib_deep_resolve ~file ~package = |
| 94 |
try findlib_deep_resolve ~package |
| 95 |
with Fl_package_base.No_such_package(p,m) -> |
| 96 |
raise (Fl_internals.No_such_package (file,p,m)) |
| 97 |
|
| 98 |
module Internal = struct |
| 99 |
let get_worker_path () = |
| 100 |
let top = "rocqworker" in |
| 101 |
let dir = Findlib.package_directory "rocq-runtime" in |
| 102 |
let exe = if Sys.(os_type = "Win32" || os_type = "Cygwin") then ".exe" else "" in |
| 103 |
let file = Filename.concat dir (top^exe) in |
| 104 |
relative_if_dune file |
| 105 |
end |