diff options
| author | ruki <[email protected]> | 2017-01-04 00:00:56 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-01-06 17:20:08 +0800 |
| commit | fb6f2e286398021f9c9a4331246cc3553efed925 (patch) | |
| tree | ea03404bac4a334634d8d9bc0392d731257d8825 | |
| parent | c2dc890bc38a34c10fd01afa01fb92d3da1587f2 (diff) | |
remove installer and add on_install on_uninstall for platform
| -rwxr-xr-x | xmake/actions/install/main.lua | 26 | ||||
| -rwxr-xr-x | xmake/actions/uninstall/main.lua | 26 | ||||
| -rw-r--r-- | xmake/core/platform/installer.lua | 86 | ||||
| -rw-r--r-- | xmake/core/platform/platform.lua | 65 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/platform/platform.lua | 7 | ||||
| -rw-r--r-- | xmake/core/sandbox/sandbox.lua | 4 | ||||
| -rw-r--r-- | xmake/platforms/linux/install.lua (renamed from xmake/platforms/macosx/installer.lua) | 19 | ||||
| -rw-r--r-- | xmake/platforms/linux/uninstall.lua (renamed from xmake/core/sandbox/modules/import/core/platform/installer.lua) | 41 | ||||
| -rwxr-xr-x | xmake/platforms/linux/xmake.lua | 9 | ||||
| -rw-r--r-- | xmake/platforms/macosx/install.lua (renamed from xmake/platforms/linux/installer.lua) | 32 | ||||
| -rw-r--r-- | xmake/platforms/macosx/uninstall.lua | 43 | ||||
| -rwxr-xr-x | xmake/platforms/macosx/xmake.lua | 9 |
12 files changed, 110 insertions, 257 deletions
diff --git a/xmake/actions/install/main.lua b/xmake/actions/install/main.lua index 6246b5a3d..d75b4fab6 100755 --- a/xmake/actions/install/main.lua +++ b/xmake/actions/install/main.lua @@ -27,31 +27,9 @@ import("core.project.config") import("core.project.global") import("core.project.project") import("core.platform.platform") -import("core.platform.installer") - --- install target -function _install_target(target) - - -- get kind - local kind = target:get("kind") - - -- get script - local scripts = - { - binary = installer.install - , static = installer.install - , shared = installer.install - } - - -- check - assert(scripts[kind], "this target(%s) with kind(%s) can not be installd!", target:name(), kind) - - -- install it - scripts[kind](target) -end -- install the given target -function _install(target) +function _install_target(target) -- enter project directory local olddir = os.cd(project.directory()) @@ -60,7 +38,7 @@ function _install(target) local scripts = { target:get("install_before") - , target:get("install") or _install_target + , target:get("install") or platform.get("install") , target:get("install_after") } diff --git a/xmake/actions/uninstall/main.lua b/xmake/actions/uninstall/main.lua index 0930cd576..6a4478dff 100755 --- a/xmake/actions/uninstall/main.lua +++ b/xmake/actions/uninstall/main.lua @@ -27,31 +27,9 @@ import("core.project.config") import("core.project.global") import("core.project.project") import("core.platform.platform") -import("core.platform.installer") - --- uninstall target -function _uninstall_target(target) - - -- get kind - local kind = target:get("kind") - - -- get script - local scripts = - { - binary = installer.uninstall - , static = installer.uninstall - , shared = installer.uninstall - } - - -- check - assert(scripts[kind], "this target(%s) with kind(%s) can not be uninstalld!", target:name(), kind) - - -- uninstall it - scripts[kind](target) -end -- uninstall the given target -function _uninstall(target) +function _uninstall_target(target) -- enter project directory local olddir = os.cd(project.directory()) @@ -60,7 +38,7 @@ function _uninstall(target) local scripts = { target:get("uninstall_before") - , target:get("uninstall") or _uninstall_target + , target:get("uninstall") or platform.get("uninstall") , target:get("uninstall_after") } diff --git a/xmake/core/platform/installer.lua b/xmake/core/platform/installer.lua deleted file mode 100644 index 3f8740359..000000000 --- a/xmake/core/platform/installer.lua +++ /dev/null @@ -1,86 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- XMake is free software; you can redistribute it and/or modify --- it under the terms of the GNU Lesser General Public License as published by --- the Free Software Foundation; either version 2.1 of the License, or --- (at your option) any later version. --- --- XMake is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU Lesser General Public License for more details. --- --- You should have received a copy of the GNU Lesser General Public License --- along with XMake; --- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> --- --- Copyright (C) 2015 - 2016, ruki All rights reserved. --- --- @author ruki --- @file installer.lua --- - --- define module -local installer = installer or {} - --- load modules -local platform = require("platform/platform") -local sandbox = require("sandbox/sandbox") - --- load the given installer from the given platform -function installer.load(plat) - - -- load platform - local instance, errors = platform.load(plat) - if not instance then - return nil, errors - end - - -- get installer - return instance:installer() -end - --- install the target for the current platform -function installer.install(target, plat) - - -- load the installer module - local module, errors = installer.load() - if not module and errors then - return false, errors - end - - -- install it - if module then - local ok, errors = sandbox.load(module.install, target) - if not ok then - return false, errors - end - end - - -- ok - return true -end - --- uninstall target for the current platform -function installer.uninstall(target) - - -- load the installer module - local module, errors = installer.load() - if not module and errors then - return false, errors - end - - -- uninstall it - if module then - local ok, errors = sandbox.load(module.uninstall, target) - if not ok then - return false, errors - end - end - - -- ok - return true -end - --- return module -return installer diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index a33852866..079e42de3 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -109,7 +109,13 @@ function _instance:get(name) -- the info local info = self._INFO - -- load it first + -- get if from info first + local value = info[name] + if value ~= nil then + return value + end + + -- load _g if self._g == nil and info.load ~= nil then -- load it @@ -122,10 +128,8 @@ function _instance:get(name) self._g = getfenv(info.load)._g end - -- get it - if self._g ~= nil then - return self._g[name] - end + -- get it from _g + return self._g[name] end -- get the platform os @@ -170,13 +174,6 @@ function _instance:checker() return self:_load("checker") end --- get the installer -function _instance:installer() - - -- load installer - return self:_load("installer") -end - -- get the environment function _instance:environment() @@ -219,12 +216,13 @@ function platform._interpreter() , "platform.set_checker" , "platform.set_tooldirs" , "platform.set_environment" - , "platform.set_installer" } , script = { -- platform.on_xxx "platform.on_load" + , "platform.on_install" + , "platform.on_uninstall" } } @@ -291,21 +289,11 @@ function platform.load(plat) end --- get the platform os -function platform.os(plat) - - -- load the platform - local instance = platform.load(plat) - if instance then - return instance:os() - end -end - -- get the given platform configure -function platform.get(name) +function platform.get(name, plat) -- get the current platform configure - local instance = platform.load() + local instance = platform.load(plat) if instance then return instance:get(name) end @@ -321,16 +309,6 @@ function platform.tool(kind) return config.get(kind) end --- get the platform archs -function platform.archs(plat) - - -- load the platform - local instance = platform.load(plat) - if instance then - return instance:archs() - end -end - -- get the all platforms function platform.plats() @@ -362,14 +340,19 @@ function platform.plats() return plats end +-- get the platform os +function platform.os(plat) + return platform.get("os", plat) +end + +-- get the platform archs +function platform.archs(plat) + return platform.get("archs", plat) +end + -- get the tool directories function platform.tooldirs(plat) - - -- get the tool directories for the current platform - local instance = platform.load(plat) - if instance then - return instance:tooldirs() - end + return platform.get("tooldirs", plat) end -- get the given format diff --git a/xmake/core/sandbox/modules/import/core/platform/platform.lua b/xmake/core/sandbox/modules/import/core/platform/platform.lua index 9b86939b6..e16e186d3 100644 --- a/xmake/core/sandbox/modules/import/core/platform/platform.lua +++ b/xmake/core/sandbox/modules/import/core/platform/platform.lua @@ -59,5 +59,12 @@ function sandbox_core_platform_platform.archs(plat) return archs end +-- get the current platform configure +function sandbox_core_platform_platform.get(name, plat) + + -- get the given platform configure + return platform.get(name, plat) +end + -- return module return sandbox_core_platform_platform diff --git a/xmake/core/sandbox/sandbox.lua b/xmake/core/sandbox/sandbox.lua index 64bfd92f5..cac1a8baf 100644 --- a/xmake/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/sandbox.lua @@ -173,10 +173,10 @@ function sandbox.new(script, filter, rootdir) -- import module as script local modulename = script - script = function () + script = function (...) -- import it - import(modulename).main() + import(modulename).main(...) end end diff --git a/xmake/platforms/macosx/installer.lua b/xmake/platforms/linux/install.lua index aba11fef5..abe69edaf 100644 --- a/xmake/platforms/macosx/installer.lua +++ b/xmake/platforms/linux/install.lua @@ -24,7 +24,7 @@ import("platforms.installer", {rootdir = os.programdir()}) -- install target -function install(target) +function main(target) -- the scripts local scripts = @@ -41,21 +41,4 @@ function install(target) end end --- uninstall target -function uninstall(target) - - -- the scripts - local scripts = - { - binary = installer.uninstall_binary_on_unix - , static = installer.uninstall_library_on_unix - , shared = installer.uninstall_library_on_unix - } - - -- call script - local script = scripts[target:get("kind")] - if script then - script(target) - end -end diff --git a/xmake/core/sandbox/modules/import/core/platform/installer.lua b/xmake/platforms/linux/uninstall.lua index 9bcb4ca28..a87cd62f9 100644 --- a/xmake/core/sandbox/modules/import/core/platform/installer.lua +++ b/xmake/platforms/linux/uninstall.lua @@ -17,36 +17,27 @@ -- Copyright (C) 2015 - 2016, ruki All rights reserved. -- -- @author ruki --- @file installer.lua +-- @file uninstall.lua -- --- define module -local sandbox_core_platform_installer = sandbox_core_platform_installer or {} +-- imports +import("platforms.installer", {rootdir = os.programdir()}) --- load modules -local platform = require("platform/platform") -local installer = require("platform/installer") -local raise = require("sandbox/modules/raise") +-- uninstall target +function main(target) --- install target -function sandbox_core_platform_installer.install(target) - - -- enter it - local ok, errors = installer.install(target) - if not ok then - raise(errors) - end -end + -- the scripts + local scripts = + { + binary = installer.uninstall_binary_on_unix + , static = installer.uninstall_library_on_unix + , shared = installer.uninstall_library_on_unix + } --- uninstall target -function sandbox_core_platform_installer.uninstall(target) - - -- enter it - local ok, errors = installer.uninstall(target) - if not ok then - raise(errors) + -- call script + local script = scripts[target:get("kind")] + if script then + script(target) end end --- return module -return sandbox_core_platform_installer diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua index 6e486deed..9a64b8918 100755 --- a/xmake/platforms/linux/xmake.lua +++ b/xmake/platforms/linux/xmake.lua @@ -35,12 +35,15 @@ platform("linux") -- set checker set_checker("checker") - -- set installer - set_installer("installer") - -- set tooldirs set_tooldirs("/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin") + -- on install + on_install("install") + + -- on uninstall + on_uninstall("uninstall") + -- on load on_load(function () diff --git a/xmake/platforms/linux/installer.lua b/xmake/platforms/macosx/install.lua index 68091f903..abe69edaf 100644 --- a/xmake/platforms/linux/installer.lua +++ b/xmake/platforms/macosx/install.lua @@ -21,17 +21,10 @@ -- -- imports -import("core.project.config") import("platforms.installer", {rootdir = os.programdir()}) -- install target -function install(target) - - -- check architecture - local arch = config.get("arch") - if arch ~= "i386" and arch ~= "x86_64" then - raise("cannot install target(%s) for arch(%s)!", target:name(), arch) - end +function main(target) -- the scripts local scripts = @@ -48,27 +41,4 @@ function install(target) end end --- uninstall target -function uninstall(target) - - -- check architecture - local arch = config.get("arch") - if arch ~= "i386" and arch ~= "x86_64" then - raise("cannot uninstall target(%s) for arch(%s)!", target:name(), arch) - end - - -- the scripts - local scripts = - { - binary = installer.uninstall_binary_on_unix - , static = installer.uninstall_library_on_unix - , shared = installer.uninstall_library_on_unix - } - - -- call script - local script = scripts[target:get("kind")] - if script then - script(target) - end -end diff --git a/xmake/platforms/macosx/uninstall.lua b/xmake/platforms/macosx/uninstall.lua new file mode 100644 index 000000000..a87cd62f9 --- /dev/null +++ b/xmake/platforms/macosx/uninstall.lua @@ -0,0 +1,43 @@ +--!The Make-like Build Utility based on Lua +-- +-- XMake is free software; you can redistribute it and/or modify +-- it under the terms of the GNU Lesser General Public License as published by +-- the Free Software Foundation; either version 2.1 of the License, or +-- (at your option) any later version. +-- +-- XMake is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Lesser General Public License for more details. +-- +-- You should have received a copy of the GNU Lesser General Public License +-- along with XMake; +-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> +-- +-- Copyright (C) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file uninstall.lua +-- + +-- imports +import("platforms.installer", {rootdir = os.programdir()}) + +-- uninstall target +function main(target) + + -- the scripts + local scripts = + { + binary = installer.uninstall_binary_on_unix + , static = installer.uninstall_library_on_unix + , shared = installer.uninstall_library_on_unix + } + + -- call script + local script = scripts[target:get("kind")] + if script then + script(target) + end +end + diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 95e85f518..c6c3588e5 100755 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -35,12 +35,15 @@ platform("macosx") -- set checker set_checker("checker") - -- set installer - set_installer("installer") - -- set tooldirs set_tooldirs("/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin") + -- on install + on_install("install") + + -- on uninstall + on_uninstall("uninstall") + -- on load on_load(function () |
