summaryrefslogtreecommitdiff
path: root/xmake/plugins
diff options
context:
space:
mode:
authorruki <[email protected]>2023-11-14 23:28:30 +0800
committerruki <[email protected]>2023-11-14 23:28:30 +0800
commitaa38c3aa417f60f1015446ac4254cae3fa1e16be (patch)
tree21cdd735f2417034635871a913c65cba83dc2c8f /xmake/plugins
parent2a70793d5afbca2417bc65601f3a1785a1328d76 (diff)
improve installfiles
Diffstat (limited to 'xmake/plugins')
-rw-r--r--xmake/plugins/pack/nsis/main.lua32
-rw-r--r--xmake/plugins/pack/xpack.lua84
2 files changed, 110 insertions, 6 deletions
diff --git a/xmake/plugins/pack/nsis/main.lua b/xmake/plugins/pack/nsis/main.lua
index 9d1840b0c..15afe9881 100644
--- a/xmake/plugins/pack/nsis/main.lua
+++ b/xmake/plugins/pack/nsis/main.lua
@@ -74,19 +74,27 @@ function _get_command_strings(package, cmd)
dstfile = path.join(dstfile, path.filename(srcfile))
end
end
- table.insert(result, string.format("SetOutPath \"$INSTDIR\\%s\"", path.directory(dstfile)))
+ srcfile = path.normalize(srcfile)
+ dstfile = path.normalize(path.join("$INSTDIR", dstfile))
+ table.insert(result, string.format("SetOutPath \"%s\"", path.directory(dstfile)))
table.insert(result, string.format("File /oname=%s \"%s\"", path.filename(dstfile), srcfile))
end
elseif kind == "rm" then
- table.insert(result, string.format("Delete \"$INSTDIR\\%s\"", cmd.filepath))
+ local filepath = path.normalize(path.join("$INSTDIR", cmd.filepath))
+ table.insert(result, string.format("Delete \"%s\"", filepath))
elseif kind == "rmdir" then
- table.insert(result, string.format("RMDir /r \"$INSTDIR\\%s\"", cmd.dir))
+ local dir = path.normalize(path.join("$INSTDIR", cmd.dir))
+ table.insert(result, string.format("RMDir /r \"%s\"", dir))
elseif kind == "mv" then
- table.insert(result, string.format("Rename \"$INSTDIR\\%s\" \"$INSTDIR\\%s\"", cmd.srcpath, cmd.dstpath))
+ local srcpath = path.normalize(path.join("$INSTDIR", cmd.srcpath))
+ local dstpath = path.normalize(path.join("$INSTDIR", cmd.dstpath))
+ table.insert(result, string.format("Rename \"%s\" \"%s\"", srcpath, dstpath))
elseif kind == "cd" then
- table.insert(result, string.format("SetOutPath \"$INSTDIR\\%s\"", cmd.dir))
+ local dir = path.normalize(path.join("$INSTDIR", cmd.dir))
+ table.insert(result, string.format("SetOutPath \"%s\"", dir))
elseif kind == "mkdir" then
- table.insert(result, string.format("CreateDirectory \"$INSTDIR\\%s\"", cmd.dir))
+ local dir = path.normalize(path.join("$INSTDIR", cmd.dir))
+ table.insert(result, string.format("CreateDirectory \"%s\"", dir))
end
return result
end
@@ -106,6 +114,12 @@ function _get_installcmds(package)
-- TODO
+ -- install files
+ local srcfiles, dstfiles = package:installfiles(".")
+ for idx, srcfile in ipairs(srcfiles) do
+ batchcmds_:cp(srcfile, dstfiles[idx])
+ end
+
-- get custom install commands
local script = package:script("installcmd")
if script then
@@ -122,6 +136,12 @@ function _get_uninstallcmds(package)
-- TODO
+ -- uninstall files
+ local _, dstfiles = package:installfiles(".")
+ for _, dstfile in ipairs(dstfiles) do
+ batchcmds_:rm(dstfile)
+ end
+
-- get custom uninstall commands
local script = package:script("uninstallcmd")
if script then
diff --git a/xmake/plugins/pack/xpack.lua b/xmake/plugins/pack/xpack.lua
index c308328ab..b0a7b7394 100644
--- a/xmake/plugins/pack/xpack.lua
+++ b/xmake/plugins/pack/xpack.lua
@@ -334,6 +334,90 @@ function xpack:version()
return version, version_build
end
+-- get the copied files
+function xpack:_copiedfiles(filetype, outputdir)
+
+ -- no copied files?
+ local copiedfiles = self:get(filetype)
+ if not copiedfiles then return end
+
+ -- get the extra information
+ local extrainfo = table.wrap(self:get("__extra_" .. filetype))
+
+ -- get the source paths and destinate paths
+ local srcfiles = {}
+ local dstfiles = {}
+ local fileinfos = {}
+ for _, copiedfile in ipairs(table.wrap(copiedfiles)) do
+
+ -- get the root directory
+ local rootdir, count = copiedfile:gsub("|.*$", ""):gsub("%(.*%)$", "")
+ if count == 0 then
+ rootdir = nil
+ end
+ if rootdir and rootdir:trim() == "" then
+ rootdir = "."
+ end
+
+ -- remove '(' and ')'
+ local srcpaths = copiedfile:gsub("[%(%)]", "")
+ if srcpaths then
+
+ -- get the source paths
+ srcpaths = os.match(srcpaths)
+ if srcpaths and #srcpaths > 0 then
+
+ -- add the source copied files
+ table.join2(srcfiles, srcpaths)
+
+ -- the copied directory exists?
+ if outputdir then
+
+ -- get the file info
+ local fileinfo = extrainfo[copiedfile] or {}
+
+ -- get the prefix directory
+ local prefixdir = fileinfo.prefixdir
+
+ -- add the destinate copied files
+ for _, srcpath in ipairs(srcpaths) do
+
+ -- get the destinate directory
+ local dstdir = outputdir
+ if prefixdir then
+ dstdir = path.join(dstdir, prefixdir)
+ end
+
+ -- the destinate file
+ local dstfile = nil
+ if rootdir then
+ dstfile = path.absolute(path.relative(srcpath, rootdir), dstdir)
+ else
+ dstfile = path.join(dstdir, path.filename(srcpath))
+ end
+ assert(dstfile)
+
+ -- modify filename
+ if fileinfo.filename then
+ dstfile = path.join(path.directory(dstfile), fileinfo.filename)
+ end
+
+ -- add it
+ table.insert(dstfiles, dstfile)
+ table.insert(fileinfos, fileinfo)
+ end
+ end
+ end
+ end
+ end
+ return srcfiles, dstfiles, fileinfos
+end
+
+-- get the install files
+function xpack:installfiles(outputdir)
+ return self:_copiedfiles("installfiles", outputdir)
+end
+
-- new a xpack
function _new(name, info)
return xpack {name, info}