diff options
| author | ruki <[email protected]> | 2017-05-17 21:43:04 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-05-17 21:43:04 +0800 |
| commit | c315b83eb9a5b84aeab8fb1f93a9086664f5177e (patch) | |
| tree | 34f49bfe3f37a309c24a62a6b6e417e631c1889f | |
| parent | b406ed83128331bf9360154606fbcde2ca4f325d (diff) | |
add find gzip module
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_programver.lua | 14 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/find_ccache.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/find_git.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/find_gzip.lua | 58 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/find_tar.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/find_unzip.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/find_wget.lua | 2 |
7 files changed, 75 insertions, 7 deletions
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 7da62a6c6..50eb72cef 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua @@ -39,7 +39,7 @@ local raise = require("sandbox/modules/raise") -- find program version -- -- @param program the program --- @param command the version command, default: --version +-- @param command the version command string or script, default: --version -- @param parse the version parse script or lua match pattern -- -- @return the version string @@ -49,6 +49,7 @@ local raise = require("sandbox/modules/raise") -- 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) -- @endcode -- function sandbox_lib_detect_find_programver.main(program, command, parse) @@ -64,7 +65,16 @@ function sandbox_lib_detect_find_programver.main(program, command, parse) end -- attempt to get version output info - local ok, outdata = os.iorunv(program, {command or "--version"}) + local ok = false + local outdata = nil + if type(command) == "function" then + ok, outdata = sandbox.load(command) + if not ok then + utils.verror(outdata) + end + else + ok, outdata = os.iorunv(program, {command or "--version"}) + end -- find version info if ok and outdata and #outdata > 0 then diff --git a/xmake/modules/lib/detect/find_ccache.lua b/xmake/modules/lib/detect/find_ccache.lua index 55f0d5a95..30348c6e6 100644 --- a/xmake/modules/lib/detect/find_ccache.lua +++ b/xmake/modules/lib/detect/find_ccache.lua @@ -46,7 +46,7 @@ function main(argv) -- find program version local version = nil - if argv and argv.version then + if program and argv and argv.version then version = find_programver(program) end diff --git a/xmake/modules/lib/detect/find_git.lua b/xmake/modules/lib/detect/find_git.lua index de34651ec..00665d8be 100644 --- a/xmake/modules/lib/detect/find_git.lua +++ b/xmake/modules/lib/detect/find_git.lua @@ -46,7 +46,7 @@ function main(argv) -- find program version local version = nil - if argv and argv.version then + if program and argv and argv.version then version = find_programver(program) end diff --git a/xmake/modules/lib/detect/find_gzip.lua b/xmake/modules/lib/detect/find_gzip.lua new file mode 100644 index 000000000..2ec660cfe --- /dev/null +++ b/xmake/modules/lib/detect/find_gzip.lua @@ -0,0 +1,58 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_gzip.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find gzip +-- +-- @param argv the arguments, .e.g {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local gzip = find_gzip() +-- local gzip, version = find_gzip({version = true}) +-- +-- @endcode +-- +function main(argv) + + -- find program + local program = find_program("gzip", { "/usr/bin", "/usr/local/bin"}) + + -- find program version + local version = nil + if program and argv and argv.version then + version = find_programver(program, function() + local outdata, errdata = os.iorunv(program, {"--version"}) + return (outdata or "") .. (errdata or "") + end) + end + + -- ok? + return program, version +end diff --git a/xmake/modules/lib/detect/find_tar.lua b/xmake/modules/lib/detect/find_tar.lua index b785b2d1d..503701e0a 100644 --- a/xmake/modules/lib/detect/find_tar.lua +++ b/xmake/modules/lib/detect/find_tar.lua @@ -46,7 +46,7 @@ function main(argv) -- find program version local version = nil - if argv and argv.version then + if program and argv and argv.version then version = find_programver(program) end diff --git a/xmake/modules/lib/detect/find_unzip.lua b/xmake/modules/lib/detect/find_unzip.lua index 87c49e888..006d18be2 100644 --- a/xmake/modules/lib/detect/find_unzip.lua +++ b/xmake/modules/lib/detect/find_unzip.lua @@ -46,7 +46,7 @@ function main(argv) -- find program version local version = nil - if argv and argv.version then + if program and argv and argv.version then version = find_programver(program, "-v") end diff --git a/xmake/modules/lib/detect/find_wget.lua b/xmake/modules/lib/detect/find_wget.lua index 5c0891327..13b12c43e 100644 --- a/xmake/modules/lib/detect/find_wget.lua +++ b/xmake/modules/lib/detect/find_wget.lua @@ -46,7 +46,7 @@ function main(argv) -- find program version local version = nil - if argv and argv.version then + if program and argv and argv.version then version = find_programver(program) end |
