Skip to content

Commit cd41fcc

Browse files
committed
OCaml 4.08+ compat
1 parent 3fbf3c9 commit cd41fcc

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/odoc/classify.ml renamed to src/odoc/classify.cppo.ml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
(* Given a directory with cmis, cmas and so on, partition the modules between the libraries *)
44
(* open Bos *)
55

6-
open Misc
76
open Cmo_format
87

98
module StringSet = Set.Make (String)
@@ -148,14 +147,26 @@ let read_cmxa ic init =
148147
close_in ic;
149148
Ok (List.fold_left Archive.add_unit_info init (List.map fst li.lib_units))
150149

150+
#if OCAML_VERSION > (4, 10, 0)
151+
open Misc
152+
151153
let read_library ic init =
152154
let open Magic_number in
153155
match read_current_info ~expected_kind:None ic with
154156
| Ok { kind = Cma; version = _ } -> read_cma ic init
155157
| Ok { kind = Cmxa _; version = _ } -> read_cmxa ic init
156158
| Ok { kind = _; version = _ } -> Error (`Msg "Not a valid library")
157159
| Error _ -> Error (`Msg "Not a valid file")
158-
160+
#else
161+
let read_library ic init =
162+
let len_magic_number = String.length Config.cmo_magic_number in
163+
let magic_number = really_input_string ic len_magic_number in
164+
if magic_number = Config.cma_magic_number then read_cma ic init
165+
else if magic_number = Config.cmxa_magic_number then read_cmxa ic init
166+
else Error (`Msg "Not a valid library")
167+
#endif
168+
169+
#if OCAML_VERSION > (4, 10, 0)
159170
let read_cmi ic =
160171
let open Magic_number in
161172
match read_current_info ~expected_kind:None ic with
@@ -165,6 +176,18 @@ let read_cmi ic =
165176
Ok cmi
166177
| Ok { kind = _; version = _ } -> Error (`Msg "Not a valid cmi")
167178
| Error _ -> Error (`Msg "Not a valid file")
179+
#else
180+
let read_cmi ic =
181+
let len_magic_number = String.length Config.cmo_magic_number in
182+
let magic_number = really_input_string ic len_magic_number in
183+
if magic_number = Config.cmi_magic_number
184+
then begin
185+
let cmi = (input_value ic : Cmi_format.cmi_infos) in
186+
close_in ic;
187+
Ok cmi
188+
end else Error (`Msg "Not a valid file")
189+
190+
#endif
168191

169192
let classify dir files libraries =
170193
let libraries = StringSet.elements libraries in

src/odoc/dune

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,14 @@
1919
(instrumentation
2020
(backend bisect_ppx)))
2121

22+
(rule
23+
(targets classify.ml)
24+
(deps
25+
(:x classify.cppo.ml))
26+
(action
27+
(chdir
28+
%{workspace_root}
29+
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{x} -o %{targets}))))
30+
2231
(documentation
2332
(package odoc))

0 commit comments

Comments
 (0)