Skip to content

Commit 146bebd

Browse files
committed
return qt qml detect
1 parent f650879 commit 146bebd

File tree

1 file changed

+103
-49
lines changed

1 file changed

+103
-49
lines changed

xmake/plugins/pack/dmg/main.lua

Lines changed: 103 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ end
4545
-- detect if this is a Qt project
4646
function _is_qt_project(package)
4747
-- method 1: check Qt rules
48-
local rules = package:rules()
48+
local rules = target:rules()
4949
if rules then
5050
for _, rule in ipairs(rules) do
5151
local rule_name = rule:name()
@@ -58,7 +58,7 @@ function _is_qt_project(package)
5858
end
5959

6060
-- method 2: check target's Qt data
61-
local qt_data = package:data("qt")
61+
local qt_data = target:data("qt")
6262
if qt_data then
6363
return true
6464
end
@@ -72,66 +72,120 @@ function _is_qt_project(package)
7272
return false
7373
end
7474

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
75+
-- detect if this is a Qt project
76+
function _is_qt_project(package)
77+
-- Method 1: Check for Qt libraries in links
78+
local links = package:get("links")
79+
if links then
80+
for _, link in ipairs(links) do
81+
if link:lower():find("qt") then
82+
print("Qt project detected via link:", link)
8283
return true
8384
end
8485
end
8586
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
87+
88+
-- Method 2: Check executable for Qt dependencies using otool
89+
local app_source, _ = _find_app_bundle(package)
90+
if app_source then
91+
local macos_dir = path.join(app_source, "Contents", "MacOS")
92+
if os.isdir(macos_dir) then
93+
local executables = os.files(path.join(macos_dir, "*"))
94+
for _, executable in ipairs(executables) do
95+
if os.isfile(executable) then
96+
print("Checking executable for Qt dependencies:", executable)
97+
local otool_output = os.iorunv("otool", {"-L", executable})
98+
if otool_output then
99+
-- Check for Qt frameworks in otool output
100+
if otool_output:lower():find("qt") or
101+
otool_output:find("QtCore") or
102+
otool_output:find("QtGui") or
103+
otool_output:find("QtWidgets") then
104+
print("Qt project detected via otool analysis")
105+
return true
106+
end
107+
end
108+
end
109+
end
110+
end
91111
end
92-
93-
-- method 3: check for .qml files
94-
local qml_files = os.files("**.qml")
95-
if qml_files and #qml_files > 0 then
96-
return true
112+
113+
-- Method 3: Check source files for Qt headers/includes
114+
local srcfiles, _ = package:sourcefiles()
115+
for _, srcfile in ipairs(srcfiles or {}) do
116+
if srcfile:endswith(".cpp") or srcfile:endswith(".cc") or srcfile:endswith(".cxx") or srcfile:endswith(".mm") then
117+
if os.isfile(srcfile) then
118+
local content = io.readfile(srcfile)
119+
if content and (content:find("#include.*[Qq][Tt]") or
120+
content:find("#include.*<Q") or
121+
content:find("QApplication") or
122+
content:find("QWidget") or
123+
content:find("QMainWindow")) then
124+
print("Qt project detected via source file analysis:", srcfile)
125+
return true
126+
end
127+
end
128+
end
97129
end
98-
print("No QML usage detected")
130+
131+
print("No Qt dependencies detected")
99132
return false
100133
end
101134

102-
function _find_valid_qml_dir(qt)
103-
local possible_qml_dirs = {}
104-
105-
-- Standard QML directory locations
106-
if qt.sdkdir then
107-
table.insert(possible_qml_dirs, path.join(qt.sdkdir, "qml"))
108-
table.insert(possible_qml_dirs, path.join(qt.sdkdir, "lib", "qml"))
109-
table.insert(possible_qml_dirs, path.join(qt.sdkdir, "share", "qt6", "qml"))
110-
end
111-
112-
-- Qt-specific qmldir if available
113-
if qt.qmldir then
114-
table.insert(possible_qml_dirs, qt.qmldir)
135+
function _check_qml_usage(package, app_source)
136+
-- Method 1: Check for QML-related libraries in links
137+
local links = package:get("links")
138+
if links then
139+
for _, link in ipairs(links) do
140+
if link:lower():find("qml") or link:lower():find("quick") then
141+
print("QML usage detected via link:", link)
142+
return true
143+
end
144+
end
115145
end
116-
117-
-- Project-specific QML directories
118-
table.insert(possible_qml_dirs, "qml")
119-
table.insert(possible_qml_dirs, "src/qml")
120-
table.insert(possible_qml_dirs, "resources/qml")
121-
122-
for _, qml_dir in ipairs(possible_qml_dirs) do
123-
if os.isdir(qml_dir) then
124-
return qml_dir
146+
147+
-- Method 2: Check executable for QML/Quick dependencies
148+
local macos_dir = path.join(app_source, "Contents", "MacOS")
149+
if os.isdir(macos_dir) then
150+
local executables = os.files(path.join(macos_dir, "*"))
151+
for _, executable in ipairs(executables) do
152+
if os.isfile(executable) then
153+
local otool_output = os.iorunv("otool", {"-L", executable})
154+
if otool_output then
155+
if otool_output:find("QtQml") or otool_output:find("QtQuick") then
156+
print("QML usage detected via otool analysis")
157+
return true
158+
end
159+
end
160+
end
125161
end
126162
end
127-
128-
-- If no existing QML directory found, create a temporary empty one
129-
local temp_qml_dir = path.join(os.tmpdir(), "empty_qml")
130-
if not os.isdir(temp_qml_dir) then
131-
os.mkdir(temp_qml_dir)
163+
164+
-- Method 3: Check for .qml files in project
165+
local qml_files = os.files("**.qml")
166+
if qml_files and #qml_files > 0 then
167+
print("QML usage detected via .qml files:", #qml_files, "files found")
168+
return true
132169
end
133-
134-
return temp_qml_dir
170+
171+
-- Method 4: Check source files for QML-related includes
172+
local srcfiles, _ = package:sourcefiles()
173+
for _, srcfile in ipairs(srcfiles or {}) do
174+
if srcfile:endswith(".cpp") or srcfile:endswith(".cc") or srcfile:endswith(".cxx") or srcfile:endswith(".mm") then
175+
if os.isfile(srcfile) then
176+
local content = io.readfile(srcfile)
177+
if content and (content:find("#include.*QQml") or
178+
content:find("#include.*QQuick") or
179+
content:find("QQmlEngine") or
180+
content:find("QQuickView")) then
181+
print("QML usage detected via source file analysis:", srcfile)
182+
return true
183+
end
184+
end
185+
end
186+
end
187+
188+
return false
135189
end
136190

137191
-- deploy Qt dependencies using macdeployqt

0 commit comments

Comments
 (0)