Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add 'msvc9compiler' patch to support building using VS Express and Wi…

…ndows SDK

The issue has been discussed here:

  http://bugs.python.org/issue7511


This patch combines Steve Dower's patch and Li Wah's definition for
KEY_BASE.

It solves the following error occurring when building Numpy 64-bit using
VS2010 Express and Windows SDK:

//-----------------------------------
Traceback (most recent call last):
  File "setup.py", line 187, in <module>
    setup_package()
  File "setup.py", line 180, in setup_package
    configuration=configuration )
  File "C:\P\SarrpTPS-64-R\Slicer-build\NUMPY\numpy\distutils\core.py", line 186, in setup
    return old_setup(**new_attr)
  File "C:\P\SarrpTPS-64-R\Slicer-build\python-install\Lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\P\SarrpTPS-64-R\Slicer-build\python-install\Lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\P\SarrpTPS-64-R\Slicer-build\python-install\Lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\P\SarrpTPS-64-R\Slicer-build\NUMPY\numpy\distutils\command\build.py", line 37, in run
    old_build.run(self)
  File "C:\P\SarrpTPS-64-R\Slicer-build\python-install\Lib\distutils\command\build.py", line 127, in run
    self.run_command(cmd_name)
  File "C:\P\SarrpTPS-64-R\Slicer-build\python-install\Lib\distutils\cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "C:\P\SarrpTPS-64-R\Slicer-build\python-install\Lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\P\SarrpTPS-64-R\Slicer-build\NUMPY\numpy\distutils\command\build_src.py", line 152, in run
    self.build_sources()
  File "C:\P\SarrpTPS-64-R\Slicer-build\NUMPY\numpy\distutils\command\build_src.py", line 163, in build_sources
    self.build_library_sources(*libname_info)
  File "C:\P\SarrpTPS-64-R\Slicer-build\NUMPY\numpy\distutils\command\build_src.py", line 298, in build_library_sources
    sources = self.generate_sources(sources, (lib_name, build_info))
  File "C:\P\SarrpTPS-64-R\Slicer-build\NUMPY\numpy\distutils\command\build_src.py", line 385, in generate_sources
    source = func(extension, build_dir)
  File "numpy\core\setup.py", line 655, in get_mathlib_info
    st = config_cmd.try_link('int main(void) { return 0;}')
  File "C:\P\SarrpTPS-64-R\Slicer-build\python-install\Lib\distutils\command\config.py", line 248, in try_link
    self._check_compiler()
  File "C:\P\SarrpTPS-64-R\Slicer-build\NUMPY\numpy\distutils\command\config.py", line 55, in _check_compiler
    self.compiler.initialize()
  File "C:\P\SarrpTPS-64-R\Slicer-build\python-install\Lib\distutils\msvc9compiler.py", line 383, in initialize
    vc_env = query_vcvarsall(VERSION, plat_spec)
  File "C:\P\SarrpTPS-64-R\Slicer-build\python-install\Lib\distutils\msvc9compiler.py", line 299, in query_vcvarsall
    raise ValueError(str(list(result.keys())))
ValueError: [u'path']
//-----------------------------------
  • Loading branch information...
