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

fix deployers not creating output_folder #11977

Merged
merged 4 commits into from
Sep 5, 2022
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
8 changes: 5 additions & 3 deletions conan/api/subapi/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from conans.client.installer import BinaryInstaller, call_system_requirements
from conans.client.loader import load_python_file
from conans.errors import ConanException, ConanInvalidConfiguration
from conans.util.files import rmdir
from conans.util.files import rmdir, mkdir


class InstallAPI:
Expand Down Expand Up @@ -46,8 +46,10 @@ def install_consumer(self, deps_graph, generators=None, source_folder=None, outp
conanfile.folders.set_base_folders(source_folder, output_folder)

# The previous .set_base_folders has already decided between the source_folder and output
base_folder = conanfile.folders.base_build
_do_deploys(self.conan_api, deps_graph, deploy, base_folder)
if deploy:
base_folder = conanfile.folders.base_build
mkdir(base_folder)
_do_deploys(self.conan_api, deps_graph, deploy, base_folder)

conanfile.generators = list(set(conanfile.generators).union(generators or []))
app = ConanApp(self.conan_api.cache_folder)
Expand Down
15 changes: 15 additions & 0 deletions conan/tools/env/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ def get_value(self, subsystem, pathsep):
previous_value = os.getenv(self._name)
return self.get_str(previous_value, subsystem, pathsep)

def deploy_base_folder(self, package_folder, deploy_folder):
"""Make the path relative to the deploy_folder"""
if not self._path:
return
for i, v in enumerate(self._values):
if v is _EnvVarPlaceHolder:
continue
rel_path = os.path.relpath(v, package_folder)
self._values[i] = os.path.join(deploy_folder, rel_path)


class Environment:
"""
Expand Down Expand Up @@ -286,6 +296,11 @@ def vars(self, conanfile, scope="build"):
"""
return EnvVars(conanfile, self, scope)

def deploy_base_folder(self, package_folder, deploy_folder):
"""Make the paths relative to the deploy_folder"""
for varvalues in self._values.values():
varvalues.deploy_base_folder(package_folder, deploy_folder)


class EnvVars:
"""
Expand Down
2 changes: 2 additions & 0 deletions conans/model/conan_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,6 @@ def __repr__(self):

def set_deploy_folder(self, deploy_folder):
self.cpp_info.deploy_base_folder(self.package_folder, deploy_folder)
self.buildenv_info.deploy_base_folder(self.package_folder, deploy_folder)
self.runenv_info.deploy_base_folder(self.package_folder, deploy_folder)
self.folders.set_base_package(deploy_folder)
28 changes: 25 additions & 3 deletions conans/test/functional/command/test_install_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from conans.test.assets.cmake import gen_cmakelists
from conans.test.assets.genconanfile import GenConanfile
from conans.test.assets.sources import gen_function_cpp
from conans.test.utils.test_files import temp_folder
from conans.test.utils.tools import TestClient
from conans.util.files import save

Expand Down Expand Up @@ -45,6 +46,25 @@ def deploy(conanfile, output_folder, **kwargs):
c.run_command("cmake --build . --config Release")


def test_copy_files_deploy():
c = TestClient()
deploy = textwrap.dedent("""
import os, shutil

def deploy(conanfile, output_folder, **kwargs):
for r, d in conanfile.dependencies.items():
bindir = os.path.join(d.package_folder, "bin")
for f in os.listdir(bindir):
shutil.copy2(os.path.join(bindir, f), os.path.join(output_folder, f))
""")
c.save({"conanfile.txt": "[requires]\nhello/0.1",
"deploy.py": deploy,
"hello/conanfile.py": GenConanfile("hello", "0.1").with_package_file("bin/file.txt",
"content!!")})
c.run("create hello")
c.run("install . --deploy=deploy.py -of=mydeploy")


def test_multi_deploy():
""" check that we can add more than 1 deployer in the command line, both in local folders
and in cache.
Expand Down Expand Up @@ -168,9 +188,11 @@ def test_deploy_editable():
"src/include/hi.h": "hi"})
c.run("editable add . pkg/1.0")

c.run("install --requires=pkg/1.0 --deploy=full_deploy --output-folder=output")
header = c.load("output/host/pkg/1.0/src/include/hi.h")
assert "hi" in header
# If we don't change to another folder, the full_deploy will be recursive and fail
with c.chdir(temp_folder()):
c.run("install --requires=pkg/1.0 --deploy=full_deploy --output-folder=output")
header = c.load("output/host/pkg/1.0/src/include/hi.h")
assert "hi" in header


def test_deploy_single_package():
Expand Down