summaryrefslogtreecommitdiff
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
parent2a70793d5afbca2417bc65601f3a1785a1328d76 (diff)
improve installfiles
-rw-r--r--tests/plugins/pack/xmake.lua3
-rw-r--r--xmake/includes/xpack/xmake.lua4
-rw-r--r--xmake/plugins/pack/nsis/main.lua32
-rw-r--r--xmake/plugins/pack/xpack.lua84
-rw-r--r--xmake/scripts/xpack/nsis/makensis.nsi3
5 files changed, 114 insertions, 12 deletions
diff --git a/tests/plugins/pack/xmake.lua b/tests/plugins/pack/xmake.lua
index 3311a0965..fc73ec247 100644
--- a/tests/plugins/pack/xmake.lua
+++ b/tests/plugins/pack/xmake.lua
@@ -12,8 +12,7 @@ xpack("test")
set_description("hello")
add_targets("test")
set_basename("test-$(plat)-$(arch)-v$(version)")
- add_installfiles("src/assets/*.png")
- set_installdir("resources")
+ add_installfiles("src/(assets/*.png)", {prefixdir = "images"})
set_iconfile("src/assets/xmake.ico")
on_installcmd(function (package, batchcmds)
batchcmds:cp("src/assets/*.txt", "resources/", {rootdir = "src"})
diff --git a/xmake/includes/xpack/xmake.lua b/xmake/includes/xpack/xmake.lua
index 970c8ee24..1e53e37dd 100644
--- a/xmake/includes/xpack/xmake.lua
+++ b/xmake/includes/xpack/xmake.lua
@@ -53,9 +53,7 @@ local apis = {
-- set icon file path, e.g foo.ico
"xpack.set_iconfile",
-- add install files, we will also get them from target
- "xpack.add_installfiles",
- -- set install directory, we will also get it from target
- "xpack.set_installdir"
+ "xpack.add_installfiles"
},
script = {
-- add custom install commands script, we will also get it from target/rules
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}
diff --git a/xmake/scripts/xpack/nsis/makensis.nsi b/xmake/scripts/xpack/nsis/makensis.nsi
index 77b3c10fa..6870c32b3 100644
--- a/xmake/scripts/xpack/nsis/makensis.nsi
+++ b/xmake/scripts/xpack/nsis/makensis.nsi
@@ -191,6 +191,7 @@ Section "${PACKAGE_NAME} (required)" InstallExeutable
; set output path to the installation directory.
SetOutPath $InstDir
+ ; TODO
; remove previous directories used
IfFileExists "$InstDir\${PACKAGE_FILENAME}" file_found file_not_found_or_end
file_found:
@@ -207,7 +208,7 @@ Section "${PACKAGE_NAME} (required)" InstallExeutable
!macro AddReg RootKey
WriteRegStr ${RootKey} ${RegUninstall} "NoAdmin" "$NOADMIN"
WriteRegStr ${RootKey} ${RegUninstall} "DisplayName" "${PACKAGE_NAME} (${PACKAGE_ARCH})"
- WriteRegStr ${RootKey} ${RegUninstall} "DisplayIcon" '"$InstDir\${PACKAGE_FILENAME}"'
+ WriteRegStr ${RootKey} ${RegUninstall} "DisplayIcon" '"$InstDir\${PACKAGE_FILENAME}"' ; TODO
WriteRegStr ${RootKey} ${RegUninstall} "Comments" "${PACKAGE_DESCRIPTION}"
WriteRegStr ${RootKey} ${RegUninstall} "Publisher" "${PACKAGE_COPYRIGHT}"
WriteRegStr ${RootKey} ${RegUninstall} "UninstallString" '"$InstDir\uninstall.exe"'