Skip to content

Commit

Permalink
fix issue with PkgConfigDeps not creating xxx.pc in build context (#1…
Browse files Browse the repository at this point in the history
…2712)

this stills @memsharded's work on
#12675

Co-authored-by: ericLemanissier <[email protected]>
  • Loading branch information
franramirez688 and ericLemanissier authored Dec 20, 2022
1 parent ead8f79 commit 17e487b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conan/tools/gnu/pkgconfigdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def content(self):
# Require is not used at the moment, but its information could be used,
# and will be used in Conan 2.0
# Filter the build_requires not activated with PkgConfigDeps.build_context_activated
if dep.is_build_context and dep.ref.name not in self.build_context_activated:
if require.build and dep.ref.name not in self.build_context_activated:
continue

pc_generator = _PCGenerator(self._conanfile, dep, build_context_suffix=self.build_context_suffix)
Expand Down
45 changes: 45 additions & 0 deletions conans/test/integration/toolchains/gnu/test_pkgconfigdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,3 +725,48 @@ def generate(self):
client.save({"conanfile.py": conanfile}, clean_first=True)
client.run("install . -pr:h default -pr:b default", assert_error=True)
assert "The packages ['tool'] exist both as 'require' and as 'build require'" in client.out


def test_error_missing_pc_build_context():
"""
PkgConfigDeps was failing, not generating the zlib.pc in the
build context, for a test_package that both requires(example/1.0) and
tool_requires(example/1.0), which depends on zlib
# https://github.com/conan-io/conan/issues/12664
"""
c = TestClient()
example = textwrap.dedent("""
import os
from conan import ConanFile
class Example(ConanFile):
name = "example"
version = "1.0"
requires = "game/1.0"
generators = "PkgConfigDeps"
settings = "build_type"
def build(self):
assert os.path.exists("math.pc")
assert os.path.exists("engine.pc")
assert os.path.exists("game.pc")
""")
c.save({"math/conanfile.py": GenConanfile("math", "1.0").with_settings("build_type"),
"engine/conanfile.py": GenConanfile("engine", "1.0").with_settings("build_type")
.with_require("math/1.0"),
"game/conanfile.py": GenConanfile("game", "1.0").with_settings("build_type")
.with_requires("engine/1.0"),
"example/conanfile.py": example,
"example/test_package/conanfile.py": GenConanfile().with_requires("example/1.0")
.with_build_requires("example/1.0")
.with_test("pass")})
c.run("create math")
c.run("create engine")
c.run("create game")
# This used to crash because of the assert inside the build() method
c.run("create example -pr:b=default -pr:h=default")
# Now make sure we can actually build with build!=host context
# The debug binaries are missing, so adding --build=missing
c.run("create example -pr:b=default -pr:h=default -s:h build_type=Debug --build=missing "
"--build=example")

assert "example/1.0: Package '5949422937e5ea462011eb7f38efab5745e4b832' created" in c.out
assert "example/1.0: Package '03ed74784e8b09eda4f6311a2f461897dea57a7e' created" in c.out

0 comments on commit 17e487b

Please sign in to comment.