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

[develop2] fix powershell and test_package #13084

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/cli/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def test_package(conan_api, deps_graph, test_conanfile_path, tested_python_requi
"package being created.".format(test_conanfile_path))
conanfile_folder = os.path.dirname(test_conanfile_path)
conanfile = deps_graph.root.conanfile
# To make sure the folders are correct
conanfile.folders.set_base_folders(conanfile_folder, output_folder=None)
if conanfile.build_folder and conanfile.build_folder != conanfile.source_folder:
# should be the same as build folder, but we can remove it
Expand Down
12 changes: 9 additions & 3 deletions conan/tools/env/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,25 @@ def environment_wrap_command(env_filenames, env_folder, cmd, subsystem=None,
path_sh = subsystem_path(subsystem, path_sh)
shs.append(path_sh)

if bool(bats) + bool(shs) + bool(ps1s) > 1:
if bool(bats + ps1s) + bool(shs) > 1:
raise ConanException("Cannot wrap command with different envs,"
" {} - {} - {}".format(bats, shs, ps1s))
"{} - {}".format(bats+ps1s, shs))

if bats:
launchers = " && ".join('"{}"'.format(b) for b in bats)
return '{} && {}'.format(launchers, cmd)
if ps1s:
ps1_launchers = " ; ".join('"&\'{}\'"'.format(f) for f in ps1s)
cmd = cmd.replace('"', "'")
return '{} && powershell.exe {} ; cmd /c {}'.format(launchers, ps1_launchers, cmd)
else:
return '{} && {}'.format(launchers, cmd)
elif shs:
launchers = " && ".join('. "{}"'.format(f) for f in shs)
return '{} && {}'.format(launchers, cmd)
elif ps1s:
# TODO: at the moment it only works with path without spaces
launchers = " ; ".join('"&\'{}\'"'.format(f) for f in ps1s)
cmd = cmd.replace('"', "'")
return 'powershell.exe {} ; cmd /c {}'.format(launchers, cmd)
else:
return cmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,49 @@ def build(self):
client.run("create .")
assert "MYPATH1=c:/path/to/ar" in client.out
assert 'MYVAR1=some nice content" with quotes' in client.out


@pytest.mark.skipif(platform.system() != "Windows", reason="Requires Windows powershell")
def test_virtualenv_test_package():
""" 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
https://github.com/conan-io/conan/issues/12764
"""
client = TestClient()
test_package = textwrap.dedent(r"""
from conan import ConanFile
from conan.tools.files import save
class Test(ConanFile):
def requirements(self):
self.requires(self.tested_reference_str)
def generate(self):
# Emulates vcvars.bat behavior
save(self, "myenv.bat", "echo MYENV!!!\nset MYVC_CUSTOMVAR1=PATATA1")
self.env_scripts.setdefault("build", []).append("myenv.bat")
save(self, "myps.ps1", "echo MYPS1!!!!\n$env:MYVC_CUSTOMVAR2=\"PATATA2\"")
self.env_scripts.setdefault("build", []).append("myps.ps1")
def layout(self):
self.folders.build = "mybuild"
self.folders.generators = "mybuild"
def test(self):
self.run('mkdir "hello world"')
self.run("dir")
self.run('cd "hello world"')
self.run("set MYVC_CUSTOMVAR1")
self.run("set MYVC_CUSTOMVAR2")
""")
client.save({"conanfile.py": GenConanfile("pkg", "1.0"),
"test_package/conanfile.py": test_package})
client.run("create .")
assert "hello world" in client.out
assert "MYENV!!!" in client.out
assert "MYPS1!!!!" in client.out
assert "MYVC_CUSTOMVAR1=PATATA1" in client.out
assert "MYVC_CUSTOMVAR2=PATATA2" in client.out
# This was crashing because the .ps1 of test_package was not being cleaned
client.run("create . -c tools.env.virtualenv:powershell=True")
assert "hello world" in client.out
assert "MYENV!!!" in client.out
assert "MYPS1!!!!" in client.out
assert "MYVC_CUSTOMVAR1=PATATA1" in client.out
assert "MYVC_CUSTOMVAR2=PATATA2" in client.out