diff --git a/conans/client/loader.py b/conans/client/loader.py index 82d10a097d6..3bab76cbaaa 100644 --- a/conans/client/loader.py +++ b/conans/client/loader.py @@ -176,11 +176,16 @@ def _initialize_conanfile(conanfile, profile): tmp_settings = profile.processed_settings.copy() package_settings_values = profile.package_settings_values if package_settings_values: + # First, try to get a match directly by name (without needing *) + # TODO: Conan 2.0: We probably want to remove this, and leave a pure fnmatch pkg_settings = package_settings_values.get(conanfile.name) - if pkg_settings is None: - # FIXME: This seems broken for packages without user/channel - ref = "%s/%s@%s/%s" % (conanfile.name, conanfile.version, - conanfile._conan_user, conanfile._conan_channel) + if pkg_settings is None: # If there is not exact match by package name, do fnmatch + if conanfile._conan_user is not None: + ref = "%s/%s@%s/%s" % (conanfile.name, conanfile.version, + conanfile._conan_user, conanfile._conan_channel) + else: + ref = "%s/%s" % (conanfile.name, conanfile.version) + for pattern, settings in package_settings_values.items(): if fnmatch.fnmatchcase(ref, pattern): pkg_settings = settings diff --git a/conans/test/functional/configuration/profile_test.py b/conans/test/functional/configuration/profile_test.py index 3811d79732a..7831dd9f8bd 100644 --- a/conans/test/functional/configuration/profile_test.py +++ b/conans/test/functional/configuration/profile_test.py @@ -1,5 +1,6 @@ import os import platform +import textwrap import unittest from collections import OrderedDict from textwrap import dedent @@ -314,6 +315,30 @@ def test_install_profile_package_settings(self): self.assertNotIn("gcc", info) self.assertNotIn("libcxx", info) + def test_package_settings_no_user_channel(self): + conanfile = textwrap.dedent(""" + from conans import ConanFile + class Pkg(ConanFile): + settings = "os" + def build(self): + self.output.info("SETTINGS! os={}!!".format(self.settings.os)) + """) + profile = textwrap.dedent(""" + [settings] + os=Windows + # THIS FAILED BEFORE WITH NO MATCH + mypkg/0.1:os=Linux + mypkg/0.1@user/channel:os=FreeBSD + """) + client = TestClient() + client.save({"conanfile.py": conanfile, + "profile": profile}) + + client.run("create . mypkg/0.1@user/channel -pr=profile") + assert "mypkg/0.1@user/channel: SETTINGS! os=FreeBSD!!" in client.out + client.run("create . mypkg/0.1@ -pr=profile") + assert "mypkg/0.1: SETTINGS! os=Linux!!" in client.out + @pytest.mark.tool_compiler def test_install_profile_options(self): files = cpp_hello_conan_files("Hello0", "0.1", build=False)