Python support for win32 adxe compile command

This commit is contained in:
halx99 2021-05-27 17:23:03 +08:00
parent c4dc07d1aa
commit a7fe3e01a9
2 changed files with 41 additions and 38 deletions

View File

@ -7,6 +7,12 @@ import shutil
import adxe import adxe
import re import re
if sys.platform == 'win32':
if(sys.version_info.major >= 3):
import winreg
else:
import _winreg as winreg
VS_VERSION_MAP = { VS_VERSION_MAP = {
2012 : "11.0", 2012 : "11.0",
2013 : "12.0", 2013 : "12.0",
@ -16,9 +22,7 @@ VS_VERSION_MAP = {
} }
def get_msbuild_path(vs_version): def get_msbuild_path(vs_version):
if adxe.os_is_win32(): if not adxe.os_is_win32():
import _winreg
else:
return None return None
if isinstance(vs_version, int): if isinstance(vs_version, int):
@ -37,21 +41,21 @@ def get_msbuild_path(vs_version):
# If the system is 64bit, find VS in both 32bit & 64bit registry # If the system is 64bit, find VS in both 32bit & 64bit registry
# If the system is 32bit, only find VS in 32bit registry # If the system is 32bit, only find VS in 32bit registry
if adxe.os_is_32bit_windows(): if adxe.os_is_32bit_windows():
reg_flag_list = [ _winreg.KEY_WOW64_32KEY ] reg_flag_list = [ winreg.KEY_WOW64_32KEY ]
else: else:
reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ] reg_flag_list = [ winreg.KEY_WOW64_64KEY, winreg.KEY_WOW64_32KEY ]
# Find VS path # Find VS path
msbuild_path = None msbuild_path = None
for reg_flag in reg_flag_list: for reg_flag in reg_flag_list:
try: try:
vs = _winreg.OpenKey( vs = winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_LOCAL_MACHINE,
r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\%s" % vs_ver, r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\%s" % vs_ver,
0, 0,
_winreg.KEY_READ | reg_flag winreg.KEY_READ | reg_flag
) )
msbuild_path, type = _winreg.QueryValueEx(vs, 'MSBuildToolsPath') msbuild_path, type = winreg.QueryValueEx(vs, 'MSBuildToolsPath')
except: except:
continue continue
@ -65,9 +69,7 @@ def get_msbuild_path(vs_version):
return msbuild_path return msbuild_path
def get_devenv_path(vs_version): def get_devenv_path(vs_version):
if adxe.os_is_win32(): if not adxe.os_is_win32():
import _winreg
else:
return None return None
if isinstance(vs_version, int): if isinstance(vs_version, int):
@ -86,26 +88,26 @@ def get_devenv_path(vs_version):
# If the system is 64bit, find VS in both 32bit & 64bit registry # If the system is 64bit, find VS in both 32bit & 64bit registry
# If the system is 32bit, only find VS in 32bit registry # If the system is 32bit, only find VS in 32bit registry
if adxe.os_is_32bit_windows(): if adxe.os_is_32bit_windows():
reg_flag_list = [ _winreg.KEY_WOW64_32KEY ] reg_flag_list = [ winreg.KEY_WOW64_32KEY ]
else: else:
reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ] reg_flag_list = [ winreg.KEY_WOW64_64KEY, winreg.KEY_WOW64_32KEY ]
devenv_path = None devenv_path = None
for reg_flag in reg_flag_list: for reg_flag in reg_flag_list:
try: try:
vs = _winreg.OpenKey( vs = winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_LOCAL_MACHINE,
r"SOFTWARE\Microsoft\VisualStudio", r"SOFTWARE\Microsoft\VisualStudio",
0, 0,
_winreg.KEY_READ | reg_flag winreg.KEY_READ | reg_flag
) )
except: except:
continue continue
# find specified VS # find specified VS
try: try:
key = _winreg.OpenKey(vs, r"SxS\VS7") key = winreg.OpenKey(vs, r"SxS\VS7")
devenv_path, type = _winreg.QueryValueEx(key, vs_ver) devenv_path, type = winreg.QueryValueEx(key, vs_ver)
except: except:
pass pass
@ -121,26 +123,24 @@ def get_devenv_path(vs_version):
def get_vs_versions(): def get_vs_versions():
# Get the VS versions # Get the VS versions
ret = [] ret = []
if adxe.os_is_win32(): if not adxe.os_is_win32():
import _winreg
else:
return ret return ret
# If the system is 64bit, find VS in both 32bit & 64bit registry # If the system is 64bit, find VS in both 32bit & 64bit registry
# If the system is 32bit, only find VS in 32bit registry # If the system is 32bit, only find VS in 32bit registry
if adxe.os_is_32bit_windows(): if adxe.os_is_32bit_windows():
reg_flag_list = [ _winreg.KEY_WOW64_32KEY ] reg_flag_list = [ winreg.KEY_WOW64_32KEY ]
else: else:
reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ] reg_flag_list = [ winreg.KEY_WOW64_64KEY, winreg.KEY_WOW64_32KEY ]
version_pattern = re.compile(r'(\d+)\.(\d+)') version_pattern = re.compile(r'(\d+)\.(\d+)')
for reg_flag in reg_flag_list: for reg_flag in reg_flag_list:
try: try:
vs = _winreg.OpenKey( vs = winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_LOCAL_MACHINE,
r"SOFTWARE\Microsoft\VisualStudio", r"SOFTWARE\Microsoft\VisualStudio",
0, 0,
_winreg.KEY_READ | reg_flag winreg.KEY_READ | reg_flag
) )
except: except:
continue continue
@ -149,7 +149,7 @@ def get_vs_versions():
while True: while True:
# enum the keys in vs reg # enum the keys in vs reg
try: try:
version = _winreg.EnumKey(vs, i) version = winreg.EnumKey(vs, i)
except: except:
break break
i += 1 i += 1

