Skip to content

Commit f650879

Browse files
committed
test version for dmg
1 parent c2a0df3 commit f650879

File tree

4 files changed

+88
-113
lines changed

4 files changed

+88
-113
lines changed

xmake/includes/xpack/xmake.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ local apis = {
6969
"xpack.add_buildrequires",
7070
-- set nsis display icon
7171
"xpack.set_nsis_displayicon",
72-
-- set appimage icon name
72+
-- set icon name
7373
"xpack.set_iconname",
74-
-- set appimage tool
75-
"xpack.set_appimage_tool",
7674
-- set dmg window position
7775
"xpack.set_dmg_window_pos",
7876
-- set dmg window size
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--!A cross-platform build utility based on Lua
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
--
15+
-- Copyright (C) 2015-present, Xmake Open Source Community.
16+
--
17+
-- @author RubMaker
18+
-- @file find_macdeployqt.lua
19+
--
20+
21+
-- imports
22+
import("lib.detect.find_program")
23+
import("detect.sdks.find_qt")
24+
25+
-- find macdeployqt
26+
--
27+
-- @return program
28+
--
29+
-- @code
30+
--
31+
-- local macdeployqt = find_macdeployqt()
32+
--
33+
-- @endcode
34+
--
35+
function main()
36+
37+
-- find program from system PATH
38+
local program = find_program("macdeployqt")
39+
40+
-- If not found, try to find it in the Qt installation
41+
if not program then
42+
local qt = find_qt()
43+
if qt and qt.bindir then
44+
local macdeployqt_path = path.join(qt.bindir, "macdeployqt")
45+
if os.isfile(macdeployqt_path) then
46+
program = {program = macdeployqt_path}
47+
end
48+
end
49+
end
50+
51+
return program
52+
end

xmake/plugins/pack/dmg/main.lua

Lines changed: 35 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -38,128 +38,64 @@ end
3838

3939
-- get macdeployqt tool for Qt applications
4040
function _get_macdeployqt()
41-
local macdeployqt = find_tool("macdeployqt")
42-
if not macdeployqt then
43-
-- Try to find it in Qt installation
44-
local qt = find_qt()
45-
if qt and qt.bindir then
46-
local macdeployqt_path = path.join(qt.bindir, "macdeployqt")
47-
if os.isfile(macdeployqt_path) then
48-
macdeployqt = {program = macdeployqt_path}
49-
end
50-
end
51-
52-
if not macdeployqt then
53-
return nil
54-
end
55-
end
41+
local macdeployqt = assert(find_tool("macdeployqt"), "macdeployqt not found!")
5642
return macdeployqt
5743
end
5844

5945
-- detect if this is a Qt project
6046
function _is_qt_project(package)
61-
-- Method 1: Check for Qt libraries in links
62-
local links = package:get("links")
63-
if links then
64-
for _, link in ipairs(links) do
65-
if link:lower():find("qt") then
47+
-- method 1: check Qt rules
48+
local rules = package:rules()
49+
if rules then
50+
for _, rule in ipairs(rules) do
51+
local rule_name = rule:name()
52+
if rule_name and (rule_name:find("qt", 1, true) or
53+
rule_name:find("qt6", 1, true) or
54+
rule_name:find("qt5", 1, true)) then
6655
return true
6756
end
6857
end
6958
end
7059

71-
-- Method 2: Check executable for Qt dependencies using otool
72-
local app_source, _ = _find_app_bundle(package)
73-
if app_source then
74-
local macos_dir = path.join(app_source, "Contents", "MacOS")
75-
if os.isdir(macos_dir) then
76-
local executables = os.files(path.join(macos_dir, "*"))
77-
for _, executable in ipairs(executables) do
78-
if os.isfile(executable) then
79-
local otool_output = os.iorunv("otool", {"-L", executable})
80-
if otool_output then
81-
-- Check for Qt frameworks in otool output
82-
if otool_output:lower():find("qt") or
83-
otool_output:find("QtCore") or
84-
otool_output:find("QtGui") or
85-
otool_output:find("QtWidgets") then
86-
return true
87-
end
88-
end
89-
end
90-
end
91-
end
60+
-- method 2: check target's Qt data
61+
local qt_data = package:data("qt")
62+
if qt_data then
63+
return true
9264
end
93-
94-
-- Method 3: Check source files for Qt headers/includes
95-
local srcfiles, _ = package:sourcefiles()
96-
for _, srcfile in ipairs(srcfiles or {}) do
97-
if srcfile:endswith(".cpp") or srcfile:endswith(".cc") or srcfile:endswith(".cxx") or srcfile:endswith(".mm") then
98-
if os.isfile(srcfile) then
99-
local content = io.readfile(srcfile)
100-
if content and (content:find("#include.*[Qq][Tt]") or
101-
content:find("#include.*<Q") or
102-
content:find("QApplication") or
103-
content:find("QWidget") or
104-
content:find("QMainWindow")) then
105-
return true
106-
end
107-
end
108-
end
65+
66+
-- method 3: check Qt environment variables
67+
local qt_env = os.getenv("QTDIR") or os.getenv("QT_DIR") or os.getenv("Qt6_DIR") or os.getenv("Qt5_DIR")
68+
if qt_env then
69+
return true
10970
end
110-
71+
print("Not a Qt project")
11172
return false
11273
end
11374

114-
function _check_qml_usage(package, app_source)
115-
-- Method 1: Check for QML-related libraries in links
116-
local links = package:get("links")
117-
if links then
118-
for _, link in ipairs(links) do
119-
if link:lower():find("qml") or link:lower():find("quick") then
75+
function _check_qml_usage(package)
76+
-- method 1: check Qt rules
77+
local rules = package:rules()
78+
if rules then
79+
for _, rule in ipairs(rules) do
80+
local rule_name = rule:name()
81+
if rule_name and (rule_name:find("qml", 1, true) or rule_name:find("quick", 1, true)) then
12082
return true
12183
end
12284
end
12385
end
124-
125-
-- Method 2: Check executable for QML/Quick dependencies
126-
local macos_dir = path.join(app_source, "Contents", "MacOS")
127-
if os.isdir(macos_dir) then
128-
local executables = os.files(path.join(macos_dir, "*"))
129-
for _, executable in ipairs(executables) do
130-
if os.isfile(executable) then
131-
local otool_output = os.iorunv("otool", {"-L", executable})
132-
if otool_output then
133-
if otool_output:find("QtQml") or otool_output:find("QtQuick") then
134-
return true
135-
end
136-
end
137-
end
138-
end
86+
87+
-- method 2: check Qt data for QML
88+
local qml_data = package:data("qml")
89+
if qml_data then
90+
return true
13991
end
140-
141-
-- Method 3: Check for .qml files in project
92+
93+
-- method 3: check for .qml files
14294
local qml_files = os.files("**.qml")
14395
if qml_files and #qml_files > 0 then
14496
return true
14597
end
146-
147-
-- Method 4: Check source files for QML-related includes
148-
local srcfiles, _ = package:sourcefiles()
149-
for _, srcfile in ipairs(srcfiles or {}) do
150-
if srcfile:endswith(".cpp") or srcfile:endswith(".cc") or srcfile:endswith(".cxx") or srcfile:endswith(".mm") then
151-
if os.isfile(srcfile) then
152-
local content = io.readfile(srcfile)
153-
if content and (content:find("#include.*QQml") or
154-
content:find("#include.*QQuick") or
155-
content:find("QQmlEngine") or
156-
content:find("QQuickView")) then
157-
return true
158-
end
159-
end
160-
end
161-
end
162-
98+
print("No QML usage detected")
16399
return false
164100
end
165101

@@ -557,10 +493,8 @@ function _pack_dmg(package)
557493
print("Warning: macdeployqt not available, Qt dependencies may not be properly bundled")
558494
end
559495
end
560-
561-
-- find background image (optional)
496+
-- find background image
562497
local bg_image = _find_background_image(package)
563-
564498
-- get output dmg path
565499
local dmg_file = package:outputfile() or _get_dmg_file(package)
566500
dmg_file = dmg_file:gsub("%.dmg+$", ".dmg") -- clean up extension
@@ -569,15 +503,12 @@ function _pack_dmg(package)
569503
if not staging_dir then
570504
return false
571505
end
572-
573506
-- create dmg
574507
local success = _create_dmg_with_create_dmg(create_dmg, package, staging_dir, dmg_file, appbundle_name, bg_image)
575-
576508
if success then
577509
-- verify the result
578510
success = _verify_dmg(dmg_file)
579511
end
580-
581512
-- cleanup staging directory
582513
os.tryrm(staging_dir)
583514
return success
@@ -587,7 +518,6 @@ end
587518
function main(package)
588519
-- only for macOS
589520
if not is_host("macosx") then
590-
print("DMG packaging is only supported on macOS")
591521
return
592522
end
593523

@@ -599,7 +529,5 @@ function main(package)
599529
local success = _pack_dmg(package)
600530
if success then
601531
print("Final DMG file:", dmg_file)
602-
else
603-
os.exit(1)
604532
end
605533
end

xmake/plugins/pack/xpack.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ function xpack:inputkind()
211211
deb = "source",
212212
srpm = "source",
213213
rpm = "source",
214-
appimage = "binary",
215214
dmg = "binary"
216215
}
217216
inputkind = inputkinds[self:format()] or "binary"
@@ -232,7 +231,6 @@ function xpack:outputkind()
232231
deb = "binary",
233232
srpm = "source",
234233
rpm = "binary",
235-
appimage = "binary",
236234
dmg = "binary"
237235
}
238236
local outputkind = outputkinds[self:format()] or "binary"
@@ -383,7 +381,6 @@ function xpack:extension()
383381
deb = ".deb",
384382
srpm = ".src.rpm",
385383
rpm = ".rpm",
386-
appimage = ".AppImage",
387384
dmg = ".dmg"
388385
}
389386
extension = extensions[self:format()] or ""

0 commit comments

Comments
 (0)