Skip to content

Commit

Permalink
[Bugfix] Option --require-override is not working for `conanfile.tx…
Browse files Browse the repository at this point in the history
…t` (#10013)

* Added test to reproduce issue #10010

* Fixed bug override_requires when using conanfile.txt
  • Loading branch information
franramirez688 committed Nov 15, 2021
1 parent f31fdba commit d27b8b3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion conans/client/graph/graph_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def _load_root_consumer(self, path, graph_lock, profile, ref, require_overrides)
ref.user, ref.channel, validate=False)
root_node = Node(ref, conanfile, context=CONTEXT_HOST, recipe=RECIPE_CONSUMER, path=path)
else:
conanfile = self._loader.load_conanfile_txt(path, profile, ref=ref)
conanfile = self._loader.load_conanfile_txt(path, profile, ref=ref,
require_overrides=require_overrides)
root_node = Node(None, conanfile, context=CONTEXT_HOST, recipe=RECIPE_CONSUMER,
path=path)

Expand Down
8 changes: 7 additions & 1 deletion conans/client/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,20 @@ def load_conanfile(self, conanfile_path, profile, ref, lock_python_requires=None
except Exception as e: # re-raise with file name
raise ConanException("%s: %s" % (conanfile_path, str(e)))

def load_conanfile_txt(self, conan_txt_path, profile_host, ref=None):
def load_conanfile_txt(self, conan_txt_path, profile_host, ref=None, require_overrides=None):
if not os.path.exists(conan_txt_path):
raise NotFoundException("Conanfile not found!")

contents = load(conan_txt_path)
path, basename = os.path.split(conan_txt_path)
display_name = "%s (%s)" % (basename, ref) if ref and ref.name else basename
conanfile = self._parse_conan_txt(contents, path, display_name, profile_host)

if require_overrides is not None:
for req_override in require_overrides:
req_override = ConanFileReference.loads(req_override)
conanfile.requires.override(req_override)

return conanfile

def _parse_conan_txt(self, contents, path, display_name, profile):
Expand Down
11 changes: 11 additions & 0 deletions conans/test/integration/command/install/install_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,17 @@ def test_install_cli_override(self, client):
client.run("install . --require-override=zlib/2.0")
assert "zlib/2.0: Already installed" in client.out

def test_install_cli_override_in_conanfile_txt(self, client):
client.save({"conanfile.py": GenConanfile()})
client.run("create . zlib/1.0@")
client.run("create . zlib/2.0@")
client.save({"conanfile.txt": textwrap.dedent("""\
[requires]
zlib/1.0
""")}, clean_first=True)
client.run("install . --require-override=zlib/2.0")
assert "zlib/2.0: Already installed" in client.out

def test_install_ref_cli_override(self, client):
client.save({"conanfile.py": GenConanfile()})
client.run("create . zlib/1.0@")
Expand Down

0 comments on commit d27b8b3

Please sign in to comment.