Source file OCamlbuildDocPlugin.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
open OASISTypes
open OASISGettext
open OCamlbuildCommon
type run_t =
{
extra_args: string list;
run_path: unix_filename;
}
let doc_build ~ctxt run _ (cs, _) argv =
let index_html =
OASISUnixPath.make
[
run.run_path;
cs.cs_name^".docdir";
"index.html";
]
in
let tgt_dir =
OASISHostPath.make
[
build_dir argv;
OASISHostPath.of_unix run.run_path;
cs.cs_name^".docdir";
]
in
run_ocamlbuild ~ctxt (index_html :: run.extra_args) argv;
List.iter
(fun glb ->
match OASISFileUtil.glob ~ctxt (Filename.concat tgt_dir glb) with
| (_ :: _) as filenames ->
BaseBuilt.register ~ctxt BaseBuilt.BDoc cs.cs_name [filenames]
| [] -> ())
["*.html"; "*.css"]
let doc_clean ~ctxt _ _ (cs, _) argv =
run_clean ~ctxt argv;
BaseBuilt.unregister ~ctxt BaseBuilt.BDoc cs.cs_name
open OASISFileTemplate
open OASISValues
open OASISUtils
open OASISPlugin
open OASISSchema
open OCamlbuildId
let plugin =
`Doc, name, Some version
type t =
{
path: unix_dirname;
modules: string list;
libraries: findlib_full list;
intro: unix_filename option;
flags: string list;
common: ocamlbuild_common;
}
let pivot_data = data_new_property plugin
let pivot_sub_data = data_new_property plugin
let self_id, all_id =
Doc.create plugin
let new_field nm ?default vl hlp sync =
new_field
OASISDocument.schema
all_id
nm
?default
vl
(fun () -> s_ hlp)
pivot_data sync
let path =
new_field
"Path"
directory
(ns_ "Top level directory for building ocamldoc documentation")
(fun _ t -> t.path)
let modules =
new_field
"Modules"
~default:[]
modules
(ns_ "List of OCaml modules used to generate ocamldoc documentation")
(fun _ t -> t.modules)
let libraries =
new_field
"Libraries"
~default:[]
(comma_separated findlib_full)
(ns_ "Findlib names of internal libraries used to generate the ocamldoc \
documentation")
(fun _ t -> t.libraries)
let generator =
let generator_common =
ocamlbuild_common_generator pivot_sub_data OASISDocument.schema all_id
in
fun data pkg ->
let path = path data in
let modules_from_libraries =
let lib_of_findlib =
let _, _, library_name_of_findlib_name =
OASISFindlib.findlib_mapping pkg
in
let lib_of_name =
List.fold_left
(fun mp ->
function
| Library ({cs_name = name; _}, bs, lib) ->
MapString.add name (bs, lib) mp
| _ ->
mp)
MapString.empty
pkg.sections
in
fun fndlb_nm ->
let nm =
library_name_of_findlib_name fndlb_nm
in
MapString.find nm lib_of_name
in
List.flatten
(List.map
(fun fndlb_nm ->
let bs, lib =
lib_of_findlib fndlb_nm
in
List.map
(fun modul ->
OASISUnixPath.make_relative
path
(OASISUnixPath.concat bs.bs_path modul))
lib.lib_modules)
(libraries data))
in
let modules_from_doc =
modules data
in
let modules =
modules_from_libraries @ modules_from_doc
in
{
path = path;
modules = modules;
libraries = libraries data;
intro = None;
flags = [];
common = generator_common data;
}
let doit ctxt pkg (cs, doc) =
let t = generator cs.cs_data pkg in
let ctxt =
add_file
(template_make
(OASISHostPath.add_extension
(Filename.concat t.path cs.cs_name)
"odocl")
comment_ocamlbuild
[]
t.modules
[])
ctxt
in
let ctxt =
List.fold_left
(fun ctxt f -> f ctxt)
ctxt
[
set_error
(not (List.mem (ExternalTool "ocamldoc") doc.doc_build_tools))
(Printf.sprintf
(f_ "ocamldoc in field BuildTools of document %s is mandatory.")
cs.cs_name);
set_error
(not (List.mem (ExternalTool "ocamlbuild") doc.doc_build_tools))
(Printf.sprintf
(f_ "ocamlbuild in field BuildTools of document %s is mandatory.")
cs.cs_name);
set_error
(t.modules = [])
(Printf.sprintf
(f_ "No module defined for document %s.")
cs.cs_name);
]
in
let , ctxt =
extra_args_ocamlbuild_common ctxt pkg t.common
in
let run = {run_path = t.path; extra_args = extra_args} in
let odn_of_run_t (v: run_t) =
OASISDataNotation.REC ("OCamlbuildDocPlugin",
[ ("extra_args", ((fun x -> OASISDataNotation.of_list OASISDataNotation.of_string x) v.extra_args));
("run_path", (odn_of_unix_filename v.run_path)) ])
in
ctxt,
{
chng_moduls =
[OCamlbuildData.ocamlbuildsys_ml];
chng_main =
OASISDataNotation.func_with_arg_ctxt
doc_build "OCamlbuildDocPlugin.doc_build"
run odn_of_run_t;
chng_clean =
Some
(OASISDataNotation.func_with_arg_ctxt
doc_clean "OCamlbuildDocPlugin.doc_clean"
run odn_of_run_t);
chng_distclean =
None;
}
let qstrt_completion pkg =
List.fold_left
(fun pkg tool -> fix_build_tools tool pkg)
pkg
[ExternalTool "ocamlbuild";
ExternalTool "ocamldoc"]
let init () =
OCamlbuildId.init ();
Doc.register_act self_id doit;
register_quickstart_completion all_id qstrt_completion