@@ -29,52 +29,41 @@ import("detect.sdks.find_qt")
29
29
30
30
-- get the create-dmg tool
31
31
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!" )
37
33
end
38
34
39
35
-- get macdeployqt tool for Qt applications
40
36
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
43
52
return macdeployqt
44
53
end
45
54
46
55
-- detect if this is a Qt project
47
56
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
56
62
return true
57
63
end
58
64
end
59
65
end
60
66
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 )
78
67
-- Method 2: Check executable for Qt dependencies using otool
79
68
local app_source , _ = _find_app_bundle (package )
80
69
if app_source then
@@ -83,15 +72,13 @@ function _is_qt_project(package)
83
72
local executables = os .files (path .join (macos_dir , " *" ))
84
73
for _ , executable in ipairs (executables ) do
85
74
if os .isfile (executable ) then
86
- print (" Checking executable for Qt dependencies:" , executable )
87
75
local otool_output = os .iorunv (" otool" , {" -L" , executable })
88
76
if otool_output then
89
77
-- Check for Qt frameworks in otool output
90
78
if otool_output :lower ():find (" qt" ) or
91
79
otool_output :find (" QtCore" ) or
92
80
otool_output :find (" QtGui" ) or
93
81
otool_output :find (" QtWidgets" ) then
94
- print (" Qt project detected via otool analysis" )
95
82
return true
96
83
end
97
84
end
@@ -111,14 +98,12 @@ function _is_qt_project(package)
111
98
content :find (" QApplication" ) or
112
99
content :find (" QWidget" ) or
113
100
content :find (" QMainWindow" )) then
114
- print (" Qt project detected via source file analysis:" , srcfile )
115
101
return true
116
102
end
117
103
end
118
104
end
119
105
end
120
106
121
- print (" No Qt dependencies detected" )
122
107
return false
123
108
end
124
109
@@ -128,7 +113,6 @@ function _check_qml_usage(package, app_source)
128
113
if links then
129
114
for _ , link in ipairs (links ) do
130
115
if link :lower ():find (" qml" ) or link :lower ():find (" quick" ) then
131
- print (" QML usage detected via link:" , link )
132
116
return true
133
117
end
134
118
end
@@ -143,7 +127,6 @@ function _check_qml_usage(package, app_source)
143
127
local otool_output = os .iorunv (" otool" , {" -L" , executable })
144
128
if otool_output then
145
129
if otool_output :find (" QtQml" ) or otool_output :find (" QtQuick" ) then
146
- print (" QML usage detected via otool analysis" )
147
130
return true
148
131
end
149
132
end
@@ -154,7 +137,6 @@ function _check_qml_usage(package, app_source)
154
137
-- Method 3: Check for .qml files in project
155
138
local qml_files = os .files (" **.qml" )
156
139
if qml_files and # qml_files > 0 then
157
- print (" QML usage detected via .qml files:" , # qml_files , " files found" )
158
140
return true
159
141
end
160
142
@@ -168,7 +150,6 @@ function _check_qml_usage(package, app_source)
168
150
content :find (" #include.*QQuick" ) or
169
151
content :find (" QQmlEngine" ) or
170
152
content :find (" QQuickView" )) then
171
- print (" QML usage detected via source file analysis:" , srcfile )
172
153
return true
173
154
end
174
155
end
@@ -178,6 +159,41 @@ function _check_qml_usage(package, app_source)
178
159
return false
179
160
end
180
161
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
+
181
197
-- deploy Qt dependencies using macdeployqt
182
198
function _deploy_qt_dependencies (package , app_source , macdeployqt )
183
199
517
533
function _pack_dmg (package )
518
534
local is_qt = _is_qt_project (package )
519
535
-- find required tools
520
- local create_dmg = assert (_get_create_dmg (), " create-dmg not found" )
521
-
536
+ local create_dmg = _get_create_dmg ()
522
537
-- find existing .app bundle
523
538
local app_source , appbundle_name = _find_app_bundle (package )
524
539
if not app_source then
@@ -528,11 +543,16 @@ function _pack_dmg(package)
528
543
-- handle Qt dependencies if this is a Qt project
529
544
if is_qt then
530
545
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
533
551
end
534
- -- find background image
552
+
553
+ -- find background image (optional)
535
554
local bg_image = _find_background_image (package )
555
+
536
556
-- get output dmg path
537
557
local dmg_file = package :outputfile () or _get_dmg_file (package )
538
558
dmg_file = dmg_file :gsub (" %.dmg+$" , " .dmg" ) -- clean up extension
@@ -541,12 +561,15 @@ function _pack_dmg(package)
541
561
if not staging_dir then
542
562
return false
543
563
end
564
+
544
565
-- create dmg
545
566
local success = _create_dmg_with_create_dmg (create_dmg , package , staging_dir , dmg_file , appbundle_name , bg_image )
567
+
546
568
if success then
547
569
-- verify the result
548
570
success = _verify_dmg (dmg_file )
549
571
end
572
+
550
573
-- cleanup staging directory
551
574
os .tryrm (staging_dir )
552
575
return success
@@ -556,16 +579,13 @@ end
556
579
function main (package )
557
580
-- only for macOS
558
581
if not is_host (" macosx" ) then
582
+ print (" DMG packaging is only supported on macOS" )
559
583
return
560
584
end
561
585
562
586
local dmg_file = package :outputfile () or _get_dmg_file (package )
563
587
dmg_file = dmg_file :gsub (" %.dmg+$" , " .dmg" )
564
588
565
589
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 )
571
591
end
0 commit comments