|
16 | 16 | #![allow(clippy::too_many_arguments)]
|
17 | 17 |
|
18 | 18 | mod builder;
|
19 |
| -pub use builder::{QResource, QResourceBuilder, QResourceFile, QmlDirBuilder, QmlUriBuilder}; |
| 19 | +pub use builder::{ |
| 20 | + QResource, QResourceBuilder, QResourceFile, QmlDirBuilder, QmlPluginCppBuilder, QmlUriBuilder, |
| 21 | +}; |
20 | 22 |
|
21 | 23 | mod error;
|
22 | 24 | pub use error::QtBuildError;
|
@@ -172,7 +174,7 @@ impl QtBuild {
|
172 | 174 | // Generate qmldir file
|
173 | 175 | let qmldir_file_path = qml_module_dir.join("qmldir");
|
174 | 176 | {
|
175 |
| - let qmldir = QmlDirBuilder::new(qml_uri) |
| 177 | + let qmldir = QmlDirBuilder::new(qml_uri.clone()) |
176 | 178 | .with_plugin(plugin_name.to_string(), true)
|
177 | 179 | .with_class_name(plugin_class_name.clone())
|
178 | 180 | .with_type_info(plugin_type_info.to_string())
|
@@ -272,58 +274,11 @@ impl QtBuild {
|
272 | 274 | let qml_plugin_cpp_path = qml_plugin_dir.join(format!("{plugin_class_name}.cpp"));
|
273 | 275 | let include_path;
|
274 | 276 | {
|
275 |
| - let mut declarations = Vec::default(); |
276 |
| - let mut usages = Vec::default(); |
277 |
| - |
278 |
| - let mut generate_usage = |return_type: &str, function_name: &str| { |
279 |
| - declarations.push(format!("extern {return_type} {function_name}();")); |
280 |
| - usages.push(format!("volatile auto {function_name}_usage = &{function_name};\nQ_UNUSED({function_name}_usage);")); |
281 |
| - }; |
282 |
| - |
283 |
| - // This function is generated by qmltyperegistrar |
284 |
| - generate_usage("void", &format!("qml_register_types_{qml_uri_underscores}")); |
285 |
| - generate_usage( |
286 |
| - "int", |
287 |
| - &format!("qInitResources_qml_module_resources_{qml_uri_underscores}_qrc"), |
288 |
| - ); |
289 |
| - |
290 |
| - if !qml_files.is_empty() && !qmlcachegen_file_paths.is_empty() { |
291 |
| - generate_usage( |
292 |
| - "int", |
293 |
| - &format!("qInitResources_qmlcache_{qml_uri_underscores}"), |
294 |
| - ); |
295 |
| - } |
296 |
| - let declarations = declarations.join("\n"); |
297 |
| - let usages = usages.join("\n"); |
298 |
| - |
299 |
| - std::fs::write( |
300 |
| - &qml_plugin_cpp_path, |
301 |
| - format!( |
302 |
| - r#" |
303 |
| -#include <QtQml/qqmlextensionplugin.h> |
304 |
| -
|
305 |
| -// TODO: Add missing handling for GHS (Green Hills Software compiler) that is in |
306 |
| -// https://code.qt.io/cgit/qt/qtbase.git/plain/src/corelib/global/qtsymbolmacros.h |
307 |
| -{declarations} |
308 |
| -
|
309 |
| -class {plugin_class_name} : public QQmlEngineExtensionPlugin |
310 |
| -{{ |
311 |
| - Q_OBJECT |
312 |
| - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlEngineExtensionInterface") |
313 |
| -
|
314 |
| -public: |
315 |
| - {plugin_class_name}(QObject *parent = nullptr) : QQmlEngineExtensionPlugin(parent) |
316 |
| - {{ |
317 |
| - {usages} |
318 |
| - }} |
319 |
| -}}; |
320 |
| -
|
321 |
| -// The moc-generated cpp file doesn't compile on its own; it needs to be #included here. |
322 |
| -#include "moc_{plugin_class_name}.cpp.cpp" |
323 |
| -"#, |
324 |
| - ), |
325 |
| - ) |
326 |
| - .expect("Failed to write plugin definition"); |
| 277 | + let qml_plugin_cpp = QmlPluginCppBuilder::new(qml_uri, plugin_class_name.clone()) |
| 278 | + .with_qml_cache(!qml_files.is_empty() && !qmlcachegen_file_paths.is_empty()) |
| 279 | + .build(); |
| 280 | + std::fs::write(&qml_plugin_cpp_path, qml_plugin_cpp) |
| 281 | + .expect("Failed to write plugin definition"); |
327 | 282 |
|
328 | 283 | let moc_product = self.moc().compile(
|
329 | 284 | &qml_plugin_cpp_path,
|
|
0 commit comments