summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-11-15 00:43:52 +0800
committerruki <[email protected]>2023-11-15 00:43:52 +0800
commit232d49f245224019a5c69a17702a3c3ad15d467e (patch)
tree4bcf5c02f3108c98b85b2253bb2008e4652fafc4
parent6e6b5bb6959d2e0f6b393d881170b3a0eb81fe9d (diff)
add tryrm for nsis
-rw-r--r--xmake/modules/private/utils/batchcmds.lua14
-rw-r--r--xmake/plugins/pack/nsis/main.lua28
2 files changed, 35 insertions, 7 deletions
diff --git a/xmake/modules/private/utils/batchcmds.lua b/xmake/modules/private/utils/batchcmds.lua
index 347b40be3..fe518cbec 100644
--- a/xmake/modules/private/utils/batchcmds.lua
+++ b/xmake/modules/private/utils/batchcmds.lua
@@ -144,6 +144,14 @@ function _runcmd_rm(cmd, opt)
end
end
+-- run command: os.tryrm
+function _runcmd_tryrm(cmd, opt)
+ local filepath = cmd.filepath
+ if not opt.dryrun then
+ os.tryrm(filepath)
+ end
+end
+
-- run command: os.rmdir
function _runcmd_rmdir(cmd, opt)
local dir = cmd.dir
@@ -189,6 +197,7 @@ function _runcmd(cmd, opt)
rmdir = _runcmd_rmdir,
cd = _runcmd_cd,
rm = _runcmd_rm,
+ tryrm = _runcmd_tryrm,
cp = _runcmd_cp,
mv = _runcmd_mv,
ln = _runcmd_ln
@@ -352,6 +361,11 @@ function batchcmds:rm(filepath)
table.insert(self:cmds(), {kind = "rm", filepath = filepath})
end
+-- add command: os.tryrm
+function batchcmds:tryrm(filepath)
+ table.insert(self:cmds(), {kind = "tryrm", filepath = filepath})
+end
+
-- add command: os.cp
function batchcmds:cp(srcpath, dstpath, opt)
table.insert(self:cmds(), {kind = "cp", srcpath = srcpath, dstpath = dstpath, opt = opt})
diff --git a/xmake/plugins/pack/nsis/main.lua b/xmake/plugins/pack/nsis/main.lua
index 5acb3c055..e0df55ccf 100644
--- a/xmake/plugins/pack/nsis/main.lua
+++ b/xmake/plugins/pack/nsis/main.lua
@@ -83,6 +83,21 @@ function _get_command_strings(package, cmd)
elseif kind == "rm" then
local filepath = path.normalize(path.join("$INSTDIR", cmd.filepath))
table.insert(result, string.format("Delete \"%s\"", filepath))
+ elseif kind == "tryrm" then
+ --[[
+ IfFileExists "$InstDir\file" file_found file_not_found_or_end
+ file_found:
+ Delete "$InstDir\file"
+ goto file_not_found_or_end
+ file_not_found_or_end:
+ --]]
+ local filepath = path.normalize(path.join("$INSTDIR", cmd.filepath))
+ local tag = hash.uuid(filepath):split("-", {plain = true})[1]:lower()
+ table.insert(result, string.format("IfFileExists \"%s\" file_found_%s file_not_found_or_end_%s", filepath, tag, tag))
+ table.insert(result, string.format("file_found_%s:", tag))
+ table.insert(result, string.format(" Delete \"%s\"", filepath))
+ table.insert(result, string.format(" goto file_not_found_or_end_%s", tag))
+ table.insert(result, string.format("file_not_found_or_end_%s:", tag))
elseif kind == "rmdir" then
local dir = path.normalize(path.join("$INSTDIR", cmd.dir))
table.insert(result, string.format("RMDir /r \"%s\"", dir))
@@ -180,8 +195,7 @@ function _on_target_uninstallcmd_binary(target, batchcmds_, opt)
-- uninstall target file
batchcmds_:rm(path.join(bindir, target:filename()))
-
- -- TODO: tryrm symbolfile
+ batchcmds_:tryrm(path.join(bindir, path.filename(target:symbolfile())))
end
-- on uninstall shared target command
@@ -191,24 +205,24 @@ function _on_target_uninstallcmd_shared(target, batchcmds_, opt)
-- uninstall target file
batchcmds_:rm(path.join(bindir, target:filename()))
+ batchcmds_:tryrm(path.join(bindir, path.filename(target:symbolfile())))
end
-- on uninstall static target command
function _on_target_uninstallcmd_static(target, batchcmds_, opt)
local package = opt.package
- local bindir = package:bindir()
+ local libdir = package:libdir()
-- uninstall target file
- batchcmds_:rm(path.join(bindir, target:filename()))
+ batchcmds_:rm(path.join(libdir, target:filename()))
+ batchcmds_:tryrm(path.join(libdir, path.filename(target:symbolfile())))
end
-- on uninstall headeronly target command
function _on_target_uninstallcmd_headeronly(target, batchcmds_, opt)
local package = opt.package
- local bindir = package:bindir()
+ local includedir = package:includedir()
- -- uninstall target file
- batchcmds_:rm(path.join(bindir, target:filename()))
end
-- on uninstall target command