Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0416fda

Browse files
committed
Merge pull request pythonnet#45 from tonyroberts/develop
Add manifest to npython to load the same c runtime as the python.exe used to build it. fixes pythonnet#43
2 parents 820cae3 + 8f45bed commit 0416fda

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

setup.py

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,30 @@
2020
PLATFORM = "x64" if architecture()[0] == "64bit" else "x86"
2121

2222

23-
def _find_msbuild_path():
24-
"""Return full path to msbuild.exe"""
23+
def _find_msbuild_tool(tool="msbuild.exe", use_windows_sdk=False):
24+
"""Return full path to one of the microsoft build tools"""
2525
import _winreg
2626

27-
hreg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
28-
try:
27+
if use_windows_sdk:
28+
value_name = "InstallationFolder"
29+
sdk_name = "Windows SDK"
30+
keys_to_check = [
31+
r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1\WinSDKWin32Tools",
32+
r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0\WinSDKWin32Tools",
33+
r"SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0A\WinSDKWin32Tools",
34+
]
35+
else:
36+
value_name = "MSBuildToolsPath"
37+
sdk_name = "MSBuild"
2938
keys_to_check = [
3039
r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\12.0",
3140
r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0",
3241
r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\3.5",
3342
r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\2.0"
3443
]
44+
45+
hreg = _winreg.ConnectRegistry(None, _winreg.HKEY_LOCAL_MACHINE)
46+
try:
3547
hkey = None
3648
for key in keys_to_check:
3749
try:
@@ -41,23 +53,26 @@ def _find_msbuild_path():
4153
pass
4254

4355
if hkey is None:
44-
raise RuntimeError("msbuild.exe could not be found")
56+
raise RuntimeError("%s could not be found" % sdk_name)
4557

4658
try:
47-
val, type_ = _winreg.QueryValueEx(hkey, "MSBuildToolsPath")
59+
val, type_ = _winreg.QueryValueEx(hkey, value_name)
4860
if type_ != _winreg.REG_SZ:
49-
raise RuntimeError("msbuild.exe could not be found")
61+
raise RuntimeError("%s could not be found" % sdk_name)
62+
63+
path = os.path.join(val, tool)
64+
if os.path.exists(path):
65+
return path
5066
finally:
5167
hkey.Close()
5268
finally:
5369
hreg.Close()
5470

55-
msbuildpath = os.path.join(val, "msbuild.exe")
56-
return msbuildpath
57-
71+
raise RuntimeError("%s could not be found" % tool)
72+
5873

5974
if DEVTOOLS == "MsDev":
60-
_xbuild = "\"%s\"" % _find_msbuild_path()
75+
_xbuild = "\"%s\"" % _find_msbuild_tool("msbuild.exe")
6176
_defines_sep = ";"
6277
_config = "%sWin" % CONFIG
6378
_npython_exe = "nPython.exe"
@@ -107,6 +122,10 @@ def build_extension(self, ext):
107122
"/verbosity:%s" % VERBOSITY,
108123
]
109124

125+
manifest = self._get_manifest(dest_dir)
126+
if manifest:
127+
cmd.append("/p:PythonManifest=\"%s\"" % manifest)
128+
110129
self.announce("Building: %s" % " ".join(cmd))
111130
use_shell = True if DEVTOOLS == "Mono" else False
112131
check_call(" ".join(cmd + ["/t:Clean"]), shell=use_shell)
@@ -116,6 +135,16 @@ def build_extension(self, ext):
116135
self._build_monoclr(ext)
117136

118137

138+
def _get_manifest(self, build_dir):
139+
if DEVTOOLS == "MsDev" and sys.version_info[:2] > (2,5):
140+
mt = _find_msbuild_tool("mt.exe", use_windows_sdk=True)
141+
manifest = os.path.abspath(os.path.join(build_dir, "app.manifest"))
142+
cmd = [mt, '-inputresource:"%s"' % sys.executable, '-out:"%s"' % manifest]
143+
self.announce("Extracting manifest from %s" % sys.executable)
144+
check_call(" ".join(cmd), shell=False)
145+
return manifest
146+
147+
119148
def _build_monoclr(self, ext):
120149
mono_libs = _check_output("pkg-config --libs mono-2", shell=True)
121150
mono_cflags = _check_output("pkg-config --cflags mono-2", shell=True)

src/console/Console.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@
180180
<WarningLevel>4</WarningLevel>
181181
<Optimize>False</Optimize>
182182
</PropertyGroup>
183+
<PropertyGroup Condition="'$(PythonManifest)' != ''">
184+
<ApplicationManifest>$(PythonManifest)</ApplicationManifest>
185+
</PropertyGroup>
183186
<ItemGroup>
184187
<Reference Include="System" />
185188
<Reference Include="System.Core">

0 commit comments

Comments
 (0)