Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions conan/internal/graph/profile_node_definer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def initialize_conanfile_profile(conanfile, profile_build, profile_host, base_co
else:
conanfile.settings_target = parent.settings_target.copy()

if parent is not None:
conanfile.settings_consumer = getattr(parent, "settings_consumer", parent.settings)


def _per_package_settings(conanfile, profile, ref):
# Prepare the settings for the loaded conanfile
Expand Down
78 changes: 78 additions & 0 deletions test/integration/package_id/compatible_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,3 +724,81 @@ def libc_compat(conanfile):
tc.run("install --requires=dep/1.0 -s=libc_version=3 -s=compiler.cppstd=14")
assert f"dep/1.0: Found compatible package '{dep_package_id}': compiler.cppstd=17, " \
f"libc_version=2" in tc.out


class TestCompatibleFlags:
def test_compatible_flags(self):
""" The compiler flags depends on the consumer settings, not on the binary compatible
settings used to create that compatible binary. This test shows how the new info
can be used to parameterize on the consumer settings
"""
c = TestClient(light=True)
conanfile = textwrap.dedent("""
from conan import ConanFile

class Pkg(ConanFile):
settings = "os"

def compatibility(self):
if self.settings.os == "Windows":
return [{"settings": [("os", "Linux")]}]

def package_info(self):
if self.settings_consumer.os == "Linux":
self.cpp_info.cxxflags = ["-mylinuxflag"]
elif self.settings_consumer.os == "Windows":
self.cpp_info.cxxflags = ["-mywinflag"]
""")
consumer = textwrap.dedent("""
from conan import ConanFile
class Pkg(ConanFile):
settings = "os"
requires = "pkg/0.1"
def generate(self):
flags = self.dependencies["pkg"].cpp_info.cxxflags
self.output.info(f"FLAGS: {flags}!!!")
""")
c.save({"pkg/conanfile.py": conanfile,
"consumer/conanfile.py": consumer})

c.run("create pkg --name=pkg --version=0.1 -s os=Linux")

c.run("install consumer -s os=Linux")
assert "conanfile.py: FLAGS: ['-mylinuxflag']!!!" in c.out
c.run("install consumer -s os=Windows")
assert "conanfile.py: FLAGS: ['-mywinflag']!!!" in c.out

def test_compatible_flags_direct(self):
""" same as above but without compatibility
"""
c = TestClient(light=True)
conanfile = textwrap.dedent("""
from conan import ConanFile

class Pkg(ConanFile):
settings = "os"

def package_info(self):
if self.settings_consumer.os == "Linux":
self.cpp_info.cxxflags = ["-mylinuxflag"]
elif self.settings_consumer.os == "Windows":
self.cpp_info.cxxflags = ["-mywinflag"]
""")
consumer = textwrap.dedent("""
from conan import ConanFile
class Pkg(ConanFile):
settings = "os"
requires = "pkg/0.1"
def generate(self):
flags = self.dependencies["pkg"].cpp_info.cxxflags
self.output.info(f"FLAGS: {flags}!!!")
""")
c.save({"pkg/conanfile.py": conanfile,
"consumer/conanfile.py": consumer})

c.run("create pkg --name=pkg --version=0.1 -s os=Linux")

c.run("install consumer -s os=Linux")
assert "conanfile.py: FLAGS: ['-mylinuxflag']!!!" in c.out
c.run("install consumer -s os=Windows -s pkg*:os=Linux")
assert "conanfile.py: FLAGS: ['-mywinflag']!!!" in c.out
Loading