summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-11-14 23:37:34 +0800
committerruki <[email protected]>2023-11-14 23:37:34 +0800
commit43ce5f9a3ae10403cfc67ad4ce38bf52dff13629 (patch)
treeb269024ea9945ab19baae0fb5927f1033adb9378
parentf112896723402213c49453f8f4b5938abeb5020e (diff)
use custom commands
-rw-r--r--xmake/plugins/pack/nsis/main.lua62
1 files changed, 40 insertions, 22 deletions
diff --git a/xmake/plugins/pack/nsis/main.lua b/xmake/plugins/pack/nsis/main.lua
index c7ce49606..d3ecdd9a2 100644
--- a/xmake/plugins/pack/nsis/main.lua
+++ b/xmake/plugins/pack/nsis/main.lua
@@ -135,11 +135,8 @@ function _get_uninstallcmds_from_target(batchcmds_, target)
end
end
--- get install commands
-function _get_installcmds(package)
- local batchcmds_ = batchcmds.new()
-
- -- install files
+-- on install command
+function _on_installcmd(package, batchcmds_)
local srcfiles, dstfiles = package:installfiles(".")
for idx, srcfile in ipairs(srcfiles) do
batchcmds_:cp(srcfile, dstfiles[idx])
@@ -147,11 +144,34 @@ function _get_installcmds(package)
for _, target in ipairs(package:targets()) do
_get_installcmds_from_target(batchcmds_, target)
end
+end
+
+-- on uninstall command
+function _on_uninstallcmd(package, batchcmds_)
+ local _, dstfiles = package:installfiles(".")
+ for _, dstfile in ipairs(dstfiles) do
+ batchcmds_:rm(dstfile)
+ end
+ for _, target in ipairs(package:targets()) do
+ _get_uninstallcmds_from_target(batchcmds_, target)
+ end
+end
- -- get custom install commands
- local script = package:script("installcmd")
- if script then
- script(package, batchcmds_)
+-- get install commands
+function _get_installcmds(package)
+ local batchcmds_ = batchcmds.new()
+
+ -- call script to get install commands
+ local scripts = {
+ package:script("installcmd_before"),
+ package:script("installcmd", _on_installcmd),
+ package:script("installcmd_after")
+ }
+ for i = 1, 3 do
+ local script = scripts[i]
+ if script ~= nil then
+ script(package, batchcmds_)
+ end
end
-- generate command string
@@ -162,19 +182,17 @@ end
function _get_uninstallcmds(package)
local batchcmds_ = batchcmds.new()
- -- uninstall files
- local _, dstfiles = package:installfiles(".")
- for _, dstfile in ipairs(dstfiles) do
- batchcmds_:rm(dstfile)
- end
- for _, target in ipairs(package:targets()) do
- _get_uninstallcmds_from_target(batchcmds_, target)
- end
-
- -- get custom uninstall commands
- local script = package:script("uninstallcmd")
- if script then
- script(package, batchcmds_)
+ -- call script to get uninstall commands
+ local scripts = {
+ package:script("uninstallcmd_before"),
+ package:script("uninstallcmd", _on_uninstallcmd),
+ package:script("uninstallcmd_after")
+ }
+ for i = 1, 3 do
+ local script = scripts[i]
+ if script ~= nil then
+ script(package, batchcmds_)
+ end
end
-- generate command string