From f4a307852ee6251a0d53968e7a02452d5693f297 Mon Sep 17 00:00:00 2001 From: Sabine Schmaltz Date: Tue, 25 Jul 2023 09:20:23 +0200 Subject: [PATCH] WIP: Attempt to fix Cmi_format error in voodoo-do, by checking in prep that the magic numbers are ok #115 (58ec9ae) --- src/voodoo-prep/prep.ml | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/voodoo-prep/prep.ml b/src/voodoo-prep/prep.ml index 0d1be66e..43a7aca6 100644 --- a/src/voodoo-prep/prep.ml +++ b/src/voodoo-prep/prep.ml @@ -12,10 +12,37 @@ 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 + try + 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 + with _ -> + Printf.eprintf "ERROR: Failed to run ocamlobjinfo on %s\n" + (Fpath.to_string path); + false + 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_blacklisted = let package_blacklist = [ "ocaml-secondary-compiler" ] in not (List.mem package.name package_blacklist) in @@ -33,16 +60,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 + not is_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 = not is_blacklisted && List.mem ext [ ".cma"; ".cmxa" ] in let copy = if do_copy then Fpath.(root // fpath, dest // fpath) :: acc.copy else acc.copy