diff options
| author | ruki <[email protected]> | 2017-03-27 14:27:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-03-27 14:27:15 +0800 |
| commit | cbe9a6b04ec8fca881fc39d360e941bf795c86da (patch) | |
| tree | 294c965dce015b444bc9277bd6b7763b85d7d2aa | |
| parent | f3611f44a7afda2e651eac6336d3494e011c9272 (diff) | |
tip admin permission
| -rw-r--r-- | xmake/actions/install/install.lua | 90 | ||||
| -rw-r--r-- | xmake/actions/install/install_admin.lua | 60 | ||||
| -rw-r--r-- | xmake/actions/install/main.lua | 107 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/base/option.lua | 17 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/task.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/io.lua | 4 |
6 files changed, 218 insertions, 62 deletions
diff --git a/xmake/actions/install/install.lua b/xmake/actions/install/install.lua new file mode 100644 index 000000000..e3080e5ce --- /dev/null +++ b/xmake/actions/install/install.lua @@ -0,0 +1,90 @@ +--!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 install.lua +-- + +-- imports +import("core.project.task") +import("core.project.project") +import("core.platform.platform") + +-- install the given target +function _install_target(target) + + -- enter project directory + local olddir = os.cd(project.directory()) + + -- the target scripts + local scripts = + { + target:get("install_before") + , target:get("install") or platform.get("install") + , target:get("install_after") + } + + -- install the target scripts + for i = 1, 3 do + local script = scripts[i] + if script ~= nil then + script(target) + end + end + + -- leave project directory + os.cd(olddir) +end + +-- install the given target and deps +function _install_target_and_deps(target) + + -- this target have been finished? + if _g.finished[target:name()] then + return + end + + -- install for all dependent targets + for _, depname in ipairs(target:get("deps")) do + _install_target_and_deps(project.target(depname)) + end + + -- install target + _install_target(target) + + -- finished + _g.finished[target:name()] = true +end + +-- install targets +function install(targetname) + + -- init finished states + _g.finished = {} + + -- install all? + if targetname == "all" then + for _, target in pairs(project.targets()) do + _install_target_and_deps(target) + end + else + _install_target_and_deps(project.target(targetname)) + end +end diff --git a/xmake/actions/install/install_admin.lua b/xmake/actions/install/install_admin.lua new file mode 100644 index 000000000..386911027 --- /dev/null +++ b/xmake/actions/install/install_admin.lua @@ -0,0 +1,60 @@ +--!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 install_admin.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("core.project.project") +import("core.platform.platform") +import("install") + +-- install +function main(targetname, installdir) + + -- enter project directory + os.cd(project.directory()) + + -- load config + config.load() + + -- load platform + platform.load(config.plat()) + + -- laod project + project.load() + + -- save the current option and push a new option context + option.save() + + -- pass installdir to option + if installdir then + option.set("installdir", installdir) + end + + -- install target + install.install(targetname) + + -- restore the previous option context + option.restore() +end diff --git a/xmake/actions/install/main.lua b/xmake/actions/install/main.lua index 766d50aa7..2f7ca12a4 100644 --- a/xmake/actions/install/main.lua +++ b/xmake/actions/install/main.lua @@ -25,56 +25,7 @@ -- imports import("core.base.option") import("core.project.task") -import("core.project.config") -import("core.project.global") -import("core.project.project") -import("core.platform.platform") - --- install the given target -function _install_target(target) - - -- enter project directory - local olddir = os.cd(project.directory()) - - -- the target scripts - local scripts = - { - target:get("install_before") - , target:get("install") or platform.get("install") - , target:get("install_after") - } - - -- install the target scripts - for i = 1, 3 do - local script = scripts[i] - if script ~= nil then - script(target) - end - end - - -- leave project directory - os.cd(olddir) -end - --- install the given target and deps -function _install_target_and_deps(target) - - -- this target have been finished? - if _g.finished[target:name()] then - return - end - - -- install for all dependent targets - for _, depname in ipairs(target:get("deps")) do - _install_target_and_deps(project.target(depname)) - end - - -- install target - _install_target(target) - - -- finished - _g.finished[target:name()] = true -end +import("install") -- main function main() @@ -82,18 +33,52 @@ function main() -- get the target name local targetname = option.get("target") - -- init finished states - _g.finished = {} - -- build it first task.run("build", {target = targetname}) - -- install all? - if targetname == "all" then - for _, target in pairs(project.targets()) do - _install_target_and_deps(target) - end - else - _install_target_and_deps(project.target(targetname)) - end + -- attempt to install directly + try + { + function () + -- install target + install.install(targetname) + end, + + catch + { + -- failed or not permission? request administrator permission and install it again + function (errors) + + -- TODO wrap xmake + -- init argv + local argv = {"xmake", "lua"} + for _, name in ipairs({"file", "project", "backtrace", "verbose", "quiet"}) do + local value = option.get(name) + if type(value) == "string" then + table.insert(argv, "--" .. name .. "=" .. value) + elseif value then + table.insert(argv, "--" .. name) + end + end + table.insert(argv, path.join(os.scriptdir(), "install_admin.lua")) + table.insert(argv, targetname) + table.insert(argv, option.get("installdir")) + + -- show tips + cprint("${bright red}error: ${default red}installation failed, may permission denied!") + cprint("${bright yellow}note: ${default yellow}try continue to install with administrator permission again?") + cprint("please input: y (y/n)") + + -- TODO read + -- get answer + io.flush() + if io._read() == 'y' then + + -- TODO wrap sudo + -- install target with administrator permission + os.runv("sudo", argv) + end + end + } + } end diff --git a/xmake/core/sandbox/modules/import/core/base/option.lua b/xmake/core/sandbox/modules/import/core/base/option.lua index e6d725693..bc5e261b9 100644 --- a/xmake/core/sandbox/modules/import/core/base/option.lua +++ b/xmake/core/sandbox/modules/import/core/base/option.lua @@ -37,6 +37,13 @@ function sandbox_core_base_option.get(name) return option.get(name) end +-- set the option value +function sandbox_core_base_option.set(name, value) + + -- set it + option.set(name, value) +end + -- get the default option value function sandbox_core_base_option.default(name) @@ -104,5 +111,15 @@ function sandbox_core_base_option.parse(argv, options, ...) return results end +-- save context +function sandbox_core_base_option.save(taskname) + return option.save(taskname) +end + +-- restore context +function sandbox_core_base_option.restore() + option.restore() +end + -- return module return sandbox_core_base_option diff --git a/xmake/core/sandbox/modules/import/core/project/task.lua b/xmake/core/sandbox/modules/import/core/project/task.lua index f0fb69380..c5e098ec4 100644 --- a/xmake/core/sandbox/modules/import/core/project/task.lua +++ b/xmake/core/sandbox/modules/import/core/project/task.lua @@ -41,7 +41,7 @@ function sandbox_core_project_task.run(taskname, options, ...) options = table.wrap(options) -- inherit some parent options - for _, name in ipairs({"file", "project", "verbose", "quiet"}) do + for _, name in ipairs({"file", "project", "backtrace", "verbose", "quiet"}) do if not options[name] and option.get(name) then options[name] = option.get(name) end diff --git a/xmake/core/sandbox/modules/io.lua b/xmake/core/sandbox/modules/io.lua index 7a34cc649..d8b110c6e 100644 --- a/xmake/core/sandbox/modules/io.lua +++ b/xmake/core/sandbox/modules/io.lua @@ -32,6 +32,10 @@ local vformat = require("sandbox/modules/vformat") -- define module local sandbox_io = sandbox_io or {} +-- inherit some builtin interfaces +sandbox_io.flush = io.flush +sandbox_io._read = io.read + -- print file function sandbox_io._print(self, ...) |
