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 aggregated env scripts deactivate order #13707

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
2 changes: 1 addition & 1 deletion conans/client/generators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _generate_aggregated_env(conanfile):
def deactivates(filenames):
# FIXME: Probably the order needs to be reversed
result = []
for s in filenames:
for s in reversed(filenames):
folder, f = os.path.split(s)
result.append(os.path.join(folder, "deactivate_{}".format(f)))
return result
Expand Down
43 changes: 43 additions & 0 deletions conans/test/integration/environment/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,49 @@ def generate(self):
assert "VAR2=!!" in out


def test_multiple_deactivate_order():
"""
https://github.com/conan-io/conan/issues/13693
"""
conanfile = textwrap.dedent(r"""
from conan import ConanFile
from conan.tools.env import Environment
class Pkg(ConanFile):
def generate(self):
e1 = Environment()
e1.define("MYVAR", "Value1")
e1.vars(self).save_script("mybuild1")
e2 = Environment()
e2.define("MYVAR", "Value2")
e2.vars(self).save_script("mybuild2")
""")
display_bat = textwrap.dedent("""\
@echo off
echo MYVAR=%MYVAR%!!
""")
display_sh = textwrap.dedent("""\
echo MYVAR=$MYVAR!!
""")
client = TestClient()
client.save({"conanfile.py": conanfile,
"display.bat": display_bat,
"display.sh": display_sh})
os.chmod(os.path.join(client.current_folder, "display.sh"), 0o777)
client.run("install .")

for _ in range(2): # Just repeat it, so we can check things keep working
if platform.system() == "Windows":
cmd = "conanbuild.bat && display.bat && deactivate_conanbuild.bat && display.bat"
else:
cmd = '. ./conanbuild.sh && ./display.sh && . ./deactivate_conanbuild.sh && ./display.sh'
out, _ = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
shell=True, cwd=client.current_folder).communicate()
out = out.decode()
assert "MYVAR=Value2!!" in out
assert 3 == str(out).count("Restoring environment")
assert "MYVAR=!!" in out


@pytest.mark.skipif(platform.system() != "Windows", reason="Path problem in Windows only")
@pytest.mark.parametrize("num_deps", [3, ])
def test_massive_paths(num_deps):
Expand Down