Skip to content

Commit

Permalink
Merge pull request #6324 from kit-ty-kate/speedup-depexts-archlinux-h…
Browse files Browse the repository at this point in the history
…omebrew

Speedup the detection of available system packages with pacman and brew
  • Loading branch information
kit-ty-kate authored Jan 18, 2025
2 parents 436b4fe + 3093083 commit 636e10f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ users)
* Add apt-rpm/ALTLinux family support for depext [#6207 @RiderALT]
* Lookup at `gpatch` before `patch` on macOS now that both homebrew and macports expose `gpatch` as `gpatch` since Homebrew/homebrew-core#174687 [#6255 @kit-ty-kate]
* Relax lookup on OpenBSD to consider all installed packages [#6362 @semarie]
* Speedup the detection of available system packages with pacman and brew [#6324 @kit-ty-kate]

## Format upgrade

Expand Down
49 changes: 27 additions & 22 deletions src/state/opamSysInteract.ml
Original file line number Diff line number Diff line change
Expand Up @@ -588,20 +588,26 @@ let packages_status ?(env=OpamVariable.Map.empty) config packages =
number of packages not found. *)
run_command ~discard_err:true pacman ["-Si"]
|> snd
|> List.fold_left (fun (avail, provides, latest) l ->
match OpamStd.String.split l ' ' with
| "Name"::":"::p::_ ->
p +++ avail, provides, Some (OpamSysPkg.of_string p)
| "Provides"::":"::"None"::[] -> avail, provides, latest
| "Provides"::":"::pkgs ->
let ps = OpamSysPkg.Set.of_list (List.map package_provided pkgs) in
let provides =
match latest with
| Some p -> OpamSysPkg.Map.add p ps provides
| None -> provides (* Bad pacman output ?? *)
in
ps ++ avail, provides, None
| _ -> avail, provides, latest)
|> List.fold_left (fun ((avail, provides, latest) as acc) l ->
if OpamStd.String.starts_with ~prefix:"Name" l then
match OpamStd.String.split l ' ' with
| "Name"::":"::p::_ ->
p +++ avail, provides, Some (OpamSysPkg.of_string p)
| _ -> acc
else if OpamStd.String.starts_with ~prefix:"Provides" l then
match OpamStd.String.split l ' ' with
| "Provides"::":"::"None"::[] -> acc
| "Provides"::":"::pkgs ->
let ps = OpamSysPkg.Set.of_list (List.map package_provided pkgs) in
let provides =
match latest with
| Some p -> OpamSysPkg.Map.add p ps provides
| None -> provides (* Bad pacman output ?? *)
in
ps ++ avail, provides, None
| _ -> acc
else
acc)
(OpamSysPkg.Set.empty, OpamSysPkg.Map.empty, None)
|> (fun (a,p,_) -> a,p)
in
Expand Down Expand Up @@ -682,7 +688,7 @@ let packages_status ?(env=OpamVariable.Map.empty) config packages =
try (* package name *)
Re.(Group.get (exec pkg_name l) 1), false, instavail
with Not_found ->
if l.[2] != ' ' then (* only version field is after two spaces *)
if l.[2] <> ' ' then (* only version field is after two spaces *)
pkg, false, instavail
else if l = " lib/apk/db/installed" then
(* from https://git.alpinelinux.org/apk-tools/tree/src/database.c#n58 *)
Expand All @@ -693,7 +699,7 @@ let packages_status ?(env=OpamVariable.Map.empty) config packages =
with Not_found -> None
in
pkg, installed, add_pkg pkg repo installed instavail)
("", false, OpamSysPkg.Set.(empty, empty))
("", false, OpamSysPkg.Set.(empty, empty))
|> (fun (_,_, instavail) -> instavail)
in
compute_sets sys_installed ~sys_available
Expand Down Expand Up @@ -755,7 +761,7 @@ let packages_status ?(env=OpamVariable.Map.empty) config packages =
*)
run_query_command "apt-cache"
["search"; names_re (); "--names-only"; "--full"]
|> List.fold_left (fun (avail, provides, latest) l ->
|> List.fold_left (fun ((avail, provides, latest) as acc) l ->
if OpamStd.String.starts_with ~prefix:"Package: " l then
let p = String.sub l 9 (String.length l - 9) in
p +++ avail, provides, Some (OpamSysPkg.of_string p)
Expand All @@ -769,7 +775,7 @@ let packages_status ?(env=OpamVariable.Map.empty) config packages =
| Some p -> OpamSysPkg.Map.add p ps provides
| None -> provides (* Bad apt-cache output ?? *)),
None
else avail, provides, latest)
else acc)
(OpamSysPkg.Set.empty, OpamSysPkg.Map.empty, None)
|> (fun (a,p,_) -> a,p)
in
Expand Down Expand Up @@ -864,10 +870,9 @@ let packages_status ?(env=OpamVariable.Map.empty) config packages =
|> List.fold_left (fun res s ->
List.fold_left (fun res spkg ->
let parse_fullname pkg =
match List.rev (String.split_on_char '/' pkg) with
| [] -> assert false (* split_on_char is guaranteed to never return [] *)
| [pkg] -> [pkg]
| simple_name::_ -> [pkg; simple_name]
match OpamStd.String.rcut_at pkg '/' with
| None -> [pkg]
| Some (_, simple_name) -> [pkg; simple_name]
in
match OpamStd.String.cut_at spkg '@' with
| Some (n,_v) -> parse_fullname n@parse_fullname spkg@res
Expand Down

0 comments on commit 636e10f

Please sign in to comment.