Skip to content

Commit d889806

Browse files
authored
fixing vcvars for VS18 (#19294)
* fixing vcvars for VS18 * try to fix test
1 parent 91cc2d6 commit d889806

File tree

2 files changed

+33
-59
lines changed

2 files changed

+33
-59
lines changed

conan/tools/microsoft/visual.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ def generate(self, scope="build"):
171171
if is_ps1 is not None:
172172
ConanOutput().warning(
173173
"Boolean values for 'tools.env.virtualenv:powershell' are deprecated. "
174-
"Please specify 'powershell.exe' or 'pwsh' instead, appending arguments if needed "
175-
"(for example: 'powershell.exe -argument'). "
176-
"To unset this configuration, use `tools.env.virtualenv:powershell=!`, which matches "
177-
"the previous 'False' behavior.",
174+
"Please specify 'powershell.exe' or 'pwsh' instead, appending arguments "
175+
"if needed (for example: 'powershell.exe -argument'). "
176+
"To unset this configuration, use `tools.env.virtualenv:powershell=!`, "
177+
"which matches the previous 'False' behavior.",
178178
warn_tag="deprecated"
179179
)
180180
except ConanException:
@@ -315,15 +315,18 @@ def _vcvars_versions(conanfile):
315315
"v141": "15",
316316
"v142": "16",
317317
"v143": "17",
318-
"v144": "17"}.get(toolset_version)
318+
"v144": "17",
319+
"v145": "18"}.get(toolset_version)
319320
if vs_version is None:
320-
raise ConanException("Visual Studio Runtime version (v140-v144) not defined. Please, "
321-
"add the compiler.runtime_version=[v140-v144] setting to your profile.")
321+
raise ConanException("Visual Studio Runtime version (v140-v145) not defined. Please, "
322+
"add the compiler.runtime_version=[v140-v145] setting to your "
323+
"profile.")
322324
vcvars_ver = {"v140": "14.0",
323325
"v141": "14.1",
324326
"v142": "14.2",
325327
"v143": "14.3",
326-
"v144": "14.4"}.get(toolset_version)
328+
"v144": "14.4",
329+
"v145": "14.5"}.get(toolset_version)
327330
if vcvars_ver and msvc_update is not None:
328331
vcvars_ver += f"{msvc_update}"
329332
else:

