Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the performance of opam update/init on Windows #5966

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ AS_CASE([${support_static},${enable_static}],
[no,yes],[AC_MSG_ERROR([--enable-static is not available on this platform (${TARGET}).])],
[*,auto],[enable_static=${default_static}])
AS_IF([test "${enable_static}" = yes],[
echo "(-noautolink -cclib -lunix -cclib -lmccs_stubs -cclib -lmccs_glpk_stubs -cclib -lsha_stubs ${platform_dependant_stuff})" > src/client/linking.sexp
echo "(-noautolink -cclib -lunixnat -cclib -lmccs_stubs -cclib -lmccs_glpk_stubs -cclib -lsha_stubs ${platform_dependant_stuff})" > src/client/linking.sexp
AC_MSG_RESULT([static])
],[
AC_MSG_RESULT([shared])
Expand Down
64 changes: 34 additions & 30 deletions src/client/opamAction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ let preprocess_dot_install_t st nv build_dir =
let check ~src ~dst base =
let src_file = OpamFilename.create src base.c in
if base.optional && not (OpamFilename.exists src_file) then
log "Not installing %a is not present and optional."
(slog OpamFilename.to_string) src_file;
log (fun fmt ->
fmt "Not installing %a is not present and optional."
(slog OpamFilename.to_string) src_file);
let exists = OpamFilename.exists src_file in
let warn =
if not base.optional && not exists then
Expand All @@ -76,7 +77,7 @@ let preprocess_dot_install_t st nv build_dir =
if OpamFilename.exists_dir dst_dir || files = [] then [] else
let dir = OpamFilename.remove_prefix_dir switch_prefix dst_dir in
let inst _ =
log "creating %a" (slog OpamFilename.Dir.to_string) dst_dir;
log (fun fmt -> fmt "creating %a" (slog OpamFilename.Dir.to_string) dst_dir);
OpamFilename.mkdir dst_dir;
None
in
Expand Down Expand Up @@ -211,8 +212,7 @@ let preprocess_dot_install st nv build_dir =
else
(OpamSystem.default_install_warning, (fun () -> false))
in
OpamFilename.in_dir build_dir @@ fun () ->
log "Installing %s.\n" (OpamPackage.to_string nv);
log (fun fmt -> fmt "Installing %s.\n" (OpamPackage.to_string nv));
let warnings =
OpamStd.List.filter_map (fun install -> install warning) installs
in
Expand All @@ -239,11 +239,12 @@ let preprocess_dot_install st nv build_dir =

let download_shared_source st url nvs =
let labelise pkg_str = OpamStd.List.concat_map ", " pkg_str nvs in
log "download_package: %a%a"
(slog (fun _ -> labelise OpamPackage.to_string)) ()
(slog (fun url -> match url, nvs with
| None, _ | _, [_] -> ""
| Some url, _ -> " " ^ OpamUrl.to_string (OpamFile.URL.url url))) url;
log (fun fmt ->
fmt "download_package: %a%a"
(slog (fun _ -> labelise OpamPackage.to_string)) ()
(slog (fun url -> match url, nvs with
| None, _ | _, [_] -> ""
| Some url, _ -> " " ^ OpamUrl.to_string (OpamFile.URL.url url))) url);
if OpamStateConfig.(!r.dryrun) || OpamClientConfig.(!r.fake)
then Done None else
let nvs =
Expand Down Expand Up @@ -345,8 +346,9 @@ let prepare_package_build env opam nv dir =
let patches = OpamFile.OPAM.patches opam in

let print_apply basename =
log "%s: applying %s.\n" (OpamPackage.name_to_string nv)
(OpamFilename.Base.to_string basename);
log (fun fmt ->
fmt "%s: applying %s.\n" (OpamPackage.name_to_string nv)
(OpamFilename.Base.to_string basename));
if OpamConsole.verbose () then
OpamConsole.msg "[%s: patch] applying %s\n"
(OpamConsole.colorise `green (OpamPackage.name_to_string nv))
Expand All @@ -355,9 +357,10 @@ let prepare_package_build env opam nv dir =
let print_subst basename =
let file = OpamFilename.Base.to_string basename in
let file_in = file ^ ".in" in
log "%s: expanding opam variables in %s, generating %s.\n"
(OpamPackage.name_to_string nv)
file_in file;
log (fun fmt ->
fmt "%s: expanding opam variables in %s, generating %s.\n"
(OpamPackage.name_to_string nv)
file_in file);
if OpamConsole.verbose () then
OpamConsole.msg
"[%s: subst] expanding opam variables in %s, generating %s\n"
Expand Down Expand Up @@ -393,7 +396,6 @@ let prepare_package_build env opam nv dir =
apply_patches ~dryrun:true ()) @@| fun _ -> None
else
let subst_errs =
OpamFilename.in_dir dir @@ fun () ->
List.fold_left (fun errs f ->
try
print_subst f;
Expand All @@ -415,7 +417,6 @@ let prepare_package_build env opam nv dir =
substitution files (see [OpamFilter.expand_interpolations_in_file] and
[OpamFilename.of_basename]. *)
let subst_errs =
OpamFilename.in_dir dir @@ fun () ->
List.fold_left (fun errs f ->
try
print_subst f;
Expand Down Expand Up @@ -449,9 +450,10 @@ let prepare_package_build env opam nv dir =
Done None

let prepare_package_source st nv dir =
log "prepare_package_source: %a at %a"
(slog OpamPackage.to_string) nv
(slog OpamFilename.Dir.to_string) dir;
log (fun fmt ->
fmt "prepare_package_source: %a at %a"
(slog OpamPackage.to_string) nv
(slog OpamFilename.Dir.to_string) dir);
if OpamStateConfig.(!r.dryrun) then Done None else
let opam = OpamSwitchState.opam st nv in
let get_extra_sources_job =
Expand Down Expand Up @@ -695,8 +697,9 @@ let make_command st opam ?dir ?text_command (cmd, args) =
let remove_commands t nv =
match installed_opam_opt t nv with
| None ->
log "No opam file was found for removing %a\n"
(slog OpamPackage.to_string) nv;
log (fun fmt ->
fmt "No opam file was found for removing %a\n"
(slog OpamPackage.to_string) nv);
[]
| Some opam ->
OpamFilter.commands (OpamPackageVar.resolve ~opam t)
Expand Down Expand Up @@ -725,7 +728,7 @@ let noop_remove_package t nv =
(* Remove a given package *)
let remove_package_aux
t ?(silent=false) ?changes ?force ?build_dir nv =
log "Removing %a" (slog OpamPackage.to_string) nv;
log (fun fmt -> fmt "Removing %a" (slog OpamPackage.to_string) nv);
let name = nv.name in
let root = t.switch_global.root in

Expand Down Expand Up @@ -786,7 +789,7 @@ let remove_package_aux
if OpamFilename.rec_files dir = [] then OpamFilename.rmdir dir
in

log "Removing files from .install";
log (fun fmt -> fmt "Removing files from .install");
remove_files OpamPath.Switch.sbin OpamFile.Dot_install.sbin;
remove_files OpamPath.Switch.bin OpamFile.Dot_install.bin;
remove_files_and_dir
Expand All @@ -800,7 +803,7 @@ let remove_package_aux
remove_files_and_dir OpamPath.Switch.doc OpamFile.Dot_install.doc;

(* Remove the misc files *)
log "Removing the misc files";
log (fun fmt -> fmt "Removing the misc files");
List.iter (fun (_,dst) ->
if OpamFilename.exists dst then begin
OpamConsole.msg "Removing %s." (OpamFilename.to_string dst);
Expand Down Expand Up @@ -886,7 +889,7 @@ let remove_package_aux

(* Removes build dir and source cache of package if unneeded *)
let cleanup_package_artefacts t nv =
log "Cleaning up artefacts of %a" (slog OpamPackage.to_string) nv;
log (fun fmt -> fmt "Cleaning up artefacts of %a" (slog OpamPackage.to_string) nv);

let build_dir = OpamPath.Switch.build t.switch_global.root t.switch nv in
if not OpamClientConfig.(!r.keep_build_dir) then OpamFilename.rmdir build_dir;
Expand All @@ -897,7 +900,7 @@ let cleanup_package_artefacts t nv =
(if not (OpamSwitchState.is_dev_package t nv) then
OpamFilename.rmdir dev_dir)
else
(log "Removing the local metadata";
(log (fun fmt -> fmt "Removing the local metadata");
OpamSwitchAction.remove_metadata t (OpamPackage.Set.singleton nv);
if not (OpamPackage.Set.mem nv t.pinned) then
OpamFilename.rmdir dev_dir)
Expand Down Expand Up @@ -1117,9 +1120,10 @@ let install_package t ?(test=false) ?(doc=false) ?(dev_setup=false) ?build_dir
| Left config, changes ->
let changes_f = OpamPath.Switch.changes root t.switch nv.name in
if OpamStateConfig.(not !r.dryrun) then
(log "changes recorded for %s: %a"
(OpamPackage.to_string nv)
(slog OpamDirTrack.to_summary_string) changes;
(log (fun fmt ->
fmt "changes recorded for %s: %a"
(OpamPackage.to_string nv)
(slog OpamDirTrack.to_summary_string) changes);
OpamFile.Changes.write changes_f changes);
OpamConsole.msg "%s installed %s.%s\n"
(if not (OpamConsole.utf8 ()) then "->"
Expand Down
8 changes: 4 additions & 4 deletions src/client/opamAdminCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -488,10 +488,10 @@ let add_hashes_command cli =
tbl [] |> fun lines ->
try OpamFile.Lines.write file lines with e ->
OpamStd.Exn.fatal e;
OpamConsole.log "ADMIN"
"Could not write hash cache to %s, skipping (%s)"
(OpamFile.to_string file)
(Printexc.to_string e))
OpamConsole.log "ADMIN" (fun fmt ->
fmt "Could not write hash cache to %s, skipping (%s)"
(OpamFile.to_string file)
(Printexc.to_string e)))
hash_tables
in
let additions_count = ref 0 in
Expand Down
14 changes: 7 additions & 7 deletions src/client/opamAdminRepoUpgrade.ml
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ let do_upgrade repo_root =
url_md5 [] |> fun lines ->
try OpamFile.Lines.write cache_file lines with e ->
OpamStd.Exn.fatal e;
OpamConsole.log "REPO_UPGRADE"
"Could not write archive hash cache to %s, skipping (%s)"
(OpamFile.to_string cache_file)
(Printexc.to_string e))
OpamConsole.log "REPO_UPGRADE" (fun fmt ->
fmt "Could not write archive hash cache to %s, skipping (%s)"
(OpamFile.to_string cache_file)
(Printexc.to_string e)))
in
let ocaml_versions =
OpamStd.String.Map.fold (fun c comp_file ocaml_versions ->
Expand Down Expand Up @@ -411,9 +411,9 @@ let do_upgrade repo_root =

let packages = OpamRepository.packages_with_prefixes repo_root in

OpamConsole.log "REPO_UPGRADE"
"Will not update base packages: %s\n"
(OpamPackage.Name.Set.to_string all_base_packages);
OpamConsole.log "REPO_UPGRADE" (fun fmt ->
fmt "Will not update base packages: %s\n"
(OpamPackage.Name.Set.to_string all_base_packages));

OpamPackage.Map.iter (fun package prefix ->
let opam_file = OpamRepositoryPath.opam repo_root prefix package in
Expand Down
19 changes: 10 additions & 9 deletions src/client/opamAuxCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,14 @@ let autopin_aux st ?quiet ?(for_view=false) ?recurse ?subpath ?locked
| _ -> None)
atom_or_local_list
in
log "autopin: %a"
(slog @@ OpamStd.List.to_string (fun pin ->
Printf.sprintf "%s%s => %s"
(OpamPackage.Name.to_string pin.pin_name)
(if pin.pin.pin_locked = None then "" else "[locked]")
(OpamUrl.to_string_w_subpath pin.pin.pin_subpath pin.pin.pin_url)))
to_pin;
log (fun fmt ->
fmt "autopin: %a"
(slog @@ OpamStd.List.to_string (fun pin ->
Printf.sprintf "%s%s => %s"
(OpamPackage.Name.to_string pin.pin_name)
(if pin.pin.pin_locked = None then "" else "[locked]")
(OpamUrl.to_string_w_subpath pin.pin.pin_subpath pin.pin.pin_url)))
to_pin);
let obsolete_pins =
(* Packages not current but pinned to the same dirs *)
OpamPackage.Set.filter (fun nv ->
Expand Down Expand Up @@ -534,8 +535,8 @@ let check_and_revert_sandboxing root config =
in
try
(* Don't assume that we can mount the CWD *)
OpamSystem.in_tmp_dir @@ fun () ->
OpamSystem.read_command_output ~env ~allow_stdin:false (cmd @ test_cmd)
OpamSystem.with_tmp_dir @@ fun dir ->
OpamSystem.read_command_output ~env ~dir ~allow_stdin:false (cmd @ test_cmd)
= ["SUCCESS"]
with e ->
(OpamConsole.error "Sandboxing is not working on your platform%s:\n%s"
Expand Down
Loading
Loading