Skip to content

Commit 10ff1e7

Browse files
authored
Improve environment output dumps prepend order (#17863)
* fix environment output dumps prepend order * fix unrelated test * printing out * fix clang-cl version in CI * fixed test check in CI using VS 19.38
1 parent 86f29e1 commit 10ff1e7

File tree

3 files changed

+93
-6
lines changed

3 files changed

+93
-6
lines changed

conan/tools/env/environment.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def dumps(self):
8989
result.append("{}=!".format(self._name))
9090
elif _EnvVarPlaceHolder in self._values:
9191
index = self._values.index(_EnvVarPlaceHolder)
92-
for v in self._values[:index]:
92+
for v in reversed(self._values[:index]): # Reverse to prepend
9393
result.append("{}=+{}{}{}".format(self._name, path, sep, v))
9494
for v in self._values[index+1:]:
9595
result.append("{}+={}{}{}".format(self._name, path, sep, v))

test/functional/toolchains/cmake/test_cmake_toolchain_win_clang.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ def test_clang_visual_studio_generator(self, client):
150150
""" This is using the embedded ClangCL compiler, not the external one"""
151151
generator = "Visual Studio 17"
152152
client.run("create . --name=pkg --version=0.1 -pr=clang -s compiler.runtime=dynamic "
153-
"-s compiler.cppstd=17 -s compiler.runtime_version=v143 "
153+
"-s compiler.cppstd=17 -s compiler.runtime_version=v144 "
154154
'-c tools.cmake.cmaketoolchain:generator="{}"'.format(generator))
155155
assert 'cmake -G "{}"'.format(generator) in client.out
156156
assert "MSVC-like command-line" in client.out
157-
# My local is 17, but CI ClangCL still 16
158-
assert "main __clang_major__18" in client.out
157+
assert "main __clang_major__19" in client.out
159158
# Check this! Clang compiler in Windows is reporting MSC_VER and MSVC_LANG!
160-
assert "main _MSC_VER1938" in client.out
159+
# CI forced the installation of 19.38, seems to prevail there
160+
assert "main _MSC_VER193" in client.out
161161
assert "main _MSVC_LANG201703" in client.out
162162
assert "main _M_X64 defined" in client.out
163163
assert "main __x86_64__ defined" in client.out

test/unittests/tools/env/test_env.py

+88-1
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,24 @@ def test_append(self):
368368
MyPath1+=(path)/my/path1
369369
""")
370370

371+
def test_append_multiple(self):
372+
myprofile = textwrap.dedent("""
373+
# define
374+
MyVar1+=MyValue1
375+
MyVar1+=MyValue2
376+
MyPath1 +=(path)/my/path1
377+
MyPath1 +=(path)/my/path2
378+
""")
379+
380+
env = ProfileEnvironment.loads(myprofile)
381+
text = env.dumps()
382+
assert text == textwrap.dedent("""\
383+
MyVar1+=MyValue1
384+
MyVar1+=MyValue2
385+
MyPath1+=(path)/my/path1
386+
MyPath1+=(path)/my/path2
387+
""")
388+
371389
def test_prepend(self):
372390
myprofile = textwrap.dedent("""
373391
# define
@@ -382,6 +400,24 @@ def test_prepend(self):
382400
MyPath1=+(path)/my/path1
383401
""")
384402

403+
def test_prepend_multiple(self):
404+
myprofile = textwrap.dedent("""
405+
# define
406+
MyVar1=+MyValue1
407+
MyVar1=+MyValue2
408+
MyPath1=+(path)/my/path1
409+
MyPath1=+(path)/my/path2
410+
""")
411+
412+
env = ProfileEnvironment.loads(myprofile)
413+
text = env.dumps()
414+
assert text == textwrap.dedent("""\
415+
MyVar1=+MyValue1
416+
MyVar1=+MyValue2
417+
MyPath1=+(path)/my/path1
418+
MyPath1=+(path)/my/path2
419+
""")
420+
385421
def test_combined(self):
386422
myprofile = textwrap.dedent("""
387423
MyVar1=+MyValue11
@@ -399,22 +435,73 @@ def test_combined(self):
399435
MyPath1+=(path)/my/path12
400436
""")
401437

402-
def test_combined2(self):
438+
def test_combined_multiple(self):
439+
myprofile = textwrap.dedent("""
440+
MyVar1=+MyValue11
441+
MyVar1=+MyValue12
442+
MyVar1+=MyValue13
443+
MyVar1+=MyValue14
444+
MyPath1=+(path)/my/path11
445+
MyPath1=+(path)/my/path12
446+
MyPath1+=(path)/my/path13
447+
MyPath1+=(path)/my/path12
448+
""")
449+
450+
env = ProfileEnvironment.loads(myprofile)
451+
text = env.dumps()
452+
assert text == textwrap.dedent("""\
453+
MyVar1=+MyValue11
454+
MyVar1=+MyValue12
455+
MyVar1+=MyValue13
456+
MyVar1+=MyValue14
457+
MyPath1=+(path)/my/path11
458+
MyPath1=+(path)/my/path12
459+
MyPath1+=(path)/my/path13
460+
MyPath1+=(path)/my/path12
461+
""")
462+
463+
def test_combined_prepend_first(self):
464+
myprofile = textwrap.dedent("""
465+
MyVar1+=MyValue11
466+
MyVar1=+MyValue12
467+
MyPath1+=(path)/my/path11
468+
MyPath1=+(path)/my/path12
469+
""")
470+
471+
env = ProfileEnvironment.loads(myprofile)
472+
text = env.dumps()
473+
# NOTE: This is reversed order compared to origin, prepend always first
474+
assert text == textwrap.dedent("""\
475+
MyVar1=+MyValue12
476+
MyVar1+=MyValue11
477+
MyPath1=+(path)/my/path12
478+
MyPath1+=(path)/my/path11
479+
""")
480+
481+
def test_combined_prepend_first_multiple(self):
403482
myprofile = textwrap.dedent("""
404483
MyVar1+=MyValue11
405484
MyVar1=+MyValue12
485+
MyVar1+=MyValue13
486+
MyVar1=+MyValue14
406487
MyPath1+=(path)/my/path11
407488
MyPath1=+(path)/my/path12
489+
MyPath1+=(path)/my/path13
490+
MyPath1=+(path)/my/path14
408491
""")
409492

410493
env = ProfileEnvironment.loads(myprofile)
411494
text = env.dumps()
412495
# NOTE: This is reversed order compared to origin, prepend always first
413496
assert text == textwrap.dedent("""\
414497
MyVar1=+MyValue12
498+
MyVar1=+MyValue14
415499
MyVar1+=MyValue11
500+
MyVar1+=MyValue13
416501
MyPath1=+(path)/my/path12
502+
MyPath1=+(path)/my/path14
417503
MyPath1+=(path)/my/path11
504+
MyPath1+=(path)/my/path13
418505
""")
419506

420507

0 commit comments

Comments
 (0)