summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-06-01 11:23:19 +0800
committerruki <[email protected]>2017-06-01 11:23:19 +0800
commit2743cb2ee2b2640bbb22aa39d63c134563949a05 (patch)
tree937f1ac22b73da7bb6149bdb99671e80074dc879
parent95a3f4499e5fb575613b4192519a53d323a7a19c (diff)
improve find program, file and path modules
-rw-r--r--xmake/core/base/filter.lua4
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_file.lua13
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_path.lua13
-rw-r--r--xmake/core/sandbox/modules/import/lib/detect/find_program.lua13
-rw-r--r--xmake/modules/detect/sdk/find_vstudio.lua19
-rw-r--r--xmake/modules/detect/tool/find_ollydbg.lua9
-rw-r--r--xmake/modules/detect/tool/find_vsjitdebugger.lua7
-rw-r--r--xmake/modules/detect/tool/find_windbg.lua9
-rw-r--r--xmake/modules/detect/tool/find_x64dbg.lua9
9 files changed, 79 insertions, 17 deletions
diff --git a/xmake/core/base/filter.lua b/xmake/core/base/filter.lua
index b84c5f8e6..27442cf7c 100644
--- a/xmake/core/base/filter.lua
+++ b/xmake/core/base/filter.lua
@@ -87,7 +87,7 @@ function filter.reg(path)
end
-- query registry value
- return (winreg.query(regpath))
+ return (winreg.query(path))
end
-- register handler
@@ -110,7 +110,7 @@ function filter:get(variable, handler)
elseif variable:startswith("env ") then
return filter.env(variable:sub(5))
elseif variable:startswith("reg ") then
- return filter:reg(variable:sub(5))
+ return filter.reg(variable:sub(5))
end
-- parse variable:mode
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_file.lua b/xmake/core/sandbox/modules/import/lib/detect/find_file.lua
index ef9f52784..a9d13de62 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_file.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_file.lua
@@ -44,6 +44,8 @@ local vformat = require("sandbox/modules/vformat")
--
-- local file = find_file("ccache", { "/usr/bin", "/usr/local/bin"})
-- local file = find_file("test.h", { "/usr/include", "/usr/local/include/**"})
+-- local file = find_file("xxx.h", { "$(env PATH)", "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\XXXX;Name)"})
+-- local file = find_file("xxx.h", { "$(env PATH)", function () return val("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\XXXX;Name"):match("\"(.-)\"") end})
--
-- @endcode
--
@@ -54,7 +56,16 @@ function sandbox_lib_detect_find_file.main(name, pathes)
for _, _path in ipairs(table.wrap(pathes)) do
-- format path for builtin variables
- _path = vformat(_path)
+ if type(_path) == "function" then
+ local ok, results = sandbox.load(_path)
+ if ok then
+ _path = results or ""
+ else
+ raise(results)
+ end
+ else
+ _path = vformat(_path)
+ end
-- get file path
local filepath = nil
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_path.lua b/xmake/core/sandbox/modules/import/lib/detect/find_path.lua
index 4e83291f3..8748bd08a 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_path.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_path.lua
@@ -43,6 +43,8 @@ local vformat = require("sandbox/modules/vformat")
--
-- local p = find_path("include/test.h", { "/usr", "/usr/local"})
-- local p = find_path("include/*.h", { "/usr", "/usr/local/**"})
+-- local p = find_path("lib/xxx", { "$(env PATH)", "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\XXXX;Name)"})
+-- local p = find_path("lib/xxx", { "$(env PATH)", function () return val("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\XXXX;Name"):match("\"(.-)\"") end})
--
-- @endcode
--
@@ -53,7 +55,16 @@ function sandbox_lib_detect_find_path.main(name, pathes)
for _, _path in ipairs(table.wrap(pathes)) do
-- format path for builtin variables
- _path = vformat(_path)
+ if type(_path) == "function" then
+ local ok, results = sandbox.load(_path)
+ if ok then
+ _path = results or ""
+ else
+ raise(results)
+ end
+ else
+ _path = vformat(_path)
+ end
-- get file path
local filepath = nil
diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
index 8f53cfe2a..2ac078152 100644
--- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
+++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua
@@ -76,7 +76,16 @@ function sandbox_lib_detect_find_program._find(name, pathes, check)
for _, _path in ipairs(table.wrap(pathes)) do
-- format path for builtin variables
- _path = vformat(_path)
+ if type(_path) == "function" then
+ local ok, results = sandbox.load(_path)
+ if ok then
+ _path = results or ""
+ else
+ raise(results)
+ end
+ else
+ _path = vformat(_path)
+ end
-- get program path
local program_path = nil
@@ -125,6 +134,8 @@ end
-- local program = find_program("ccache", { "/usr/bin", "/usr/local/bin"})
-- local program = find_program("ccache", { "/usr/bin", "/usr/local/bin"}, "--help") -- simple check command: ccache --help
-- local program = find_program("ccache", { "/usr/bin", "/usr/local/bin"}, function (program) os.run("%s -h", program) end)
+-- local program = find_program("ccache", { "$(env PATH)", "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger)"})
+-- local program = find_program("ccache", { "$(env PATH)", function () return val("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger"):match("\"(.-)\"") end})
--
-- @endcode
--
diff --git a/xmake/modules/detect/sdk/find_vstudio.lua b/xmake/modules/detect/sdk/find_vstudio.lua
index d1a071c1f..1e2c88f1a 100644
--- a/xmake/modules/detect/sdk/find_vstudio.lua
+++ b/xmake/modules/detect/sdk/find_vstudio.lua
@@ -49,6 +49,22 @@ function main()
, ["4.2"] = "4.2"
}
+ -- init vsenvs
+ local vsenvs =
+ {
+ ["14.0"] = "VS140COMNTOOLS"
+ , ["12.0"] = "VS120COMNTOOLS"
+ , ["11.0"] = "VS110COMNTOOLS"
+ , ["10.0"] = "VS100COMNTOOLS"
+ , ["9.0"] = "VS90COMNTOOLS"
+ , ["8.0"] = "VS80COMNTOOLS"
+ , ["7.1"] = "VS71COMNTOOLS"
+ , ["7.0"] = "VS70COMNTOOLS"
+ , ["6.0"] = "VS60COMNTOOLS"
+ , ["5.0"] = "VS50COMNTOOLS"
+ , ["4.2"] = "VS42COMNTOOLS"
+ }
+
-- find vs2017 -> vs4.2
local results = {}
for _, version in ipairs({"15.0", "14.0", "12.0", "11.0", "10.0", "9.0", "8.0", "7.1", "7.0", "6.0", "5.0", "4.2"}) do
@@ -57,7 +73,8 @@ function main()
local vcvarsall = find_file("vcvarsall.bat", {format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC", version),
format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC", version),
format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC\\Auxiliary\\Build", version),
- format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC\\Auxiliary\\Build", version)})
+ format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\VC\\Auxiliary\\Build", version),
+ format("$(env %s)\\..\\..\\VC", vsenvs[version] or "")})
-- found?
if vcvarsall then
diff --git a/xmake/modules/detect/tool/find_ollydbg.lua b/xmake/modules/detect/tool/find_ollydbg.lua
index eaef184ea..636f52932 100644
--- a/xmake/modules/detect/tool/find_ollydbg.lua
+++ b/xmake/modules/detect/tool/find_ollydbg.lua
@@ -51,7 +51,10 @@ function main(opt)
opt = opt or {}
-- find program
- return find_program(opt.program or "ollydbg", {"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger]",
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger]"}
- , function (program) if not os.isfile(program) then raise() end end)
+ return find_program(opt.program or "ollydbg", {function ()
+ for _, reg in ipairs({"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger"}) do
+ return (val("reg " .. reg) or ""):match("\"(.-)\"")
+ end
+ end}
+ , function (program) if not os.isfile(program) then raise() end end)
end
diff --git a/xmake/modules/detect/tool/find_vsjitdebugger.lua b/xmake/modules/detect/tool/find_vsjitdebugger.lua
index 922d3fdf3..879fd0a5d 100644
--- a/xmake/modules/detect/tool/find_vsjitdebugger.lua
+++ b/xmake/modules/detect/tool/find_vsjitdebugger.lua
@@ -51,7 +51,10 @@ function main(opt)
opt = opt or {}
-- find program
- return find_program(opt.program or "vsjitdebugger", {"$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger)",
- "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger)"}
+ return find_program(opt.program or "vsjitdebugger", {function ()
+ for _, reg in ipairs({"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger"}) do
+ return (val("reg " .. reg) or ""):match("\"(.-)\"")
+ end
+ end}
, function (program) if not os.isfile(program) then raise() end end)
end
diff --git a/xmake/modules/detect/tool/find_windbg.lua b/xmake/modules/detect/tool/find_windbg.lua
index 7b57f2c1f..323855d79 100644
--- a/xmake/modules/detect/tool/find_windbg.lua
+++ b/xmake/modules/detect/tool/find_windbg.lua
@@ -51,7 +51,10 @@ function main(opt)
opt = opt or {}
-- find program
- return find_program(opt.program or "windbg", {"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger]",
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger]"}
- , function (program) if not os.isfile(program) then raise() end end)
+ return find_program(opt.program or "windbg", {function ()
+ for _, reg in ipairs({"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger"}) do
+ return (val("reg " .. reg) or ""):match("\"(.-)\"")
+ end
+ end}
+ , function (program) if not os.isfile(program) then raise() end end)
end
diff --git a/xmake/modules/detect/tool/find_x64dbg.lua b/xmake/modules/detect/tool/find_x64dbg.lua
index 86aea7ebc..431fea112 100644
--- a/xmake/modules/detect/tool/find_x64dbg.lua
+++ b/xmake/modules/detect/tool/find_x64dbg.lua
@@ -51,7 +51,10 @@ function main(opt)
opt = opt or {}
-- find program
- return find_program(opt.program or "x64dbg", {"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger]",
- "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger]"}
- , function (program) if not os.isfile(program) then raise() end end)
+ return find_program(opt.program or "x64dbg", {function ()
+ for _, reg in ipairs({"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger"}) do
+ return (val("reg " .. reg) or ""):match("\"(.-)\"")
+ end
+ end}
+ , function (program) if not os.isfile(program) then raise() end end)
end