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

Update powershell conf to select from powershell and pwsh #17416

Merged
merged 30 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use string with arguments
  • Loading branch information
czoido committed Dec 12, 2024
commit cb2fef770200dd358929449aff7be2ae6856b8d2
20 changes: 9 additions & 11 deletions conan/tools/env/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,7 @@ def environment_wrap_command(conanfile, env_filenames, env_folder, cmd, subsyste
raise ConanException("Cannot wrap command with different envs,"
"{} - {}".format(bats+ps1s, shs))

try:
powershell = conanfile.conf.get("tools.env.virtualenv:powershell", check_type=str,
choices=["powershell", "pwsh"]) or "powershell"
except ConanException:
powershell = "powershell"

powershell = "powershell.exe" if powershell == "powershell" else "pwsh"
powershell = conanfile.conf.get("tools.env.virtualenv:powershell") or "powershell.exe"
czoido marked this conversation as resolved.
Show resolved Hide resolved

if bats:
launchers = " && ".join('"{}"'.format(b) for b in bats)
Expand Down Expand Up @@ -531,7 +525,8 @@ def save_sh(self, file_location, generate_deactivate=True):
def save_script(self, filename):
"""
Saves a script file (bat, sh, ps1) with a launcher to set the environment.
If the conf "tools.env.virtualenv:powershell" is set to True it will generate powershell
If the conf "tools.env.virtualenv:powershell" is not an empty string
it will generate powershell
launchers if Windows.

:param filename: Name of the file to generate. If the extension is provided, it will generate
Expand All @@ -548,11 +543,14 @@ def save_script(self, filename):
is_ps1 = self._conanfile.conf.get("tools.env.virtualenv:powershell", check_type=bool)
ConanOutput().warning(
"Boolean values for 'tools.env.virtualenv:powershell' are deprecated. "
"Please use 'powershell' or 'pwsh'. "
"Use `tools.env.virtualenv:powershell=!` to unset the conf, equivalent to the old False value behaviour", warn_tag="deprecated"
"Please specify 'powershell.exe' or 'pwsh' instead, appending arguments if needed "
"(for example: 'powershell.exe -argument'). "
"To unset this configuration, use `tools.env.virtualenv:powershell=!`, which matches "
"the previous 'False' behavior.",
warn_tag="deprecated"
)
except ConanException:
is_ps1 = self._conanfile.conf.get("tools.env.virtualenv:powershell", check_type=str, choices=["powershell", "pwsh"])
is_ps1 = self._conanfile.conf.get("tools.env.virtualenv:powershell", check_type=str)
if is_ps1:
filename = filename + ".ps1"
is_bat = False
Expand Down
6 changes: 5 additions & 1 deletion conan/tools/microsoft/visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ def generate(self, scope="build"):
is_ps1 = self._conanfile.conf.get("tools.env.virtualenv:powershell", check_type=bool)
ConanOutput().warning(
"Boolean values for 'tools.env.virtualenv:powershell' are deprecated. "
"Please use 'powershell' or 'pwsh'.", warn_tag="deprecated"
"Please specify 'powershell.exe' or 'pwsh' instead, appending arguments if needed "
"(for example: 'powershell.exe -argument'). "
"To unset this configuration, use `tools.env.virtualenv:powershell=!`, which matches "
"the previous 'False' behavior.",
warn_tag="deprecated"
)
except ConanException:
is_ps1 = self._conanfile.conf.get("tools.env.virtualenv:powershell", check_type=str,
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
8 changes: 4 additions & 4 deletions test/functional/toolchains/env/test_virtualenv_powershell.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def package_info(self):
"""
client.save({"conanfile.py": conanfile})
client.run("create .")
save(client.cache.new_config_path, "tools.env.virtualenv:powershell=True\n")
save(client.cache.new_config_path, "tools.env.virtualenv:powershell=powershell.exe\n")
return client


Expand Down Expand Up @@ -75,7 +75,7 @@ def build(self):


@pytest.mark.skipif(platform.system() != "Windows", reason="Requires Windows powershell")
@pytest.mark.parametrize("powershell", ["powershell", "pwsh"])
@pytest.mark.parametrize("powershell", [True, "powershell.exe", "pwsh"])
def test_virtualenv_test_package(powershell):
""" The test_package could crash if not cleaning correctly the test_package
output folder. This will still crassh if the layout is not creating different build folders
Expand Down Expand Up @@ -121,7 +121,7 @@ def test(self):
assert "MYVC_CUSTOMVAR2=PATATA2" in client.out

@pytest.mark.skipif(platform.system() != "Windows", reason="Requires Windows powershell")
@pytest.mark.parametrize("powershell", ["powershell", "pwsh"])
@pytest.mark.parametrize("powershell", [True, "powershell.exe", "pwsh"])
def test_vcvars(powershell):
client = TestClient()
conanfile = textwrap.dedent(r"""
Expand Down Expand Up @@ -166,7 +166,7 @@ def build(self):


@pytest.mark.skipif(platform.system() != "Windows", reason="Test for powershell")
@pytest.mark.parametrize("powershell", ["powershell", "pwsh"])
@pytest.mark.parametrize("powershell", [True, "powershell.exe", "pwsh", "powershell.exe -NoProfile", "pwsh -NoProfile"])
def test_concatenate_build_and_run_env(powershell):
# this tests that if we have both build and run env, they are concatenated correctly when using
# powershell
Expand Down
Loading