Skip to content
Open
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
14 changes: 14 additions & 0 deletions conan/internal/api/profile/profile_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ def _parse_tool_requires(doc):
pattern, req_list = "*", br_line
else:
pattern, req_list = tokens
if "[" in pattern:
ConanOutput().warning(
f"Tool requires pattern {pattern} contains a version range, which has no effect. "
f"Only '&' for consumer and '*' as wildcard are supported in this context.",
warn_tag="risk")
refs = [RecipeReference.loads(r.strip()) for r in req_list.split(",")]
result.setdefault(pattern, []).extend(refs)
return result
Expand All @@ -345,6 +350,10 @@ def get_package_name_value(item):
if ":" in item:
tmp = item.split(":", 1)
packagename, item = tmp
if "[" in packagename:
ConanOutput().warning(f"Settings pattern {packagename} contains a version range, which has no effect. "
f"Only '&' for consumer and '*' as wildcard are supported in this context.",
warn_tag="risk")

result_name, result_value = item.split("=", 1)
result_name = result_name.strip()
Expand Down Expand Up @@ -397,6 +406,11 @@ def _get_simple_and_package_tuples(items):
tmp = name.split(":", 1)
ref_name = tmp[0]
name = tmp[1]
if "[" in ref_name:
ConanOutput().warning(
f"Pattern {ref_name} contains a version range, which has no effect. "
f"Only '&' for consumer and '*' as wildcard are supported in this context.",
warn_tag="risk")
package_items[ref_name].append((name, value))
else:
simple_items.append((name, value))
Expand Down
5 changes: 5 additions & 0 deletions conan/internal/model/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ def __init__(self, options=None, options_values=None):
"deprecated, use a pattern like `{}/*:{}` " \
"instead".format(k, package, option)
raise ConanException(msg)
if "[" in package:
msg = (f"Options pattern {package} contains a version range, which has no effect. "
f"Only '&' for consumer and '*' as wildcard are supported in this context.")
from conan.api.output import ConanOutput
ConanOutput().warning(msg, warn_tag="risk")
self._deps_package_options.setdefault(package, _PackageOptions())[option] = v
else:
self._package_options[k] = v
Expand Down
5 changes: 0 additions & 5 deletions conan/internal/model/recipe_ref.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
from conan.api.model import RecipeReference
from conan.api.output import ConanOutput


def ref_matches(ref, pattern, is_consumer):
if not ref or not str(ref):
assert is_consumer
ref = RecipeReference.loads("*/*") # FIXME: ugly
if "[" in pattern:
ConanOutput().warning(f"Pattern {pattern} contains a version range, which has no effect. "
f"Only '&' for consumer and '*' as wildcard are supported "
f"in this context.", warn_tag="risk")
return ref.matches(pattern, is_consumer=is_consumer)
22 changes: 19 additions & 3 deletions test/integration/options/options_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,25 @@ def configure(self):

def test_pattern_version_range_warn(self):
c = TestClient(light=True)
c.save({"conanfile.py": GenConanfile("foo", "1.0")})
c.run("create -o=foo/[>1]:shared=True")
assert "WARN: risk: Pattern foo/[>1] contains a version range" in c.out
profile = textwrap.dedent("""
include(default)

[tool_requires]
fmt/[*]:cmake/3.31.0

[options]
fmt/[*]:shared=True

[settings]
fmt/[*]:compiler.cppstd=17
""")
c.save({
"profile": profile,
"conanfile.py": GenConanfile("fmt", "1.0")})
c.run("create -pr=profile")
assert "WARN: risk: Settings pattern fmt/[*] contains a version range" in c.out
assert "WARN: risk: Options pattern fmt/[*] contains a version range" in c.out
assert "WARN: risk: Tool requires pattern fmt/[*] contains a version range" in c.out

def test_pattern_version_range_wrong_split(self):
c = TestClient(light=True)
Expand Down
Loading