diff options
| author | ruki <[email protected]> | 2020-09-24 22:38:59 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-09-24 22:38:59 +0800 |
| commit | 0a16fbb6015cac803db1a119e3fa85d15bfabf0f (patch) | |
| tree | 3384927b7ce9ac98fde4abcdf75b56d4d31f7f67 | |
| parent | eb0434f929fd00e69bb5710bd1ab0f950b59e1b8 (diff) | |
improve uninstall action
| -rw-r--r-- | xmake/actions/uninstall/uninstall.lua | 89 | ||||
| -rw-r--r-- | xmake/actions/uninstall/uninstall/unix.lua | 50 | ||||
| -rw-r--r-- | xmake/actions/uninstall/uninstall/windows.lua | 72 |
3 files changed, 133 insertions, 78 deletions
diff --git a/xmake/actions/uninstall/uninstall.lua b/xmake/actions/uninstall/uninstall.lua index 3143199cd..f0c3a513c 100644 --- a/xmake/actions/uninstall/uninstall.lua +++ b/xmake/actions/uninstall/uninstall.lua @@ -25,60 +25,12 @@ import("core.project.project") -- uninstall files function _uninstall_files(target) - local _, dstfiles = target:installfiles() for _, dstfile in ipairs(dstfiles) do os.vrm(dstfile) end end --- uninstall binary -function _uninstall_binary(target) - - -- is phony target? - if target:isphony() then - return - end - - -- the binary directory - local binarydir = path.join(target:installdir(), "bin") - - -- remove the target file - os.vrm(path.join(binarydir, path.filename(target:targetfile()))) - - -- remove the dependent shared/windows (*.dll) target - -- @see https://github.com/xmake-io/xmake/issues/961 - for _, dep in ipairs(target:orderdeps()) do - if dep:targetkind() == "shared" and is_plat("windows", "mingw") then - os.vrm(path.join(binarydir, path.filename(dep:targetfile()))) - end - end -end - --- uninstall library -function _uninstall_library(target) - - -- is phony target? - if target:isphony() then - return - end - - -- the library directory - local librarydir = path.join(target:installdir(), "lib") - - -- the include directory - local includedir = path.join(target:installdir(), "include") - - -- remove the target file - os.vrm(path.join(librarydir, path.filename(target:targetfile()))) - - -- remove headers from the include directory - local _, dstheaders = target:headerfiles(includedir) - for _, dstheader in ipairs(dstheaders) do - os.vrm(dstheader) - end -end - -- do uninstall target function _do_uninstall_target(target) @@ -91,18 +43,13 @@ function _do_uninstall_target(target) -- trace print("uninstalling from %s ..", installdir) - -- the scripts - local scripts = - { - binary = _uninstall_binary - , static = _uninstall_library - , shared = _uninstall_library - } - -- call script - local script = scripts[target:targetkind()] - if script then - script(target) + if not target:isphony() then + local install_style = target:is_plat("windows", "mingw") and "windows" or "unix" + local script = import("uninstall." .. install_style, {anonymous = true})["uninstall_" .. target:targetkind()] + if script then + script(target) + end end -- uninstall the other files @@ -112,11 +59,6 @@ end -- on uninstall target function _on_uninstall_target(target) - -- has been disabled? - if target:get("enabled") == false then - return - end - -- trace print("uninstalling %s ..", target:name()) @@ -138,6 +80,11 @@ end -- uninstall the given target function _uninstall_target(target) + -- has been disabled? + if target:get("enabled") == false then + return + end + -- enter project directory local oldir = os.cd(project.directory()) @@ -153,13 +100,6 @@ function _uninstall_target(target) { target:script("uninstall_before") , function (target) - - -- has been disabled? - if target:get("enabled") == false then - return - end - - -- uninstall rules for _, r in ipairs(target:orderules()) do local before_uninstall = r:script("uninstall_before") if before_uninstall then @@ -169,13 +109,6 @@ function _uninstall_target(target) end , target:script("uninstall", _on_uninstall_target) , function (target) - - -- has been disabled? - if target:get("enabled") == false then - return - end - - -- uninstall rules for _, r in ipairs(target:orderules()) do local after_uninstall = r:script("uninstall_after") if after_uninstall then diff --git a/xmake/actions/uninstall/uninstall/unix.lua b/xmake/actions/uninstall/uninstall/unix.lua new file mode 100644 index 000000000..4200f91ce --- /dev/null +++ b/xmake/actions/uninstall/uninstall/unix.lua @@ -0,0 +1,50 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed 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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file unix.lua +-- + +-- uninstall library +function _uninstall_library(target) + + -- remove the target file + local librarydir = path.join(target:installdir(), "lib") + os.vrm(path.join(librarydir, path.filename(target:targetfile()))) + + -- remove headers from the include directory + local includedir = path.join(target:installdir(), "include") + local _, dstheaders = target:headerfiles(includedir) + for _, dstheader in ipairs(dstheaders) do + os.vrm(dstheader) + end +end + +-- uninstall binary +function uninstall_binary(target) + local binarydir = path.join(target:installdir(), "bin") + os.vrm(path.join(binarydir, path.filename(target:targetfile()))) +end + +-- uninstall shared library +function uninstall_shared(target) + _uninstall_library(target) +end + +-- uninstall static library +function uninstall_static(target) + _uninstall_library(target) +end diff --git a/xmake/actions/uninstall/uninstall/windows.lua b/xmake/actions/uninstall/uninstall/windows.lua new file mode 100644 index 000000000..fb726a24a --- /dev/null +++ b/xmake/actions/uninstall/uninstall/windows.lua @@ -0,0 +1,72 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed 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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file windows.lua +-- + +-- uninstall headers +function _uninstall_headers(target) + local includedir = path.join(target:installdir(), "include") + local _, dstheaders = target:headerfiles(includedir) + for _, dstheader in ipairs(dstheaders) do + os.vrm(dstheader) + end +end + +-- uninstall binary +function uninstall_binary(target) + + -- remove the target file + local binarydir = path.join(target:installdir(), "bin") + os.vrm(path.join(binarydir, path.filename(target:targetfile()))) + + -- remove the dependent shared/windows (*.dll) target + -- @see https://github.com/xmake-io/xmake/issues/961 + for _, dep in ipairs(target:orderdeps()) do + if dep:targetkind() == "shared" and is_plat("windows", "mingw") then + os.vrm(path.join(binarydir, path.filename(dep:targetfile()))) + end + end +end + +-- uninstall shared library +function uninstall_shared(target) + + -- remove the target file + local binarydir = path.join(target:installdir(), "bin") + os.vrm(path.join(binarydir, path.filename(target:targetfile()))) + + -- remove *.lib for shared/windows (*.dll) target + -- @see https://github.com/xmake-io/xmake/issues/714 + local targetfile = target:targetfile() + local librarydir = path.join(target:installdir(), "lib") + os.vrm(path.join(librarydir, path.basename(targetfile) .. ".lib")) + + -- remove headers from the include directory + _uninstall_headers(target) +end + +-- uninstall static library +function uninstall_static(target) + + -- remove the target file + local librarydir = path.join(target:installdir(), "lib") + os.vrm(path.join(librarydir, path.filename(target:targetfile()))) + + -- remove headers from the include directory + _uninstall_headers(target) +end |
