diff options
| author | ruki <[email protected]> | 2016-07-14 16:51:17 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-07-14 16:51:17 +0800 |
| commit | dfe578f0d1ffc49f280a6b60724cf8c69674d451 (patch) | |
| tree | 5b0d3f4e0fabb2badfc0ac8544a71ca4c087ac1c | |
| parent | 8eb084ef12dccf72659704252f13cc3eea4b8fa6 (diff) | |
fix check vs issue
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | xmake/core/base/utils.lua | 11 | ||||
| -rw-r--r-- | xmake/core/tool/tool.lua | 6 | ||||
| -rw-r--r-- | xmake/platforms/windows/checker.lua | 228 |
4 files changed, 144 insertions, 103 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 83cc2e913..d2f36a03b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ * Fix install directory bug * Fix the root directory error for `import` interface +* Fix check visual stdio error on windows ## v2.0.2 @@ -137,6 +138,7 @@ * ����װĿ¼�������� * ��`import`��Ŀ¼�������� +* ���ڶ�汾vsͬʱ���ڵ�����£����vs����ʧ������ ## v2.0.2 diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua index b3891c0ce..eba9bcf35 100644 --- a/xmake/core/base/utils.lua +++ b/xmake/core/base/utils.lua @@ -78,6 +78,17 @@ function utils.verbose(format, ...) end end +-- the verbose error function +function utils.verror(format, ...) + + -- enable verbose? + if option.get("verbose") and format ~= nil then + + -- trace + utils.cprint("${bright red}error: ${default red}" .. string.format(format, ...)) + end +end + -- the error function function utils.error(format, ...) diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua index 03cc38bc8..ddfe715f2 100644 --- a/xmake/core/tool/tool.lua +++ b/xmake/core/tool/tool.lua @@ -192,7 +192,7 @@ function tool._check(shellname, check) -- check it local ok, errors = sandbox.load(check, shellname) if not ok then - utils.verbose(errors) + utils.verror(errors) end -- ok? @@ -202,7 +202,7 @@ function tool._check(shellname, check) -- load the tool module local module, errors = tool._load(shellname) if not module then - utils.verbose(errors) + utils.verror(errors) end -- no checker? attempt to run it directly @@ -213,7 +213,7 @@ function tool._check(shellname, check) -- check it local ok, errors = sandbox.load(module.check) if not ok then - utils.verbose(errors) + utils.verror(errors) end -- ok? diff --git a/xmake/platforms/windows/checker.lua b/xmake/platforms/windows/checker.lua index 001789227..a435fa74d 100644 --- a/xmake/platforms/windows/checker.lua +++ b/xmake/platforms/windows/checker.lua @@ -22,125 +22,155 @@ -- imports import("core.tool.tool") +import("core.base.option") import("platforms.checker", {rootdir = os.programdir()}) import("environment") --- check the vs version -function _check_vs_version(config) +-- attempt to apply this visual stdio from the given the envirnoment variable +function _apply_vs(config, envalue) - -- get the vs version - local vs = config.get("vs") - if not vs then - - -- make the map table - local map = - { - VS140COMNTOOLS = "2015" - , VS120COMNTOOLS = "2013" - , VS110COMNTOOLS = "2012" - , VS100COMNTOOLS = "2010" - , VS90COMNTOOLS = "2008" - , VS80COMNTOOLS = "2005" - , VS71COMNTOOLS = "2003" - , VS70COMNTOOLS = "7.0" - , VS60COMNTOOLS = "6.0" - , VS50COMNTOOLS = "5.0" - , VS42COMNTOOLS = "4.2" - } + -- get the vcvarsall.bat path + local vcvarsall = format("%s\\..\\..\\VC\\vcvarsall.bat", envalue) - -- attempt to get it from the envirnoment variable - for k, v in pairs(map) do - if os.getenv(k) then - vs = v - break - end + -- skip it if vcvarsall.bat not found + if not os.isfile(vcvarsall) then + if option.get("verbose") then + print("not found %s", vcvarsall) end + return + end - -- check ok? update it - if vs then + -- make the genvcvars.bat + local genvcvars_bat = path.join(os.tmpdir(), "xmake.genvcvars.bat") + local genvcvars_dat = path.join(os.tmpdir(), "xmake.genvcvars.dat") + local file = io.open(genvcvars_bat, "w") + file:print("@echo off") + file:print("call \"%s\" %s > nul", vcvarsall, config.get("arch")) + file:print("echo { > %s", genvcvars_dat) + file:print("echo path = \"%%path%%\" >> %s", genvcvars_dat) + file:print("echo , lib = \"%%lib%%\" >> %s", genvcvars_dat) + file:print("echo , libpath = \"%%libpath%%\" >> %s", genvcvars_dat) + file:print("echo , include = \"%%include%%\" >> %s", genvcvars_dat) + file:print("echo , devenvdir = \"%%devenvdir%%\" >> %s", genvcvars_dat) + file:print("echo , vsinstalldir = \"%%vsinstalldir%%\" >> %s", genvcvars_dat) + file:print("echo , vcinstalldir = \"%%vcinstalldir%%\" >> %s", genvcvars_dat) + file:print("echo } >> %s", genvcvars_dat) + file:close() - -- save it - config.set("vs", vs) + -- run genvcvars.bat + os.run(genvcvars_bat) - -- trace - print("checking for the Microsoft Visual Studio version ... %s", vs) - else - -- failed - print("checking for the Microsoft Visual Studio version ... no") - print("please run:") - print(" - xmake config --vs=xxx") - print("or - xmake global --vs=xxx") - raise() - end + -- replace "\" => "\\" + io.gsub(genvcvars_dat, "\\", "\\\\") + + -- load all envirnoment variables + local variables = io.load(genvcvars_dat) + + -- save the variables + for k, v in pairs(variables) do + config.set("__vsenv_" .. k, v) end + + -- enter environment + environment.enter("toolchains") + + -- done + local toolpath = tool.check("cl.exe") + + -- leave environment + environment.leave("toolchains") + + -- ok? + return toolpath end --- check the vs path -function _check_vs_path(config) +-- check the visual stdio +function _check_vs(config) - -- no vs path? - if not config.get("__vsenv_path") then + -- checked? + if config.get("vs") and config.get("__vsenv_path") then + return + end - -- get the vs version - local vs = config.get("vs") + -- envname => version + local envname2version = + { + VS140COMNTOOLS = "2015" + , VS120COMNTOOLS = "2013" + , VS110COMNTOOLS = "2012" + , VS100COMNTOOLS = "2010" + , VS90COMNTOOLS = "2008" + , VS80COMNTOOLS = "2005" + , VS71COMNTOOLS = "2003" + , VS70COMNTOOLS = "7.0" + , VS60COMNTOOLS = "6.0" + , VS50COMNTOOLS = "5.0" + , VS42COMNTOOLS = "4.2" + } - -- make the map table - local map = - { - ["2015"] = "VS140COMNTOOLS" - , ["2013"] = "VS120COMNTOOLS" - , ["2012"] = "VS110COMNTOOLS" - , ["2010"] = "VS100COMNTOOLS" - , ["2008"] = "VS90COMNTOOLS" - , ["2005"] = "VS80COMNTOOLS" - , ["2003"] = "VS71COMNTOOLS" - , ["7.0"] = "VS70COMNTOOLS" - , ["6.0"] = "VS60COMNTOOLS" - , ["5.0"] = "VS50COMNTOOLS" - , ["4.2"] = "VS42COMNTOOLS" - } + -- version => envname + local version2envname = + { + ["2015"] = "VS140COMNTOOLS" + , ["2013"] = "VS120COMNTOOLS" + , ["2012"] = "VS110COMNTOOLS" + , ["2010"] = "VS100COMNTOOLS" + , ["2008"] = "VS90COMNTOOLS" + , ["2005"] = "VS80COMNTOOLS" + , ["2003"] = "VS71COMNTOOLS" + , ["7.0"] = "VS70COMNTOOLS" + , ["6.0"] = "VS60COMNTOOLS" + , ["5.0"] = "VS50COMNTOOLS" + , ["4.2"] = "VS42COMNTOOLS" + } - -- check - if not map[vs] then - raise("vs %s not support!", vs) - end + -- attempt to check the given vs version first + local vs = config.get("vs") + if vs then + + -- get the envname + local envname = version2envname[vs] - -- the vcvarsall.bat path - local vcvarsall = format("%s\\..\\..\\VC\\vcvarsall.bat", os.getenv(map[vs])) - if not os.isfile(vcvarsall) then - raise("not found %s", vcvarsall) + -- clear vs first + vs = nil + + -- attempt to check it + if envname then + local envalue = os.getenv(envname) + if envalue and _apply_vs(config, envalue) then + vs = version + end end + end - -- make the genvcvars.bat - local genvcvars_bat = path.join(os.tmpdir(), "xmake.genvcvars.bat") - local genvcvars_dat = path.join(os.tmpdir(), "xmake.genvcvars.dat") - local file = io.open(genvcvars_bat, "w") - file:print("@echo off") - file:print("call \"%s\" %s > nul", vcvarsall, config.get("arch")) - file:print("echo { > %s", genvcvars_dat) - file:print("echo path = \"%%path%%\" >> %s", genvcvars_dat) - file:print("echo , lib = \"%%lib%%\" >> %s", genvcvars_dat) - file:print("echo , libpath = \"%%libpath%%\" >> %s", genvcvars_dat) - file:print("echo , include = \"%%include%%\" >> %s", genvcvars_dat) - file:print("echo , devenvdir = \"%%devenvdir%%\" >> %s", genvcvars_dat) - file:print("echo , vsinstalldir = \"%%vsinstalldir%%\" >> %s", genvcvars_dat) - file:print("echo , vcinstalldir = \"%%vcinstalldir%%\" >> %s", genvcvars_dat) - file:print("echo } >> %s", genvcvars_dat) - file:close() + -- attempt to check them from the envirnoment variables again + if not vs then + for envname, version in pairs(envname2version) do - -- run genvcvars.bat - os.run(genvcvars_bat) + -- attempt to get envirnoment variable and check it + local envalue = os.getenv(envname) + if envalue and _apply_vs(config, envalue) then + vs = version + break + end + end + end - -- replace "\" => "\\" - io.gsub(genvcvars_dat, "\\", "\\\\") + -- check ok? update it + if vs then - -- load all envirnoment variables - local variables = io.load(genvcvars_dat) + -- save it + config.set("vs", vs) - -- save the variables - for k, v in pairs(variables) do - config.set("__vsenv_" .. k, v) - end + -- trace + print("checking for the Microsoft Visual Studio version ... %s", vs) + else + -- failed + print("checking for the Microsoft Visual Studio version ... no") + print("please run:") + print(" - xmake config --vs=xxx") + print("or - xmake global --vs=xxx") + raise() end end @@ -170,16 +200,14 @@ function init() _g.config = { { checker.check_arch, "x86" } - , _check_vs_version - , _check_vs_path + , _check_vs , _check_toolchains } -- init the check list of global _g.global = { - _check_vs_version - , _check_vs_path + _check_vs } end |
