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

define install_folder to be usable by custom generators #5569

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions conans/client/manager.py
Expand Up @@ -20,6 +20,7 @@ def deps_install(app, ref_or_path, install_folder, graph_info, remotes=None, bui
manifest_interactive=False, generators=None, no_imports=False,
create_reference=None, keep_build=False, use_lock=False, recorder=None):
""" Fetch and build all dependencies for the given reference
:param app: The ConanApp instance with all collaborators
@param ref_or_path: ConanFileReference or path to user space conanfile
@param install_folder: where the output files will be saved
@param build_modes: List of build_modes specified
Expand All @@ -31,6 +32,7 @@ def deps_install(app, ref_or_path, install_folder, graph_info, remotes=None, bui
@param generators: List of generators from command line. If False, no generator will be
written
@param no_imports: Install specified packages but avoid running imports

"""
out, user_io, graph_manager, cache = app.out, app.user_io, app.graph_manager, app.cache
remote_manager, hook_manager = app.remote_manager, app.hook_manager
Expand Down Expand Up @@ -77,6 +79,7 @@ def deps_install(app, ref_or_path, install_folder, graph_info, remotes=None, bui
manifest_manager.print_log()

if install_folder:
conanfile.install_folder = install_folder
# Write generators
output = conanfile.output if conanfile.display_name != "virtual" else out
if generators is not False:
Expand Down
25 changes: 25 additions & 0 deletions conans/test/functional/generators/custom_generator_test.py
@@ -1,4 +1,5 @@
import os
import textwrap
import unittest

from conans.model.ref import ConanFileReference
Expand Down Expand Up @@ -147,3 +148,27 @@ class MyCustomGeneratorWithTemplatePackage(ConanFile):
client.run("install gen/0.1@user/stable -g=MyCustomTemplateGenerator")
generated = load(os.path.join(client.current_folder, "customfile.gen"))
self.assertEqual(generated, "Template: Hello")

def install_folder_test(self):
# https://github.com/conan-io/conan/issues/5568
templated_generator = textwrap.dedent("""
from conans import ConanFile
from conans.model import Generator
class MyGenerator(Generator):
@property
def filename(self):
return "customfile.gen"
@property
def content(self):
return self.conanfile.install_folder

class MyCustomGenerator(ConanFile):
pass
""")
client = TestClient()
client.save({CONANFILE: templated_generator, "mytemplate.txt": "Template: %s"})
client.run("create . gen/0.1@user/stable")
client.run("install gen/0.1@user/stable -g=MyGenerator")
generated = load(os.path.join(client.current_folder, "customfile.gen"))
self.assertEqual(generated, client.current_folder)