Skip to content

Commit

Permalink
fix deploy absolute folders (conan-io#15244)
Browse files Browse the repository at this point in the history
* fix deploy absolute folders

* fix tests
  • Loading branch information
memsharded authored Dec 11, 2023
1 parent 63ee9c7 commit 1d058e9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions conan/tools/env/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ def deploy_base_folder(self, package_folder, deploy_folder):
if v is _EnvVarPlaceHolder:
continue
rel_path = os.path.relpath(v, package_folder)
if rel_path.startswith(".."):
# If it is pointing to a folder outside of the package, then do not relocate
continue
self._values[i] = os.path.join(deploy_folder, rel_path)

def set_relative_base_folder(self, folder):
Expand Down
3 changes: 3 additions & 0 deletions conans/model/build_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ def set_relative_base_folder(self, folder):
def deploy_base_folder(self, package_folder, deploy_folder):
def relocate(el):
rel_path = os.path.relpath(el, package_folder)
if rel_path.startswith(".."):
# If it is pointing to a folder outside of the package, then do not relocate
return el
return os.path.join(deploy_folder, rel_path)

for varname in _DIRS_VAR_NAMES:
Expand Down
30 changes: 30 additions & 0 deletions conans/test/functional/command/test_install_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,33 @@ def deploy(graph, output_folder, **kwargs):
tc.run(f"install . --deployer=my_deploy -of='{tmp_folder}' --deployer-folder='{deployer_output}'")
assert f"Deployer output: {deployer_output}" in tc.out
assert f"Deployer output: {tmp_folder}" not in tc.out


def test_not_deploy_absolute_paths():
""" Absolute paths, for system packages, don't need to be relativized
https://github.com/conan-io/conan/issues/15242
"""
c = TestClient()
some_abs_path = temp_folder().replace("\\", "/")
conanfile = textwrap.dedent(f"""
from conan import ConanFile
class Pkg(ConanFile):
name = "pkg"
version = "1.0"
def package_info(self):
self.cpp_info.includedirs = ["{some_abs_path}/myusr/include"]
self.cpp_info.libdirs = ["{some_abs_path}/myusr/lib"]
self.buildenv_info.define_path("MYPATH", "{some_abs_path}/mypath")
""")
c.save({"conanfile.py": conanfile})
c.run("create .")

# if we deploy one --requires, we get that package
c.run("install --requires=pkg/1.0 --deployer=full_deploy -g CMakeDeps -g CMakeToolchain "
"-s os=Linux -s:b os=Linux -s arch=x86_64 -s:b arch=x86_64")
data = c.load("pkg-release-x86_64-data.cmake")
assert f'set(pkg_INCLUDE_DIRS_RELEASE "{some_abs_path}/myusr/include")' in data
assert f'set(pkg_LIB_DIRS_RELEASE "{some_abs_path}/myusr/lib")' in data

env = c.load("conanbuildenv-release-x86_64.sh")
assert f'export MYPATH="{some_abs_path}/mypath"' in env

0 comments on commit 1d058e9

Please sign in to comment.