Skip to content

Commit

Permalink
fix relativize powershell (#14391)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored Jul 29, 2023
1 parent bc4ed4d commit daf32ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions conan/tools/env/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions conans/test/functional/command/test_install_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit daf32ac

Please sign in to comment.