Use the full path of archives when linking (#197)

Instead of passing `-I <path> file.cma` to the compiler, pass `-I
<path> <path>/file.cma`.

Fixes #118 and #177. Using the fill path should also be slightly
faster as the compiler won't have to do the lookup through all include
paths. The only drawback is that it makes linking command line
slightly longer.
This commit is contained in:
Jérémie Dimino 2017-07-25 14:08:39 +01:00 committed by GitHub
parent a75e5c4c31
commit c7e67d49b8
8 changed files with 21 additions and 30 deletions

View File

@ -4,6 +4,10 @@
- Fix the quoting of `FLG` lines in generated `.merlin` files (#200, - Fix the quoting of `FLG` lines in generated `.merlin` files (#200,
Marcello Seri) Marcello Seri)
- Use the full path of archive files when linking. Before jbuilder
would do: `-I <path> file.cmxa`, now it does `-I <path>
<path>/file.cmxa`. Fixes #118 and #177
1.0+beta11 (21/07/2017) 1.0+beta11 (21/07/2017)
----------------------- -----------------------

View File

@ -8,8 +8,6 @@ type 'a t =
| S of 'a t list | S of 'a t list
| Dep of Path.t | Dep of Path.t
| Deps of Path.t list | Deps of Path.t list
| Dep_rel of Path.t * string
| Deps_rel of Path.t * string list
| Target of Path.t | Target of Path.t
| Path of Path.t | Path of Path.t
| Paths of Path.t list | Paths of Path.t list
@ -20,10 +18,6 @@ let rec add_deps ts set =
match t with match t with
| Dep fn -> Pset.add fn set | Dep fn -> Pset.add fn set
| Deps fns -> Pset.union set (Pset.of_list fns) | Deps fns -> Pset.union set (Pset.of_list fns)
| Dep_rel (dir, fn) -> Pset.add (Path.relative dir fn) set
| Deps_rel (dir, fns) ->
List.fold_left fns ~init:set ~f:(fun set fn ->
Pset.add (Path.relative dir fn) set)
| S ts -> add_deps ts set | S ts -> add_deps ts set
| _ -> set) | _ -> set)
@ -40,12 +34,6 @@ let expand ~dir ts x =
let rec loop_dyn : nothing t -> string list = function let rec loop_dyn : nothing t -> string list = function
| A s -> [s] | A s -> [s]
| As l -> l | As l -> l
| Dep_rel (dir, fn) ->
add_dep (Path.relative dir fn);
[fn]
| Deps_rel (dir, fns) ->
List.iter fns ~f:(fun fn -> add_dep (Path.relative dir fn));
fns
| Dep fn -> | Dep fn ->
add_dep fn; add_dep fn;
[Path.reach fn ~from:dir] [Path.reach fn ~from:dir]
@ -63,8 +51,6 @@ let expand ~dir ts x =
let rec loop = function let rec loop = function
| A s -> [s] | A s -> [s]
| As l -> l | As l -> l
| Dep_rel (_, fn) -> [fn]
| Deps_rel (_, fns) -> fns
| (Dep fn | Path fn) -> [Path.reach fn ~from:dir] | (Dep fn | Path fn) -> [Path.reach fn ~from:dir]
| (Deps fns | Paths fns) -> List.map fns ~f:(Path.reach ~from:dir) | (Deps fns | Paths fns) -> List.map fns ~f:(Path.reach ~from:dir)
| S ts -> List.concat_map ts ~f:loop | S ts -> List.concat_map ts ~f:loop

View File

@ -6,8 +6,6 @@ type 'a t =
| S of 'a t list | S of 'a t list
| Dep of Path.t (** A path that is a dependency *) | Dep of Path.t (** A path that is a dependency *)
| Deps of Path.t list | Deps of Path.t list
| Dep_rel of Path.t * string
| Deps_rel of Path.t * string list
| Target of Path.t | Target of Path.t
| Path of Path.t | Path of Path.t
| Paths of Path.t list | Paths of Path.t list

View File

@ -123,8 +123,8 @@ type package =
; dir : Path.t ; dir : Path.t
; version : string ; version : string
; description : string ; description : string
; archives : string list Mode.Dict.t ; archives : Path.t list Mode.Dict.t
; plugins : string list Mode.Dict.t ; plugins : Path.t list Mode.Dict.t
; jsoo_runtime : string list ; jsoo_runtime : string list
; requires : package list ; requires : package list
; ppx_runtime_deps : package list ; ppx_runtime_deps : package list
@ -238,7 +238,8 @@ let parse_package t ~name ~parent_dir ~vars ~required_by =
in in
let archives var preds = let archives var preds =
Mode.Dict.of_func (fun ~mode -> Mode.Dict.of_func (fun ~mode ->
Vars.get_words vars var (Mode.findlib_predicate mode :: preds)) List.map (Vars.get_words vars var (Mode.findlib_predicate mode :: preds))
~f:(Path.relative dir))
in in
let jsoo_runtime = Vars.get_words vars "jsoo_runtime" [] in let jsoo_runtime = Vars.get_words vars "jsoo_runtime" [] in
let preds = ["ppx_driver"; "mt"; "mt_posix"] in let preds = ["ppx_driver"; "mt"; "mt_posix"] in
@ -557,7 +558,8 @@ let all_unavailable_packages t =
let stdlib_with_archives t = let stdlib_with_archives t =
let x = find_exn t ~required_by:[] "stdlib" in let x = find_exn t ~required_by:[] "stdlib" in
let archives = let archives =
{ Mode.Dict.byte = "stdlib.cma" :: x.archives.byte { Mode.Dict.byte = Path.relative x.dir "stdlib.cma" :: x.archives.byte
; Mode.Dict.native = "stdlib.cmxa" :: x.archives.native } ; Mode.Dict.native = Path.relative x.dir "stdlib.cmxa" :: x.archives.native
}
in in
{ x with archives } { x with archives }

View File

@ -50,8 +50,8 @@ type package =
; dir : Path.t ; dir : Path.t
; version : string ; version : string
; description : string ; description : string
; archives : string list Mode.Dict.t ; archives : Path.t list Mode.Dict.t
; plugins : string list Mode.Dict.t ; plugins : Path.t list Mode.Dict.t
; jsoo_runtime : string list ; jsoo_runtime : string list
; requires : package list ; requires : package list
; ppx_runtime_deps : package list ; ppx_runtime_deps : package list

View File

@ -123,7 +123,7 @@ end
List.concat List.concat
[ [ "-I"; "+compiler-libs" ] [ [ "-I"; "+compiler-libs" ]
; includes ; includes
; cmas ; List.map cmas ~f:(Path.reach ~from:dir)
; [ Path.reach ~from:dir wrapper ] ; [ Path.reach ~from:dir wrapper ]
] ]
in in

View File

@ -69,8 +69,8 @@ let link_rule ~sctx ~dir ~runtime ~target =
let all_libs = let all_libs =
List.concat_map (stdlib :: libs) ~f:(function List.concat_map (stdlib :: libs) ~f:(function
| Lib.External pkg -> | Lib.External pkg ->
List.map (Mode.Dict.get pkg.archives Mode.Byte) ~f:(fun name -> List.map (Mode.Dict.get pkg.archives Mode.Byte) ~f:(fun fn ->
in_build_dir ~ctx [pkg.name; sprintf "%s.js" name]) in_build_dir ~ctx [pkg.name; sprintf "%s.js" (Path.basename fn)])
| Lib.Internal (dir, lib) -> | Lib.Internal (dir, lib) ->
[ Path.relative dir (sprintf "%s.cma.js" lib.name) ] [ Path.relative dir (sprintf "%s.cma.js" lib.name) ]
) )
@ -120,7 +120,8 @@ let setup_separate_compilation_rules sctx =
in in
List.concat_map all_pkg List.concat_map all_pkg
~f:(fun (pkg_name,pkg_dir,archives) -> ~f:(fun (pkg_name,pkg_dir,archives) ->
List.map archives ~f:(fun name -> List.map archives ~f:(fun fn ->
let name = Path.basename fn in
let src = Path.relative pkg_dir name in let src = Path.relative pkg_dir name in
let target = in_build_dir ~ctx [ pkg_name; sprintf "%s.js" name] in let target = in_build_dir ~ctx [ pkg_name; sprintf "%s.js" name] in
let dir = in_build_dir ~ctx [ pkg_name ] in let dir = in_build_dir ~ctx [ pkg_name ] in

View File

@ -58,14 +58,14 @@ let link_flags ts ~mode =
List.map ts ~f:(fun t -> List.map ts ~f:(fun t ->
match t with match t with
| External pkg -> | External pkg ->
Arg_spec.Deps_rel (pkg.dir, Mode.Dict.get pkg.archives mode) Arg_spec.Deps (Mode.Dict.get pkg.archives mode)
| Internal (dir, lib) -> | Internal (dir, lib) ->
Dep_rel (dir, lib.name ^ Mode.compiled_lib_ext mode))) Dep (Path.relative dir (lib.name ^ Mode.compiled_lib_ext mode))))
let archive_files ts ~mode ~ext_lib = let archive_files ts ~mode ~ext_lib =
List.concat_map ts ~f:(function List.concat_map ts ~f:(function
| External pkg -> | External pkg ->
List.map (Mode.Dict.get pkg.archives mode) ~f:(Path.relative pkg.dir) Mode.Dict.get pkg.archives mode
| Internal (dir, lib) -> | Internal (dir, lib) ->
let l = let l =
[Path.relative dir (lib.name ^ Mode.compiled_lib_ext mode)] [Path.relative dir (lib.name ^ Mode.compiled_lib_ext mode)]