From 2c694ac58f1d6e28ca17dfaef1313daaeb7ab128 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 20 Sep 2024 11:47:53 +0200 Subject: [PATCH] redirect PkgConfig stderr (#17020) --- conan/tools/gnu/pkgconfig.py | 10 ++++++++-- test/functional/toolchains/gnu/test_pkg_config.py | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/conan/tools/gnu/pkgconfig.py b/conan/tools/gnu/pkgconfig.py index 9d053819dc4..fb911ba936f 100644 --- a/conan/tools/gnu/pkgconfig.py +++ b/conan/tools/gnu/pkgconfig.py @@ -1,3 +1,4 @@ +import textwrap from io import StringIO from conan.tools.build import cmd_args_to_string @@ -30,8 +31,13 @@ def _parse_output(self, option): env.prepend_path("PKG_CONFIG_PATH", self._pkg_config_path) with env.vars(self._conanfile).apply(): # This way we get the environment from ConanFile, from profile (default buildenv) - output = StringIO() - self._conanfile.run(command, stdout=output, quiet=True) + output, err = StringIO(), StringIO() + ret = self._conanfile.run(command, stdout=output, stderr=err, quiet=True, + ignore_errors=True) + if ret != 0: + raise ConanException(f"PkgConfig failed. Command: {command}\n" + f" stdout:\n{textwrap.indent(output.getvalue(), ' ')}\n" + f" stderr:\n{textwrap.indent(err.getvalue(), ' ')}\n") value = output.getvalue().strip() return value diff --git a/test/functional/toolchains/gnu/test_pkg_config.py b/test/functional/toolchains/gnu/test_pkg_config.py index 5b9105f25fc..6d972f4a130 100644 --- a/test/functional/toolchains/gnu/test_pkg_config.py +++ b/test/functional/toolchains/gnu/test_pkg_config.py @@ -24,6 +24,8 @@ def generate(self): """) c.save({"conanfile.py": conanfile}) c.run("install .", assert_error=True) + assert "PkgConfig failed. Command: pkg-config --libs-only-l something_that_not_exist " \ + "--print-errors" in c.out assert "Package something_that_not_exist was not found" in c.out def test_pc(self):