Skip to content

Commit b71f514

Browse files
committed
Simplify and clarify test_cpp17_modern_msvc_workaround
1 parent 1775c61 commit b71f514

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

test/10_cpp_standards/cibuildwheel_test.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,26 @@ def test_cpp17_modern_msvc_workaround(tmp_path):
8282
# Use existing setuptools code to run Visual Studio's vcvarsall.bat and get the
8383
# necessary environment variables, since running vcvarsall.bat in a subprocess
8484
# does not keep the relevant environment variables
85-
# In normal CI setup: run vcvarsall.bat before running cibuildwheel
85+
# There are different environment variables for 32-bit/64-bit targets, so we
86+
# need to run cibuildwheel twice, once for 32-bit with `vcvarsall.bat x86, and
87+
# once for 64-bit with `vcvarsall.bat x64`
88+
# In a normal CI setup, just run vcvarsall.bat before running cibuildwheel and set
89+
# DISTUTILS_USE_SDK and MSSdk
8690
import setuptools
8791

88-
# Different environment variables for 32-bit/64-bit targets
89-
# First, 32-bit (or x86)
90-
vcvarsall_env = setuptools.msvc.msvc14_get_vc_env('x86')
91-
add_env_x86 = add_env.copy()
92+
def add_vcvars(prev_env, platform):
93+
vcvarsall_env = setuptools.msvc.msvc14_get_vc_env(platform)
94+
env = prev_env.copy()
95+
for vcvar in ['path', 'include', 'lib']:
96+
env[vcvar] = vcvarsall_env[vcvar]
97+
return env
98+
99+
add_env_x86 = add_vcvars(add_env, 'x86')
92100
add_env_x86['CIBW_BUILD'] = '*-win32'
93-
for vc_var in ['path', 'include', 'lib']:
94-
add_env_x86[vc_var] = vcvarsall_env[vc_var]
95101
actual_wheels = utils.cibuildwheel_run(project_dir, add_env=add_env_x86)
96102

97-
# Then, 64-bit (or x64)
98-
vcvarsall_env = setuptools.msvc.msvc14_get_vc_env('x64')
99-
add_env_x64 = add_env.copy()
103+
add_env_x64 = add_vcvars(add_env, 'x64')
100104
add_env_x64['CIBW_BUILD'] = '*-win_amd64'
101-
for vc_var in ['path', 'include', 'lib']:
102-
add_env_x64[vc_var] = vcvarsall_env[vc_var]
103105
actual_wheels += utils.cibuildwheel_run(project_dir, add_env=add_env_x64)
104106

105107
expected_wheels = utils.expected_wheels('spam', '0.1.0')

0 commit comments

Comments
 (0)