Skip to content

Commit

Permalink
Simplified discover.ml
Browse files Browse the repository at this point in the history
  • Loading branch information
mmottl committed Dec 9, 2024
1 parent 5059766 commit a2fafbe
Showing 1 changed file with 13 additions and 28 deletions.
41 changes: 13 additions & 28 deletions src/config/discover.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,19 @@ let major_minor_from_pgconfig () =
in
Fun.protect ~finally:(fun () -> close_in ic) (fun () -> pg_major_minor ic)

let major_minor_from_pkg_config =
let pkg_config_prefix () =
let pkg_config_args =
match Sys.getenv "PKG_CONFIG_ARGN" with
| s -> String.split_on_char ' ' s
| exception Not_found -> []
in
let bin =
match Sys.getenv "PKG_CONFIG" with
| s -> s
| exception Not_found -> "pkg-config"
in
Format.asprintf "%s %s " bin (String.concat " " pkg_config_args)
in
fun () ->
let ic =
Unix.open_process_in (pkg_config_prefix () ^ " --modversion libpq")
in
Fun.protect ~finally:(fun () -> close_in ic) @@ fun () ->
let version_line = input_line ic in
(* Typically something like "14.1" *)
match String.split_on_char '.' version_line with
| major :: minor :: _ ->
( "-DPG_OCAML_MAJOR_VERSION=" ^ major,
"-DPG_OCAML_MINOR_VERSION=" ^ minor )
| _ ->
eprintf "Unable to parse libpq version: %s" version_line;
exit 1
let major_minor_from_pkg_config () =
let bin = Sys.getenv_opt "PKG_CONFIG" |> Option.value ~default:"pkg-config" in
let args = Sys.getenv_opt "PKG_CONFIG_ARGN" |> Option.value ~default:"" in
let cmd = Format.asprintf "%s %s --modversion libpq" bin args in
let ic = Unix.open_process_in cmd in
Fun.protect ~finally:(fun () -> close_in ic) @@ fun () ->
let version_line = input_line ic in
match String.split_on_char '.' version_line with
| major :: minor :: _ ->
("-DPG_OCAML_MAJOR_VERSION=" ^ major, "-DPG_OCAML_MINOR_VERSION=" ^ minor)
| _ ->
eprintf "Unable to parse libpq version: %s" version_line;
exit 1

let from_pgconfig () =
let cmd = "pg_config --includedir --libdir --version" in
Expand Down

0 comments on commit a2fafbe

Please sign in to comment.