Skip to content

Commit 879520d

Browse files
christinerosejonludlam
authored andcommitted
line edits for driver.mld
Signed-off-by: Christine Rose <[email protected]>
1 parent e606965 commit 879520d

File tree

1 file changed

+63
-27
lines changed

1 file changed

+63
-27
lines changed

doc/driver.mld

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
{0 How to drive [odoc]}
1+
{0 How to Drive [odoc]}
22

33
This 'live' document describes how to use [odoc] to produce the documentation of [odoc] itself. The aim is
44
to show a short, simple example of how [odoc] can be used, covering most of the important features.
55
The document built here includes not only the documentation of [odoc] itself, but it also builds the
66
docs for a subset of [odoc]'s dependent libraries to show how this may be done. For a much more
7-
complete and comprehensive use of [odoc], see the {{: https://github.com/ocaml-doc/voodoo} Voodoo project}, the tool that is being used to build
8-
the package docs for
9-
{{: https://v3.ocaml.org/} v3.ocaml.org}.
7+
complete and comprehensive use of [odoc], see the {{: https://github.com/ocaml-doc/voodoo} Voodoo project},
8+
the tool used to build the
9+
{{: https://v3.ocaml.org/} v3.ocaml.org} package docs.
1010

11-
First we need to initialise MDX with some libraries and helpful values.
11+
First, we need to initialise MDX with some libraries and helpful values:
1212

1313
{[
1414
(* Prelude *)
@@ -24,7 +24,8 @@ let get_ok = function | Ok x -> x | Error (`Msg m) -> failwith m
2424

2525
{1 Desired Output}
2626

27-
[odoc] produces output files (html or others) in a structured directory tree, so before running [odoc], the structure of the output must be decided. For these docs, we want the following structure:
27+
[odoc] produces output files (HTML or others) in a structured directory tree, so before running [odoc],
28+
the structure of the output must be decided. For these docs, we want the following structure:
2829
{ul {- [odoc/index.html] : main page
2930
}{- [odoc/\{odoc_for_authors.html,...\}] : other documentation pages
3031
}{- [odoc/odoc_model/index.html] : [odoc] model library subpage
@@ -37,9 +38,14 @@ let get_ok = function | Ok x -> x | Error (`Msg m) -> failwith m
3738
}{- [odoc/deps/...] : other dependencies
3839
}}
3940

40-
The [odoc] model for achieving this is that we have {e pages} ([.mld] files) that have {e children} which are either {e further pages} ([.mld] files) or {e modules} (from [.cmti] files). This {{!page-parent_child_spec} parent/child relationship} is specified on the command line. Parent pages must be {e compiled} by [odoc] before their children. Then compiling a page [mypage.mld] will produce the file [page-mypage.odoc].
41+
The [odoc] model for achieving this is that we have {e pages} ([.mld] files) that have {e children}
42+
which are either {e further pages} ([.mld] files) or {e modules} (from [.cmti] files).
43+
This {{!page-parent_child_spec} parent/child relationship} is specified on the command line.
44+
Parent pages must be {e compiled} by [odoc] before their children. Then compiling a page [mypage.mld]
45+
will produce the file [page-mypage.odoc].
4146

42-
In the example below, there will be a file [odoc.mld] that corresponds with the top-level directory [odoc/]. It will be compiled as follows:
47+
In the example below, there will be a file [odoc.mld] that corresponds with the top-level directory [odoc/].
48+
It will be compiled as follows:
4349

4450
{[
4551
odoc compile odoc.mld --child page-odoc_model --child deps ...
@@ -57,16 +63,25 @@ The file [odoc_model.mld] will have a child module [Odoc_model]. It will be comp
5763
odoc compile odoc_model.mld -I . --parent `odoc` --child module-Odoc_model
5864
]}
5965

60-
When compiling any [.mld] file, the parent and all children must be specified. Parents can only be pages from other [.mld] files, and children may be pages (from [.mld] files) or modules (from [.cmti]/[.cmt] or [.cmi] files).
66+
When compiling any [.mld] file, the parent and all children must be specified. Parents can only
67+
be pages from other [.mld] files, but children may be pages (from [.mld] files) or modules
68+
(from [.cmti]/[.cmt] or [.cmi] files).
6169

62-
The parent page must exist before the child page is created, and it must have had the child specified when it was initially compiled.
70+
The parent page must exist before the child page is created, and it must have had the child specified
71+
when it was initially compiled.
6372

6473
{1 Document Generation Phases}
6574

6675
Using [odoc] is a three-phase process:
6776
{ol {- Compilation: [odoc compile]
6877

69-
This takes the output from the compiler in the form of [.cmti], [.cmt], or [.cmi] files (in order of preference), translates it into [odoc]'s internal format, and performs some initial expansion and resolution operations. For a given input [/path/to/file.cmti] it will output the file [/path/to/file.odoc] unless the [-o] option is used to override the output file. If there were [.cmi] dependencies required for OCaml to compile these files, then there will be equivalent [.odoc] dependencies needed for the [odoc compile] step. [odoc] will search for these dependencies in the paths specified with the [-I] directive on compilation. [odoc] provides a command to help with this: [odoc compile-deps]:
78+
This takes the output from the compiler in the form of [.cmti], [.cmt], or [.cmi] files (in order of preference),
79+
translates it into [odoc]'s internal format, and performs some initial expansion and resolution operations.
80+
For a given input [/path/to/file.cmti], it will output the file [/path/to/file.odoc], unless the [-o] option
81+
is used to override the output file. If there were [.cmi] dependencies required for OCaml to compile these files,
82+
then there will be equivalent [.odoc] dependencies needed for the [odoc compile] step. [odoc] will search for
83+
these dependencies in the paths specified with the [-I] directive on compilation. [odoc] provides a command to
84+
help with this: [odoc compile-deps]:
7085

7186
As an example we can run [odoc compile-deps] on the file [../src/xref2/.odoc_xref2.objs/byte/odoc_xref2__Compile.cmti]:
7287

@@ -79,27 +94,35 @@ Stdlib__uchar ab6f1df93abf9e800a3e0d1543523c96
7994
Odoc_xref2__Compile e0d620d652a724705f7ed620dfe07be0
8095
]}
8196

82-
so we can see we will need to run [odoc compile] against several [Stdlib] modules before we can compile [odoc_xref2__Compile.cmti]
97+
It's necessary to run [odoc compile] against several [Stdlib] modules before we can compile [odoc_xref2__Compile.cmti]
8398
}
8499
{- Linking: [odoc link]
85100

86101

87-
This takes the [odoc] files produced during the compilation step and performs the final steps of expansion and resolution. It is during this phase that all the references in the documentation comments are resolved. In order for these to be resolved, everything that is referenced must have been compiled already, and their [odoc] files must be on the
88-
include path as specified by the [-I] arguments to [odoc link]. In this example, we achieve that by compiling all modules and [.mld] files before linking anything. The output of the
102+
This takes the [odoc] files produced during the compilation step and performs the final steps of
103+
expansion and resolution. It's during this phase that all the references in the documentation comments are
104+
resolved. In order for these to be resolved, everything that's referenced must have been compiled already,
105+
and their [odoc] files must be on the include path as specified by the [-I] arguments to [odoc link].
106+
In this example, we achieve that by compiling all modules and [.mld] files before linking anything. The output of the
89107
link step is an [odocl] file, which is in the same path as the original [odoc] file by default.
90108

91109
Please note: it's only necessary to link the non-hidden modules (i.e., without a double underscore).
92110
}
93111
{- Generation: [odoc html-generate]
94112

95113

96-
Once the compile and link phases are complete, the resulting [odocl] files may be rendered in a variety of formats. In this example we output HTML.
114+
Once the compile and link phases are complete, the resulting [odocl] files may be rendered in a variety
115+
of formats. In this example, we output HTML:
97116
}}
98117

99118
{1 [odoc] Documentation}
100119

101-
In this section [odoc] is used to generate the documentation of [odoc] and some of its dependent packages. We can make a few simplifying assumptions here:
102-
{ol {- Since we're working with one leaf package, we can assume that there can be no module name clashes in the dependencies. As such, we can afford to put all of our [.odoc] files into one directory and then hard-code the include path to be this directory. When using [odoc] in a context where there may be module name clashes, it requires more careful partitioning of output directories.
120+
In this section, [odoc] is used to generate the documentation of [odoc] and some of its dependent packages.
121+
We can make a few simplifying assumptions here:
122+
{ol {- Since we're working with one leaf package, we can assume that there can be no module name
123+
clashes in the dependencies. As such, we can afford to put all of our [.odoc] files into one directory
124+
and then hard-code the include path to be this directory. When using [odoc] in a context where there may
125+
be module name clashes, it requires more careful partitioning of output directories.
103126
}{- We'll do all of the compiling before any linking.
104127
}}
105128

@@ -180,9 +203,10 @@ let support_files () =
180203
]}
181204

182205
We'll now make some library lists. We have not only external dependency libraries, but
183-
[odoc] itself is also separated into libraries too. These two sets of libraries will be
206+
[odoc] itself is also separated into libraries. These two sets of libraries will be
184207
documented in different sections, so we'll keep them in separate lists.
185-
Additionally we'll also construct a list containing the extra documentation pages. Finally let's create a list mapping the section to its parent, which matches
208+
Additionally we'll construct a list containing the extra documentation pages. Finally,
209+
let's create a list mapping the section to its parent, which matches
186210
the hierarchy declared above.
187211

188212
{[
@@ -253,7 +277,8 @@ let parents =
253277
add_parent "deps" dep_libraries @ add_parent "odoc" odoc_libraries
254278
]}
255279

256-
[odoc] operates on the compiler outputs. We need to find them for both the files compiled by Dune within this project and those in libraries we compile against.
280+
[odoc] operates on the compiler outputs. We need to find them for both the files
281+
compiled by Dune within this project and those in libraries we compile against.
257282
The following uses [ocamlfind] to locate the library paths for our dependencies:
258283

259284
{[
@@ -273,7 +298,7 @@ let lib_paths =
273298
]}
274299

275300
We need a function to find [odoc] inputs given a search path. [odoc]
276-
operates on [.cmti], [.cmt] or [.cmi] files, in order of preference, and the following
301+
operates on [.cmti], [.cmt], or [.cmi] files, in order of preference, and the following
277302
function finds all matching files given a search path. Then it returns an [Fpath.Set.t]
278303
that contains the [Fpath.t] values representing the absolute file path, without its extension.
279304

@@ -304,7 +329,7 @@ let best_file base =
304329
|> List.find (fun f -> Bos.OS.File.exists f |> get_ok)
305330
]}
306331

307-
Many of the units will be 'hidden' -- that is, their name will be mangled by Dune
332+
Many of the units will be 'hidden', meaning that Dune will mangle their name
308333
in order to namespace them. This is achieved by prefixing the namespace module and
309334
a double underscore, so we can tell by the existence of a double underscore that
310335
a module is intended to be hidden. The following predicate tests for that condition:
@@ -313,7 +338,8 @@ a module is intended to be hidden. The following predicate tests for that condit
313338
let is_hidden path = Astring.String.is_infix ~affix:"__" (Fpath.to_string path)
314339
]}
315340

316-
To build the documentation, we start with these files. With the following function, we'll call [odoc compile-deps] on the file to
341+
To build the documentation, we start with these files. With the following function, we'll
342+
call [odoc compile-deps] on the file to
317343
find all other compilation units upon which it depends:
318344

319345
{[
@@ -362,7 +388,9 @@ let all_units =
362388
odoc_units @ lib_units |> List.flatten
363389
]}
364390

365-
Now we'll compile all of the parent [.mld] files. To ensure that the parents are compiled before the children, we start with [odoc.mld], then [deps.mld], and so on. The result of this file is a list of the resulting [odoc] files.
391+
Now we'll compile all of the parent [.mld] files. To ensure that the parents are
392+
compiled before the children, we start with [odoc.mld], then [deps.mld], and so on. The result
393+
of this file is a list of the resulting [odoc] files.
366394

367395
{[
368396
let compile_mlds () =
@@ -400,7 +428,13 @@ let compile_mlds () =
400428
("page-odoc.odoc" :: "page-deps.odoc" :: odocs @ extra_odocs)
401429
]}
402430

403-
Now we get to the compilation phase. For each unit, we query its dependencies, then recursively call to compile these dependencies. Once this is done we compile the unit itself. If the unit has already been compiled we don't do anything. Note that we aren't checking the hashes of the dependencies which a build system should do to ensure that the module being compiled is the correct one. Again we benefit from the fact that we're creating the docs for one leaf package and that there must be no module name clashes in its dependencies. The result of this function is a list of the resulting [odoc] files.
431+
Now we get to the compilation phase. For each unit, we query its dependencies,
432+
then recursively call to compile these dependencies. Once this is done, we compile the unit itself.
433+
If the unit has already been compiled, we don't do anything. Note that we aren't checking the
434+
hashes of the dependencies which a build system should do to ensure that the module being compiled
435+
is the correct one. Again, we benefit from the fact that we're creating the docs for one
436+
leaf package and that there must be no module name clashes in its dependencies. The result
437+
of this function is a list of the resulting [odoc] files.
404438

405439
{[
406440
let compile_all () =
@@ -435,7 +469,9 @@ let compile_all () =
435469
@ mld_odocs
436470
]}
437471

438-
Linking is now straightforward. We only need to link non-hidden [odoc] files, as any hidden are almost certainly aliased inside the non-hidden ones (a result of namespacing usually, and these aliases will be expanded).
472+
Linking is now straightforward. We only need to link non-hidden [odoc] files, as
473+
any hidden ones are almost certainly aliased inside the non-hidden ones
474+
(a result of namespacing, usually, and these aliases will be expanded).
439475

440476
{[
441477
let link_all odoc_files =
@@ -455,7 +491,7 @@ let generate_all odocl_files =
455491
support_files ()
456492
]}
457493

458-
The following code actually executes all of the above, and we're done!
494+
The following code executes all of the above, and we're done!
459495

460496
{[
461497
let compiled = compile_all () in

0 commit comments

Comments
 (0)