Skip to content

Commit

Permalink
Merge pull request #900 from msarahan/fix_win_vs2010
Browse files Browse the repository at this point in the history
  • Loading branch information
msarahan committed May 6, 2016
2 parents fc9fc65 + ad23fa4 commit c6b9aba
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 17 deletions.
2 changes: 1 addition & 1 deletion conda_build/main_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ def execute(args, parser):
if not isdir(d):
makedirs(d)
update_index(d)
index = build.get_build_index(clear_cache=True)

already_built = []
to_build_recursive = []
Expand Down Expand Up @@ -258,6 +257,7 @@ def execute(args, parser):
m = render_recipe(recipe_dir, no_download_source=False)
if m.get_value('build/noarch_python'):
config.noarch = True

if args.check and len(args.recipe) > 1:
print(m.path)
m.check_fields()
Expand Down
26 changes: 14 additions & 12 deletions conda_build/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
PROGRAM_FILES_PATH = os.environ['ProgramFiles']

# Note that we explicitly want "Program Files" and not "Program Files (x86)"
WIN_SDK_BAT_PATH = os.path.join(os.path.abspath(os.sep),
'Program Files', 'Microsoft SDKs',
'Windows', 'v7.1', 'Bin', 'SetEnv.cmd')
WIN_SDK_BAT_PATH = os.path.join(PROGRAM_FILES_PATH.replace(" (x86)", ""),
'Microsoft SDKs', 'Windows', 'v7.1', 'Bin', 'SetEnv.cmd')
VS_TOOLS_PY_LOCAL_PATH = os.path.join(
os.getenv('localappdata', os.path.abspath(os.sep)),
'Programs', 'Common', 'Microsoft', 'Visual C++ for Python', '9.0',
Expand Down Expand Up @@ -111,30 +110,32 @@ def msvc_env_cmd(bits, override=None):
def build_vcvarsall_cmd(cmd, arch=arch_selector):
return 'call "{cmd}" {arch}'.format(cmd=cmd, arch=arch)

msvc_env_lines.append('set VS_VERSION="{}"'.format(version))
msvc_env_lines.append('set VS_MAJOR="{}"'.format(version.split('.')[0]))
msvc_env_lines.append('set VS_YEAR="{}"'.format(VS_VERSION_STRING[version][-4:]))
msvc_env_lines.append('set CMAKE_GENERATOR="{}"'.format(VS_VERSION_STRING[version] +
msvc_env_lines.append('set "VS_VERSION={}"'.format(version))
msvc_env_lines.append('set "VS_MAJOR={}"'.format(version.split('.')[0]))
msvc_env_lines.append('set "VS_YEAR={}"'.format(VS_VERSION_STRING[version][-4:]))
msvc_env_lines.append('set "CMAKE_GENERATOR={}"'.format(VS_VERSION_STRING[version] +
{64: ' Win64', 32: ''}[bits]))
# tell msys2 to ignore path conversions for issue-causing windows-style flags in build
# See https://github.com/conda-forge/icu-feedstock/pull/5
msvc_env_lines.append('set "MSYS2_ARG_CONV_EXCL=/AI;/AL;/OUT;/out;%MSYS2_ARG_CONV_EXCL%"')
msvc_env_lines.append('set "MSYS2_ENV_CONV_EXCL=CL"')
if version == '10.0':
# Unfortunately, the Windows SDK takes a different command format for
# the arch selector - debug is default so explicitly set 'Release'
win_sdk_arch = '/x86 /Release' if bits == 32 else '/x64 /Release'
win_sdk_arch = '/Release /x86' if bits == 32 else '/Release /x64'
win_sdk_cmd = build_vcvarsall_cmd(WIN_SDK_BAT_PATH, arch=win_sdk_arch)

# Always call the Windows SDK first - if VS 2010 exists but was
# installed using the broken installer then it will try and call the
# vcvars script, which will fail but NOT EXIT 1. To work around this,
# we always call the Windows SDK, and then try calling VS 2010 which
# will overwrite any environemnt variables it needs, if necessary.
msvc_env_lines.append(win_sdk_cmd)
msvc_env_lines.append(build_vcvarsall_cmd(vcvarsall_vs_path))

elif version == '9.0':
error1 = 'if errorlevel 1 {}'

# First, check for Microsoft Visual C++ Compiler for Python 2.7
msvc_env_lines.append(build_vcvarsall_cmd(VS_TOOLS_PY_LOCAL_PATH))

msvc_env_lines.append(error1.format(
build_vcvarsall_cmd(VS_TOOLS_PY_COMMON_PATH)))
# The Visual Studio 2008 Express edition does not properly contain
Expand All @@ -149,6 +150,7 @@ def build_vcvarsall_cmd(cmd, arch=arch_selector):
else:
msvc_env_lines.append(error1.format(
build_vcvarsall_cmd(vcvarsall_vs_path)))

else:
# Visual Studio 14 or otherwise
msvc_env_lines.append(build_vcvarsall_cmd(vcvarsall_vs_path))
Expand Down
5 changes: 5 additions & 0 deletions tests/test-recipes/metadata/_cmake_generator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PROJECT(HELLO)

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

add_executable(hello hello.c)
7 changes: 7 additions & 0 deletions tests/test-recipes/metadata/_cmake_generator/bld.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
where cl.exe
where link.exe
:: maybe informative for MinGW?
where gcc.exe

cmake -G "%CMAKE_GENERATOR:"=%" "%RECIPE_DIR%"
cmake --build . --config Release
2 changes: 2 additions & 0 deletions tests/test-recipes/metadata/_cmake_generator/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cmake -G "$CMAKE_GENERATOR" $RECIPE_DIR
cmake --build . --config Release
5 changes: 5 additions & 0 deletions tests/test-recipes/metadata/_cmake_generator/hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdio.h>

int main() {
printf("Hello world!\n");
}
7 changes: 7 additions & 0 deletions tests/test-recipes/metadata/_cmake_generator/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package:
name: conda-build-test-cmake-generator
version: 1.0

requirements:
build:
- cmake
15 changes: 15 additions & 0 deletions tests/test_build_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ def test_checkout_tool_as_dependency():
shutil.rmtree(tmpdir)


platforms = ["64" if sys.maxsize > 2**32 else "32"]
if sys.platform=="win32":
platforms = set(["32",] + platforms)
compilers = ["2.7", "3.4", "3.5"]
else:
compilers = [".".join([str(sys.version_info.major), str(sys.version_info.minor)])]

@pytest.mark.parametrize("platform", platforms)
@pytest.mark.parametrize("target_compiler", compilers)
def test_cmake_generator(platform, target_compiler):
# TODO: need a better way to specify compiler more directly on win
cmd = 'conda build --no-anaconda-upload {}/_cmake_generator --python={}'.format(metadata_dir, target_compiler)
subprocess.check_call(cmd.split())


@pytest.mark.skipif(sys.platform=="win32",
reason="No windows symlinks")
Expand All @@ -89,6 +103,7 @@ def test_symlink_fail():
error = error.decode('utf-8')
assert error.count("Error") == 6


@pytest.mark.skipif(sys.platform=="win32",
reason="Windows doesn't show this error")
def test_broken_conda_meta():
Expand Down
8 changes: 4 additions & 4 deletions tests/test_win_vs_activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ def test_activation(bits, compiler):
# this is effectively the test condition for all below tests.
with open('tmp_call.bat', "w") as f:
f.write(msvc_env_cmd(bits, compiler_version))
f.write('\nif not %VS_VERSION% == "{}" exit /b 1'.format(compiler_version))
f.write('\nif not %VS_MAJOR% == "{}" exit /b 1'.format(compiler_version.split('.')[0]))
f.write('\nif not %VS_YEAR% == "{}" exit /b 1'.format(VS_VERSION_STRING[compiler_version][-4:]))
f.write('\nif not %CMAKE_GENERATOR% == "{}" exit /b 1'.format(VS_VERSION_STRING[compiler_version] +
f.write('\nif not "%VS_VERSION%" == "{}" exit /b 1'.format(compiler_version))
f.write('\nif not "%VS_MAJOR%" == "{}" exit /b 1'.format(compiler_version.split('.')[0]))
f.write('\nif not "%VS_YEAR%" == "{}" exit /b 1'.format(VS_VERSION_STRING[compiler_version][-4:]))
f.write('\nif not "%CMAKE_GENERATOR%" == "{}" exit /b 1'.format(VS_VERSION_STRING[compiler_version] +
{64: ' Win64', 32: ''}[bits]))
try:
subprocess.check_call(['cmd.exe', '/C', 'tmp_call.bat'], shell=True)
Expand Down

0 comments on commit c6b9aba

Please sign in to comment.