diff options
| author | ruki <[email protected]> | 2017-09-22 00:40:49 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-09-21 22:04:55 +0800 |
| commit | ab5456ca3457c7b59de6cc590068d91d7749d096 (patch) | |
| tree | 329742618ea8ef110542f27fa48f4226a20dde9c | |
| parent | 034185734b5bc91f8188c15c9e02b0ce8ebaa850 (diff) | |
modify find_program interface
48 files changed, 266 insertions, 186 deletions
diff --git a/xmake/actions/require/action/install.lua b/xmake/actions/require/action/install.lua index a412820f8..a1c6dc343 100644 --- a/xmake/actions/require/action/install.lua +++ b/xmake/actions/require/action/install.lua @@ -261,8 +261,8 @@ function main(package) process.asyncrun(installtask) end - -- fetch package - assert(package:fetch(), "fetch %s failed!", tipname) + -- fetch package and force to flush the cache + assert(package:fetch(true), "fetch %s failed!", tipname) -- trace cprint("${green}ok") diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 04b243105..98fd4bb97 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -286,18 +286,25 @@ end -- -- @return {packageinfo}, fetchfrom (.e.g local/global/system) -- -function _instance:fetch() +function _instance:fetch(force) + + -- attempt to get it from cache + local fetchfrom = self._FETCHFROM + local fetchinfo = self._FETCHINFO + if not force and fetchinfo then + return fetchinfo, fetchfrom + end -- fetch binary tool? - local fetchfrom = self._FETCHFROM - local fetchinfo = self._FETCHINFO + fetchinfo = nil + fetchfrom = nil if self:kind() == "binary" then -- import find_tool self._find_tool = self._find_tool or sandbox_module.import("lib.detect.find_tool", {anonymous = true}) -- fetch it from the system directories - fetchinfo = self._find_tool(self:name()) + fetchinfo = self._find_tool(self:name(), {force = force}) if fetchinfo then fetchfrom = "system" -- ignore self:requireinfo().system end @@ -309,7 +316,7 @@ function _instance:fetch() -- fetch it from the package directories first local installdir = self:installdir() if not fetchinfo and installdir then - fetchinfo = self._find_package(self:name(), {packagedirs = installdir, system = false, force = true}) -- disable cache and system packages + fetchinfo = self._find_package(self:name(), {packagedirs = installdir, system = false, cachekey = "package:fetch", force = force}) if fetchinfo then fetchfrom = self._FROMKIND end end @@ -320,7 +327,7 @@ function _instance:fetch() system = true end if system then - fetchinfo = self._find_package(self:name()) + fetchinfo = self._find_package(self:name(), {force = force}) if fetchinfo then fetchfrom = "system" end end end diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua index caf88b50b..7f17568d3 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_package.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_package.lua @@ -283,7 +283,7 @@ end -- @param opt the package options. -- e.g. { verbose = false, force = false, plat = "iphoneos", arch = "arm64", mode = "debug", version = "1.0.1", -- linkdirs = {"/usr/lib"}, includedirs = "/usr/include", links = {"ssl"}, includes = {"ssl.h"} --- packagedirs = {"/tmp/packages"}, system = true} +-- packagedirs = {"/tmp/packages"}, system = true, cachekey = "xxxx"} -- -- @return {links = {"ssl", "crypto", "z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}} -- @@ -312,6 +312,9 @@ function sandbox_lib_detect_find_package.main(name, opt) -- init cache key local key = "find_package_" .. opt.plat .. "_" .. opt.arch + if opt.cachekey then + key = key .. "_" .. opt.cachekey + end -- attempt to get result from cache first local cacheinfo = cache.load(key) @@ -324,10 +327,8 @@ function sandbox_lib_detect_find_package.main(name, opt) result = sandbox_lib_detect_find_package._find(name, opt) -- cache result - if not opt.force then - cacheinfo[name] = utils.ifelse(result, result, false) - cache.save(key, cacheinfo) - end + cacheinfo[name] = utils.ifelse(result, result, false) + cache.save(key, cacheinfo) -- trace if opt.verbose or option.get("verbose") then 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 b9c6cbf93..2182f4d90 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua @@ -126,23 +126,24 @@ end -- find program -- -- @param name the program name --- @param pathes the program pathes (.e.g dirs, pathes, winreg pathes, script pathes) --- @param check the check script or command +-- @param opt the options, .e.g {pathes = {"/usr/bin"}, check = function (program) os.run("%s -h", program) end, verbose = true, force = true, cachekey = "xxx"} +-- - opt.pathes the program pathes (.e.g dirs, pathes, winreg pathes, script pathes) +-- - opt.check the check script or command -- -- @return the program name or path -- -- @code -- -- local program = find_program("ccache") --- 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 "/usr/local/bin" end}) +-- local program = find_program("ccache", {pathes = {"/usr/bin", "/usr/local/bin"}}) +-- local program = find_program("ccache", {pathes = {"/usr/bin", "/usr/local/bin"}, check = "--help"}) -- simple check command: ccache --help +-- local program = find_program("ccache", {pathes = {"/usr/bin", "/usr/local/bin"}, check = function (program) os.run("%s -h", program) end}) +-- local program = find_program("ccache", {pathes = {"$(env PATH)", "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug;Debugger)"}}) +-- local program = find_program("ccache", {pathes = {"$(env PATH)", function () return "/usr/local/bin" end}}) -- -- @endcode -- -function sandbox_lib_detect_find_program.main(name, pathes, check) +function sandbox_lib_detect_find_program.main(name, opt) -- @note avoid detect the same program in the same time leading to deadlock if running in the coroutine (.e.g ccache) local coroutine_running = coroutine.running() @@ -154,21 +155,31 @@ function sandbox_lib_detect_find_program.main(name, pathes, check) end end + -- init options + opt = opt or {} + + -- init cachekey + local cachekey = "find_program" + if opt.cachekey then + cachekey = cachekey .. "_" .. opt.cachekey + end + -- attempt to get result from cache first - local cacheinfo = cache.load("find_program") + local cacheinfo = cache.load(cachekey) local result = cacheinfo[name] - if result ~= nil then + if result ~= nil and not opt.force then return utils.ifelse(result, result, nil) end -- add default search pathes + local pathes = opt.pathes if os.host() ~= "windows" then pathes = table.join(table.wrap(pathes), "/usr/local/bin", "/usr/bin") end -- find executable program checking = utils.ifelse(coroutine_running, name, nil) - result = sandbox_lib_detect_find_program._find(name, pathes, check) + result = sandbox_lib_detect_find_program._find(name, pathes, opt.check) checking = nil -- cache result @@ -178,7 +189,7 @@ function sandbox_lib_detect_find_program.main(name, pathes, check) cache.save("find_program", cacheinfo) -- trace - if option.get("verbose") then + if option.get("verbose") or opt.verbose then if result then utils.cprint("checking for the %s ... ${green}%s", name, result) else diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua b/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua index 3f9520a9f..c4ab3af5c 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua @@ -39,31 +39,42 @@ local cache = require("sandbox/modules/import/lib/detect/cache") -- find program version -- -- @param program the program --- @param command the version command string or script, default: --version --- @param parse the version parse script or lua match pattern +-- @param opt the options, .e.g {command = "--version", parse = "(%d+%.?%d*%.?%d*.-)%s", verbose = true, force = true, cachekey = "xxx"} +-- - opt.command the version command string or script, default: --version +-- - opt.parse the version parse script or lua match pattern -- -- @return the version string -- -- @code -- local version = find_programver("ccache") --- local version = find_programver("ccache", "-v") --- local version = find_programver("ccache", "--version", "(%d+%.?%d*%.?%d*.-)%s") --- local version = find_programver("ccache", "--version", function (output) return output:match("(%d+%.?%d*%.?%d*.-)%s") end) --- local version = find_programver("ccache", function () return os.iorun("ccache --version") end) +-- local version = find_programver("ccache", {command = "-v"}) +-- local version = find_programver("ccache", {command = "--version", parse = "(%d+%.?%d*%.?%d*.-)%s"}) +-- local version = find_programver("ccache", {command = "--version", parse = function (output) return output:match("(%d+%.?%d*%.?%d*.-)%s") end}) +-- local version = find_programver("ccache", {command = function () return os.iorun("ccache --version") end}) -- @endcode -- -function sandbox_lib_detect_find_programver.main(program, command, parse) +function sandbox_lib_detect_find_programver.main(program, opt) + + -- init options + opt = opt or {} + + -- init cachekey + local cachekey = "find_programver" + if opt.cachekey then + cachekey = cachekey .. "_" .. opt.cachekey + end -- attempt to get result from cache first - local cacheinfo = cache.load("find_programver") + local cacheinfo = cache.load(cachekey) local result = cacheinfo[program] - if result ~= nil then + if result ~= nil and not opt.force then return utils.ifelse(result, result, nil) end -- attempt to get version output info local ok = false local outdata = nil + local command = opt.command if type(command) == "function" then ok, outdata = sandbox.load(command) if not ok then @@ -75,6 +86,7 @@ function sandbox_lib_detect_find_programver.main(program, command, parse) -- find version info if ok and outdata and #outdata > 0 then + local parse = opt.parse if type(parse) == "function" then ok, result = sandbox.load(parse, outdata) if not ok then diff --git a/xmake/modules/detect/tools/find_7z.lua b/xmake/modules/detect/tools/find_7z.lua index be9e50137..58f081240 100644 --- a/xmake/modules/detect/tools/find_7z.lua +++ b/xmake/modules/detect/tools/find_7z.lua @@ -42,15 +42,18 @@ import("lib.detect.find_programver") function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.check = opt.check or "--help" + opt.command = opt.command or "--help" + opt.parse = "(%d+%.?%d*)%s" -- find program - local program = find_program(opt.program or "7z", opt.pathes, opt.check or "--help") + local program = find_program(opt.program or "7z", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program, "--help", "(%d+%.?%d*)%s") + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_apt.lua b/xmake/modules/detect/tools/find_apt.lua index aa0c5ab68..7407aa0b4 100644 --- a/xmake/modules/detect/tools/find_apt.lua +++ b/xmake/modules/detect/tools/find_apt.lua @@ -45,15 +45,15 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "apt", opt.pathes, opt.check) + local program = find_program(opt.program or "apt", opt) if not program and not opt.program then - program = find_program("apt-get", opt.pathes, opt.check) + program = find_program("apt-get", opt) end -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_ar.lua b/xmake/modules/detect/tools/find_ar.lua index f6ec6a7c9..2fb701c75 100644 --- a/xmake/modules/detect/tools/find_ar.lua +++ b/xmake/modules/detect/tools/find_ar.lua @@ -63,8 +63,9 @@ end function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.check = opt.check or _check -- find program - return find_program(opt.program or "ar", opt.pathes, opt.check or _check) + return find_program(opt.program or "ar", opt) end diff --git a/xmake/modules/detect/tools/find_brew.lua b/xmake/modules/detect/tools/find_brew.lua index 1d6ffcb1c..33e4c8870 100644 --- a/xmake/modules/detect/tools/find_brew.lua +++ b/xmake/modules/detect/tools/find_brew.lua @@ -45,12 +45,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "brew", opt.pathes, opt.check) + local program = find_program(opt.program or "brew", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_ccache.lua b/xmake/modules/detect/tools/find_ccache.lua index 9c8f837be..883ff216e 100644 --- a/xmake/modules/detect/tools/find_ccache.lua +++ b/xmake/modules/detect/tools/find_ccache.lua @@ -45,12 +45,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "ccache", opt.pathes, opt.check) + local program = find_program(opt.program or "ccache", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_cl.lua b/xmake/modules/detect/tools/find_cl.lua index 9703363ed..c7f92c8e4 100644 --- a/xmake/modules/detect/tools/find_cl.lua +++ b/xmake/modules/detect/tools/find_cl.lua @@ -41,16 +41,18 @@ import("lib.detect.find_programver") function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.check = opt.check or function (program) os.run(program) end + opt.command = opt.command or function () local _, info = os.iorun(program); return info end + opt.parse = opt.parse or function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end -- find program - local program = find_program(opt.program or "cl.exe", opt.pathes, opt.check or function (program) os.run(program) end) + local program = find_program(opt.program or "cl.exe", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program, function () local _, info = os.iorun(program); return info end, - function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_clang.lua b/xmake/modules/detect/tools/find_clang.lua index ba09b7720..95b1e71b0 100644 --- a/xmake/modules/detect/tools/find_clang.lua +++ b/xmake/modules/detect/tools/find_clang.lua @@ -45,12 +45,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "clang", opt.pathes, opt.check) + local program = find_program(opt.program or "clang", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_clangxx.lua b/xmake/modules/detect/tools/find_clangxx.lua index b7ca869d8..c907093c4 100644 --- a/xmake/modules/detect/tools/find_clangxx.lua +++ b/xmake/modules/detect/tools/find_clangxx.lua @@ -45,12 +45,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "clang++", opt.pathes, opt.check) + local program = find_program(opt.program or "clang++", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_curl.lua b/xmake/modules/detect/tools/find_curl.lua index a17e77a14..97fc3a35b 100644 --- a/xmake/modules/detect/tools/find_curl.lua +++ b/xmake/modules/detect/tools/find_curl.lua @@ -45,12 +45,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "curl", opt.pathes, opt.check) + local program = find_program(opt.program or "curl", opt) -- find program version local version = nil if opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_dmd.lua b/xmake/modules/detect/tools/find_dmd.lua index 731cb53f4..d6794b9da 100644 --- a/xmake/modules/detect/tools/find_dmd.lua +++ b/xmake/modules/detect/tools/find_dmd.lua @@ -41,15 +41,17 @@ import("lib.detect.find_programver") function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.command = opt.command or "--version" + opt.parse = opt.parse or function (output) return output:match("v(%d+%.?%d*%.?%d*.-)%s") end -- find program - local program = find_program(opt.program or "dmd", opt.pathes, opt.check) + local program = find_program(opt.program or "dmd", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program, "--version", function (output) return output:match("v(%d+%.?%d*%.?%d*.-)%s") end) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_doxygen.lua b/xmake/modules/detect/tools/find_doxygen.lua index c0eb3aee6..f5a3d8406 100644 --- a/xmake/modules/detect/tools/find_doxygen.lua +++ b/xmake/modules/detect/tools/find_doxygen.lua @@ -45,12 +45,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "doxygen", opt.pathes, opt.check) + local program = find_program(opt.program or "doxygen", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_gcc.lua b/xmake/modules/detect/tools/find_gcc.lua index af27e0e0a..ae98c4a3a 100644 --- a/xmake/modules/detect/tools/find_gcc.lua +++ b/xmake/modules/detect/tools/find_gcc.lua @@ -45,12 +45,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "gcc", opt.pathes, opt.check) + local program = find_program(opt.program or "gcc", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_gccgo.lua b/xmake/modules/detect/tools/find_gccgo.lua index e447dfb1f..b3cdf100d 100644 --- a/xmake/modules/detect/tools/find_gccgo.lua +++ b/xmake/modules/detect/tools/find_gccgo.lua @@ -41,15 +41,17 @@ import("lib.detect.find_programver") function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.command = opt.command or "--version" + opt.parse = opt.parse or function (output) return output:match("%s(%d+%.?%d+%.?%d+)%s") end -- find program - local program = find_program(opt.program or "gccgo", opt.pathes, opt.check) + local program = find_program(opt.program or "gccgo", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program, "--version", function (output) return output:match("%s(%d+%.?%d+%.?%d+)%s") end) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_gdb.lua b/xmake/modules/detect/tools/find_gdb.lua index 7b97dd6b4..a199fd483 100644 --- a/xmake/modules/detect/tools/find_gdb.lua +++ b/xmake/modules/detect/tools/find_gdb.lua @@ -46,12 +46,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "gdb", opt.pathes, opt.check) + local program = find_program(opt.program or "gdb", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_gdc.lua b/xmake/modules/detect/tools/find_gdc.lua index 83b986cde..1ee950f34 100644 --- a/xmake/modules/detect/tools/find_gdc.lua +++ b/xmake/modules/detect/tools/find_gdc.lua @@ -41,15 +41,17 @@ import("lib.detect.find_programver") function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.command = opt.command or "--version" + opt.parse = opt.parse or function (output) return output:match("%s(%d+%.?%d+%.?%d+)%s") end -- find program - local program = find_program(opt.program or "gdc", opt.pathes, opt.check) + local program = find_program(opt.program or "gdc", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program, "--version", function (output) return output:match("%s(%d+%.?%d+%.?%d+)%s") end) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_git.lua b/xmake/modules/detect/tools/find_git.lua index 10e4b6ee8..fe1c36539 100644 --- a/xmake/modules/detect/tools/find_git.lua +++ b/xmake/modules/detect/tools/find_git.lua @@ -45,12 +45,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "git", opt.pathes, opt.check) + local program = find_program(opt.program or "git", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_go.lua b/xmake/modules/detect/tools/find_go.lua index fc1eaec9f..c7962a83a 100644 --- a/xmake/modules/detect/tools/find_go.lua +++ b/xmake/modules/detect/tools/find_go.lua @@ -41,15 +41,17 @@ import("lib.detect.find_programver") function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.check = opt.check or "version" + opt.command = opt.command or "version" -- find program - local program = find_program(opt.program or "go", opt.pathes, opt.check or "version") + local program = find_program(opt.program or "go", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program, "version") + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_gxx.lua b/xmake/modules/detect/tools/find_gxx.lua index be41b57a7..f2462ffed 100644 --- a/xmake/modules/detect/tools/find_gxx.lua +++ b/xmake/modules/detect/tools/find_gxx.lua @@ -45,12 +45,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "g++", opt.pathes, opt.check) + local program = find_program(opt.program or "g++", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_gzip.lua b/xmake/modules/detect/tools/find_gzip.lua index c07440a89..4f663bac7 100644 --- a/xmake/modules/detect/tools/find_gzip.lua +++ b/xmake/modules/detect/tools/find_gzip.lua @@ -45,15 +45,16 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "gzip", opt.pathes, opt.check) + local program = find_program(opt.program or "gzip", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program, function() - local outdata, errdata = os.iorunv(program, {"--version"}) - return (outdata or "") .. (errdata or "") - end) + opt.command = opt.command or function() + local outdata, errdata = os.iorunv(program, {"--version"}) + return (outdata or "") .. (errdata or "") + end + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_ldc2.lua b/xmake/modules/detect/tools/find_ldc2.lua index df241763f..082c2b6d2 100644 --- a/xmake/modules/detect/tools/find_ldc2.lua +++ b/xmake/modules/detect/tools/find_ldc2.lua @@ -41,15 +41,17 @@ import("lib.detect.find_programver") function main(opt) -- init options - opt = opt or {} - + opt = opt or {} + opt.command = opt.command or "--version" + opt.parse = opt.parse or function (output) return output:match("%((%d+%.?%d*%.?%d*.-)%)") end + -- find program - local program = find_program(opt.program or "ldc2", opt.pathes, opt.check) + local program = find_program(opt.program or "ldc2", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program, "--version", function (output) return output:match("%((%d+%.?%d*%.?%d*.-)%)") end) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_lib.lua b/xmake/modules/detect/tools/find_lib.lua index ae493e879..29fced8d0 100644 --- a/xmake/modules/detect/tools/find_lib.lua +++ b/xmake/modules/detect/tools/find_lib.lua @@ -40,12 +40,12 @@ import("lib.detect.find_programver") -- function main(opt) - -- init options - opt = opt or {} - - -- find program + -- init version info first local verinfo = nil - local program = find_program(opt.program or "lib.exe", opt.pathes, opt.check or function (program) + + -- init options + opt = opt or {} + opt.check = opt.check or function (program) -- make an stub source file local libraryfile = os.tmpfile() .. ".lib" @@ -62,13 +62,17 @@ function main(opt) os.rm(objectfile) os.rm(sourcefile) os.rm(libraryfile) - end) + end + opt.command = opt.command or function () return verinfo end + opt.parse = opt.parse or function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end + + -- find program + local program = find_program(opt.program or "lib.exe", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program, function () return verinfo end, - function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_link.lua b/xmake/modules/detect/tools/find_link.lua index 0523dc9fc..e732c4e7f 100644 --- a/xmake/modules/detect/tools/find_link.lua +++ b/xmake/modules/detect/tools/find_link.lua @@ -40,12 +40,12 @@ import("lib.detect.find_programver") -- function main(opt) + -- init version info first + local version = nil + -- init options - opt = opt or {} - - -- find program - local verinfo = nil - local program = find_program(opt.program or "link.exe", opt.pathes, opt.check or function (program) + opt = opt or {} + opt.check = opt.check or function (program) -- make an stub source file local binaryfile = os.tmpfile() .. ".exe" @@ -63,13 +63,17 @@ function main(opt) os.rm(objectfile) os.rm(sourcefile) os.rm(binaryfile) - end) + end + opt.command = opt.command or function () return verinfo end + opt.parse = opt.parse or function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end + + -- find program + local verinfo = nil + local program = find_program(opt.program or "link.exe", opt) -- find program version - local version = nil if program and opt and opt.version then - version = find_programver(program, function () return verinfo end, - function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_lipo.lua b/xmake/modules/detect/tools/find_lipo.lua index 303724049..ee685236b 100644 --- a/xmake/modules/detect/tools/find_lipo.lua +++ b/xmake/modules/detect/tools/find_lipo.lua @@ -41,8 +41,9 @@ import("lib.detect.find_programver") function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.check = opt.check or function (program) os.run("%s -info %s", program, os.programfile()) end -- find program - return find_program(opt.program or "lipo", opt.pathes, opt.check or function (program) os.run("%s -info %s", program, os.programfile()) end) + return find_program(opt.program or "lipo", opt) end diff --git a/xmake/modules/detect/tools/find_lldb.lua b/xmake/modules/detect/tools/find_lldb.lua index 00130895d..f40c843e9 100644 --- a/xmake/modules/detect/tools/find_lldb.lua +++ b/xmake/modules/detect/tools/find_lldb.lua @@ -46,12 +46,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "lldb", opt.pathes, opt.check) + local program = find_program(opt.program or "lldb", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_ml.lua b/xmake/modules/detect/tools/find_ml.lua index 479396c0c..136e5a8f7 100644 --- a/xmake/modules/detect/tools/find_ml.lua +++ b/xmake/modules/detect/tools/find_ml.lua @@ -41,16 +41,18 @@ import("lib.detect.find_programver") function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.check = opt.check or function (program) os.run(program) end -- find program - local program = find_program(opt.program or "ml.exe", opt.pathes, opt.check or function (program) os.run(program) end) + local program = find_program(opt.program or "ml.exe", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program, function () local _, info = os.iorun(program); return info end, - function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end) + opt.command = opt.command or function () local _, info = os.iorun(program); return info end + opt.parse = opt.parse or function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_ml64.lua b/xmake/modules/detect/tools/find_ml64.lua index c87772e04..f0eef393f 100644 --- a/xmake/modules/detect/tools/find_ml64.lua +++ b/xmake/modules/detect/tools/find_ml64.lua @@ -41,16 +41,18 @@ import("lib.detect.find_programver") function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.check = opt.check or function (program) os.run(program) end -- find program - local program = find_program(opt.program or "ml64.exe", opt.pathes, opt.check or function (program) os.run(program) end) + local program = find_program(opt.program or "ml64.exe", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program, function () local _, info = os.iorun(program); return info end, - function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end) + opt.command = opt.command or function () local _, info = os.iorun(program); return info end + opt.parse = opt.parse or function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_ollydbg.lua b/xmake/modules/detect/tools/find_ollydbg.lua index 6398f303b..385908fd8 100644 --- a/xmake/modules/detect/tools/find_ollydbg.lua +++ b/xmake/modules/detect/tools/find_ollydbg.lua @@ -48,13 +48,14 @@ function main(opt) end -- init options - opt = opt or {} - + opt = opt or {} + opt.pathes = opt.pathes or 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 + opt.check = opt.check or function (program) if not os.isfile(program) then raise() end end + -- find program - 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) + return find_program(opt.program or "ollydbg", opt) end diff --git a/xmake/modules/detect/tools/find_pacman.lua b/xmake/modules/detect/tools/find_pacman.lua index 724985ece..3d53c6e99 100644 --- a/xmake/modules/detect/tools/find_pacman.lua +++ b/xmake/modules/detect/tools/find_pacman.lua @@ -45,12 +45,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "pacman", opt.pathes, opt.check) + local program = find_program(opt.program or "pacman", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_ping.lua b/xmake/modules/detect/tools/find_ping.lua index bf877a452..63d769d1e 100644 --- a/xmake/modules/detect/tools/find_ping.lua +++ b/xmake/modules/detect/tools/find_ping.lua @@ -35,14 +35,15 @@ import("lib.detect.find_program") function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.check = opt.check or function (program) + if os.host() == "windows" then + os.run("%s -n 1 127.0.0.1", program) + else + os.run("%s -c 1 127.0.0.1", program) + end + end -- find program - return find_program(opt.program or "ping", opt.pathes, opt.check or function (program) - if os.host() == "windows" then - os.run("%s -n 1 127.0.0.1", program) - else - os.run("%s -c 1 127.0.0.1", program) - end - end) + return find_program(opt.program or "ping", opt) end diff --git a/xmake/modules/detect/tools/find_pkg_config.lua b/xmake/modules/detect/tools/find_pkg_config.lua index 8e8f59ca3..e989b4e1e 100644 --- a/xmake/modules/detect/tools/find_pkg_config.lua +++ b/xmake/modules/detect/tools/find_pkg_config.lua @@ -40,14 +40,17 @@ import("lib.detect.find_programver") -- @endcode -- function main(opt) + + -- init options + opt = opt or {} -- find program - local program = find_program("pkg-config") + local program = find_program(opt.program or "pkg-config", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_rc.lua b/xmake/modules/detect/tools/find_rc.lua index cc2696c45..6390118dc 100644 --- a/xmake/modules/detect/tools/find_rc.lua +++ b/xmake/modules/detect/tools/find_rc.lua @@ -41,15 +41,18 @@ import("lib.detect.find_programver") function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.check = opt.check or "-?" + opt.command = opt.command or "-?" + opt.parse = opt.parse or function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end -- find program - local program = find_program(opt.program or "rc.exe", opt.pathes, "-?") + local program = find_program(opt.program or "rc.exe", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program, "-?", function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_rustc.lua b/xmake/modules/detect/tools/find_rustc.lua index 187995224..3cd14701a 100644 --- a/xmake/modules/detect/tools/find_rustc.lua +++ b/xmake/modules/detect/tools/find_rustc.lua @@ -44,12 +44,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "rustc", opt.pathes, opt.check) + local program = find_program(opt.program or "rustc", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_sudo.lua b/xmake/modules/detect/tools/find_sudo.lua index 12a9f3f28..ce8d33ff1 100644 --- a/xmake/modules/detect/tools/find_sudo.lua +++ b/xmake/modules/detect/tools/find_sudo.lua @@ -42,15 +42,17 @@ import("lib.detect.find_programver") function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.check = opt.check or "-h" + opt.command = opt.command or "-V" -- find program - local program = find_program(opt.program or "sudo", opt.pathes, opt.check or "-h") + local program = find_program(opt.program or "sudo", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program, "-V") + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_swiftc.lua b/xmake/modules/detect/tools/find_swiftc.lua index 8465de63e..2090d8869 100644 --- a/xmake/modules/detect/tools/find_swiftc.lua +++ b/xmake/modules/detect/tools/find_swiftc.lua @@ -45,12 +45,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "swiftc", opt.pathes, opt.check) + local program = find_program(opt.program or "swiftc", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_tar.lua b/xmake/modules/detect/tools/find_tar.lua index b1b9f067f..a22a92896 100644 --- a/xmake/modules/detect/tools/find_tar.lua +++ b/xmake/modules/detect/tools/find_tar.lua @@ -45,12 +45,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "tar", opt.pathes, opt.check) + local program = find_program(opt.program or "tar", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_unzip.lua b/xmake/modules/detect/tools/find_unzip.lua index 4f5c8d2ec..6955448eb 100644 --- a/xmake/modules/detect/tools/find_unzip.lua +++ b/xmake/modules/detect/tools/find_unzip.lua @@ -42,15 +42,17 @@ import("lib.detect.find_programver") function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.check = opt.check or "-v" + opt.command = opt.command or "-v" -- find program - local program = find_program(opt.program or "unzip", opt.pathes, opt.check or "-v") + local program = find_program(opt.program or "unzip", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program, "-v") + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_vsjitdebugger.lua b/xmake/modules/detect/tools/find_vsjitdebugger.lua index 008a2b0b2..7ab985f0c 100644 --- a/xmake/modules/detect/tools/find_vsjitdebugger.lua +++ b/xmake/modules/detect/tools/find_vsjitdebugger.lua @@ -48,13 +48,14 @@ function main(opt) end -- init options - opt = opt or {} - + opt = opt or {} + opt.pathes = opt.pathes or 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 + opt.check = opt.check or function (program) if not os.isfile(program) then raise() end end + -- find program - 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) + return find_program(opt.program or "vsjitdebugger", opt) end diff --git a/xmake/modules/detect/tools/find_wget.lua b/xmake/modules/detect/tools/find_wget.lua index b2dd3718e..39ece645a 100644 --- a/xmake/modules/detect/tools/find_wget.lua +++ b/xmake/modules/detect/tools/find_wget.lua @@ -45,12 +45,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "wget", opt.pathes, opt.check) + local program = find_program(opt.program or "wget", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_windbg.lua b/xmake/modules/detect/tools/find_windbg.lua index e5547ed25..a7d66cf5e 100644 --- a/xmake/modules/detect/tools/find_windbg.lua +++ b/xmake/modules/detect/tools/find_windbg.lua @@ -48,13 +48,14 @@ function main(opt) end -- init options - opt = opt or {} - + opt = opt or {} + opt.pathes = opt.pathes or 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 + opt.check = opt.check or function (program) if not os.isfile(program) then raise() end end + -- find program - 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) + return find_program(opt.program or "windbg", opt) end diff --git a/xmake/modules/detect/tools/find_x64dbg.lua b/xmake/modules/detect/tools/find_x64dbg.lua index 7611466ed..fc003cd66 100644 --- a/xmake/modules/detect/tools/find_x64dbg.lua +++ b/xmake/modules/detect/tools/find_x64dbg.lua @@ -46,15 +46,16 @@ function main(opt) if os.host() ~= "windows" then return end - + -- init options - opt = opt or {} - + opt = opt or {} + opt.pathes = opt.pathes or 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 + opt.check = opt.check or function (program) if not os.isfile(program) then raise() end end + -- find program - 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) + return find_program(opt.program or "x64dbg", opt) end diff --git a/xmake/modules/detect/tools/find_yum.lua b/xmake/modules/detect/tools/find_yum.lua index 4c8b382a1..7e671725a 100644 --- a/xmake/modules/detect/tools/find_yum.lua +++ b/xmake/modules/detect/tools/find_yum.lua @@ -45,12 +45,12 @@ function main(opt) opt = opt or {} -- find program - local program = find_program(opt.program or "yum", opt.pathes, opt.check) + local program = find_program(opt.program or "yum", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/detect/tools/find_zip.lua b/xmake/modules/detect/tools/find_zip.lua index 9b2cf2824..0de995cd0 100644 --- a/xmake/modules/detect/tools/find_zip.lua +++ b/xmake/modules/detect/tools/find_zip.lua @@ -42,15 +42,17 @@ import("lib.detect.find_programver") function main(opt) -- init options - opt = opt or {} + opt = opt or {} + opt.check = opt.check or "-v" + opt.command = opt.command or "-v" -- find program - local program = find_program(opt.program or "zip", opt.pathes, opt.check or "-v") + local program = find_program(opt.program or "zip", opt) -- find program version local version = nil if program and opt and opt.version then - version = find_programver(program, "-v") + version = find_programver(program, opt) end -- ok? diff --git a/xmake/modules/lib/detect/find_tool.lua b/xmake/modules/lib/detect/find_tool.lua index f2d5af68c..964d687ea 100644 --- a/xmake/modules/lib/detect/find_tool.lua +++ b/xmake/modules/lib/detect/find_tool.lua @@ -43,7 +43,9 @@ end -- find tool -- -- @param name the tool name --- @param opt the options, .e.g {program = "xcrun -sdk macosx clang", pathes = {"/usr/bin"}, check = function (tool) os.run("%s -h", tool) end, version = true} +-- @param opt the options, .e.g {program = "xcrun -sdk macosx clang", pathes = {"/usr/bin"}, +-- check = function (tool) os.run("%s -h", tool) end, version = true +-- force = true, cachekey = "xxx"} -- -- @return {name = "", program = "", version = ""} or nil -- @@ -81,7 +83,7 @@ function main(name, opt) end -- find tool - local program = find_program(opt.program, opt.pathes, opt.check) + local program = find_program(opt.program, opt.pathes, opt.check, opt) if not program then return end @@ -89,7 +91,7 @@ function main(name, opt) -- find tool version local version = nil if program and opt.version then - version = find_programver(program) + version = find_programver(program, opt) end -- ok? |
