summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-03 11:14:42 +0800
committerruki <[email protected]>2015-06-03 11:14:42 +0800
commit648d0f6875478a5184668996f3948a0e61e862a0 (patch)
tree1609c20c7e40bd60007f54e0943209c135b4f3d7
parent08bba742c061c93f28c14499fa17af2f1edc2df8 (diff)
probe the windows envirnoment
-rw-r--r--xmake/scripts/base/config.lua7
-rw-r--r--xmake/scripts/base/global.lua6
-rw-r--r--xmake/scripts/base/preprocessor.lua4
-rw-r--r--xmake/scripts/platform/macosx/_macosx.lua1
-rw-r--r--xmake/scripts/platform/windows/_prober.lua146
-rw-r--r--xmake/scripts/platform/windows/_windows.lua6
6 files changed, 157 insertions, 13 deletions
diff --git a/xmake/scripts/base/config.lua b/xmake/scripts/base/config.lua
index f53338a05..92721fa70 100644
--- a/xmake/scripts/base/config.lua
+++ b/xmake/scripts/base/config.lua
@@ -38,7 +38,7 @@ function config._save_with_level(file, object, level)
-- save string
if type(object) == "string" then
- file:write(object)
+ file:write(string.format("%q", object))
-- save boolean
elseif type(object) == "boolean" then
file:write(tostring(object))
@@ -153,7 +153,7 @@ function config._make()
-- get configs from all targets
for k, v in pairs(configs) do
- if type(k) == "string" and not k:find("_%u+") then
+ if type(k) == "string" and not k:find("^_%u+") then
current[k] = v
end
end
@@ -217,7 +217,8 @@ end
function config.set(name, value)
-- check
- assert(config._CURRENT and name and value)
+ assert(config._CURRENT)
+ assert(name and value and type(value) ~= "table")
-- get the current target
local target = config._target()
diff --git a/xmake/scripts/base/global.lua b/xmake/scripts/base/global.lua
index 64836bd2c..2371445ee 100644
--- a/xmake/scripts/base/global.lua
+++ b/xmake/scripts/base/global.lua
@@ -38,7 +38,7 @@ function global._save_with_level(file, object, level)
-- save string
if type(object) == "string" then
- file:write(object)
+ file:write(string.format("%q", object))
-- save boolean
elseif type(object) == "boolean" then
file:write(tostring(object))
@@ -120,7 +120,7 @@ function global._make()
-- make current global configure
for k, v in pairs(configs) do
- if type(k) == "string" and not k:find("_%u+") then
+ if type(k) == "string" and not k:find("^_%u+") then
current[k] = v
end
end
@@ -147,7 +147,7 @@ function global.set(name, value)
-- check
assert(global._CURRENT and global._CONFIGS)
- assert(name and value)
+ assert(name and value and type(value) ~= "table")
-- set it to the current configure
global._CURRENT[name] = value
diff --git a/xmake/scripts/base/preprocessor.lua b/xmake/scripts/base/preprocessor.lua
index 10a64593b..0ea137307 100644
--- a/xmake/scripts/base/preprocessor.lua
+++ b/xmake/scripts/base/preprocessor.lua
@@ -129,11 +129,11 @@ function preprocessor._init(root, configures, scopes, filter, import)
_current[key] = nil
elseif table.getn(arg) == 1 then
-- save only one argument
- _current[key] = preprocessor._filter(newenv, arg[1], filter)
+ _current[key] = arg[1]
else
-- save all arguments
for i, v in ipairs(arg) do
- _current[key][i] = preprocessor._filter(newenv, v, filter)
+ _current[key][i] = v
end
end
end
diff --git a/xmake/scripts/platform/macosx/_macosx.lua b/xmake/scripts/platform/macosx/_macosx.lua
index 8ff4d31cc..6ab67da0f 100644
--- a/xmake/scripts/platform/macosx/_macosx.lua
+++ b/xmake/scripts/platform/macosx/_macosx.lua
@@ -59,7 +59,6 @@ function _macosx.make(configs)
-- init xcode sdk directory
configs.xcode_sdkdir = config.get("xcode_dir") .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. config.get("xcode_sdkver") .. ".sdk"
-
end
-- get the option menu for action: xmake config or global
diff --git a/xmake/scripts/platform/windows/_prober.lua b/xmake/scripts/platform/windows/_prober.lua
index 13cb0b52f..3361e8939 100644
--- a/xmake/scripts/platform/windows/_prober.lua
+++ b/xmake/scripts/platform/windows/_prober.lua
@@ -45,12 +45,158 @@ function _prober._probe_arch(configs)
return true
end
+-- probe the vs version
+function _prober._probe_vs_version(configs)
+
+ -- get the vs version
+ local vs = configs.vs
+
+ -- ok?
+ if vs then return true end
+
+ -- clear it first
+ vs = nil
+
+ -- make the map table
+ local map =
+ {
+ VS120COMNTOOLS = "2013"
+ , VS110COMNTOOLS = "2012"
+ , VS100COMNTOOLS = "2010"
+ , VS90COMNTOOLS = "2008"
+ , VS80COMNTOOLS = "2005"
+ , VS71COMNTOOLS = "2003"
+ , VS70COMNTOOLS = "7.0"
+ , VS60COMNTOOLS = "6.0"
+ , VS50COMNTOOLS = "5.0"
+ , VS42COMNTOOLS = "4.2"
+ }
+
+ -- attempt to get it from the envirnoment variable
+ if not vs then
+ for k, v in pairs(map) do
+ if os.getenv(k) then
+ vs = v
+ break
+ end
+ end
+ end
+
+ -- probe ok? update it
+ if vs then
+ configs.vs = vs
+ else
+ -- failed
+ utils.error("The Microsoft Visual Studio is unknown now, please config it first!")
+ utils.error(" - xmake config --vs=xxx")
+ utils.error("or - xmake global --vs=xxx")
+ return false
+ end
+
+ -- ok
+ return true
+end
+
+-- probe the vs path
+function _prober._probe_vs_path(configs)
+
+ -- ok?
+ if configs.__vsenv_path then return true end
+
+ -- get the vs version
+ local vs = configs.vs
+ assert(vs)
+
+ -- make the map table
+ local map =
+ {
+ ["2013"] = "VS120COMNTOOLS"
+ , ["2012"] = "VS110COMNTOOLS"
+ , ["2010"] = "VS100COMNTOOLS"
+ , ["2008"] = "VS90COMNTOOLS"
+ , ["2005"] = "VS80COMNTOOLS"
+ , ["2003"] = "VS71COMNTOOLS"
+ , ["7.0"] = "VS70COMNTOOLS"
+ , ["6.0"] = "VS60COMNTOOLS"
+ , ["5.0"] = "VS50COMNTOOLS"
+ , ["4.2"] = "VS42COMNTOOLS"
+ }
+
+ -- attempt to get the tools directory from the envirnoment variable
+ local toolsdir = map[vs]
+ if toolsdir then
+ toolsdir = os.getenv(toolsdir)
+ end
+
+ -- the vsvars32.bat path
+ local vsvars32 = toolsdir .. "\\vsvars32.bat"
+ if not os.isfile(vsvars32) then
+ -- error
+ utils.error("not found %s", vsvars32)
+ return false
+ end
+
+ -- get the temporary directory
+ local tmpdir = os.tmpdir()
+ assert(tmpdir)
+
+ -- make the call(vsvars32.bat) file
+ local callpath = tmpdir .. "\\call_vsvars32.bat"
+ local callfile = io.open(callpath, "w")
+ assert(callfile)
+
+ -- make call scripts
+ callfile:write("@echo off\n")
+ callfile:write(string.format("call \"%s\" > nul\n", vsvars32))
+ callfile:write("echo return \n")
+ callfile:write("echo { \n")
+ callfile:write("echo path = \"%path%\"\n")
+ callfile:write("echo , lib = \"%lib%\"\n")
+ callfile:write("echo , libpath = \"%libpath%\"\n")
+ callfile:write("echo , include = \"%include%\"\n")
+ callfile:write("echo , devenvdir = \"%devenvdir%\"\n")
+ callfile:write("echo , vsinstalldir = \"%vsinstalldir%\"\n")
+ callfile:write("echo , vcinstalldir = \"%vcinstalldir%\"\n")
+ callfile:write("echo } \n")
+
+ -- close the file
+ callfile:close()
+
+ -- execute the call(vsvars32.bat) file and get all envirnoment variables
+ local cmd = io.popen(callpath)
+ local results = cmd:read("*all")
+ cmd:close()
+
+ -- translate '\' => '\\'
+ results = results:gsub("\\", "\\\\")
+
+ -- get all envirnoment variables
+ local variables = assert(loadstring(results))()
+ if not variables or not variables.path then
+ return false
+ end
+
+ -- save the variables
+ for k, v in pairs(variables) do
+ configs["__vsenv_" .. k] = v
+ end
+
+ -- ok
+ return true
+end
+
-- probe the configure
function _prober.done(configs)
-- probe the architecture
if not _prober._probe_arch(configs) then return end
+ -- probe the vs version
+ if not _prober._probe_vs_version(configs) then return end
+
+ -- probe the vs path
+ if not _prober._probe_vs_path(configs) then return end
+
end
-- return module: _prober
diff --git a/xmake/scripts/platform/windows/_windows.lua b/xmake/scripts/platform/windows/_windows.lua
index cfe3e422d..1e13e134b 100644
--- a/xmake/scripts/platform/windows/_windows.lua
+++ b/xmake/scripts/platform/windows/_windows.lua
@@ -64,15 +64,13 @@ function _windows.menu(action)
-- init config option menu
_windows._MENU_CONFIG = _windows._MENU_CONFIG or
{ {}
- , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio Directory" }
- , {nil, "vs_sdk", "kv", "auto", "The Microsoft Visual Studio SDK Directory" }
+ , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio" }
, }
-- init global option menu
_windows._MENU_GLOBAL = _windows._MENU_GLOBAL or
{ {}
- , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio Directory" }
- , {nil, "vs_sdk", "kv", "auto", "The Microsoft Visual Studio SDK Directory" }
+ , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio" }
, }
-- get the option menu