2016-12-02 13:54:32 +00:00
|
|
|
open Import
|
|
|
|
|
2016-12-15 11:20:46 +00:00
|
|
|
module Internal = struct
|
2017-06-02 13:32:05 +00:00
|
|
|
type t = Path.t * Jbuild.Library.t
|
2016-12-15 11:20:46 +00:00
|
|
|
end
|
|
|
|
|
2016-12-02 13:54:32 +00:00
|
|
|
module T = struct
|
|
|
|
type t =
|
2016-12-15 11:20:46 +00:00
|
|
|
| Internal of Internal.t
|
2016-12-02 13:54:32 +00:00
|
|
|
| External of Findlib.package
|
|
|
|
|
|
|
|
let best_name = function
|
|
|
|
| External pkg -> pkg.name
|
2017-12-17 14:56:05 +00:00
|
|
|
| Internal (_, lib) -> Jbuild.Library.best_name lib
|
2016-12-02 13:54:32 +00:00
|
|
|
|
|
|
|
let compare a b = String.compare (best_name a) (best_name b)
|
|
|
|
end
|
|
|
|
|
|
|
|
include T
|
|
|
|
module Set = Set.Make(T)
|
2017-05-18 12:49:56 +00:00
|
|
|
|
2017-07-21 16:30:51 +00:00
|
|
|
let dir = function
|
|
|
|
| Internal (dir, _) -> dir
|
2016-12-02 13:54:32 +00:00
|
|
|
| External pkg -> pkg.dir
|
|
|
|
|
2018-02-06 11:49:44 +00:00
|
|
|
let include_paths ts ~stdlib_dir =
|
2017-02-02 10:31:36 +00:00
|
|
|
List.fold_left ts ~init:Path.Set.empty ~f:(fun acc t ->
|
2017-07-21 16:30:51 +00:00
|
|
|
Path.Set.add (dir t) acc)
|
2018-02-06 11:49:44 +00:00
|
|
|
|> Path.Set.remove stdlib_dir
|
2017-02-02 10:31:36 +00:00
|
|
|
|
2018-02-06 11:49:44 +00:00
|
|
|
let include_flags ts ~stdlib_dir =
|
|
|
|
let dirs = include_paths ts ~stdlib_dir in
|
2016-12-02 13:54:32 +00:00
|
|
|
Arg_spec.S (List.concat_map (Path.Set.elements dirs) ~f:(fun dir ->
|
|
|
|
[Arg_spec.A "-I"; Path dir]))
|
|
|
|
|
2017-07-21 16:30:51 +00:00
|
|
|
let c_include_flags ts =
|
2016-12-15 11:20:46 +00:00
|
|
|
let dirs =
|
|
|
|
List.fold_left ts ~init:Path.Set.empty ~f:(fun acc t ->
|
2017-07-21 16:30:51 +00:00
|
|
|
Path.Set.add (dir t) acc)
|
2016-12-15 11:20:46 +00:00
|
|
|
in
|
|
|
|
Arg_spec.S (List.concat_map (Path.Set.elements dirs) ~f:(fun dir ->
|
|
|
|
[Arg_spec.A "-I"; Path dir]))
|
|
|
|
|
2016-12-02 13:54:32 +00:00
|
|
|
let describe = function
|
|
|
|
| Internal (_, lib) ->
|
2017-03-01 15:03:09 +00:00
|
|
|
sprintf "%s (local)"
|
|
|
|
(match lib.public with
|
|
|
|
| Some p -> p.name
|
|
|
|
| None -> lib.name)
|
2016-12-02 13:54:32 +00:00
|
|
|
| External pkg ->
|
|
|
|
sprintf "%s (external)" pkg.name
|
|
|
|
|
2018-02-06 11:49:44 +00:00
|
|
|
let link_flags ts ~mode ~stdlib_dir =
|
2016-12-02 13:54:32 +00:00
|
|
|
Arg_spec.S
|
2018-02-06 11:49:44 +00:00
|
|
|
(include_flags ts ~stdlib_dir ::
|
2017-02-26 21:28:30 +00:00
|
|
|
List.map ts ~f:(fun t ->
|
2016-12-02 13:54:32 +00:00
|
|
|
match t with
|
|
|
|
| External pkg ->
|
2017-07-25 13:08:39 +00:00
|
|
|
Arg_spec.Deps (Mode.Dict.get pkg.archives mode)
|
2016-12-02 13:54:32 +00:00
|
|
|
| Internal (dir, lib) ->
|
2017-07-25 13:08:39 +00:00
|
|
|
Dep (Path.relative dir (lib.name ^ Mode.compiled_lib_ext mode))))
|
2016-12-02 13:54:32 +00:00
|
|
|
|
2016-12-31 13:26:29 +00:00
|
|
|
let archive_files ts ~mode ~ext_lib =
|
2016-12-02 13:54:32 +00:00
|
|
|
List.concat_map ts ~f:(function
|
|
|
|
| External pkg ->
|
2017-07-25 13:08:39 +00:00
|
|
|
Mode.Dict.get pkg.archives mode
|
2016-12-02 13:54:32 +00:00
|
|
|
| Internal (dir, lib) ->
|
2016-12-31 13:26:29 +00:00
|
|
|
let l =
|
|
|
|
[Path.relative dir (lib.name ^ Mode.compiled_lib_ext mode)]
|
|
|
|
in
|
2017-06-02 13:32:05 +00:00
|
|
|
if Jbuild.Library.has_stubs lib then
|
|
|
|
Jbuild.Library.stubs_archive lib ~dir ~ext_lib :: l
|
2016-12-31 13:26:29 +00:00
|
|
|
else
|
|
|
|
l)
|
2017-05-02 10:25:37 +00:00
|
|
|
|
|
|
|
let jsoo_runtime_files ts =
|
|
|
|
List.concat_map ts ~f:(function
|
|
|
|
| External pkg ->
|
|
|
|
List.map pkg.jsoo_runtime ~f:(Path.relative pkg.dir)
|
|
|
|
| Internal (dir, lib) ->
|
2017-05-02 12:30:58 +00:00
|
|
|
List.map lib.buildable.js_of_ocaml.javascript_files ~f:(Path.relative dir))
|
2016-12-15 11:20:46 +00:00
|
|
|
(*
|
2016-12-02 13:54:32 +00:00
|
|
|
let ppx_runtime_libraries ts =
|
|
|
|
List.fold_left ts ~init:String_set.empty ~f:(fun acc t ->
|
|
|
|
match t with
|
|
|
|
| Internal (_, lib) ->
|
|
|
|
String_set.union acc (String_set.of_list lib.ppx_runtime_libraries)
|
|
|
|
| External pkg ->
|
|
|
|
String_set.union acc (String_set.of_list pkg.ppx_runtime_deps))
|
2016-12-15 11:20:46 +00:00
|
|
|
*)
|
|
|
|
|
|
|
|
let remove_dups_preserve_order libs =
|
|
|
|
let rec loop seen libs acc =
|
|
|
|
match libs with
|
|
|
|
| [] -> List.rev acc
|
|
|
|
| lib :: libs ->
|
|
|
|
let name = best_name lib in
|
|
|
|
if String_set.mem name seen then
|
|
|
|
loop seen libs acc
|
|
|
|
else
|
|
|
|
loop (String_set.add name seen) libs (lib :: acc)
|
|
|
|
in
|
|
|
|
loop String_set.empty libs []
|
|
|
|
;;
|
2018-01-30 12:12:38 +00:00
|
|
|
|
|
|
|
let public_name = function
|
|
|
|
| External pkg -> Some pkg.name
|
|
|
|
| Internal (_, lib) -> Option.map lib.public ~f:(fun p -> p.name)
|