Skip to content

Commit 27f4b0b

Browse files
committed
returen dmg pack
1 parent ce86e57 commit 27f4b0b

File tree

2 files changed

+75
-54
lines changed

2 files changed

+75
-54
lines changed

xmake/modules/detect/tools/find_macdeployqt.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ import("detect.sdks.find_qt")
3232
--
3333
-- @endcode
3434
--
35-
function main()
35+
function main(opt)
36+
37+
-- init options
38+
opt = opt or {}
3639

3740
-- find program from system PATH
38-
local program = find_program("macdeployqt")
41+
local program = find_program(opt.program or "macdeployqt")
3942

4043
-- If not found, try to find it in the Qt installation
4144
if not program then
@@ -44,10 +47,8 @@ function main()
4447
local macdeployqt_path = path.join(qt.bindir, "macdeployqt")
4548
if os.isfile(macdeployqt_path) then
4649
program = {program = macdeployqt_path}
47-
print("found macdeployqt in Qt SDK: %s", macdeployqt_path)
4850
end
4951
end
5052
end
51-
print("macdeployqt: %s", program and program.program or "not found")
5253
return program
5354
end

xmake/plugins/pack/dmg/main.lua

Lines changed: 70 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,52 +29,41 @@ import("detect.sdks.find_qt")
2929

3030
-- get the create-dmg tool
3131
function _get_create_dmg()
32-
local create_dmg = find_tool("create-dmg")
33-
if not create_dmg then
34-
return nil
35-
end
36-
return create_dmg
32+
return assert(find_tool("create-dmg"), "create-dmg not found!")
3733
end
3834

3935
-- get macdeployqt tool for Qt applications
4036
function _get_macdeployqt()
41-
local macdeployqt = assert(find_tool("macdeployqt"), "macdeployqt not found!")
42-
print("11111111111111macdeployqt: %s", macdeployqt.program)
37+
local macdeployqt = find_tool("macdeployqt")
38+
if not macdeployqt then
39+
-- Try to find it in Qt installation
40+
local qt = find_qt()
41+
if qt and qt.bindir then
42+
local macdeployqt_path = path.join(qt.bindir, "macdeployqt")
43+
if os.isfile(macdeployqt_path) then
44+
macdeployqt = {program = macdeployqt_path}
45+
end
46+
end
47+
48+
if not macdeployqt then
49+
return nil
50+
end
51+
end
4352
return macdeployqt
4453
end
4554

4655
-- detect if this is a Qt project
4756
function _is_qt_project(package)
48-
-- method 1: check Qt rules
49-
local rules = target:rules()
50-
if rules then
51-
for _, rule in ipairs(rules) do
52-
local rule_name = rule:name()
53-
if rule_name and (rule_name:find("qt", 1, true) or
54-
rule_name:find("qt6", 1, true) or
55-
rule_name:find("qt5", 1, true)) then
57+
-- Method 1: Check for Qt libraries in links
58+
local links = package:get("links")
59+
if links then
60+
for _, link in ipairs(links) do
61+
if link:lower():find("qt") then
5662
return true
5763
end
5864
end
5965
end
6066

61-
-- method 2: check target's Qt data
62-
local qt_data = target:data("qt")
63-
if qt_data then
64-
return true
65-
end
66-
67-
-- method 3: check Qt environment variables
68-
local qt_env = os.getenv("QTDIR") or os.getenv("QT_DIR") or os.getenv("Qt6_DIR") or os.getenv("Qt5_DIR")
69-
if qt_env then
70-
return true
71-
end
72-
print("Not a Qt project")
73-
return false
74-
end
75-
76-
-- detect if this is a Qt project
77-
function _is_qt_project(package)
7867
-- Method 2: Check executable for Qt dependencies using otool
7968
local app_source, _ = _find_app_bundle(package)
8069
if app_source then
@@ -83,15 +72,13 @@ function _is_qt_project(package)
8372
local executables = os.files(path.join(macos_dir, "*"))
8473
for _, executable in ipairs(executables) do
8574
if os.isfile(executable) then
86-
print("Checking executable for Qt dependencies:", executable)
8775
local otool_output = os.iorunv("otool", {"-L", executable})
8876
if otool_output then
8977
-- Check for Qt frameworks in otool output
9078
if otool_output:lower():find("qt") or
9179
otool_output:find("QtCore") or
9280
otool_output:find("QtGui") or
9381
otool_output:find("QtWidgets") then
94-
print("Qt project detected via otool analysis")
9582
return true
9683
end
9784
end
@@ -111,14 +98,12 @@ function _is_qt_project(package)
11198
content:find("QApplication") or
11299
content:find("QWidget") or
113100
content:find("QMainWindow")) then
114-
print("Qt project detected via source file analysis:", srcfile)
115101
return true
116102
end
117103
end
118104
end
119105
end
120106

121-
print("No Qt dependencies detected")
122107
return false
123108
end
124109

