diff options
| author | ruki <[email protected]> | 2017-09-20 22:36:46 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-09-20 09:40:39 +0800 |
| commit | 218e2711e1afacd334ce50b37b0fa2d2db573e8e (patch) | |
| tree | 1f335873793c96d5e3cd1e9e9d149bb3fcba0bef | |
| parent | 8edce1f3f7f2e779eb3bf66702d4b5271e82a63b (diff) | |
add some install scripts for package manager
| -rw-r--r-- | xmake/actions/require/install.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/devel/git/checkout.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/devel/git/clean.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/devel/git/clone.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/devel/git/ls_remote.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/devel/git/pull.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/devel/package/apt.lua | 58 | ||||
| -rw-r--r-- | xmake/modules/devel/package/brew.lua | 58 | ||||
| -rw-r--r-- | xmake/modules/devel/package/manager.lua | 30 | ||||
| -rw-r--r-- | xmake/modules/devel/package/pacman.lua | 58 | ||||
| -rw-r--r-- | xmake/modules/devel/package/yum.lua | 58 |
11 files changed, 285 insertions, 25 deletions
diff --git a/xmake/actions/require/install.lua b/xmake/actions/require/install.lua index 6d16de732..764745c33 100644 --- a/xmake/actions/require/install.lua +++ b/xmake/actions/require/install.lua @@ -26,7 +26,7 @@ import("core.base.option") import("core.base.task") import("core.project.project") -import("detect.tools.find_git") +import("lib.detect.find_tool") import("action") import("package") import("repository") @@ -114,7 +114,7 @@ function _install_packages(requires) -- -- attempt to install git from the builtin-packages first if git not found -- - if find_git() and not repository.pulled() then + if find_tool("git") and not repository.pulled() then task.run("repo", {update = true}) end @@ -192,7 +192,7 @@ function main(requires) environment.enter() -- git not found? install it first - if not find_git() then + if not find_tool("git") then _install_packages("git") end diff --git a/xmake/modules/devel/git/checkout.lua b/xmake/modules/devel/git/checkout.lua index 5a754ebe4..3644f414e 100644 --- a/xmake/modules/devel/git/checkout.lua +++ b/xmake/modules/devel/git/checkout.lua @@ -24,7 +24,7 @@ -- imports import("core.base.option") -import("detect.tools.find_git") +import("lib.detect.find_tool") -- checkout to given branch, tag or commit -- @@ -43,8 +43,8 @@ import("detect.tools.find_git") function main(commit, opt) -- find git - local program = find_git() - if not program then + local git = find_tool("git") + if not git then return end @@ -58,7 +58,7 @@ function main(commit, opt) end -- checkout it - os.vrunv(program, argv) + os.vrunv(git.program, argv) -- leave repository directory if oldir then diff --git a/xmake/modules/devel/git/clean.lua b/xmake/modules/devel/git/clean.lua index b69db1150..839ee2fe3 100644 --- a/xmake/modules/devel/git/clean.lua +++ b/xmake/modules/devel/git/clean.lua @@ -24,7 +24,7 @@ -- imports import("core.base.option") -import("detect.tools.find_git") +import("lib.detect.find_tool") -- clean files -- @@ -42,8 +42,8 @@ import("detect.tools.find_git") function main(opt) -- find git - local program = find_git() - if not program then + local git = find_tool("git") + if not git then return end @@ -67,7 +67,7 @@ function main(opt) end -- clean it - os.vrunv(program, argv) + os.vrunv(git.program, argv) -- leave repository directory if oldir then diff --git a/xmake/modules/devel/git/clone.lua b/xmake/modules/devel/git/clone.lua index 4134db25e..f10e3e33e 100644 --- a/xmake/modules/devel/git/clone.lua +++ b/xmake/modules/devel/git/clone.lua @@ -24,7 +24,7 @@ -- imports import("core.base.option") -import("detect.tools.find_git") +import("lib.detect.find_tool") -- clone url -- @@ -43,8 +43,8 @@ import("detect.tools.find_git") function main(url, opt) -- find git - local program = find_git() - if not program then + local git = find_tool("git") + if not git then return end @@ -70,5 +70,5 @@ function main(url, opt) end -- clone it - os.vrunv(program, argv) + os.vrunv(git.program, argv) end diff --git a/xmake/modules/devel/git/ls_remote.lua b/xmake/modules/devel/git/ls_remote.lua index a76494337..30853224b 100644 --- a/xmake/modules/devel/git/ls_remote.lua +++ b/xmake/modules/devel/git/ls_remote.lua @@ -24,7 +24,7 @@ -- imports import("core.base.option") -import("detect.tools.find_git") +import("lib.detect.find_tool") -- ls_remote to given branch, tag or commit -- @@ -46,16 +46,16 @@ import("detect.tools.find_git") function main(reftype, url) -- find git - local program = find_git() - if not program then - return {} + local git = find_tool("git") + if not git then + return end -- init reference type reftype = reftype or "refs" -- get refs - local data = os.iorunv(program, {"ls-remote", "--" .. reftype, url or "."}) + local data = os.iorunv(git.program, {"ls-remote", "--" .. reftype, url or "."}) -- get commmits and tags local refs = {} diff --git a/xmake/modules/devel/git/pull.lua b/xmake/modules/devel/git/pull.lua index 2bba0184b..758a5f930 100644 --- a/xmake/modules/devel/git/pull.lua +++ b/xmake/modules/devel/git/pull.lua @@ -24,7 +24,7 @@ -- imports import("core.base.option") -import("detect.tools.find_git") +import("lib.detect.find_tool") -- pull remote commits -- @@ -42,8 +42,8 @@ import("detect.tools.find_git") function main(opt) -- find git - local program = find_git() - if not program then + local git = find_tool("git") + if not git then return end @@ -68,7 +68,7 @@ function main(opt) end -- pull it - os.vrunv(program, argv) + os.vrunv(git.program, argv) -- leave repository directory if oldir then diff --git a/xmake/modules/devel/package/apt.lua b/xmake/modules/devel/package/apt.lua new file mode 100644 index 000000000..b44801bd2 --- /dev/null +++ b/xmake/modules/devel/package/apt.lua @@ -0,0 +1,58 @@ +--!A cross-platform 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 apt.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_tool") + +-- install package +-- +-- @param name the package name +-- @param opt the options, .e.g {verbose = true, apt = "the package name"} +-- +-- @return true or false +-- +function install(name, opt) + + -- init options + opt = opt or {} + + -- find apt + local apt = find_tool("apt") + if not apt then + return false + end + + -- init argv + local argv = {"install", "-y", opt.apt or name} + if opt.verbose or option.get("verbose") then + table.insert(argv, "--verbose") + end + + -- install package + os.vrunv(apt.program, argv) + + -- ok + return true +end diff --git a/xmake/modules/devel/package/brew.lua b/xmake/modules/devel/package/brew.lua new file mode 100644 index 000000000..c9d6ae60f --- /dev/null +++ b/xmake/modules/devel/package/brew.lua @@ -0,0 +1,58 @@ +--!A cross-platform 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 brew.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_tool") + +-- install package +-- +-- @param name the package name +-- @param opt the options, .e.g {verbose = true, brew = "the package name"} +-- +-- @return true or false +-- +function install(name, opt) + + -- init options + opt = opt or {} + + -- find brew + local brew = find_tool("brew") + if not brew then + return false + end + + -- init argv + local argv = {"install", opt.brew or name} + if opt.verbose or option.get("verbose") then + table.insert(argv, "--verbose") + end + + -- install package + os.vrunv(brew.program, argv) + + -- ok + return true +end diff --git a/xmake/modules/devel/package/manager.lua b/xmake/modules/devel/package/manager.lua index e05ae0c29..f927c263d 100644 --- a/xmake/modules/devel/package/manager.lua +++ b/xmake/modules/devel/package/manager.lua @@ -23,8 +23,36 @@ -- -- imports -import("core.base.option") +import("apt") +import("yum") +import("brew") +import("pacman") -- install package using third-party package manager +-- +-- @param name the package name +-- @param opt the options, .e.g {verbose = true, brew = "the package name in brew", pacman = "xxx", apt = "xxx"} +-- +-- function install(name, opt) + + -- init scripts + local scripts = {} + local host = os.host() + if host == "macosx" then + table.insert(scripts, brew.install) + elseif host == "linux" then + table.insert(scripts, apt.install) + table.insert(scripts, yum.install) + table.insert(scripts, pacman.install) + table.insert(scripts, brew.install) + end + assert(#scripts > 0, "package manager not found!") + + -- run install script + for _, script in ipairs(scripts) do + if script(name, opt) then + break + end + end end diff --git a/xmake/modules/devel/package/pacman.lua b/xmake/modules/devel/package/pacman.lua new file mode 100644 index 000000000..fdf8827bb --- /dev/null +++ b/xmake/modules/devel/package/pacman.lua @@ -0,0 +1,58 @@ +--!A cross-platform 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 pacman.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_tool") + +-- install package +-- +-- @param name the package name +-- @param opt the options, .e.g {verbose = true, pacman = "the package name"} +-- +-- @return true or false +-- +function install(name, opt) + + -- init options + opt = opt or {} + + -- find pacman + local pacman = find_tool("pacman") + if not pacman then + return false + end + + -- init argv + local argv = {"-S", "--noconfirm", "--needed", opt.pacman or name} + if opt.verbose or option.get("verbose") then + table.insert(argv, "--verbose") + end + + -- install package + os.vrunv(pacman.program, argv) + + -- ok + return true +end diff --git a/xmake/modules/devel/package/yum.lua b/xmake/modules/devel/package/yum.lua new file mode 100644 index 000000000..f4f951fde --- /dev/null +++ b/xmake/modules/devel/package/yum.lua @@ -0,0 +1,58 @@ +--!A cross-platform 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 yum.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_tool") + +-- install package +-- +-- @param name the package name +-- @param opt the options, .e.g {verbose = true, yum = "the package name"} +-- +-- @return true or false +-- +function install(name, opt) + + -- init options + opt = opt or {} + + -- find yum + local yum = find_tool("yum") + if not yum then + return false + end + + -- init argv + local argv = {"install", "-y", opt.yum or name} + if opt.verbose or option.get("verbose") then + table.insert(argv, "--verbose") + end + + -- install package + os.vrunv(yum.program, argv) + + -- ok + return true +end |
