🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/console/Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@
<WarningLevel>4</WarningLevel>
<Optimize>False</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(PythonManifest)' != ''">
<ApplicationManifest>$(PythonManifest)</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core">
Expand Down