Skip to content

Commit

Permalink
redirect PkgConfig stderr (#17020)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored Sep 20, 2024
1 parent ac8db86 commit 2c694ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions conan/tools/gnu/pkgconfig.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import textwrap
from io import StringIO

from conan.tools.build import cmd_args_to_string
Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions test/functional/toolchains/gnu/test_pkg_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 2c694ac

Please sign in to comment.