Skip to content

Commit 8f30de8

Browse files
committed
a version can run
1 parent 5b12257 commit 8f30de8

File tree

3 files changed

+49
-53
lines changed

3 files changed

+49
-53
lines changed

xmake/modules/detect/tools/find_appimagetool.lua

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@
1212
-- See the License for the specific language governing permissions and
1313
-- limitations under the License.
1414
--
15-
-- Copyright (C) 2015-present, TBOOX Open Source Group.
15+
-- Copyright (C) 2015-present, Xmake Open Source Community.
1616
--
1717
-- @author RubMaker
1818
-- @file find_appimagetool.lua
1919
--
2020

2121
-- imports
2222
import("lib.detect.find_program")
23+
import("lib.detect.find_programver")
2324

2425
-- find appimagetool
2526
--
26-
-- @param opt the argument options
27+
-- @param opt the argument options, e.g. {version = true}
2728
--
28-
-- @return program path or nil
29+
-- @return program
2930
--
3031
-- @code
3132
--
@@ -34,26 +35,26 @@ import("lib.detect.find_program")
3435
-- @endcode
3536
--
3637
function main(opt)
38+
-- init options
3739
opt = opt or {}
3840

39-
-- find appimagetool in system PATH
40-
local program = find_program("appimagetool", opt)
41-
42-
-- if not found, check common installation paths
43-
if not program then
44-
local paths = {
45-
"/usr/local/bin/appimagetool",
46-
"/usr/bin/appimagetool",
47-
"/opt/appimagetool/appimagetool"
41+
-- add common appimagetool installation paths if no specific program is given
42+
if not opt.program then
43+
opt.paths = opt.paths or {}
44+
local appimagetool_paths = {
45+
"/usr/bin", -- standard system path
46+
"/usr/local/bin", -- local installation
47+
"/opt/appimagetool", -- custom installation directory
48+
path.join(os.getenv("HOME") or "~", ".local/bin") -- user local bin
4849
}
4950

50-
for _, p in ipairs(paths) do
51-
if os.isfile(p) and os.isexec(p) then
52-
program = p
53-
break
54-
end
51+
opt.paths = table.wrap(opt.paths)
52+
for _, apppath in ipairs(appimagetool_paths) do
53+
table.insert(opt.paths, apppath)
5554
end
5655
end
5756

57+
-- find program
58+
local program = find_program(opt.program or "appimagetool", opt)
5859
return program
5960
end

xmake/modules/detect/tools/find_linuxdeploy.lua

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@
1212
-- See the License for the specific language governing permissions and
1313
-- limitations under the License.
1414
--
15-
-- Copyright (C) 2015-present, TBOOX Open Source Group.
15+
-- Copyright (C) 2015-present, Xmake Open Source Community.
1616
--
1717
-- @author RubMaker
1818
-- @file find_linuxdeploy.lua
1919
--
2020

2121
-- imports
2222
import("lib.detect.find_program")
23+
import("lib.detect.find_programver")
2324

2425
-- find linuxdeploy
2526
--
26-
-- @param opt the argument options
27+
-- @param opt the argument options, e.g. {version = true}
2728
--
28-
-- @return program path or nil
29+
-- @return program, version
2930
--
3031
-- @code
3132
--
@@ -34,38 +35,36 @@ import("lib.detect.find_program")
3435
-- @endcode
3536
--
3637
function main(opt)
38+
-- init options
3739
opt = opt or {}
3840

39-
-- find linuxdeploy in system PATH
40-
local program = find_program("linuxdeploy", opt)
41-
42-
-- if not found, check common installation paths
43-
if not program then
44-
local homedir = os.getenv("HOME")
45-
local paths = {
46-
"/usr/local/bin/linuxdeploy",
47-
"/usr/bin/linuxdeploy",
48-
"/opt/linuxdeploy/linuxdeploy",
49-
path.join(os.tmpdir(), "linuxdeploy"),
50-
path.join(homedir, "Downloads/linuxdeploy"),
51-
path.join(homedir, "downloads/linuxdeploy"),
52-
path.join(homedir, ".local/bin/linuxdeploy"),
53-
path.join(homedir, "bin/linuxdeploy"),
54-
"/snap/bin/linuxdeploy",
55-
"/var/lib/flatpak/exports/bin/linuxdeploy",
56-
path.join(homedir, ".local/share/flatpak/exports/bin/linuxdeploy"),
57-
path.join(os.curdir(), "linuxdeploy"),
58-
path.join(os.curdir(), "tools/linuxdeploy"),
59-
path.join(os.curdir(), "bin/linuxdeploy")
41+
-- add common linuxdeploy installation paths if no specific program is given
42+
if not opt.program then
43+
opt.paths = opt.paths or {}
44+
local homedir = os.getenv("HOME") or "~"
45+
local linuxdeploy_paths = {
46+
"/usr/local/bin", -- standard system path
47+
"/usr/bin", -- system binary path
48+
"/opt/linuxdeploy", -- custom installation directory
49+
path.join(homedir, ".local/bin"), -- user local bin
50+
path.join(homedir, "bin"), -- user bin
51+
path.join(homedir, "Downloads"), -- common download location
52+
path.join(homedir, "downloads"), -- lowercase download location
53+
os.tmpdir(), -- temporary directory
54+
"/snap/bin", -- snap packages
55+
"/var/lib/flatpak/exports/bin", -- flatpak system
56+
path.join(homedir, ".local/share/flatpak/exports/bin"), -- flatpak user
57+
path.join(os.curdir(), "tools"), -- project tools directory
58+
path.join(os.curdir(), "bin") -- project bin directory
6059
}
6160

62-
for _, p in ipairs(paths) do
63-
if os.isfile(p) and os.isexec(p) then
64-
program = p
65-
break
66-
end
61+
opt.paths = table.wrap(opt.paths)
62+
for _, deploypath in ipairs(linuxdeploy_paths) do
63+
table.insert(opt.paths, deploypath)
6764
end
6865
end
6966

67+
-- find program
68+
local program = find_program(opt.program or "linuxdeploy", opt)
7069
return program
7170
end

xmake/plugins/pack/appimage/main.lua

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ Version=1.0
186186
)
187187
local desktop_file = path.join(appdir, package:name() .. ".desktop")
188188
io.writefile(desktop_file, desktop_content)
189-
return desktop_file
190189
end
191190
-- create AppRun script
192191
function _create_apprun(package, appdir)
@@ -202,22 +201,18 @@ exec "${HERE}/%s" "$@"
202201
local apprun_file = path.join(appdir, "AppRun")
203202
io.writefile(apprun_file, apprun_content)
204203
os.runv("chmod", {"+x", apprun_file})
205-
return apprun_file
206204
end
207205
-- copy icon file
208206
function _copy_icon(package, appdir)
209207
local iconfile = package:get("iconfile")
210208
local iconname = package:get("iconname") or package:name()
211209
if iconfile and os.isfile(iconfile) then
212-
-- 复制图标到usr/share/icons/hicolor目录
213210
local icon_dir = path.join(appdir, "usr/share/icons/hicolor/256x256/apps")
214211
os.mkdir(icon_dir)
215212
local icon_dst = path.join(icon_dir, iconname .. path.extension(iconfile))
216213
os.cp(iconfile, icon_dst)
217-
-- 同时复制到AppDir根目录供.desktop文件使用
218214
local root_icon = path.join(appdir, iconname .. path.extension(iconfile))
219215
os.cp(iconfile, root_icon)
220-
return icon_dst
221216
else
222217
return nil
223218
end
@@ -255,7 +250,8 @@ end
255250
function _pack_appimage(appimagetool, package)
256251
-- create temporary AppDir
257252
local appdir_name = package:name() .. ".AppDir"
258-
local appdir = path.join(os.tmpdir(), appdir_name)
253+
local appdir = path.join(package:builddir(), appdir_name)
254+
print("Creating temporary AppDir: %s", appdir)
259255
os.tryrm(appdir)
260256
-- create AppDir structure
261257
os.mkdir(appdir)
@@ -321,7 +317,7 @@ function _pack_appimage(appimagetool, package)
321317
local appimage_file = package:outputfile() or _get_appimage_file(package)
322318
os.tryrm(appimage_file)
323319
-- set architecture environment variable
324-
local arch = package:get("arch") or "x86_64"
320+
local arch = package:arch() or "x86_64"
325321
local envs = {ARCH = arch}
326322
os.vrunv(appimagetool.program, {appdir, appimage_file}, {envs = envs})
327323
-- clean up temporary directory

0 commit comments

Comments
 (0)