Skip to content

Commit a25c878

Browse files
committed
Driver: Slightly nicer pkg_args
1 parent 1ce6755 commit a25c878

File tree

4 files changed

+93
-84
lines changed

4 files changed

+93
-84
lines changed

src/driver/compile.ml

+5-7
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ let link : compiled list -> _ =
214214
let link : compiled -> linked =
215215
fun c ->
216216
let link input_file output_file =
217-
let { Odoc_unit.libs; pages; _ } = c.pkg_args in
217+
let libs = Odoc_unit.Pkg_args.compiled_libs c.pkg_args in
218+
let pages = Odoc_unit.Pkg_args.compiled_pages c.pkg_args in
218219
let includes = c.include_dirs in
219220
Odoc.link ~input_file ~output_file ~includes ~libs ~docs:pages
220221
~current_package:c.pkgname ()
@@ -251,13 +252,10 @@ let html_generate ~occurrence_file output_dir linked =
251252
let compile_index : Odoc_unit.index -> _ =
252253
fun index ->
253254
let compile_index_one
254-
({
255-
pkg_args = { pages_linked; libs_linked; _ };
256-
output_file;
257-
json;
258-
search_dir = _;
259-
} as index :
255+
({ pkg_args; output_file; json; search_dir = _ } as index :
260256
Odoc_unit.index) =
257+
let libs_linked = Odoc_unit.Pkg_args.linked_libs pkg_args in
258+
let pages_linked = Odoc_unit.Pkg_args.linked_pages pkg_args in
261259
let () =
262260
Odoc.compile_index ~json ~occurrence_file ~output_file ~libs:libs_linked
263261
~docs:pages_linked ()

src/driver/landing_pages.ml

+12-14
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ open Odoc_unit
33

44
let fpf = Format.fprintf
55

6-
let make_rel dir l = List.map (fun (x, y) -> (x, Fpath.(dir // y))) l
7-
86
let make_unit ~odoc_dir ~odocl_dir ~mld_dir ~output_dir rel_path ~content
97
?(include_dirs = Fpath.Set.empty) ~pkgname ~pkg_args () =
108
let input_file = Fpath.(mld_dir // rel_path / "index.mld") in
@@ -45,10 +43,10 @@ module PackageLanding = struct
4543
let pages_rel = [ (pkg.name, rel_path) ] in
4644
let pkg_args =
4745
{
48-
pages = make_rel output_dir pages_rel;
46+
Pkg_args.pages = pages_rel;
4947
libs = [];
50-
pages_linked = make_rel odocl_dir pages_rel;
51-
libs_linked = [];
48+
compile_dir = output_dir;
49+
link_dir = odocl_dir;
5250
}
5351
in
5452
make_unit ~odoc_dir ~odocl_dir ~mld_dir ~output_dir rel_path ~content
@@ -73,10 +71,10 @@ module PackageList = struct
7371
let pages_rel = [ (pkgname, rel_path) ] in
7472
let pkg_args =
7573
{
76-
pages = make_rel odoc_dir pages_rel;
74+
Pkg_args.pages = pages_rel;
7775
libs = [];
78-
pages_linked = make_rel odocl_dir pages_rel;
79-
libs_linked = [];
76+
compile_dir = output_dir;
77+
link_dir = odocl_dir;
8078
}
8179
in
8280
make_unit ~odoc_dir ~odocl_dir ~mld_dir ~output_dir ~content ~pkgname
@@ -97,10 +95,10 @@ module LibraryLanding = struct
9795
let pages_rel = [ (pkg.name, rel_path) ] in
9896
let pkg_args =
9997
{
100-
pages = make_rel odoc_dir pages_rel;
98+
Pkg_args.pages = pages_rel;
10199
libs = [];
102-
pages_linked = make_rel odocl_dir pages_rel;
103-
libs_linked = [];
100+
link_dir = odocl_dir;
101+
compile_dir = output_dir;
104102
}
105103
in
106104
let include_dirs = Fpath.Set.singleton Fpath.(odoc_dir // rel_path) in
@@ -122,10 +120,10 @@ module PackageLibLanding = struct
122120
let pages_rel = [ (pkg.name, rel_path) ] in
123121
let pkg_args =
124122
{
125-
pages = make_rel odoc_dir pages_rel;
123+
Pkg_args.pages = pages_rel;
126124
libs = [];
127-
pages_linked = make_rel odocl_dir pages_rel;
128-
libs_linked = [];
125+
compile_dir = output_dir;
126+
link_dir = odocl_dir;
129127
}
130128
in
131129
make_unit ~odoc_dir ~odocl_dir ~mld_dir ~output_dir rel_path ~content

src/driver/odoc_unit.ml

+57-55
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,43 @@
1-
type pkg_args = {
2-
pages : (string * Fpath.t) list;
3-
libs : (string * Fpath.t) list;
4-
pages_linked : (string * Fpath.t) list;
5-
libs_linked : (string * Fpath.t) list;
6-
}
1+
module Pkg_args = struct
2+
type t = {
3+
compile_dir : Fpath.t;
4+
link_dir : Fpath.t;
5+
pages : (string * Fpath.t) list;
6+
libs : (string * Fpath.t) list;
7+
}
78

8-
let pp_pkg_args fmt x =
9-
let sfp_pp =
10-
Fmt.(
11-
list ~sep:comma (fun fmt (a, b) ->
12-
Format.fprintf fmt "(%s, %a)" a Fpath.pp b))
13-
in
14-
Format.fprintf fmt "@[<hov>pages: [%a]@;libs: [%a]@]" sfp_pp x.pages sfp_pp
15-
x.libs
9+
let map_rel dir = List.map (fun (a, b) -> (a, Fpath.(dir // b)))
10+
11+
let compiled_pages v = map_rel v.compile_dir v.pages
12+
let compiled_libs v = map_rel v.compile_dir v.libs
13+
let linked_pages v = map_rel v.link_dir v.pages
14+
let linked_libs v = map_rel v.link_dir v.libs
15+
16+
let combine v1 v2 =
17+
if v1.compile_dir <> v2.compile_dir then
18+
Fmt.invalid_arg "combine: compile_dir differs";
19+
if v1.link_dir <> v2.link_dir then
20+
Fmt.invalid_arg "combine: link_dir differs";
21+
{
22+
compile_dir = v1.compile_dir;
23+
link_dir = v1.link_dir;
24+
pages = v1.pages @ v2.pages;
25+
libs = v1.libs @ v2.libs;
26+
}
27+
28+
let pp fmt x =
29+
let sfp_pp =
30+
Fmt.(
31+
list ~sep:comma (fun fmt (a, b) ->
32+
Format.fprintf fmt "(%s, %a)" a Fpath.pp b))
33+
in
34+
Format.fprintf fmt
35+
"@[<hov>compile_dir: %a@;link_dir: %a@;pages: [%a]@;libs: [%a]@]" Fpath.pp
36+
x.compile_dir Fpath.pp x.link_dir sfp_pp x.pages sfp_pp x.libs
37+
end
1638

1739
type index = {
18-
pkg_args : pkg_args;
40+
pkg_args : Pkg_args.t;
1941
output_file : Fpath.t;
2042
json : bool;
2143
search_dir : Fpath.t;
@@ -24,7 +46,7 @@ type index = {
2446
let pp_index fmt x =
2547
Format.fprintf fmt
2648
"@[<hov>pkg_args: %a@;output_file: %a@;json: %b@;search_dir: %a@]"
27-
pp_pkg_args x.pkg_args Fpath.pp x.output_file x.json Fpath.pp x.search_dir
49+
Pkg_args.pp x.pkg_args Fpath.pp x.output_file x.json Fpath.pp x.search_dir
2850

2951
type 'a unit = {
3052
parent_id : Odoc.Id.t;
@@ -33,7 +55,7 @@ type 'a unit = {
3355
output_dir : Fpath.t;
3456
odoc_file : Fpath.t;
3557
odocl_file : Fpath.t;
36-
pkg_args : pkg_args;
58+
pkg_args : Pkg_args.t;
3759
pkgname : string;
3860
include_dirs : Fpath.Set.t;
3961
index : index option;
@@ -89,7 +111,7 @@ and pp : all_kinds unit Fmt.t =
89111
@]"
90112
(Odoc.Id.to_string x.parent_id)
91113
Fpath.pp x.odoc_dir Fpath.pp x.input_file Fpath.pp x.output_dir Fpath.pp
92-
x.odoc_file Fpath.pp x.odocl_file pp_pkg_args x.pkg_args x.pkgname
114+
x.odoc_file Fpath.pp x.odocl_file Pkg_args.pp x.pkg_args x.pkgname
93115
Fmt.(list ~sep:comma Fpath.pp)
94116
(Fpath.Set.to_list x.include_dirs)
95117
(Fmt.option pp_index) x.index pp_kind
@@ -143,17 +165,17 @@ let of_packages ~output_dir ~linked_dir ~index_dir ~extra_libs_paths
143165
[]
144166
in
145167
(* Given a pkg, *)
146-
let base_args pkg lib_deps : pkg_args =
168+
let base_args pkg lib_deps : Pkg_args.t =
147169
let own_page = dash_p pkg in
148170
let own_libs = List.concat_map dash_l (Util.StringSet.to_list lib_deps) in
149-
let map_rel dir = List.map (fun (a, b) -> (a, Fpath.(dir // b))) in
150-
let pages = map_rel output_dir [ own_page ] in
151-
let libs = map_rel output_dir own_libs in
152-
let pages_linked = map_rel linked_dir [ own_page ] in
153-
let libs_linked = map_rel linked_dir own_libs in
154-
{ pages; libs; pages_linked; libs_linked }
171+
{
172+
pages = [ own_page ];
173+
libs = own_libs;
174+
compile_dir = output_dir;
175+
link_dir = linked_dir;
176+
}
155177
in
156-
let args_of_config config : pkg_args =
178+
let args_of_config config : Pkg_args.t =
157179
let { Global_config.deps = { packages; libraries } } = config in
158180
let pages_rel =
159181
List.filter_map
@@ -164,42 +186,22 @@ let of_packages ~output_dir ~linked_dir ~index_dir ~extra_libs_paths
164186
packages
165187
in
166188
let libs_rel = List.concat_map dash_l libraries in
167-
let map_rel dir = List.map (fun (a, b) -> (a, Fpath.(dir // b))) in
168-
let pages = map_rel output_dir pages_rel in
169-
let libs = map_rel output_dir libs_rel in
170-
let pages_linked = map_rel linked_dir pages_rel in
171-
let libs_linked = map_rel linked_dir libs_rel in
172-
{ pages; libs; pages_linked; libs_linked }
189+
{
190+
pages = pages_rel;
191+
libs = libs_rel;
192+
compile_dir = output_dir;
193+
link_dir = linked_dir;
194+
}
173195
in
174196
let args_of =
175197
let cache = Hashtbl.create 10 in
176-
fun pkg lib_deps : pkg_args ->
198+
fun pkg lib_deps : Pkg_args.t ->
177199
match Hashtbl.find_opt cache (pkg, lib_deps) with
178200
| Some res -> res
179201
| None ->
180-
let {
181-
pages = own_page;
182-
libs = own_libs;
183-
pages_linked = own_p_l;
184-
libs_linked = own_l_l;
185-
} =
186-
base_args pkg lib_deps
187-
in
188-
let {
189-
pages = config_pages;
190-
libs = config_libs;
191-
pages_linked = cfg_p_l;
192-
libs_linked = cfg_l_l;
193-
} =
194-
args_of_config pkg.Packages.config
195-
in
196202
let result =
197-
{
198-
pages = own_page @ config_pages;
199-
libs = own_libs @ config_libs;
200-
pages_linked = own_p_l @ cfg_p_l;
201-
libs_linked = own_l_l @ cfg_l_l;
202-
}
203+
Pkg_args.combine (base_args pkg lib_deps)
204+
(args_of_config pkg.Packages.config)
203205
in
204206
Hashtbl.add cache (pkg, lib_deps) result;
205207
result

src/driver/odoc_unit.mli

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1-
type pkg_args = {
2-
pages : (string * Fpath.t) list;
3-
libs : (string * Fpath.t) list;
4-
pages_linked : (string * Fpath.t) list;
5-
libs_linked : (string * Fpath.t) list;
6-
}
1+
module Pkg_args : sig
2+
type t = {
3+
compile_dir : Fpath.t;
4+
link_dir : Fpath.t;
5+
pages : (string * Fpath.t) list;
6+
libs : (string * Fpath.t) list;
7+
}
8+
9+
val compiled_pages : t -> (string * Fpath.t) list
10+
val compiled_libs : t -> (string * Fpath.t) list
11+
val linked_pages : t -> (string * Fpath.t) list
12+
val linked_libs : t -> (string * Fpath.t) list
13+
14+
val combine : t -> t -> t
15+
16+
val pp : t Fmt.t
17+
end
718

819
type index = {
9-
pkg_args : pkg_args;
20+
pkg_args : Pkg_args.t;
1021
output_file : Fpath.t;
1122
json : bool;
1223
search_dir : Fpath.t;
@@ -19,7 +30,7 @@ type 'a unit = {
1930
output_dir : Fpath.t;
2031
odoc_file : Fpath.t;
2132
odocl_file : Fpath.t;
22-
pkg_args : pkg_args;
33+
pkg_args : Pkg_args.t;
2334
pkgname : string;
2435
include_dirs : Fpath.Set.t;
2536
index : index option;

0 commit comments

Comments
 (0)