-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The command `dune ocaml doc` will now lock, build, and run odoc as a dev tool if the dev tools feature is enabled. Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
- Loading branch information
Showing
9 changed files
with
124 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
val is_enabled : bool Lazy.t | ||
val lock_ocamlformat : unit -> unit Fiber.t | ||
val lock_odoc : unit -> unit Fiber.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,37 @@ | ||
open! Import | ||
|
||
type t = Ocamlformat | ||
type t = | ||
| Ocamlformat | ||
| Odoc | ||
|
||
let all = [ Ocamlformat ] | ||
let all = [ Ocamlformat; Odoc ] | ||
|
||
let equal a b = | ||
match a, b with | ||
| Ocamlformat, Ocamlformat -> true | ||
| Odoc, Odoc -> true | ||
| _ -> false | ||
;; | ||
|
||
let package_name = function | ||
| Ocamlformat -> Package_name.of_string "ocamlformat" | ||
| Odoc -> Package_name.of_string "odoc" | ||
;; | ||
|
||
let of_package_name package_name = | ||
match Package_name.to_string package_name with | ||
| "ocamlformat" -> Ocamlformat | ||
| "odoc" -> Odoc | ||
| other -> User_error.raise [ Pp.textf "No such dev tool: %s" other ] | ||
;; | ||
|
||
let exe_name = function | ||
| Ocamlformat -> "ocamlformat" | ||
| Odoc -> "odoc" | ||
;; | ||
|
||
let exe_path_components_within_package t = | ||
match t with | ||
| Ocamlformat -> [ "bin"; exe_name t ] | ||
| Odoc -> [ "bin"; exe_name t ] | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
open! Import | ||
|
||
type t = Ocamlformat | ||
type t = | ||
| Ocamlformat | ||
| Odoc | ||
|
||
val all : t list | ||
val equal : t -> t -> bool | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
test/blackbox-tests/test-cases/pkg/odoc/dev-tool-odoc-basic.t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Test that the "dune ocaml doc" command causes odoc to be locked and | ||
build, and then used to generate documentation. | ||
|
||
$ . ../helpers.sh | ||
$ . ./helpers.sh | ||
|
||
$ mkrepo | ||
$ make_mock_odoc_package | ||
|
||
$ setup_odoc_workspace | ||
|
||
$ cat > dune-project <<EOF | ||
> (lang dune 3.16) | ||
> | ||
> (package | ||
> (name foo) | ||
> (allow_empty)) | ||
> EOF | ||
|
||
Lock and build the fake odoc executable, and then use the fake | ||
executable to attempt to generate documentation. The fake executable | ||
doesn't actually do anything so the command fails but this | ||
demonstrates that it was run. | ||
$ DUNE_CONFIG__LOCK_DEV_TOOL=enabled dune ocaml doc | ||
Solution for dev-tools.locks/odoc: | ||
- odoc.0.0.1 | ||
hello from fake odoc | ||
hello from fake odoc | ||
File "_doc/_html/_unknown_", line 1, characters 0-0: | ||
Error: Rule failed to produce directory "_doc/_html/odoc.support" | ||
File "_doc/_odoc/pkg/foo/_unknown_", line 1, characters 0-0: | ||
Error: Rule failed to generate the following targets: | ||
- _doc/_odoc/pkg/foo/page-index.odoc | ||
[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(cram | ||
(deps helpers.sh) | ||
(applies_to :whole_subtree)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Create a dune-workspace file with mock repos set up for the main | ||
# project and the odoc lockdir. | ||
setup_odoc_workspace() { | ||
cat > dune-workspace <<EOF | ||
(lang dune 3.16) | ||
(lock_dir | ||
(path "dev-tools.locks/odoc") | ||
(repositories mock)) | ||
(lock_dir | ||
(repositories mock)) | ||
(repository | ||
(name mock) | ||
(source "file://$(pwd)/mock-opam-repository")) | ||
EOF | ||
} | ||
|
||
# Create a fake odoc package containing an executable that | ||
# just prints a message. | ||
make_mock_odoc_package() { | ||
mkpkg odoc <<EOF | ||
install: [ | ||
[ "sh" "-c" "echo '#!/bin/sh' > %{bin}%/odoc" ] | ||
[ "sh" "-c" "echo 'echo hello from fake odoc' >> %{bin}%/odoc" ] | ||
[ "sh" "-c" "chmod a+x %{bin}%/odoc" ] | ||
] | ||
EOF | ||
} |