diff options
| author | ruki <[email protected]> | 2025-11-28 22:37:08 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-11-28 22:37:08 +0800 |
| commit | 241d9b9ed100c437f5e659dfb626f4c037b92057 (patch) | |
| tree | 3fa4777519d8ebae0bb57dd1739b9553633ec6b8 | |
| parent | 9d6daa73dbbc1c46552d5377291339514a1b6153 (diff) | |
add uninstallcmd
| -rw-r--r-- | xmake/plugins/pack/wix/main.lua | 62 | ||||
| -rw-r--r-- | xmake/rules/qt/uninstallcmd.lua | 75 | ||||
| -rw-r--r-- | xmake/rules/qt/xmake.lua | 4 |
3 files changed, 123 insertions, 18 deletions
diff --git a/xmake/plugins/pack/wix/main.lua b/xmake/plugins/pack/wix/main.lua index 080d4e66d..896ea2339 100644 --- a/xmake/plugins/pack/wix/main.lua +++ b/xmake/plugins/pack/wix/main.lua @@ -79,26 +79,52 @@ function _get_cp_kind_table(package, cmds, opt) end local option = table.join(cmd.opt or {}, opt) - local srcfiles = os.files(cmd.srcpath) - for _, srcfile in ipairs(srcfiles) do - -- the destination is directory? append the filename - local dstfile = cmd.dstpath - if #srcfiles > 1 or path.islastsep(dstfile) then - if option.rootdir then - dstfile = path.join(dstfile, path.relative(srcfile, option.rootdir)) - else - dstfile = path.join(dstfile, path.filename(srcfile)) - end - end - srcfile = path.normalize(srcfile) - local dstname = path.filename(dstfile) - local dstdir = path.normalize(path.directory(dstfile)) - dstdir = _translate_filepath(package, dstdir) + -- match files and directories + local srcitems = os.filedirs(cmd.srcpath) + for _, srcitem in ipairs(srcitems) do + if os.isdir(srcitem) then + -- for directory, recursively collect all files in it + local rootdir = option.rootdir or srcitem + local files = os.files(path.join(srcitem, "**")) + for _, srcfile in ipairs(files) do + -- the destination is directory? append the relative path + local dstfile = cmd.dstpath + if option.rootdir then + dstfile = path.join(dstfile, path.relative(srcfile, option.rootdir)) + else + dstfile = path.join(dstfile, path.relative(srcfile, rootdir)) + end + srcfile = path.normalize(srcfile) + local dstname = path.filename(dstfile) + local dstdir = path.normalize(path.directory(dstfile)) + dstdir = _translate_filepath(package, dstdir) - if result[dstdir] then - table.insert(result[dstdir], {srcfile, dstname}) + if result[dstdir] then + table.insert(result[dstdir], {srcfile, dstname}) + else + result[dstdir] = {{srcfile, dstname}} + end + end else - result[dstdir] = {{srcfile, dstname}} + -- for file, use the original logic + local dstfile = cmd.dstpath + if #srcitems > 1 or path.islastsep(dstfile) then + if option.rootdir then + dstfile = path.join(dstfile, path.relative(srcitem, option.rootdir)) + else + dstfile = path.join(dstfile, path.filename(srcitem)) + end + end + srcitem = path.normalize(srcitem) + local dstname = path.filename(dstfile) + local dstdir = path.normalize(path.directory(dstfile)) + dstdir = _translate_filepath(package, dstdir) + + if result[dstdir] then + table.insert(result[dstdir], {srcitem, dstname}) + else + result[dstdir] = {{srcitem, dstname}} + end end end ::continue:: diff --git a/xmake/rules/qt/uninstallcmd.lua b/xmake/rules/qt/uninstallcmd.lua new file mode 100644 index 000000000..12ef3a345 --- /dev/null +++ b/xmake/rules/qt/uninstallcmd.lua @@ -0,0 +1,75 @@ +--!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-present, Xmake Open Source Community. +-- +-- @author ruki +-- @file uninstallcmd.lua +-- + +-- uninstall application for xpack +function main(target, batchcmds, opt) + local package = opt.package + + -- only for xpack (package exists) + if not package then + return + end + + -- get install directory + local installdir = package:installdir() + if not installdir then + return + end + + -- macOS: uninstall .app bundle + if target:is_plat("macosx") then + local target_app = path.join(target:targetdir(), target:basename() .. ".app") + if os.isdir(target_app) then + -- remove .app from install directory + local appname = path.filename(target_app) + local dstappdir = path.join(installdir, appname) + batchcmds:rmdir(dstappdir, {emptydirs = true}) + end + elseif target:is_plat("windows", "mingw") then + -- Windows/Mingw: remove all deployed files and directories from install directory + local installdir = package:installdir() + + -- remove all files and directories deployed by windeployqt + -- since we copied everything from deploydir to installdir, we need to remove them + -- use os.filedirs to match all files and directories, then remove them + for _, item in ipairs(os.filedirs(path.join(installdir, "*"))) do + if os.isfile(item) then + batchcmds:rm(item, {emptydirs = true}) + elseif os.isdir(item) then + batchcmds:rmdir(item, {emptydirs = true}) + end + end + else + -- Linux: remove all files from bin directory + local bindir = target:bindir() + if bindir and os.isdir(bindir) then + local package_bindir = package:installdir("bin") + -- remove all files and directories from package bindir + for _, item in ipairs(os.filedirs(path.join(package_bindir, "*"))) do + if os.isfile(item) then + batchcmds:rm(item, {emptydirs = true}) + elseif os.isdir(item) then + batchcmds:rmdir(item, {emptydirs = true}) + end + end + end + end +end + diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua index 45e47213c..db13aa913 100644 --- a/xmake/rules/qt/xmake.lua +++ b/xmake/rules/qt/xmake.lua @@ -118,6 +118,7 @@ rule("qt.widgetapp") -- install application for xpack on_installcmd("installcmd") + on_uninstallcmd("uninstallcmd") -- define rule: qt static widgetapp rule("qt.widgetapp_static") @@ -149,6 +150,7 @@ rule("qt.widgetapp_static") -- install application for xpack on_installcmd("installcmd") + on_uninstallcmd("uninstallcmd") -- define rule: qt quickapp rule("qt.quickapp") @@ -174,6 +176,7 @@ rule("qt.quickapp") -- install application for xpack on_installcmd("installcmd") + on_uninstallcmd("uninstallcmd") -- define rule: qt static quickapp rule("qt.quickapp_static") @@ -201,6 +204,7 @@ rule("qt.quickapp_static") -- install application for xpack on_installcmd("installcmd") + on_uninstallcmd("uninstallcmd") -- define rule: qt qmlplugin rule("qt.qmlplugin") |
