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

Depexts: Add support for NetBSD, DragonFlyBSD (+ fix OpenBSD, FreeBSD and Gentoo) #4396

Merged
merged 8 commits into from
Oct 21, 2020
60 changes: 44 additions & 16 deletions src/state/opamSysInteract.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type families =
| Homebrew
| Macports
| Openbsd
| Netbsd
| Suse

(* System status *)
Expand All @@ -106,10 +107,15 @@ let family =
| "amzn" | "centos" | "fedora" | "mageia" | "oraclelinux" | "ol"
| "rhel" -> Centos
| "archlinux" | "arch" -> Arch
| "bsd" when OpamSysPoll.os_distribution () = Some "freebsd" ->
Freebsd
| "bsd" when OpamSysPoll.os_distribution () = Some "openbsd" ->
Openbsd
| "bsd" ->
begin match OpamSysPoll.os_distribution () with
| Some ("freebsd" | "dragonfly") -> Freebsd
| Some "openbsd" -> Openbsd
| Some "netbsd" -> Netbsd
| _ ->
Printf.ksprintf failwith
"External dependency handling not supported for OS family 'bsd'."
end
| "debian" -> Debian
| "gentoo" -> Gentoo
| "homebrew" -> Homebrew
Expand Down Expand Up @@ -171,6 +177,18 @@ let packages_status packages =
with Not_found -> inst, avail)
OpamSysPkg.Set.(empty, empty)
in
let package_set_of_pkgpath l =
List.fold_left (fun set pkg ->
let short_name =
match String.rindex_opt pkg '/' with
| None -> pkg
| Some idx -> String.sub pkg idx (String.length pkg - idx)
in
set
|> OpamSysPkg.Set.add (OpamSysPkg.of_string pkg)
|> OpamSysPkg.Set.add (OpamSysPkg.of_string short_name)
) OpamSysPkg.Set.empty l
in
match family () with
| Alpine ->
let re_installed = Re.(compile (seq [str "[installed]"; eol])) in
Expand Down Expand Up @@ -318,7 +336,7 @@ let packages_status packages =
compute_sets sys_installed ~sys_available
| Freebsd ->
let sys_installed =
run_query_command "pkg" ["query"; "%n"]
run_query_command "pkg" ["query"; "%n\n%o"]
|> List.map OpamSysPkg.of_string
|> OpamSysPkg.Set.of_list
in
Expand All @@ -335,14 +353,18 @@ let packages_status packages =
eol ])
in
List.fold_left (fun inst dir ->
let pkg =
OpamFilename.basename_dir dir
|> OpamFilename.Base.to_string
in
try Re.(Group.get (exec re_pkg pkg) 1) +++ inst
with Not_found -> inst)
OpamSysPkg.Set.empty
(OpamFilename.rec_dirs (OpamFilename.Dir.of_string "/var/db/pkg"))
List.fold_left (fun inst pkg ->
let to_string d =
OpamFilename.basename_dir d
|> OpamFilename.Base.to_string
in
let pkg = Filename.concat (to_string dir) (to_string pkg) in
try Re.(Group.get (exec re_pkg pkg) 1) :: inst
with Not_found -> inst
) inst (OpamFilename.dirs dir))
[]
(OpamFilename.dirs (OpamFilename.Dir.of_string "/var/db/pkg"))
|> package_set_of_pkgpath
in
compute_sets sys_installed
| Homebrew ->
Expand Down Expand Up @@ -406,8 +428,13 @@ let packages_status packages =
| Openbsd ->
let sys_installed =
run_query_command "pkg_info" ["-mqP"]
|> List.map OpamSysPkg.of_string
|> OpamSysPkg.Set.of_list
|> package_set_of_pkgpath
in
compute_sets sys_installed
| Netbsd ->
let sys_installed =
run_query_command "pkg_info" ["-Q"; "PKGPATH"; "-a"]
|> package_set_of_pkgpath
in
compute_sets sys_installed
| Suse ->
Expand Down Expand Up @@ -477,6 +504,7 @@ let install_packages_commands_t sys_packages =
["port", "install"::packages], (* NOTE: Does not have any interactive mode *)
None
| Openbsd -> ["pkg_add", yes ~no:["-i"] ["-I"] packages], None
| Netbsd -> ["pkgin", yes ["-y"] ("install" :: packages)], None
| Suse -> ["zypper", yes ["--non-interactive"] ("install"::packages)], None

let install_packages_commands sys_packages =
Expand Down Expand Up @@ -527,7 +555,7 @@ let update () =
| Homebrew -> Some ("brew", ["update"])
| Macports -> Some ("port", ["sync"])
| Suse -> Some ("zypper", ["--non-interactive"; "update"])
| Freebsd | Openbsd ->
| Freebsd | Openbsd | Netbsd ->
None
in
match cmd with
Expand Down