diff --git a/src/configurator/dune b/src/configurator/dune index 0507edec9840..697f264df9b7 100644 --- a/src/configurator/dune +++ b/src/configurator/dune @@ -3,5 +3,5 @@ (library (name configurator) (public_name dune.configurator) - (libraries stdune ocaml_config dune_lang) + (libraries stdune ocaml_config dune_lang dune_caml) (flags (:standard -safe-string (:include flags/flags.sexp)))) diff --git a/src/configurator/v1.ml b/src/configurator/v1.ml index 729163ba53ea..9f93972e5500 100644 --- a/src/configurator/v1.ml +++ b/src/configurator/v1.ml @@ -256,9 +256,6 @@ module Process = struct let run_command_ok t ?dir ?env cmd = (run_command t ?dir ?env cmd).exit_code = 0 - let run_process_ok t ?dir ?env prog args = - (run_process t ?dir ?env prog args).exit_code = 0 - let run t ?dir ?env prog args = run_command t ?dir ?env (command_line prog args) @@ -615,7 +612,10 @@ module Pkg_config = struct end | _ -> None in - if Process.run_process_ok c ~dir ?env t.pkg_config [expr] then + let pc_flags = "--print-errors" in + let { Process.exit_code; stderr; _ } = + Process.run_process c ~dir ?env t.pkg_config [pc_flags; expr] in + if exit_code = 0 then let run what = match String.trim (Process.run_capture_exn c ~dir ?env t.pkg_config [what; package]) @@ -623,14 +623,18 @@ module Pkg_config = struct | "" -> [] | s -> String.split s ~on:' ' in - Some + Ok { libs = run "--libs" ; cflags = run "--cflags" } else - None + Error stderr + + let query t ~package = + match gen_query t ~package ~expr:None with + | Ok p -> Some p + | Error _msg -> None - let query t ~package = gen_query t ~package ~expr:None let query_expr t ~package ~expr = gen_query t ~package ~expr:(Some expr) end diff --git a/src/configurator/v1.mli b/src/configurator/v1.mli index 48c502f3f847..16557c49bbe9 100644 --- a/src/configurator/v1.mli +++ b/src/configurator/v1.mli @@ -93,7 +93,14 @@ module Pkg_config : sig package may contain a version constraint. For example "gtk+-3.0 >= 3.18". Returns [None] if [package] is not available *) - val query_expr : t -> package:string -> expr:string -> package_conf option + val query_expr : t + -> package:string + -> expr:string + -> (package_conf, string) Dune_caml.result + (** [query_expr t ~package ~expr] query pkg-config for the + [package]. [expr] may contain a version constraint, for example + "gtk+-3.0 >= 3.18". [package] should be just the name of the + package. Returns [Error error_msg] if [package] is not available *) end with type configurator := t module Flags : sig diff --git a/test/blackbox-tests/test-cases/pkg-config-quoting/pkg_config.ml b/test/blackbox-tests/test-cases/pkg-config-quoting/pkg_config.ml index 5a2b51db8d23..3ed607cf1d79 100644 --- a/test/blackbox-tests/test-cases/pkg-config-quoting/pkg_config.ml +++ b/test/blackbox-tests/test-cases/pkg-config-quoting/pkg_config.ml @@ -1,4 +1,8 @@ +(* We'd like to use String.equal but that's OCaml >= 4.03 *) +let not_flag x = not ("--print-errors" = x) + let () = let args = List.tl (Array.to_list Sys.argv) in + let args = List.filter not_flag args in Format.printf "%a@." (Format.pp_print_list Format.pp_print_string) args diff --git a/test/blackbox-tests/test-cases/pkg-config-quoting/run.t b/test/blackbox-tests/test-cases/pkg-config-quoting/run.t index 689fd50aced8..c04c268122c5 100644 --- a/test/blackbox-tests/test-cases/pkg-config-quoting/run.t +++ b/test/blackbox-tests/test-cases/pkg-config-quoting/run.t @@ -1,6 +1,6 @@ These tests show how various pkg-config invocations get qouted: $ dune build 2>&1 | awk '/run:.*bin\/pkg-config/{a=1}/stderr/{a=0}a' - run: $TESTCASE_ROOT/_build/install/default/bin/pkg-config gtk+-quartz-3.0 + run: $TESTCASE_ROOT/_build/install/default/bin/pkg-config --print-errors gtk+-quartz-3.0 -> process exited with code 0 -> stdout: | gtk+-quartz-3.0 @@ -14,7 +14,7 @@ These tests show how various pkg-config invocations get qouted: -> stdout: | --libs | gtk+-quartz-3.0 - run: $TESTCASE_ROOT/_build/install/default/bin/pkg-config 'gtk+-quartz-3.0 >= 3.18' + run: $TESTCASE_ROOT/_build/install/default/bin/pkg-config --print-errors 'gtk+-quartz-3.0 >= 3.18' -> process exited with code 0 -> stdout: | gtk+-quartz-3.0 >= 3.18 @@ -28,7 +28,7 @@ These tests show how various pkg-config invocations get qouted: -> stdout: | --libs | gtk+-quartz-3.0 >= 3.18 - run: $TESTCASE_ROOT/_build/install/default/bin/pkg-config 'gtksourceview-3.0 >= 3.18' + run: $TESTCASE_ROOT/_build/install/default/bin/pkg-config --print-errors 'gtksourceview-3.0 >= 3.18' -> process exited with code 0 -> stdout: | gtksourceview-3.0 >= 3.18