diff --git a/conan/tools/env/environment.py b/conan/tools/env/environment.py index 18e40ad617d..10936bfc2ae 100644 --- a/conan/tools/env/environment.py +++ b/conan/tools/env/environment.py @@ -465,6 +465,7 @@ def save_ps1(self, file_location, generate_deactivate=True,): result.append('if (Test-Path env:{0}) {{ Remove-Item env:{0} }}'.format(varname)) content = "\n".join(result) + content = relativize_generated_file(content, self._conanfile, "$PSScriptRoot") # It is very important to save it correctly with utf-16, the Conan util save() is broken # and powershell uses utf-16 files!!! os.makedirs(os.path.dirname(os.path.abspath(file_location)), exist_ok=True) diff --git a/conans/test/functional/command/test_install_deploy.py b/conans/test/functional/command/test_install_deploy.py index 8858a9db4e7..e45d70ad1b6 100644 --- a/conans/test/functional/command/test_install_deploy.py +++ b/conans/test/functional/command/test_install_deploy.py @@ -52,7 +52,8 @@ def client(_client): @pytest.mark.tool("cmake") -def test_install_deploy(client): +@pytest.mark.parametrize("powershell", [False, True]) +def test_install_deploy(client, powershell): c = client custom_content = 'message(STATUS "MY_TOOL_VARIABLE=${MY_TOOL_VARIABLE}!")' cmake = gen_cmakelists(appname="my_app", appsources=["main.cpp"], find_package=["hello", "tool"], @@ -73,8 +74,9 @@ def deploy(graph, output_folder, **kwargs): "CMakeLists.txt": cmake, "main.cpp": gen_function_cpp(name="main", includes=["hello"], calls=["hello"])}, clean_first=True) + pwsh = "-c tools.env.virtualenv:powershell=True" if powershell else "" c.run("install . -o *:shared=True " - "--deployer=deploy.py -of=mydeploy -g CMakeToolchain -g CMakeDeps") + f"--deployer=deploy.py -of=mydeploy -g CMakeToolchain -g CMakeDeps {pwsh}") c.run("remove * -c") # Make sure the cache is clean, no deps there arch = c.get_default_host_profile().settings['arch'] deps = c.load(f"mydeploy/hello-release-{arch}-data.cmake") @@ -93,7 +95,10 @@ def deploy(graph, output_folder, **kwargs): assert "MY_TOOL_VARIABLE=Hello world!!" in c2.out c2.run_command("cmake --build . --config Release") if platform.system() == "Windows": # Only the .bat env-generators are relocatable - cmd = r"mydeploy\conanrun.bat && Release\my_app.exe" + if powershell: + cmd = r"powershell.exe mydeploy\conanrun.ps1 ; Release\my_app.exe" + else: + cmd = r"mydeploy\conanrun.bat && Release\my_app.exe" # For Lunux: cmd = ". mydeploy/conanrun.sh && ./my_app" c2.run_command(cmd) assert "hello/0.1: Hello World Release!" in c2.out