summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-11-14 23:20:28 +0800
committerruki <[email protected]>2023-11-14 23:20:28 +0800
commitf070b5c9e770199d6fd5de9f696b4894238c6b58 (patch)
treeb74e1d129be1183e0bb484c874f07d2d4fe84ce2
parent661940b67e586377a362dd956b699244aa3165ec (diff)
add icon file
-rw-r--r--tests/plugins/pack/src/assets/xmake.icobin0 -> 119943 bytes
-rw-r--r--tests/plugins/pack/xmake.lua9
-rw-r--r--xmake/includes/xpack/xmake.lua8
-rw-r--r--xmake/modules/private/utils/batchcmds.lua14
-rw-r--r--xmake/plugins/pack/nsis/main.lua10
-rw-r--r--xmake/plugins/pack/xpack.lua3
-rw-r--r--xmake/plugins/project/cmake/cmakelists.lua2
-rw-r--r--xmake/plugins/project/make/makefile.lua11
-rw-r--r--xmake/scripts/xpack/nsis/makensis.nsi3
9 files changed, 49 insertions, 11 deletions
diff --git a/tests/plugins/pack/src/assets/xmake.ico b/tests/plugins/pack/src/assets/xmake.ico
new file mode 100644
index 000000000..52c8ef389
--- /dev/null
+++ b/tests/plugins/pack/src/assets/xmake.ico
Binary files differ
diff --git a/tests/plugins/pack/xmake.lua b/tests/plugins/pack/xmake.lua
index 46517107b..3311a0965 100644
--- a/tests/plugins/pack/xmake.lua
+++ b/tests/plugins/pack/xmake.lua
@@ -12,14 +12,15 @@ xpack("test")
set_description("hello")
add_targets("test")
set_basename("test-$(plat)-$(arch)-v$(version)")
- add_installfiles("assets/*.png")
- set_installdir("assets")
+ add_installfiles("src/assets/*.png")
+ set_installdir("resources")
+ set_iconfile("src/assets/xmake.ico")
on_installcmd(function (package, batchcmds)
batchcmds:cp("src/assets/*.txt", "resources/", {rootdir = "src"})
batchcmds:mkdir("stub")
end)
on_uninstallcmd(function (package, batchcmds)
- batchcmds:rm("resources")
- batchcmds:rm("stub")
+ batchcmds:rmdir("resources")
+ batchcmds:rmdir("stub")
end)
diff --git a/xmake/includes/xpack/xmake.lua b/xmake/includes/xpack/xmake.lua
index 7c05f1a11..970c8ee24 100644
--- a/xmake/includes/xpack/xmake.lua
+++ b/xmake/includes/xpack/xmake.lua
@@ -44,10 +44,14 @@ local apis = {
"xpack.set_formats",
-- set the base name of the output file
"xpack.set_basename",
+ -- add targets to be packaged
+ "xpack.add_targets"
+ },
+ paths = {
-- set the spec file path, support the custom variable pattern, e.g. set_specfile("", {pattern = "%${([^\n]-)}"})
"xpack.set_specfile",
- -- add targets to be packaged
- "xpack.add_targets",
+ -- 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
diff --git a/xmake/modules/private/utils/batchcmds.lua b/xmake/modules/private/utils/batchcmds.lua
index 6edd1d8f3..347b40be3 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.rmdir
+function _runcmd_rmdir(cmd, opt)
+ local dir = cmd.dir
+ if not opt.dryrun and os.isdir(dir) then
+ os.tryrm(dir)
+ end
+end
+
-- run command: os.cp
function _runcmd_cp(cmd, opt)
if not opt.dryrun then
@@ -178,6 +186,7 @@ function _runcmd(cmd, opt)
execv = _runcmd_execv,
vexecv = _runcmd_vexecv,
mkdir = _runcmd_mkdir,
+ rmdir = _runcmd_rmdir,
cd = _runcmd_cd,
rm = _runcmd_rm,
cp = _runcmd_cp,
@@ -333,6 +342,11 @@ function batchcmds:mkdir(dir)
table.insert(self:cmds(), {kind = "mkdir", dir = dir})
end
+-- add command: os.rmdir
+function batchcmds:rmdir(dir)
+ table.insert(self:cmds(), {kind = "rmdir", dir = dir})
+end
+
-- add command: os.rm
function batchcmds:rm(filepath)
table.insert(self:cmds(), {kind = "rm", filepath = filepath})
diff --git a/xmake/plugins/pack/nsis/main.lua b/xmake/plugins/pack/nsis/main.lua
index 1aff5114d..9d1840b0c 100644
--- a/xmake/plugins/pack/nsis/main.lua
+++ b/xmake/plugins/pack/nsis/main.lua
@@ -78,13 +78,15 @@ function _get_command_strings(package, cmd)
table.insert(result, string.format("File /oname=%s \"%s\"", path.filename(dstfile), srcfile))
end
elseif kind == "rm" then
- table.insert(result, string.format("RMDir /r \"$INSTDIR\\%s\"", path.directory(cmd.filepath)))
+ table.insert(result, string.format("Delete \"$INSTDIR\\%s\"", cmd.filepath))
+ elseif kind == "rmdir" then
+ table.insert(result, string.format("RMDir /r \"$INSTDIR\\%s\"", cmd.dir))
elseif kind == "mv" then
- -- TODO
+ table.insert(result, string.format("Rename \"$INSTDIR\\%s\" \"$INSTDIR\\%s\"", cmd.srcpath, cmd.dstpath))
elseif kind == "cd" then
- -- TODO
+ table.insert(result, string.format("SetOutPath \"$INSTDIR\\%s\"", cmd.dir))
elseif kind == "mkdir" then
- table.insert(result, string.format("CreateDirectory \"$INSTDIR\\%s\"", path.directory(cmd.dir)))
+ table.insert(result, string.format("CreateDirectory \"$INSTDIR\\%s\"", cmd.dir))
end
return result
end
diff --git a/xmake/plugins/pack/xpack.lua b/xmake/plugins/pack/xpack.lua
index 26f9dddab..c308328ab 100644
--- a/xmake/plugins/pack/xpack.lua
+++ b/xmake/plugins/pack/xpack.lua
@@ -233,7 +233,8 @@ function xpack:specvars()
PACKAGE_FILENAME = self:filename(),
PACKAGE_HOMEPAGE = self:get("homepage") or "",
PACKAGE_COPYRIGHT = self:get("copyright") or "",
- PACKAGE_COMPANY = self:get("company") or ""
+ PACKAGE_COMPANY = self:get("company") or "",
+ PACKAGE_ICONFILE = self:get("iconfile") or ""
}
-- get version
diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua
index fd0f6ff2c..4b8df1b22 100644
--- a/xmake/plugins/project/cmake/cmakelists.lua
+++ b/xmake/plugins/project/cmake/cmakelists.lua
@@ -897,6 +897,8 @@ function _get_command_string(cmd, outputdir)
end
elseif kind == "rm" then
return string.format("${CMAKE_COMMAND} -E rm -rf %s", _get_relative_unix_path_to_cmake(cmd.filepath, outputdir))
+ elseif kind == "rmdir" then
+ return string.format("${CMAKE_COMMAND} -E rm -rf %s", _get_relative_unix_path_to_cmake(cmd.dir, outputdir))
elseif kind == "mv" then
return string.format("${CMAKE_COMMAND} -E rename %s %s",
_get_relative_unix_path_to_cmake(cmd.srcpath, outputdir), _get_relative_unix_path_to_cmake(cmd.dstpath, outputdir))
diff --git a/xmake/plugins/project/make/makefile.lua b/xmake/plugins/project/make/makefile.lua
index 7d2559ea1..7d462b138 100644
--- a/xmake/plugins/project/make/makefile.lua
+++ b/xmake/plugins/project/make/makefile.lua
@@ -215,6 +215,15 @@ function _get_cmd_rm(filedir)
end
end
+-- get command: rmdir
+function _get_cmd_rmdir(filedir)
+ if is_subhost("windows") then
+ return string.format("@rmdir /S /Q %s > NUL 2>&1", filedir)
+ else
+ return string.format("@rm -rf %s", filedir)
+ end
+end
+
-- get command: echo
function _get_cmd_echo(str)
return string.format("@echo %s", colors.ignore(str))
@@ -248,6 +257,8 @@ function _get_command_string(cmd, outputdir)
end
elseif kind == "rm" then
return _get_cmd_rm(_get_relative_unix_path(cmd.filepath, outputdir))
+ elseif kind == "rmdir" then
+ return _get_cmd_rmdir(_get_relative_unix_path(cmd.dir, outputdir))
elseif kind == "mv" then
return _get_cmd_mv(_get_relative_unix_path(cmd.srcpath, outputdir), _get_relative_unix_path(cmd.dstpath, outputdir))
elseif kind == "ln" then
diff --git a/xmake/scripts/xpack/nsis/makensis.nsi b/xmake/scripts/xpack/nsis/makensis.nsi
index ecb1748d1..8bddfd54a 100644
--- a/xmake/scripts/xpack/nsis/makensis.nsi
+++ b/xmake/scripts/xpack/nsis/makensis.nsi
@@ -51,6 +51,9 @@ RequestExecutionLevel user
; set DPI aware
ManifestDPIAware true
+; set icon
+!define MUI_ICON "${PACKAGE_ICONFILE}"
+
; UAC
!macro Init thing
uac_tryagain: