2016-12-02 13:54:32 +00:00
|
|
|
open Import
|
|
|
|
|
2016-12-15 11:20:46 +00:00
|
|
|
module Internal = struct
|
|
|
|
type t = Path.t * Jbuild_types.Library.t
|
|
|
|
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-03-01 15:03:09 +00:00
|
|
|
| Internal (_, lib) ->
|
|
|
|
match lib.public with
|
|
|
|
| Some p -> p.name
|
|
|
|
| None -> lib.name
|
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)
|
2016-12-15 11:20:46 +00:00
|
|
|
(*
|
2016-12-02 13:54:32 +00:00
|
|
|
let deps = function
|
|
|
|
| Internal (_, lib) -> lib.libraries
|
|
|
|
| External pkg -> pkg.requires
|
2016-12-15 11:20:46 +00:00
|
|
|
*)
|
2016-12-02 13:54:32 +00:00
|
|
|
let dir = function
|
|
|
|
| Internal (dir, _) -> dir
|
|
|
|
| External pkg -> pkg.dir
|
|
|
|
|
2016-12-31 13:26:29 +00:00
|
|
|
let header_files ts =
|
|
|
|
List.fold_left ts ~init:[] ~f:(fun acc t ->
|
|
|
|
match t with
|
|
|
|
| External _ -> []
|
|
|
|
| Internal (dir, lib) ->
|
2017-01-19 13:19:13 +00:00
|
|
|
match lib.install_c_headers with
|
2016-12-31 13:26:29 +00:00
|
|
|
| [] -> acc
|
|
|
|
| l ->
|
|
|
|
List.fold_left l ~init:acc ~f:(fun acc fn ->
|
|
|
|
Path.relative dir (fn ^ ".h") :: acc))
|
|
|
|
|
2017-02-02 10:31:36 +00:00
|
|
|
let include_paths ts =
|
|
|
|
List.fold_left ts ~init:Path.Set.empty ~f:(fun acc t ->
|
|
|
|
Path.Set.add (dir t) acc)
|
|
|
|
|
2016-12-02 13:54:32 +00:00
|
|
|
let include_flags ts =
|
2017-02-02 10:31:36 +00:00
|
|
|
let dirs = include_paths ts 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]))
|
|
|
|
|
2016-12-15 11:20:46 +00:00
|
|
|
let has_headers = function
|
2017-01-19 13:19:13 +00:00
|
|
|
| Internal (_, lib) -> lib.install_c_headers <> []
|
2016-12-15 11:20:46 +00:00
|
|
|
| External pkg -> pkg.has_headers
|
|
|
|
|
|
|
|
let c_include_flags ts =
|
|
|
|
let dirs =
|
|
|
|
List.fold_left ts ~init:Path.Set.empty ~f:(fun acc t ->
|
|
|
|
if has_headers t then
|
|
|
|
Path.Set.add (dir t) acc
|
|
|
|
else
|
|
|
|
acc)
|
|
|
|
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
|
|
|
|
|
|
|
|
let link_flags ts ~mode =
|
|
|
|
Arg_spec.S
|
|
|
|
(include_flags ts ::
|
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-02-26 21:28:30 +00:00
|
|
|
Arg_spec.Deps_rel (pkg.dir, Mode.Dict.get pkg.archives mode)
|
2016-12-02 13:54:32 +00:00
|
|
|
| Internal (dir, lib) ->
|
|
|
|
Dep_rel (dir, lib.name ^ Mode.compiled_lib_ext mode)))
|
|
|
|
|
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 ->
|
|
|
|
List.map (Mode.Dict.get pkg.archives mode) ~f:(Path.relative pkg.dir)
|
|
|
|
| Internal (dir, lib) ->
|
2016-12-31 13:26:29 +00:00
|
|
|
let l =
|
|
|
|
[Path.relative dir (lib.name ^ Mode.compiled_lib_ext mode)]
|
|
|
|
in
|
|
|
|
if Jbuild_types.Library.has_stubs lib then
|
|
|
|
Jbuild_types.Library.stubs_archive lib ~dir ~ext_lib :: l
|
|
|
|
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 []
|
|
|
|
;;
|