Skip to content

Commit

Permalink
voodoo-prep: optimize the loop iterating over packages #121 (9f1dade)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabine committed Sep 6, 2023
1 parent d81341a commit afa22c3
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions src/voodoo-prep/prep.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ let process_package : Fpath.t -> Package.t -> Fpath.t list -> unit =
Util.write_file Fpath.(dest // set_ext "ocamlobjinfo" fpath) lines)
actions.objinfo

let write_opam_file package =
match Opam.opam_file package with
| Some lines ->
let dest = Package.prep_path package in
Util.write_file Fpath.(dest / "opam") lines
| None -> ()

let run (universes : (string * string) list) =
let get_universe =
match universes with
Expand All @@ -100,25 +107,12 @@ let run (universes : (string * string) list) =
with _ -> None)
in

let packages =
Opam.all_opam_packages ()
|> List.fold_left
(fun acc pkg ->
match get_universe pkg with Some pkg -> pkg :: acc | None -> acc)
[]
in
let root = Opam.prefix () |> Fpath.v in
let pkg_contents =
List.map (fun package -> (package, Opam.pkg_contents package)) packages
in
List.iter
(fun (package, files) -> process_package root package files)
pkg_contents;
List.iter
(fun package ->
match Opam.opam_file package with
| Some lines ->
let dest = Package.prep_path package in
Util.write_file Fpath.(dest / "opam") lines
| None -> ())
packages
Opam.all_opam_packages ()
|> List.iter (fun pkg ->
match get_universe pkg with
| Some package ->
let files = Opam.pkg_contents package in
process_package root package files;
write_opam_file package
| None -> ())

0 comments on commit afa22c3

Please sign in to comment.