Skip to content

Commit

Permalink
fix per-package settings exact match for packages without user/channel (
Browse files Browse the repository at this point in the history
#8281)

* fix per-package settings exact match for packages without user/channel

* fix test
  • Loading branch information
memsharded authored Jan 11, 2021
1 parent 8f24eb0 commit 02366ef
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
13 changes: 9 additions & 4 deletions conans/client/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions conans/test/functional/configuration/profile_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import platform
import textwrap
import unittest
from collections import OrderedDict
from textwrap import dedent
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 02366ef

Please sign in to comment.