Skip to content

Commit

Permalink
Relax lockfiles config_options and configure options evaluation (#7993)
Browse files Browse the repository at this point in the history
* PoC of not running configure for lockfiles

* trying another approach

* checking None options

* fixing tests

* review

* fix broken test

* Update conans/client/conanfile/configure.py

Co-authored-by: Javier G. Sogo <jgsogo@gmail.com>

Co-authored-by: Javier G. Sogo <jgsogo@gmail.com>
  • Loading branch information
memsharded and jgsogo committed Dec 1, 2020
1 parent 5e0add2 commit 57336f5
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 15 deletions.
10 changes: 10 additions & 0 deletions conans/client/graph/graph_binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,16 @@ def evaluate_graph(self, deps_graph, build_mode, update, remotes, nodes_subset=N
for node in deps_graph.ordered_iterate(nodes_subset=nodes_subset):
self._propagate_options(node)

# Make sure that locked options match
if (node.graph_lock_node is not None and
node.graph_lock_node.options is not None and
node.conanfile.options.values != node.graph_lock_node.options):
raise ConanException("{}: Locked options do not match computed options\n"
"Locked options:\n{}\n"
"Computed options:\n{}".format(node.ref,
node.graph_lock_node.options,
node.conanfile.options.values))

self._compute_package_id(node, default_package_id_mode, default_python_requires_id_mode)
if node.recipe in (RECIPE_CONSUMER, RECIPE_VIRTUAL):
continue
Expand Down
1 change: 0 additions & 1 deletion conans/model/graph_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ def pre_lock_node(self, node):
node.graph_lock_node = locked_node
if locked_node.options is not None: # This was a "partial" one, not a "base" one
node.conanfile.options.values = locked_node.options
node.conanfile.options.freeze()

def lock_node(self, node, requires, build_requires=False):
""" apply options and constraints on requirements of a node, given the information from
Expand Down
19 changes: 19 additions & 0 deletions conans/model/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def __delattr__(self, attr):
def clear(self):
self._dict.clear()

def __ne__(self, other):
return not self.__eq__(other)

def __eq__(self, other):
return self._dict == other._dict

def __setattr__(self, attr, value):
if attr[0] == "_":
return super(PackageOptionValues, self).__setattr__(attr, value)
Expand Down Expand Up @@ -231,6 +237,19 @@ def remove(self, name, package=None):
else:
self._package_values.remove(name)

def __ne__(self, other):
return not self.__eq__(other)

def __eq__(self, other):
if not self._package_values == other._package_values:
return False
# It is possible that the entry in the dict is not defined
for key, pkg_values in self._reqs_options.items():
other_values = other[key]
if not pkg_values == other_values:
return False
return True

def __repr__(self):
return self.dumps()

Expand Down
30 changes: 16 additions & 14 deletions conans/test/functional/graph_lock/dynamic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,18 +440,20 @@ def configure(self):
def _check(self):
client = self.client

def _validate():
client.run("lock create conanfile.py --name=LibD --version=1.0 --lockfile=libb.lock "
"--lockfile-out=libd.lock", assert_error=True)
expected = ("LibA/1.0: LibC/1.0 tried to change LibA/1.0 option myoption to False\n"
"but it was already defined as True")
self.assertIn(expected, client.out)

client.save({"conanfile.py": GenConanfile().with_require("LibB/1.0")
.with_require("LibC/1.0")})
_validate()
client.save({"conanfile.py": GenConanfile().with_requires("LibB/1.0", "LibC/1.0")})
client.run("lock create conanfile.py --name=LibD --version=1.0 --lockfile=libb.lock "
"--lockfile-out=libd.lock", assert_error=True)
expected = textwrap.dedent("""\
ERROR: LibA/1.0: Locked options do not match computed options
Locked options:
myoption=True
Computed options:
myoption=False""")
self.assertIn(expected, client.out)

# Order of LibC, LibB does matter, in this case it will not raise
client.save({"conanfile.py": GenConanfile().with_requires("LibC/1.0", "LibB/1.0")})

# Order of LibC, LibB does matter
client.save({"conanfile.py": GenConanfile().with_require("LibC/1.0")
.with_require("LibB/1.0")})
_validate()
client.run("lock create conanfile.py --name=LibD --version=1.0 --lockfile=libb.lock "
"--lockfile-out=libd.lock")
self.assertIn("LibC/1.0:777a7717c781c687b6d0fecc05d3818d0a031f92 - Missing", client.out)
68 changes: 68 additions & 0 deletions conans/test/functional/graph_lock/graph_lock_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,74 @@ def test_base_options(self):
pkg_lock = client.load("pkg.lock")
self.assertIn('"options": "shared=False"', pkg_lock)

def test_config_option(self):
# https://github.com/conan-io/conan/issues/7991
client = TestClient()
pahomqttc = textwrap.dedent("""
from conans import ConanFile
class PahoMQTCC(ConanFile):
options = {"shared": [True, False]}
default_options = {"shared": False}
def config_options(self):
# This is weaker than "configure()", will be overwritten by downstream
self.options.shared = True
""")

pahomqttcpp = textwrap.dedent("""
from conans import ConanFile
class Meta(ConanFile):
requires = "pahomqttc/1.0"
def configure(self):
self.options["pahomqttc"].shared = False
""")

client.save({"pahomqttc/conanfile.py": pahomqttc,
"pahomqttcpp/conanfile.py": pahomqttcpp,
"consumer/conanfile.txt": "[requires]\npahomqttcpp/1.0"})
client.run("export pahomqttc pahomqttc/1.0@")
client.run("export pahomqttcpp pahomqttcpp/1.0@")

client.run("install consumer/conanfile.txt --build -o paho-mqtt-c:shared=False")
lockfile = client.load("conan.lock")
self.assertIn('"options": "pahomqttc:shared=False"', lockfile)
self.assertNotIn('shared=True', lockfile)
client.run("install consumer/conanfile.txt --lockfile=conan.lock")

def test_configure(self):
# https://github.com/conan-io/conan/issues/7991
client = TestClient()
pahomqttc = textwrap.dedent("""
from conans import ConanFile
class PahoMQTCC(ConanFile):
options = {"shared": [True, False]}
default_options = {"shared": False}
def configure(self):
self.options.shared = True
""")

pahomqttcpp = textwrap.dedent("""
from conans import ConanFile
class Meta(ConanFile):
requires = "pahomqttc/1.0"
def configure(self):
self.options["pahomqttc"].shared = False
""")

client.save({"pahomqttc/conanfile.py": pahomqttc,
"pahomqttcpp/conanfile.py": pahomqttcpp,
"consumer/conanfile.txt": "[requires]\npahomqttcpp/1.0"})
client.run("export pahomqttc pahomqttc/1.0@")
client.run("export pahomqttcpp pahomqttcpp/1.0@")

client.run("install consumer/conanfile.txt --build -o paho-mqtt-c:shared=False")
lockfile = client.load("conan.lock")
self.assertIn('"options": "pahomqttc:shared=True"', lockfile)
# Check the trailing ", to not get the profile one
self.assertNotIn('shared=False"', lockfile)
client.run("install consumer/conanfile.txt --lockfile=conan.lock")


class GraphInstallArgumentsUpdated(unittest.TestCase):

Expand Down

0 comments on commit 57336f5

Please sign in to comment.