Skip to content

Commit 22ad6db

Browse files
committed
rebuidl appdir for appimage
1 parent 8f30de8 commit 22ad6db

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

xmake/plugins/pack/appimage/main.lua

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,69 +48,75 @@ end
4848
-- translate the file path for AppDir structure
4949
function _translate_filepath(package, filepath, appdir)
5050
local install_rootdir = package:install_rootdir()
51+
local dstpath = nil
5152
-- translate to relative path
5253
if filepath:startswith(install_rootdir) then
5354
local relative_path = path.relative(filepath, install_rootdir)
5455
-- translate to relative path
5556
if relative_path:startswith("usr/") then
56-
relative_path = relative_path:sub(5)
57+
relative_path = relative_path:sub(5)
5758
end
5859
-- map to AppDir's usr directory structure
5960
if relative_path:startswith("bin/") then
60-
return path.join(appdir, "usr", relative_path)
61+
dstpath = path.join(appdir, "usr", relative_path)
6162
elseif relative_path:startswith("lib/") then
62-
return path.join(appdir, "usr", relative_path)
63+
dstpath = path.join(appdir, "usr", relative_path)
6364
elseif relative_path:startswith("share/") then
64-
return path.join(appdir, "usr", relative_path)
65+
dstpath = path.join(appdir, "usr", relative_path)
6566
elseif relative_path:startswith("include/") then
66-
return path.join(appdir, "usr", relative_path)
67+
dstpath = path.join(appdir, "usr", relative_path)
6768
else
6869
local filename = path.filename(filepath)
6970
local ext = path.extension(filename):lower()
7071
-- binary executable -> usr/bin
7172
if ext == "" or ext == ".exe" then
72-
return path.join(appdir, "usr", "bin", filename)
73+
dstpath = path.join(appdir, "usr", "bin", filename)
7374
-- library file -> usr/lib
7475
elseif ext == ".so" or ext == ".dylib" or ext == ".dll" then
75-
return path.join(appdir, "usr", "lib", filename)
76+
dstpath = path.join(appdir, "usr", "lib", filename)
7677
-- icon file -> usr/share/icons/hicolor
7778
elseif ext == ".png" or ext == ".svg" or ext == ".ico" or ext == ".xpm" then
7879
local icon_dir = path.join(appdir, "usr/share/icons/hicolor/256x256/apps")
79-
return path.join(icon_dir, filename)
80+
dstpath = path.join(icon_dir, filename)
8081
-- desktop file -> usr/share/applications
8182
elseif ext == ".desktop" then
82-
return path.join(appdir, "usr/share/applications", filename)
83+
dstpath = path.join(appdir, "usr/share/applications", filename)
8384
-- other files -> usr/share/<package-name> or based on original path
8485
else
8586
local dirname = path.directory(relative_path)
8687
if dirname and dirname ~= "." then
87-
return path.join(appdir, "usr", "share", package:name(), dirname, filename)
88+
dstpath = path.join(appdir, "usr", "share", package:name(), dirname, filename)
8889
else
89-
return path.join(appdir, "usr", "share", package:name(), filename)
90+
dstpath = path.join(appdir, "usr", "share", package:name(), filename)
9091
end
9192
end
9293
end
9394
else
9495
local filename = path.filename(filepath)
9596
local ext = path.extension(filename):lower()
96-
if ext == ".cpp" or ext == ".c" or ext == ".h" or ext == ".hpp" or
97+
if ext == ".cpp" or ext == ".c" or ext == ".h" or ext == ".hpp" or
9798
ext == ".py" or ext == ".js" or ext == ".java" or ext == ".go" then
9899
return nil
99100
-- binary file
100101
elseif ext == "" or ext == ".exe" then
101-
return path.join(appdir, "usr", "bin", filename)
102+
dstpath = path.join(appdir, "usr", "bin", filename)
102103
-- library file
103104
elseif ext == ".so" or ext == ".dylib" or ext == ".dll" then
104-
return path.join(appdir, "usr", "lib", filename)
105+
dstpath = path.join(appdir, "usr", "lib", filename)
105106
-- icon file
106107
elseif ext == ".png" or ext == ".svg" or ext == ".ico" or ext == ".xpm" then
107108
local icon_dir = path.join(appdir, "usr/share/icons/hicolor/256x256/apps")
108-
return path.join(icon_dir, filename)
109+
dstpath = path.join(icon_dir, filename)
109110
else
110-
return path.join(appdir, "usr", "share", package:name(), filename)
111+
dstpath = path.join(appdir, "usr", "share", package:name(), filename)
111112
end
112113
end
114+
if dstpath then
115+
os.mkdir(path.directory(dstpath))
116+
end
117+
return dstpath
113118
end
119+
114120
-- get install command for AppDir
115121
function _get_customcmd(package, appdir, installcmds, cmd)
116122
local opt = cmd.opt or {}
@@ -127,6 +133,7 @@ function _get_customcmd(package, appdir, installcmds, cmd)
127133
end
128134
end
129135
if dstfile then
136+
os.mkdir(path.directory(dstfile))
130137
table.insert(installcmds, string.format("install -Dpm0755 \"%s\" \"%s\"", srcfile, dstfile))
131138
end
132139
end
@@ -159,6 +166,7 @@ function _get_customcmd(package, appdir, installcmds, cmd)
159166
table.insert(installcmds, string.format("%s", os.args(table.join(cmd.program, argv))))
160167
end
161168
end
169+
162170
-- get install commands for AppDir
163171
function _get_installcmds(package, appdir, installcmds, cmds)
164172
for _, cmd in ipairs(cmds) do
@@ -177,14 +185,16 @@ Exec=%s
177185
Icon=%s
178186
Categories=%s
179187
Version=1.0
180-
]],
188+
]],
181189
package:get("title") or package:name(),
182190
package:get("description") or package:get("title") or package:name(),
183191
package:name(),
184192
iconname,
185193
package:get("category") or "Utility"
186194
)
187195
local desktop_file = path.join(appdir, package:name() .. ".desktop")
196+
-- mkdir desktop file
197+
os.mkdir(path.directory(desktop_file))
188198
io.writefile(desktop_file, desktop_content)
189199
end
190200
-- create AppRun script
@@ -255,15 +265,7 @@ function _pack_appimage(appimagetool, package)
255265
os.tryrm(appdir)
256266
-- create AppDir structure
257267
os.mkdir(appdir)
258-
os.mkdir(path.join(appdir, "usr"))
259-
os.mkdir(path.join(appdir, "usr/bin"))
260-
os.mkdir(path.join(appdir, "usr/lib"))
261-
os.mkdir(path.join(appdir, "usr/share"))
262-
os.mkdir(path.join(appdir, "usr/share/applications"))
263-
os.mkdir(path.join(appdir, "usr/share/icons"))
264-
os.mkdir(path.join(appdir, "usr/share/icons/hicolor"))
265-
os.mkdir(path.join(appdir, "usr/share/icons/hicolor/256x256"))
266-
os.mkdir(path.join(appdir, "usr/share/icons/hicolor/256x256/apps"))
268+
267269
local original_prefixdir = package:get("prefixdir")
268270
package:set("prefixdir", "/usr")
269271
-- install files to AppDir

0 commit comments

Comments
 (0)