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 relativize powershell #14391

Merged
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
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