test/integration/toolchains/microsoft/vcvars_test.py

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ def test_vcvars_generator_skip_on_linux():
5858
Skip creation of conanvcvars.bat on Linux build systems
5959
"""
6060
client = TestClient()
61-
client.save({"conanfile.py": GenConanfile().with_generator("VCVars")
62-
.with_settings("os", "compiler",
63-
"arch", "build_type")})
61+
client.save({"conanfile.txt": "[generators]\nVCVars"})
6462

6563
client.run('install . -s os=Windows -s compiler=msvc -s compiler.version=193 '
6664
'-s compiler.runtime=dynamic')
@@ -70,14 +68,7 @@ def test_vcvars_generator_skip_on_linux():
7068
@pytest.mark.skipif(platform.system() not in ["Windows"], reason="Requires Windows")
7169
def test_vcvars_generator_string():
7270
client = TestClient(path_with_spaces=False)
73-
74-
conanfile = textwrap.dedent("""
75-
from conan import ConanFile
76-
class TestConan(ConanFile):
77-
generators = "VCVars"
78-
settings = "os", "compiler", "arch", "build_type"
79-
""")
80-
client.save({"conanfile.py": conanfile})
71+
client.save({"conanfile.txt": "[generators]\nVCVars"})
8172
client.run('install . -s os=Windows -s compiler="msvc" -s compiler.version=191 '
8273
'-s compiler.cppstd=14 -s compiler.runtime=static')
8374

@@ -89,14 +80,7 @@ class TestConan(ConanFile):
8980
def test_vcvars_2015_error():
9081
# https://github.com/conan-io/conan/issues/9888
9182
client = TestClient(path_with_spaces=False)
92-
93-
conanfile = textwrap.dedent("""
94-
from conan import ConanFile
95-
class TestConan(ConanFile):
96-
generators = "VCVars"
97-
settings = "os", "compiler", "arch", "build_type"
98-
""")
99-
client.save({"conanfile.py": conanfile})
83+
client.save({"conanfile.txt": "[generators]\nVCVars"})
10084
client.run('install . -s os=Windows -s compiler="msvc" -s compiler.version=190 '
10185
'-s compiler.cppstd=14 -s compiler.runtime=static')
10286

@@ -109,14 +93,7 @@ class TestConan(ConanFile):
10993
def test_vcvars_platform_x86():
11094
# https://github.com/conan-io/conan/issues/11144
11195
client = TestClient(path_with_spaces=False)
112-
113-
conanfile = textwrap.dedent("""
114-
from conan import ConanFile
115-
class TestConan(ConanFile):
116-
generators = "VCVars"
117-
settings = "os", "compiler", "arch", "build_type"
118-
""")
119-
client.save({"conanfile.py": conanfile})
96+
client.save({"conanfile.txt": "[generators]\nVCVars"})
12097
client.run('install . -s os=Windows -s compiler="msvc" -s compiler.version=193 '
12198
'-s compiler.cppstd=14 -s compiler.runtime=static -s:b arch=x86')
12299

@@ -127,14 +104,7 @@ class TestConan(ConanFile):
127104
@pytest.mark.skipif(platform.system() != "Windows", reason="Requires Windows")
128105
def test_vcvars_winsdk_version():
129106
client = TestClient(path_with_spaces=False)
130-
131-
conanfile = textwrap.dedent("""
132-
from conan import ConanFile
133-
class TestConan(ConanFile):
134-
generators = "VCVars"
135-
settings = "os", "compiler", "arch", "build_type"
136-
""")
137-
client.save({"conanfile.py": conanfile})
107+
client.save({"conanfile.txt": "[generators]\nVCVars"})
138108
client.run('install . -s os=Windows -s compiler=msvc -s compiler.version=193 '
139109
'-s compiler.cppstd=14 -s compiler.runtime=static '
140110
'-c tools.microsoft:winsdk_version=10.0')
@@ -146,35 +116,36 @@ class TestConan(ConanFile):
146116
@pytest.mark.skipif(platform.system() != "Windows", reason="Requires Windows")
147117
def test_vcvars_compiler_update():
148118
client = TestClient(path_with_spaces=False)
149-
150-
conanfile = textwrap.dedent("""
151-
from conan import ConanFile
152-
class TestConan(ConanFile):
153-
generators = "VCVars"
154-
settings = "os", "compiler", "arch", "build_type"
155-
""")
156-
client.save({"conanfile.py": conanfile})
119+
client.save({"conanfile.txt": "[generators]\nVCVars"})
157120
client.run('install . -s os=Windows -s compiler=msvc -s compiler.version=193 '
158121
'-s compiler.cppstd=14 -s compiler.runtime=static '
159122
'-s compiler.update=3')
160123

161124
vcvars = client.load("conanvcvars.bat")
162125
assert 'vcvarsall.bat" amd64 -vcvars_ver=14.33' in vcvars
163126

127+
164128
@pytest.mark.skipif(platform.system() != "Windows", reason="Requires Windows")
165129
def test_vcvars_armv8_windows_store():
166130
client = TestClient(path_with_spaces=False)
167-
168-
conanfile = textwrap.dedent("""
169-
from conan import ConanFile
170-
class TestConan(ConanFile):
171-
generators = "VCVars"
172-
settings = "os", "compiler", "arch", "build_type"
173-
""")
174-
client.save({"conanfile.py": conanfile})
131+
client.save({"conanfile.txt": "[generators]\nVCVars"})
175132
client.run('install . -s:b os=Windows -s compiler="msvc" -s compiler.version=194 '
176133
'-s compiler.cppstd=14 -s compiler.runtime=static -s:h arch=armv8 '
177134
'-s:h os=WindowsStore -s:h os.version=10.0')
178135

179136
vcvars = client.load("conanvcvars.bat")
180137
assert 'vcvarsall.bat" amd64_arm64' in vcvars
138+
139+
140+
@pytest.mark.skipif(platform.system() != "Windows", reason="Requires Windows")
141+
def test_vcvars_clang_visual2026():
142+
client = TestClient(path_with_spaces=False)
143+
client.save({"conanfile.txt": "[generators]\nVCVars"})
144+
client.run('install . -s:b os=Windows -s compiler=clang -s compiler.version=20 '
145+
'-s compiler.cppstd=14 -s compiler.runtime=static -s arch=x86_64 '
146+
'-s compiler.runtime_version=v145 '
147+
# Using a known existing path to avoid auto-detection via vswhere
148+
'-c tools.microsoft.msbuild:installation_path=C:/')
149+
150+
vcvars = client.load("conanvcvars.bat")
151+
assert '-vcvars_ver=14.5' in vcvars

0 commit comments

Comments
 (0)