diff --git a/conan/tools/env/environment.py b/conan/tools/env/environment.py index 10936bfc2ae..aac022c1f5b 100644 --- a/conan/tools/env/environment.py +++ b/conan/tools/env/environment.py @@ -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): diff --git a/conans/model/build_info.py b/conans/model/build_info.py index 9f7dd2d10eb..ca058c798de 100644 --- a/conans/model/build_info.py +++ b/conans/model/build_info.py @@ -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: diff --git a/conans/test/functional/command/test_install_deploy.py b/conans/test/functional/command/test_install_deploy.py index e45d70ad1b6..f9fd31d42af 100644 --- a/conans/test/functional/command/test_install_deploy.py +++ b/conans/test/functional/command/test_install_deploy.py @@ -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