View File

@ -87,12 +87,15 @@ class CCPluginDeploy(adxe.CCPlugin):
self.project_name = compile_dep.project_name self.project_name = compile_dep.project_name
def find_xap_deploy_tool(self): def find_xap_deploy_tool(self):
import _winreg if(sys.version_info.major >= 3):
import winreg
else:
import _winreg as winreg
import re import re
if adxe.os_is_32bit_windows(): if adxe.os_is_32bit_windows():
reg_flag_list = [ _winreg.KEY_WOW64_32KEY ] reg_flag_list = [ winreg.KEY_WOW64_32KEY ]
else: else:
reg_flag_list = [ _winreg.KEY_WOW64_64KEY, _winreg.KEY_WOW64_32KEY ] reg_flag_list = [ winreg.KEY_WOW64_64KEY, winreg.KEY_WOW64_32KEY ]
pattern = re.compile(r"v(\d+).(\d+)") pattern = re.compile(r"v(\d+).(\d+)")
find_ret = None find_ret = None
@ -100,13 +103,13 @@ class CCPluginDeploy(adxe.CCPlugin):
find_minor = -1 find_minor = -1
for reg_flag in reg_flag_list: for reg_flag in reg_flag_list:
adxe.Logging.info(MultiLanguage.get_string('DEPLOY_INFO_FIND_XAP_FMT', adxe.Logging.info(MultiLanguage.get_string('DEPLOY_INFO_FIND_XAP_FMT',
("32bit" if reg_flag == _winreg.KEY_WOW64_32KEY else "64bit"))) ("32bit" if reg_flag == winreg.KEY_WOW64_32KEY else "64bit")))
try: try:
wp = _winreg.OpenKey( wp = winreg.OpenKey(
_winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_LOCAL_MACHINE,
r"SOFTWARE\Microsoft\Microsoft SDKs\WindowsPhone", r"SOFTWARE\Microsoft\Microsoft SDKs\WindowsPhone",
0, 0,
_winreg.KEY_READ | reg_flag winreg.KEY_READ | reg_flag
) )
except: except:
# windows phone not found, continue # windows phone not found, continue
@ -115,7 +118,7 @@ class CCPluginDeploy(adxe.CCPlugin):
i = 0 i = 0
while True: while True:
try: try:
version = _winreg.EnumKey(wp, i) version = winreg.EnumKey(wp, i)
except: except:
break break
@ -126,8 +129,8 @@ class CCPluginDeploy(adxe.CCPlugin):
minor = int(match.group(2)) minor = int(match.group(2))
if major > 7: if major > 7:
try: try:
key = _winreg.OpenKey(wp, "%s\Install Path" % version) key = winreg.OpenKey(wp, "%s\Install Path" % version)
value, type = _winreg.QueryValueEx(key, "Install Path") value, type = winreg.QueryValueEx(key, "Install Path")
tool_path = os.path.join(value, "Tools", "XAP Deployment", "XapDeployCmd.exe") tool_path = os.path.join(value, "Tools", "XAP Deployment", "XapDeployCmd.exe")
if os.path.isfile(tool_path): if os.path.isfile(tool_path):
if (find_ret is None) or (major > find_major) or (major == find_major and minor > find_minor): if (find_ret is None) or (major > find_major) or (major == find_major and minor > find_minor):