@@ -128,7 +113,6 @@ function _check_qml_usage(package, app_source)
128113
if links then
129114
for _, link in ipairs(links) do
130115
if link:lower():find("qml") or link:lower():find("quick") then
131-
print("QML usage detected via link:", link)
132116
return true
133117
end
134118
end
@@ -143,7 +127,6 @@ function _check_qml_usage(package, app_source)
143127
local otool_output = os.iorunv("otool", {"-L", executable})
144128
if otool_output then
145129
if otool_output:find("QtQml") or otool_output:find("QtQuick") then
146-
print("QML usage detected via otool analysis")
147130
return true
148131
end
149132
end
@@ -154,7 +137,6 @@ function _check_qml_usage(package, app_source)
154137
-- Method 3: Check for .qml files in project
155138
local qml_files = os.files("**.qml")
156139
if qml_files and #qml_files > 0 then
157-
print("QML usage detected via .qml files:", #qml_files, "files found")
158140
return true
159141
end
160142

@@ -168,7 +150,6 @@ function _check_qml_usage(package, app_source)
168150
content:find("#include.*QQuick") or
169151
content:find("QQmlEngine") or
170152
content:find("QQuickView")) then
171-
print("QML usage detected via source file analysis:", srcfile)
172153
return true
173154
end
174155
end
@@ -178,6 +159,41 @@ function _check_qml_usage(package, app_source)
178159
return false
179160
end
180161

162+
function _find_valid_qml_dir(qt)
163+
local possible_qml_dirs = {}
164+
165+
-- Standard QML directory locations
166+
if qt.sdkdir then
167+
table.insert(possible_qml_dirs, path.join(qt.sdkdir, "qml"))
168+
table.insert(possible_qml_dirs, path.join(qt.sdkdir, "lib", "qml"))
169+
table.insert(possible_qml_dirs, path.join(qt.sdkdir, "share", "qt6", "qml"))
170+
end
171+
172+
-- Qt-specific qmldir if available
173+
if qt.qmldir then
174+
table.insert(possible_qml_dirs, qt.qmldir)
175+
end
176+
177+
-- Project-specific QML directories
178+
table.insert(possible_qml_dirs, "qml")
179+
table.insert(possible_qml_dirs, "src/qml")
180+
table.insert(possible_qml_dirs, "resources/qml")
181+
182+
for _, qml_dir in ipairs(possible_qml_dirs) do
183+
if os.isdir(qml_dir) then
184+
return qml_dir
185+
end
186+
end
187+
188+
-- If no existing QML directory found, create a temporary empty one
189+
local temp_qml_dir = path.join(os.tmpdir(), "empty_qml")
190+
if not os.isdir(temp_qml_dir) then
191+
os.mkdir(temp_qml_dir)
192+
end
193+
194+
return temp_qml_dir
195+
end
196+
181197
-- deploy Qt dependencies using macdeployqt
182198
function _deploy_qt_dependencies(package, app_source, macdeployqt)
183199

@@ -517,8 +533,7 @@ end
517533
function _pack_dmg(package)
518534
local is_qt = _is_qt_project(package)
519535
-- find required tools
520-
local create_dmg = assert(_get_create_dmg(), "create-dmg not found")
521-
536+
local create_dmg = _get_create_dmg()
522537
-- find existing .app bundle
523538
local app_source, appbundle_name = _find_app_bundle(package)
524539
if not app_source then
@@ -528,11 +543,16 @@ function _pack_dmg(package)
528543
-- handle Qt dependencies if this is a Qt project
529544
if is_qt then
530545
local macdeployqt = _get_macdeployqt()
531-
local qt_success = _deploy_qt_dependencies(package, app_source, macdeployqt)
532-
print("Qt dependencies deployment:", qt_success and "success" or "failed")
546+
if macdeployqt then
547+
local qt_success = _deploy_qt_dependencies(package, app_source, macdeployqt)
548+
else
549+
print("Warning: macdeployqt not available, Qt dependencies may not be properly bundled")
550+
end
533551
end
534-
-- find background image
552+
553+
-- find background image (optional)
535554
local bg_image = _find_background_image(package)
555+
536556
-- get output dmg path
537557
local dmg_file = package:outputfile() or _get_dmg_file(package)
538558
dmg_file = dmg_file:gsub("%.dmg+$", ".dmg") -- clean up extension
@@ -541,12 +561,15 @@ function _pack_dmg(package)
541561
if not staging_dir then
542562
return false
543563
end
564+
544565
-- create dmg
545566
local success = _create_dmg_with_create_dmg(create_dmg, package, staging_dir, dmg_file, appbundle_name, bg_image)
567+
546568
if success then
547569
-- verify the result
548570
success = _verify_dmg(dmg_file)
549571
end
572+
550573
-- cleanup staging directory
551574
os.tryrm(staging_dir)
552575
return success
@@ -556,16 +579,13 @@ end
556579
function main(package)
557580
-- only for macOS
558581
if not is_host("macosx") then
582+
print("DMG packaging is only supported on macOS")
559583
return
560584
end
561585

562586
local dmg_file = package:outputfile() or _get_dmg_file(package)
563587
dmg_file = dmg_file:gsub("%.dmg+$", ".dmg")
564588

565589
cprint("packing %s", dmg_file)
566-
567-
local success = _pack_dmg(package)
568-
if success then
569-
print("Final DMG file:", dmg_file)
570-
end
590+
_pack_dmg(package)
571591
end

0 commit comments

Comments
 (0)