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
+ }
7
8
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
16
38
17
39
type index = {
18
- pkg_args : pkg_args ;
40
+ pkg_args : Pkg_args .t ;
19
41
output_file : Fpath .t ;
20
42
json : bool ;
21
43
search_dir : Fpath .t ;
@@ -24,7 +46,7 @@ type index = {
24
46
let pp_index fmt x =
25
47
Format. fprintf fmt
26
48
" @[<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
28
50
29
51
type 'a unit = {
30
52
parent_id : Odoc.Id .t ;
@@ -33,7 +55,7 @@ type 'a unit = {
33
55
output_dir : Fpath .t ;
34
56
odoc_file : Fpath .t ;
35
57
odocl_file : Fpath .t ;
36
- pkg_args : pkg_args ;
58
+ pkg_args : Pkg_args .t ;
37
59
pkgname : string ;
38
60
include_dirs : Fpath.Set .t ;
39
61
index : index option ;
@@ -89,7 +111,7 @@ and pp : all_kinds unit Fmt.t =
89
111
@]"
90
112
(Odoc.Id. to_string x.parent_id)
91
113
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
93
115
Fmt. (list ~sep: comma Fpath. pp)
94
116
(Fpath.Set. to_list x.include_dirs)
95
117
(Fmt. option pp_index) x.index pp_kind
@@ -143,17 +165,17 @@ let of_packages ~output_dir ~linked_dir ~index_dir ~extra_libs_paths
143
165
[]
144
166
in
145
167
(* Given a pkg, *)
146
- let base_args pkg lib_deps : pkg_args =
168
+ let base_args pkg lib_deps : Pkg_args.t =
147
169
let own_page = dash_p pkg in
148
170
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
+ }
155
177
in
156
- let args_of_config config : pkg_args =
178
+ let args_of_config config : Pkg_args.t =
157
179
let { Global_config. deps = { packages; libraries } } = config in
158
180
let pages_rel =
159
181
List. filter_map
@@ -164,42 +186,22 @@ let of_packages ~output_dir ~linked_dir ~index_dir ~extra_libs_paths
164
186
packages
165
187
in
166
188
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
+ }
173
195
in
174
196
let args_of =
175
197
let cache = Hashtbl. create 10 in
176
- fun pkg lib_deps : pkg_args ->
198
+ fun pkg lib_deps : Pkg_args. t ->
177
199
match Hashtbl. find_opt cache (pkg, lib_deps) with
178
200
| Some res -> res
179
201
| 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
196
202
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)
203
205
in
204
206
Hashtbl. add cache (pkg, lib_deps) result;
205
207
result
0 commit comments