Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build_id() and package_id() modification settings with nested subsettings #15439

Merged
merged 7 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions conans/model/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def copy_conaninfo_settings(self):
else:
result._definition = {k: v.copy_conaninfo_settings()
for k, v in self._definition.items()}
result._definition["ANY"] = Settings()
return result

def __bool__(self):
Expand Down
35 changes: 35 additions & 0 deletions conans/test/integration/package_id/build_id_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,41 @@ def build(self):
client.run("create . --name=pkg --version=0.1 ", assert_error=True)
assert "ERROR: pkg/0.1: Error in build() method, line 5" in client.out

def test_any_os_arch(self):
conanfile_os = textwrap.dedent("""
import os
from conan import ConanFile

class MyTest(ConanFile):
name = "pkg"
version = "0.1"
settings = "os", "arch", "build_type", "compiler"

def build_id(self):
self.info_build.settings.build_type = "AnyValue"
self.info_build.settings.os = "AnyValue"
self.info_build.settings.arch = "AnyValue"
self.info_build.settings.compiler = "AnyValue"

def build(self):
self.output.info("Building my code!")

def package(self):
self.output.info("Packaging %s-%s!" % (self.settings.os, self.settings.arch))
""")

client = TestClient()
client.save({"conanfile.py": conanfile_os})
client.run("create . -s os=Windows -s arch=x86_64 -s build_type=Release")
assert "pkg/0.1: Calling build()" in client.out
assert "Building my code!" in client.out
assert "Packaging Windows-x86_64!" in client.out
# Others must not build
client.run("create . -s os=Linux -s arch=x86 -s build_type=Debug")
assert "pkg/0.1: Calling build()" not in client.out
assert "Building my code!" not in client.out
assert "Packaging Linux-x86!" in client.out


def test_remove_require():
c = TestClient()
Expand Down
8 changes: 4 additions & 4 deletions conans/test/integration/package_id/package_id_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class TestConan(ConanFile):

def package_id(self):
self.info.settings.arch = "kk=kk"
self.info.settings.os = "yy=yy"
""")

client = TestClient(default_server_user=True)
Expand Down Expand Up @@ -159,8 +160,7 @@ def package_id(self):


def test_package_id_validate_settings():
""" ``self.info`` has some validation, the first time it executes
https://github.com/conan-io/conan/issues/12693
""" ``self.info`` has no validation, as it allows to be mutated
"""
conanfile = textwrap.dedent("""
from conan import ConanFile
Expand All @@ -173,8 +173,8 @@ def package_id(self):
""")
c = TestClient()
c.save({"conanfile.py": conanfile})
c.run("create . --name=pkg --version=0.1", assert_error=True)
assert "ConanException: Invalid setting 'DONT_EXIST' is not a valid 'settings.os' value" in c.out
c.run("create . --name=pkg --version=0.1")
# It used to fail,


class TestBuildRequiresHeaderOnly:
Expand Down