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 /xmake/modules/detect/tools | |
| parent | 034185734b5bc91f8188c15c9e02b0ce8ebaa850 (diff) | |
modify find_program interface
Diffstat (limited to 'xmake/modules/detect/tools')
42 files changed, 196 insertions, 149 deletions
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? |
