Skip to content

Commit

Permalink
Order conf items when dumping them (#15356)
Browse files Browse the repository at this point in the history
* Order confs con dump()

* Update tests
  • Loading branch information
AbrilRBS authored Dec 27, 2023
1 parent 60438d0 commit 6fd6475
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion conans/model/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def dumps(self):
"""
Returns a string with the format ``name=conf-value``
"""
return "\n".join([v.dumps() for v in reversed(self._values.values())])
return "\n".join([v.dumps() for v in sorted(self._values.values(), key=lambda x: x._name)])

def serialize(self):
"""
Expand Down
19 changes: 17 additions & 2 deletions conans/test/integration/package_id/package_id_and_confs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import pytest

from conans.test.utils.tools import TestClient, NO_SETTINGS_PACKAGE_ID
from conans.test.utils.tools import GenConanfile, TestClient, NO_SETTINGS_PACKAGE_ID

PKG_ID_NO_CONF = "ebec3dc6d7f6b907b3ada0c3d3cdc83613a2b715"
PKG_ID_1 = "89d32f25195a77f4ae2e77414b870781853bdbc1"
PKG_ID_2 = "7f9ed92704709f56ecc7b133322479caf3ffd7ad"
PKG_ID_3 = "45b796ec237c7e2399944e79bee49b56fd022067"
PKG_ID_3 = "a9f917f3bad3b48b5bceae70214764274ccd6337"


@pytest.mark.parametrize("package_id_confs, package_id", [
Expand Down Expand Up @@ -98,3 +98,18 @@ class Pkg(ConanFile):
assert "tools.build:cxxflags" not in client.out


@pytest.mark.parametrize("conf,pkgconf", [
("user.foo:value=1\nuser.bar:value=2", "['user.foo:value', 'user.bar:value']"),
("user.foo:value=1\nuser.bar:value=2", "['user.bar:value', 'user.foo:value']"),
("user.bar:value=2\nuser.foo:value=1", "['user.foo:value', 'user.bar:value']"),
("user.bar:value=2\nuser.foo:value=1", "['user.bar:value', 'user.foo:value']"),
])
def test_package_id_order(conf, pkgconf):
"""Ensure the order of the definitions in the conf file does not affect the package_id"""
tc = TestClient(light=True)
tc.save({"profile": f"[conf]\ntools.info.package_id:confs={pkgconf}\n" +
conf,
"conanfile.py": GenConanfile("pkg", "1.0")})
tc.run("create . -pr=profile")
# They should all have the same pkg id - note that this did not happen before 2.0.17
tc.assert_listed_binary({"pkg/1.0": ("43227c40b8725e89d30a9f97c0652629933a3685", "Build")})
2 changes: 1 addition & 1 deletion conans/test/unittests/model/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ def test_compose_conf_complex():
c2.loads(text)
c.update_conf_definition(c2)
expected_text = textwrap.dedent("""\
user.company.cpu:jobs=5
user.company.build:ccflags=--m otherflag
user.company.cpu:jobs=5
user.company.list:objs=[0, 1, 2, 3, 4, 'mystr', {'a': 1}, 5, 6, {'b': 2}]
user.company.network:proxies={'url': 'http://api.site.com/apiv2'}
zlib:user.company.check:shared=!
Expand Down

0 comments on commit 6fd6475

Please sign in to comment.