commit af731e86b037795613c5af7c91d17065f4f500b0 1 parent 67dfbeb
@jcfr jcfr authored
View
185 cmake/patches-win32/07-msvc9compiler-vcexpress-and-sdk-support-issue7511.patch
@@ -0,0 +1,185 @@
+diff --git a/Lib/distutils/msvc9compiler.py b/Lib/distutils/msvc9compiler.py
+--- a/Lib/distutils/msvc9compiler.py
++++ b/Lib/distutils/msvc9compiler.py
+@@ -46,11 +46,15 @@ if NATIVE_WIN64:
+ VSEXPRESS_BASE = r"Software\Wow6432Node\Microsoft\VCExpress\%0.1f"
+ WINSDK_BASE = r"Software\Wow6432Node\Microsoft\Microsoft SDKs\Windows"
+ NET_BASE = r"Software\Wow6432Node\Microsoft\.NETFramework"
++ VC_SXS_KEY = r"Software\Wow6432Node\Microsoft\VisualStudio\SxS\VC7"
++ VS_SXS_KEY = r"Software\Wow6432Node\Microsoft\VisualStudio\SxS\VS7"
+ else:
+ VS_BASE = r"Software\Microsoft\VisualStudio\%0.1f"
+ VSEXPRESS_BASE = r"Software\Microsoft\VCExpress\%0.1f"
+ WINSDK_BASE = r"Software\Microsoft\Microsoft SDKs\Windows"
+ NET_BASE = r"Software\Microsoft\.NETFramework"
++ VC_SXS_KEY = r"Software\Microsoft\VisualStudio\SxS\VC7"
++ VS_SXS_KEY = r"Software\Microsoft\VisualStudio\SxS\VS7"
+
+ # A map keyed by get_platform() return values to values accepted by
+ # 'vcvarsall.bat'. Note a cross-compile may combine these (eg, 'x86_amd64' is
+@@ -61,6 +65,33 @@ PLAT_TO_VCVARS = {
+ 'win-ia64' : 'ia64',
+ }
+
++# Add the first found value of InstallationFolder from this list of
++# keys to %PATH%
++KEY_BASE = r"Software\Microsoft\\"
++WINSDK_PATH_KEYS = [KEY_BASE + "Microsoft SDKs\\Windows\\" + rest for rest in (
++ r"v%s\WinSDKWin32Tools-x64" if NATIVE_WIN64 else r"v%s\WinSDKWin32Tools",
++ r"v%s\WinSDKTools-x64" if NATIVE_WIN64 else r"v%s\WinSDKTools",
++ r"v%s",
++ r"v%sA"
++)]
++
++# Add the first found value of InstallationFolder, plus "include", from
++# this list of keys to %INCLUDE%.
++# Add the same value, plus "lib", to %LIB% and %LIBPATH%
++WINSDK_INCLUDE_KEYS = [KEY_BASE + "Microsoft SDKs\\Windows\\" + rest for rest in (
++ r"v%s\WinSDKBuild",
++ r"v%s",
++ r"v%sA"
++)]
++
++# A map from VC version to Windows SDK version, to be used as the format
++# parameter for each element of WINSDK_INCLUDE_KEYS.
++WINSDK_VERSION_MAP = {
++ '9.0': '7.0',
++ '10.0': '7.1',
++ '11.0': '8.0'
++}
++
+ class Reg:
+ """Helper class to read values from the registry
+ """
+@@ -216,6 +247,7 @@ def removeDuplicates(variable):
+ newVariable = os.pathsep.join(newList)
+ return newVariable
+
++# deprecated
+ def find_vcvarsall(version):
+ """Find the vcvarsall.bat file
+
+@@ -263,41 +295,88 @@ def find_vcvarsall(version):
+ def query_vcvarsall(version, arch="x86"):
+ """Launch vcvarsall.bat and read the settings from its environment
+ """
+- vcvarsall = find_vcvarsall(version)
+- interesting = set(("include", "lib", "libpath", "path"))
+- result = {}
+-
+- if vcvarsall is None:
+- raise DistutilsPlatformError("Unable to find vcvarsall.bat")
+- log.debug("Calling 'vcvarsall.bat %s' (version=%s)", arch, version)
+- popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch),
+- stdout=subprocess.PIPE,
+- stderr=subprocess.PIPE)
+- try:
+- stdout, stderr = popen.communicate()
+- if popen.wait() != 0:
+- raise DistutilsPlatformError(stderr.decode("mbcs"))
+-
+- stdout = stdout.decode("mbcs")
+- for line in stdout.split("\n"):
+- line = Reg.convert_mbcs(line)
+- if '=' not in line:
+- continue
+- line = line.strip()
+- key, value = line.split('=', 1)
+- key = key.lower()
+- if key in interesting:
+- if value.endswith(os.pathsep):
+- value = value[:-1]
+- result[key] = removeDuplicates(value)
+-
+- finally:
+- popen.stdout.close()
+- popen.stderr.close()
+-
+- if len(result) != len(interesting):
+- raise ValueError(str(list(result.keys())))
+-
++ result = {
++ "path": "",
++ "include": "",
++ "lib": "",
++ }
++
++ versionstr = '%.1f' % version
++ sdkver = WINSDK_VERSION_MAP[versionstr]
++
++ # set PATH to include:
++ # %VCINSTALLDIR%\bin
++ # %VCINSTALLDIR%\VCPackages
++ # %VSINSTALLDIR%\Common7\IDE (if it exists)
++ # %VSINSTALLDIR%\Common7\Tools (if it exists)
++ # %VSINSTALLDIR%\Common7\Tools\bin (if it exists)
++ # %FrameworkDir%\%Framework35Version%
++ # %FrameworkDir%\%FrameworkVersion%
++ # %WindowsSdkDir%bin
++
++ vcpaths = Reg.read_values(_winreg.HKEY_LOCAL_MACHINE, VC_SXS_KEY)
++ vcinstalldir = vcpaths[versionstr]
++ vsinstalldir = Reg.read_values(_winreg.HKEY_LOCAL_MACHINE, VS_SXS_KEY).get(versionstr, vcinstalldir + "..")
++
++ if vcinstalldir:
++ if arch == "x86":
++ result["path"] += "%s\\bin;%s\\VCPackages;" % (vcinstalldir, vcinstalldir)
++ else:
++ result["path"] += "%s\\bin\\%s;%s\\VCPackages;" % (vcinstalldir, arch, vcinstalldir)
++
++ if vsinstalldir:
++ result["path"] += "%s\\Common7\\IDE;%s\\Tools;%s\\Tools\\bin;" % (vsinstalldir, vsinstalldir, vsinstalldir)
++
++ frameworkdir = vcpaths.get("frameworkdir64" if arch == "amd64" else "frameworkdir32")
++ if frameworkdir:
++ result["path"] += frameworkdir + r"\v3.5;"
++ frameworkver = vcpaths.get("frameworkver64" if arch == "amd64" else "frameworkdir32")
++ if frameworkver:
++ result["path"] += r"%s\%s;" % (frameworkdir, frameworkver)
++
++ for sdkkey in WINSDK_PATH_KEYS:
++ try:
++ sdk_install = Reg.get_value(sdkkey % sdkver, "installationfolder")
++ except KeyError:
++ pass
++ else:
++ result["path"] += sdk_install + ";"
++ break
++ else:
++ log.debug("no Windows SDK found")
++
++ # set INCLUDE to include:
++ # %WindowsSdkDir%include
++ # %VCINSTALLDIR%\include
++ # and LIB to include
++ # %WindowsSdkDir%lib[\x64|\amd64|\ia64]
++ # %VCINSTALLDIR%\lib[\x64|\amd64|\ia64]
++
++ def _add_include_lib_paths(base):
++ result["include"] += base + r"\include;"
++ if arch.endswith("ia64"):
++ result["lib"] += base + r"\lib\ia64;"
++ elif arch.endswith("64") and os.path.isdir(base + r"\lib\x64"):
++ result["lib"] += base + r"\lib\x64;"
++ elif arch.endswith("64") and os.path.isdir(base + r"\lib\amd64"):
++ result["lib"] += base + r"\lib\amd64;"
++ else:
++ result["lib"] += base + r"\lib;"
++
++ for sdkkey in WINSDK_INCLUDE_KEYS:
++ try:
++ sdk_install = Reg.get_value(sdkkey % sdkver, "installationfolder")
++ except KeyError:
++ pass
++ else:
++ _add_include_lib_paths(sdk_install)
++ break
++ else:
++ log.debug("no Windows SDK found")
++
++ if vcinstalldir:
++ _add_include_lib_paths(vcinstalldir)
++
+ return result
+
+ # More globals
Please sign in to comment.
Something went wrong with that request. Please try again.