Skip to content

Commit

Permalink
fix Cmi_format error in voodoo-do, by checking in prep that the magic…
Browse files Browse the repository at this point in the history
… numbers match
  • Loading branch information
sabine committed Jul 14, 2023
1 parent 307d1fb commit 01db246
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/voodoo-prep/prep.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,32 @@ let process_package : Fpath.t -> Package.t -> Fpath.t list -> unit =
fun root package files ->
let dest = Package.prep_path package in

let format_matches_compiler_version path =
let open Unix in
let cmd = "ocamlobjinfo " ^ Fpath.to_string path in
let ic, oc = open_process cmd in
let rec matches_version ic =
try
let line = input_line ic in
let prefix = "Wrong magic number" in
let str_len = String.length line in
if str_len >= 18 && String.sub line 0 18 = prefix then (
Printf.eprintf "ERROR: Ocamlobjinfo on %s: %s\n"
(Fpath.to_string path) line;
false)
else if str_len > 0 then matches_version ic
else true
with End_of_file -> true
in
let matches_version = matches_version ic in
let _ = close_process (ic, oc) in
matches_version
in

(* Some packages produce ocaml artefacts that can't be processed with the switch's
ocaml compiler - most notably the secondary compiler! This switch is intended to
be used to ignore those files *)
let process_ocaml_artefacts =
let is_not_blacklisted =
let package_blacklist = [ "ocaml-secondary-compiler" ] in
not (List.mem package.name package_blacklist)
in
Expand All @@ -33,16 +55,17 @@ let process_package : Fpath.t -> Package.t -> Fpath.t list -> unit =
let no_ext = Fpath.rem_ext filename in
let has_hyphen = String.contains (Fpath.to_string filename) '-' in
let is_module =
process_ocaml_artefacts
is_not_blacklisted
&& List.mem ext [ ".cmt"; ".cmti"; ".cmi" ]
&& not has_hyphen
&& (not has_hyphen)
&& format_matches_compiler_version Fpath.(root // fpath)
in
let do_copy =
(not in_build_dir)
&& (is_in_doc_dir || is_module
|| List.mem no_ext (List.map Fpath.v [ "META"; "dune-package" ]))
in
let is_cma = process_ocaml_artefacts && List.mem ext [ ".cma"; ".cmxa" ] in
let is_cma = is_not_blacklisted && List.mem ext [ ".cma"; ".cmxa" ] in
let copy =
if do_copy then Fpath.(root // fpath, dest // fpath) :: acc.copy
else acc.copy
Expand Down

0 comments on commit 01db246

Please sign in to comment.