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

[profiles] Raising an error if any profile sections are duplicated #16454

Merged
merged 4 commits into from
Jun 14, 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: 0 additions & 1 deletion conans/client/profile_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ def get_profile(profile_text, base_profile=None):
"options", "conf", "buildenv", "runenv",
"replace_requires", "replace_tool_requires",
"runner"])

# Parse doc sections into Conan model, Settings, Options, etc
settings, package_settings = _ProfileValueParser._parse_settings(doc)
options = Options.loads(doc.options) if doc.options else None
Expand Down
3 changes: 3 additions & 0 deletions conans/util/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def __init__(self, text, allowed_fields=None, strip_comments=False):
if self._allowed_fields and field not in self._allowed_fields:
raise ConanException("ConfigParser: Unrecognized field '%s'" % field)
current_lines = []
# Duplicated section
if field in self._sections:
raise ConanException(f"ConfigParser: Duplicated section: [{field}]")
self._sections[field] = current_lines
else:
if current_lines is None:
Expand Down
39 changes: 39 additions & 0 deletions test/integration/configuration/profile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,3 +574,42 @@ def configure(self):
client.save({"conanfile.py": conanfile, "my_profile.txt": profile})
client.run("install . --profile my_profile.txt")
assert "I'm hello and my build type is Debug" in client.out


def test_consumer_invalid_profile_multiple_groups():
"""
Issue related: https://github.com/conan-io/conan/issues/16448
"""
client = TestClient()
conanfile = GenConanfile(name="hello", version="1.0").with_settings("os", "arch",
"build_type", "compiler")
prof1 = textwrap.dedent("""\
[settings]
arch=x86_64
os=Linux
build_type=Release
compiler=clang
compiler.libcxx=libstdc++11
compiler.version=18
compiler.cppstd=20

[conf]
tools.build:compiler_executables={'c': '/usr/bin/clang-18', 'cpp': '/usr/bin/clang++-18'}

[settings]
# Empty and duplicated section

[options]
package/*:option=Whatever

[conf]
# Another one
""")
client.save({
"conanfile.py": conanfile,
"myprofs/myprofile": prof1
})
client.run("build . --profile:host myprofs/myprofile -g CMakeToolchain",
assert_error=True)
assert ("ERROR: Error reading 'myprofs/myprofile' profile: ConfigParser: "
"Duplicated section: [settings]") in client.out