From 8f45bedb265d2af719137daf60cc70752a1aa10c Mon Sep 17 00:00:00 2001 From: Tony Roberts Date: Sat, 12 Apr 2014 13:03:05 +0100 Subject: [PATCH] Add manifest to npython to load the same c runtime as the python.exe used to build it. --- setup.py | 51 ++++++++++++++++++++++++++++++-------- src/console/Console.csproj | 3 +++ 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/setup.py b/setup.py index fca7f8312..f06b011d5 100644 --- a/setup.py +++ b/setup.py @@ -20,18 +20,30 @@ PLATFORM = "x64" if architecture()[0] == "64bit" else "x86" -def _find_msbuild_path(): - """Return full path to msbuild.exe""" +def _find_msbuild_tool(tool="msbuild.exe", use_windows_sdk=False): + """Return full path to one of the microsoft build tools""" import _winreg - hreg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE) - try: + if use_windows_sdk: + value_name = "InstallationFolder" + sdk_name = "Windows SDK" + keys_to_check = [ + r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1\WinSDKWin32Tools", + r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0\WinSDKWin32Tools", + r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0A\WinSDKWin32Tools", + ] + else: + value_name = "MSBuildToolsPath" + sdk_name = "MSBuild" keys_to_check = [ r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\12.0", r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0", r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\3.5", r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\2.0" ] + + hreg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE) + try: hkey = None for key in keys_to_check: try: @@ -41,23 +53,26 @@ def _find_msbuild_path(): pass if hkey is None: - raise RuntimeError("msbuild.exe could not be found") + raise RuntimeError("%s could not be found" % sdk_name) try: - val, type_ = _winreg.QueryValueEx(hkey, "MSBuildToolsPath") + val, type_ = _winreg.QueryValueEx(hkey, value_name) if type_ != _winreg.REG_SZ: - raise RuntimeError("msbuild.exe could not be found") + raise RuntimeError("%s could not be found" % sdk_name) + + path = os.path.join(val, tool) + if os.path.exists(path): + return path finally: hkey.Close() finally: hreg.Close() - msbuildpath = os.path.join(val, "msbuild.exe") - return msbuildpath - + raise RuntimeError("%s could not be found" % tool) + if DEVTOOLS == "MsDev": - _xbuild = "\"%s\"" % _find_msbuild_path() + _xbuild = "\"%s\"" % _find_msbuild_tool("msbuild.exe") _defines_sep = ";" _config = "%sWin" % CONFIG _npython_exe = "nPython.exe" @@ -107,6 +122,10 @@ def build_extension(self, ext): "/verbosity:%s" % VERBOSITY, ] + manifest = self._get_manifest(dest_dir) + if manifest: + cmd.append("/p:PythonManifest=\"%s\"" % manifest) + self.announce("Building: %s" % " ".join(cmd)) use_shell = True if DEVTOOLS == "Mono" else False check_call(" ".join(cmd + ["/t:Clean"]), shell=use_shell) @@ -116,6 +135,16 @@ def build_extension(self, ext): self._build_monoclr(ext) + def _get_manifest(self, build_dir): + if DEVTOOLS == "MsDev" and sys.version_info[:2] > (2,5): + mt = _find_msbuild_tool("mt.exe", use_windows_sdk=True) + manifest = os.path.abspath(os.path.join(build_dir, "app.manifest")) + cmd = [mt, '-inputresource:"%s"' % sys.executable, '-out:"%s"' % manifest] + self.announce("Extracting manifest from %s" % sys.executable) + check_call(" ".join(cmd), shell=False) + return manifest + + def _build_monoclr(self, ext): mono_libs = _check_output("pkg-config --libs mono-2", shell=True) mono_cflags = _check_output("pkg-config --cflags mono-2", shell=True) diff --git a/src/console/Console.csproj b/src/console/Console.csproj index 6a8baad95..95c1214d1 100644 --- a/src/console/Console.csproj +++ b/src/console/Console.csproj @@ -180,6 +180,9 @@ 4 False + + $(PythonManifest) +