From 9d577aad9804bb8ebb18d30d1c08bcdefe2d70d7 Mon Sep 17 00:00:00 2001 From: Be Wilson Date: Fri, 15 Jul 2022 18:16:15 -0500 Subject: [PATCH 1/4] cxx-qt-build: decouple code generation from file writing also cleanup ambiguous usage of str/String with Path/PathBuf The locations of generated files have been changed for consistency and simplifying the code. Previously, C++ code generated by cxx was put in files named based on the Rust file name and the C++ header file was confusingly put in the src directory. This has been changed so all files use the snake_cased version of the cxx module name, with the files generated by cxx having a _cxx suffix. Both cxx's and cxx-qt's generated headers are now in the include directory. --- cxx-qt-build/src/lib.rs | 246 +++++++++--------- cxx-qt-gen/src/gen_cpp.rs | 2 +- cxx-qt-gen/test_outputs/handlers.cpp | 2 +- cxx-qt-gen/test_outputs/invokables.cpp | 2 +- cxx-qt-gen/test_outputs/naming.cpp | 2 +- cxx-qt-gen/test_outputs/properties.cpp | 2 +- cxx-qt-gen/test_outputs/signals.cpp | 2 +- .../test_outputs/types_primitive_property.cpp | 2 +- .../test_outputs/types_qt_invokable.cpp | 2 +- cxx-qt-gen/test_outputs/types_qt_property.cpp | 2 +- tests/basic_cxx_only/src/main.cpp | 2 +- tests/qt_types_standalone/include/bridge.h | 2 +- tests/qt_types_standalone/src/main.cpp | 2 +- 13 files changed, 139 insertions(+), 131 deletions(-) diff --git a/cxx-qt-build/src/lib.rs b/cxx-qt-build/src/lib.rs index ef71a4665..95b9929c5 100644 --- a/cxx-qt-build/src/lib.rs +++ b/cxx-qt-build/src/lib.rs @@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize}; use std::env; use std::fs::File; use std::io::Write; +use std::path::PathBuf; use syn::*; use clang_format::ClangFormatStyle; @@ -93,7 +94,7 @@ fn manifest_dir() -> String { } /// Extract the cxx or cxx_qt module from a Rust file -fn extract_modules(file_content: &str, rs_path: &str) -> ExtractedModule { +fn extract_modules(file_content: &str, rs_path: &impl AsRef) -> ExtractedModule { let file = syn::parse_file(file_content).unwrap(); // Define a helper function that will ensure that we can extract at most one @@ -105,7 +106,7 @@ fn extract_modules(file_content: &str, rs_path: &str) -> ExtractedModule { panic!( "Unfortunately only files with either a single cxx or a single cxx_qt module are currently supported. The file {} has more than one of these.", - rs_path); + rs_path.as_ref().display()); } if qt { @@ -143,139 +144,146 @@ fn extract_modules(file_content: &str, rs_path: &str) -> ExtractedModule { extracted } -/// Write the generated cpp and h files for a qobject out to files -fn write_qobject_cpp_files(obj: CppObject, snake_name: &str) -> Vec { - let manifest_dir = manifest_dir(); - - let h_path = format!( - "{}/target/cxx-qt-gen/include/{}.h", - manifest_dir, snake_name - ); - let cpp_path = format!("{}/target/cxx-qt-gen/src/{}.cpp", manifest_dir, snake_name); - - let mut file = File::create(&h_path).expect("Could not create .h file"); - write!(file, "{}", obj.header).expect("Failed to write .h file"); - - let mut file = File::create(&cpp_path).expect("Could not create .cpp file"); - write!(file, "{}", obj.source).expect("Failed to write .cpp file"); - - vec![h_path, cpp_path] +pub struct GeneratedCpp { + cxx_qt: Option, + cxx: cxx_gen::GeneratedCode, + module_ident: String, } -/// Generate C++ files from a given Rust file, returning the generated paths -fn gen_cxx_for_file(rs_path: &str) -> Vec { - let manifest_dir = manifest_dir(); - let mut generated_cpp_paths = Vec::new(); - - // TODO: in the future use the module path as the file path - // so that src/moda/lib.rs with mod modb { cxx_qt::bridge(MyObject) } becomes src/moda/modb/my_object - // this then avoids collisions later. - // - // This will require detecting nested modules in a file - - let path = format!("{}/{}", manifest_dir, rs_path); - println!("cargo:rerun-if-changed={}", path); - let content = std::fs::read_to_string(path).expect("Could not read Rust file"); - let extracted = extract_modules(&content, rs_path); - - let h_path; - let cpp_path; - - // TODO: for now we use a fixed namespace, later this will come from the macro definition - let cpp_namespace_prefix: Vec<&'static str> = vec!["cxx_qt"]; - - let tokens = { - match extracted { - ExtractedModule::Cxx(m) => { - // Extract just the file name of the rs_path as we don't want to include sub folders - // - // TODO: later this won't be required when we are tracking the module path - let rs_file_name = { - if let Some(os_file_name) = std::path::Path::new(rs_path).file_name() { - if let Some(file_name) = os_file_name.to_str() { - file_name - } else { - panic!( - "Could not convert OsStr to str for rust source path: {}", - rs_path - ); - } - } else { - panic!("No file name found in rust source path: {}", rs_path) - } - }; - h_path = format!( - "{}/target/cxx-qt-gen/include/{}.h", - manifest_dir, rs_file_name - ); - cpp_path = format!( - "{}/target/cxx-qt-gen/src/{}.cpp", - manifest_dir, rs_file_name - ); - - m.into_token_stream() +impl GeneratedCpp { + /// Generate QObject and cxx header/source C++ file contents + pub fn new(rust_file_path: &impl AsRef) -> Self { + let content = std::fs::read_to_string(rust_file_path).expect("Could not read Rust file"); + let extracted = extract_modules(&content, rust_file_path); + + // TODO: for now we use a fixed namespace, later this will come from the macro definition + let cpp_namespace_prefix: Vec<&'static str> = vec!["cxx_qt"]; + + let cxx_qt; + let module_ident; + let tokens = { + match extracted { + ExtractedModule::Cxx(m) => { + module_ident = m.ident.to_string().to_case(Case::Snake); + cxx_qt = None; + m.into_token_stream() + } + ExtractedModule::CxxQt(m) => { + module_ident = m.ident.to_string().to_case(Case::Snake); + + let qobject = extract_qobject(m, &cpp_namespace_prefix).unwrap(); + cxx_qt = Some(generate_qobject_cpp(&qobject).unwrap()); + + generate_qobject_cxx(&qobject, &cpp_namespace_prefix).unwrap() + } + _others => panic!( + "No module to generate cxx code from could be found in {}", + rust_file_path.as_ref().display() + ), } - ExtractedModule::CxxQt(m) => { - let qobject = extract_qobject(m, &cpp_namespace_prefix).unwrap(); - let cpp_object = generate_qobject_cpp(&qobject).unwrap(); - let snake_name = qobject.ident.to_string().to_case(Case::Snake); - - h_path = format!("{}/target/cxx-qt-gen/src/{}.rs.h", manifest_dir, snake_name); - cpp_path = format!( - "{}/target/cxx-qt-gen/src/{}.rs.cpp", - manifest_dir, snake_name - ); - - generated_cpp_paths.append(&mut write_qobject_cpp_files(cpp_object, &snake_name)); - generate_qobject_cxx(&qobject, &cpp_namespace_prefix).unwrap() - } - _others => panic!( - "No module to generate cxx code from could be found in {}", - rs_path - ), + }; + + let opt = cxx_gen::Opt::default(); + let cxx = cxx_gen::generate_header_and_cc(tokens, &opt) + .expect("Could not generate C++ from Rust file"); + + GeneratedCpp { + cxx_qt, + cxx, + module_ident, } - }; + } - let opt = cxx_gen::Opt::default(); - let gen_result = cxx_gen::generate_header_and_cc(tokens, &opt) - .expect("Could not generate C++ from Rust file"); + /// Write generated code to files in a directory. Returns the absolute paths of all files written. + pub fn write_to_directory(&self, directory: &impl AsRef) -> Vec { + let directory = directory.as_ref(); + if !directory.is_dir() { + panic!( + "Output directory {} is not a directory", + directory.display() + ); + } - let mut header = File::create(&h_path).expect("Could not create header file"); - header - .write_all(&gen_result.header) - .expect("Could not write header file"); + let include_directory_path = PathBuf::from(format!("{}/include", &directory.display())); + std::fs::create_dir_all(&include_directory_path) + .expect("Could not create cxx-qt include dir"); + + let source_directory_path = PathBuf::from(format!("{}/src", &directory.display())); + std::fs::create_dir_all(&source_directory_path) + .expect("Could not create cxx-qt source dir"); + + let mut written_files = Vec::with_capacity(4); + + if let Some(cxx_qt_generated) = &self.cxx_qt { + let header_path = PathBuf::from(format!( + "{}/{}.h", + include_directory_path.display(), + self.module_ident + )); + let mut header = + File::create(&header_path).expect("Could not create cxx-qt header file"); + header + .write_all(cxx_qt_generated.header.as_bytes()) + .expect("Could not write cxx-qt header file"); + written_files.push(header_path); + + let cpp_path = PathBuf::from(format!( + "{}/{}.cpp", + source_directory_path.display(), + &self.module_ident + )); + let mut cpp = File::create(&cpp_path).expect("Could not create cxx-qt source file"); + cpp.write_all(cxx_qt_generated.source.as_bytes()) + .expect("Could not write cxx-qt source file"); + written_files.push(cpp_path); + } - let mut cpp = File::create(&cpp_path).expect("Could not create cpp file"); - cpp.write_all(&gen_result.implementation) - .expect("Could not write cpp file"); + let header_path = PathBuf::from(format!( + "{}/{}.cxx.h", + include_directory_path.display(), + self.module_ident + )); + let mut header = File::create(&header_path).expect("Could not create cxx header file"); + header + .write_all(&self.cxx.header) + .expect("Could not write cxx header file"); + written_files.push(header_path); + + let cpp_path = PathBuf::from(format!( + "{}/{}.cxx.cpp", + source_directory_path.display(), + self.module_ident + )); + let mut cpp = File::create(&cpp_path).expect("Could not create cxx source file"); + cpp.write_all(&self.cxx.implementation) + .expect("Could not write cxx source file"); + written_files.push(cpp_path); - // TODO: find a "nice" way to write this - generated_cpp_paths.push(h_path); - generated_cpp_paths.push(cpp_path); - generated_cpp_paths + written_files + } } /// Generate C++ files from a given list of Rust files, returning the generated paths -fn gen_cxx_for_files(rs_source: &[&'static str]) -> Vec { +fn write_cxx_generated_files_for_cargo(rs_source: &[&'static str]) -> Vec { let manifest_dir = manifest_dir(); - - let path = format!("{}/target/cxx-qt-gen/include", manifest_dir); - std::fs::create_dir_all(path).expect("Could not create cxx-qt include dir"); - - let path = format!("{}/target/cxx-qt-gen/src", manifest_dir); - std::fs::create_dir_all(path).expect("Could not create cxx-qt src dir"); + let directory = format!("{}/target/cxx-qt-gen", manifest_dir); + std::fs::create_dir_all(&directory).expect("Could not create cxx-qt code generation directory"); let mut cpp_files = Vec::new(); for rs_path in rs_source { - cpp_files.append(&mut gen_cxx_for_file(rs_path)); + let path = format!("{}/{}", manifest_dir, rs_path); + println!("cargo:rerun-if-changed={}", path); + + let generated_code = GeneratedCpp::new(&path); + cpp_files.append(&mut generated_code.write_to_directory(&directory)); } cpp_files } /// Write the list of C++ paths to the file -fn write_cpp_sources_list(paths: &[String]) { +fn write_cpp_sources_list(paths: &[PathBuf]) { let manifest_dir = manifest_dir(); let path = format!("{}/target/cxx-qt-gen", manifest_dir); @@ -285,7 +293,7 @@ fn write_cpp_sources_list(paths: &[String]) { let mut file = File::create(&path).expect("Could not create cpp_sources file"); for path in paths { - writeln!(file, "{}", path).unwrap(); + writeln!(file, "{}", path.display()).unwrap(); } } @@ -295,10 +303,10 @@ fn write_cxx_qt_lib_set( target_dir: &str, header: &str, source: &str, -) -> Vec { +) -> Vec { let mut paths = vec![]; - let path_h = format!("{}/include/{}.h", target_dir, file_name); - let path_cpp = format!("{}/src/{}.cpp", target_dir, file_name); + let path_h = PathBuf::from(format!("{}/include/{}.h", target_dir, file_name)); + let path_cpp = PathBuf::from(format!("{}/src/{}.cpp", target_dir, file_name)); let mut file = std::fs::File::create(&path_h).expect("Could not create header file"); file.write_all(header.as_bytes()) @@ -314,7 +322,7 @@ fn write_cxx_qt_lib_set( } /// Find all the cxx-qt-lib sources and write them to the target directory -fn write_cxx_qt_lib_sources() -> Vec { +fn write_cxx_qt_lib_sources() -> Vec { let cxx_qt_lib_target_dir = format!("{}/target/cxx-qt-lib", manifest_dir()); let cxx_qt_lib_include_dir = format!("{}/include", cxx_qt_lib_target_dir); let cxx_qt_lib_src_dir = format!("{}/src", cxx_qt_lib_target_dir); @@ -409,7 +417,7 @@ impl CxxQtBuilder { // TODO: later use the module::object to turn into module/object.h // Generate files - let mut cpp_paths = gen_cxx_for_files(&self.rust_sources); + let mut cpp_paths = write_cxx_generated_files_for_cargo(&self.rust_sources); // TODO: in large projects where where CXX-Qt is used in multiple individual // components that end up being linked together, having these same static diff --git a/cxx-qt-gen/src/gen_cpp.rs b/cxx-qt-gen/src/gen_cpp.rs index 9810f627e..27854561f 100644 --- a/cxx-qt-gen/src/gen_cpp.rs +++ b/cxx-qt-gen/src/gen_cpp.rs @@ -1039,7 +1039,7 @@ pub fn generate_qobject_cpp(obj: &QObject) -> Result { // Generate C++ source part let source = formatdoc! {r#" #include "cxx-qt-gen/include/{ident_snake}.h" - #include "cxx-qt-gen/src/{ident_snake}.rs.h" + #include "cxx-qt-gen/include/{ident_snake}.cxx.h" namespace {namespace} {{ diff --git a/cxx-qt-gen/test_outputs/handlers.cpp b/cxx-qt-gen/test_outputs/handlers.cpp index 7ce6a6e05..7f1ec5be4 100644 --- a/cxx-qt-gen/test_outputs/handlers.cpp +++ b/cxx-qt-gen/test_outputs/handlers.cpp @@ -1,5 +1,5 @@ #include "cxx-qt-gen/include/my_object.h" -#include "cxx-qt-gen/src/my_object.rs.h" +#include "cxx-qt-gen/include/my_object.cxx.h" namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/invokables.cpp b/cxx-qt-gen/test_outputs/invokables.cpp index 60fa83dd5..032908385 100644 --- a/cxx-qt-gen/test_outputs/invokables.cpp +++ b/cxx-qt-gen/test_outputs/invokables.cpp @@ -1,5 +1,5 @@ #include "cxx-qt-gen/include/my_object.h" -#include "cxx-qt-gen/src/my_object.rs.h" +#include "cxx-qt-gen/include/my_object.cxx.h" namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/naming.cpp b/cxx-qt-gen/test_outputs/naming.cpp index fa02d1554..bb068bb65 100644 --- a/cxx-qt-gen/test_outputs/naming.cpp +++ b/cxx-qt-gen/test_outputs/naming.cpp @@ -1,5 +1,5 @@ #include "cxx-qt-gen/include/my_object.h" -#include "cxx-qt-gen/src/my_object.rs.h" +#include "cxx-qt-gen/include/my_object.cxx.h" namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/properties.cpp b/cxx-qt-gen/test_outputs/properties.cpp index d9e8a3362..04d6a75bd 100644 --- a/cxx-qt-gen/test_outputs/properties.cpp +++ b/cxx-qt-gen/test_outputs/properties.cpp @@ -1,5 +1,5 @@ #include "cxx-qt-gen/include/my_object.h" -#include "cxx-qt-gen/src/my_object.rs.h" +#include "cxx-qt-gen/include/my_object.cxx.h" namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/signals.cpp b/cxx-qt-gen/test_outputs/signals.cpp index 3675b8b3e..bcdeb1fc9 100644 --- a/cxx-qt-gen/test_outputs/signals.cpp +++ b/cxx-qt-gen/test_outputs/signals.cpp @@ -1,5 +1,5 @@ #include "cxx-qt-gen/include/my_object.h" -#include "cxx-qt-gen/src/my_object.rs.h" +#include "cxx-qt-gen/include/my_object.cxx.h" namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/types_primitive_property.cpp b/cxx-qt-gen/test_outputs/types_primitive_property.cpp index f175c5e07..8fee78b31 100644 --- a/cxx-qt-gen/test_outputs/types_primitive_property.cpp +++ b/cxx-qt-gen/test_outputs/types_primitive_property.cpp @@ -1,5 +1,5 @@ #include "cxx-qt-gen/include/my_object.h" -#include "cxx-qt-gen/src/my_object.rs.h" +#include "cxx-qt-gen/include/my_object.cxx.h" namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/types_qt_invokable.cpp b/cxx-qt-gen/test_outputs/types_qt_invokable.cpp index 730f72df8..f50924079 100644 --- a/cxx-qt-gen/test_outputs/types_qt_invokable.cpp +++ b/cxx-qt-gen/test_outputs/types_qt_invokable.cpp @@ -1,5 +1,5 @@ #include "cxx-qt-gen/include/my_object.h" -#include "cxx-qt-gen/src/my_object.rs.h" +#include "cxx-qt-gen/include/my_object.cxx.h" namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/types_qt_property.cpp b/cxx-qt-gen/test_outputs/types_qt_property.cpp index 3b2b55b85..56a24e511 100644 --- a/cxx-qt-gen/test_outputs/types_qt_property.cpp +++ b/cxx-qt-gen/test_outputs/types_qt_property.cpp @@ -1,5 +1,5 @@ #include "cxx-qt-gen/include/my_object.h" -#include "cxx-qt-gen/src/my_object.rs.h" +#include "cxx-qt-gen/include/my_object.cxx.h" namespace cxx_qt::my_object { diff --git a/tests/basic_cxx_only/src/main.cpp b/tests/basic_cxx_only/src/main.cpp index 4a3aab232..10cb7194c 100644 --- a/tests/basic_cxx_only/src/main.cpp +++ b/tests/basic_cxx_only/src/main.cpp @@ -8,7 +8,7 @@ #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include "doctest.h" -#include "cxx-qt-gen/include/lib.rs.h" +#include "cxx-qt-gen/include/ffi.cxx.h" #include "main.h" int hidden_num = 100; diff --git a/tests/qt_types_standalone/include/bridge.h b/tests/qt_types_standalone/include/bridge.h index 61bba7163..9df965c50 100644 --- a/tests/qt_types_standalone/include/bridge.h +++ b/tests/qt_types_standalone/include/bridge.h @@ -21,7 +21,7 @@ #include #include -#include "cxx-qt-gen/include/lib.rs.h" +#include "cxx-qt-gen/include/ffi.cxx.h" bool test_constructed_qstring(const QString& s); diff --git a/tests/qt_types_standalone/src/main.cpp b/tests/qt_types_standalone/src/main.cpp index 225a30570..bf5658a6d 100644 --- a/tests/qt_types_standalone/src/main.cpp +++ b/tests/qt_types_standalone/src/main.cpp @@ -12,7 +12,7 @@ #include "doctest.h" #include "bridge.h" -#include "cxx-qt-gen/include/lib.rs.h" +#include "cxx-qt-gen/include/ffi.cxx.h" TEST_CASE("Can construct a QString on the Rust side") { From 084702c0180d07191255f46f80be8cc6665e5494 Mon Sep 17 00:00:00 2001 From: Be Wilson Date: Tue, 19 Jul 2022 01:03:20 -0500 Subject: [PATCH 2/4] use .cxxqt.{h/cpp} suffix for generated QObject C++ files --- cxx-qt-build/src/lib.rs | 4 ++-- cxx-qt-gen/src/gen_cpp.rs | 4 ++-- cxx-qt-gen/src/gen_rs.rs | 2 +- cxx-qt-gen/test_outputs/custom_default.rs | 2 +- cxx-qt-gen/test_outputs/handlers.cpp | 2 +- cxx-qt-gen/test_outputs/handlers.rs | 2 +- cxx-qt-gen/test_outputs/invokables.cpp | 2 +- cxx-qt-gen/test_outputs/invokables.h | 2 +- cxx-qt-gen/test_outputs/invokables.rs | 2 +- cxx-qt-gen/test_outputs/naming.cpp | 2 +- cxx-qt-gen/test_outputs/naming.rs | 2 +- cxx-qt-gen/test_outputs/passthrough.rs | 2 +- cxx-qt-gen/test_outputs/properties.cpp | 2 +- cxx-qt-gen/test_outputs/properties.h | 2 +- cxx-qt-gen/test_outputs/properties.rs | 2 +- cxx-qt-gen/test_outputs/signals.cpp | 2 +- cxx-qt-gen/test_outputs/signals.rs | 2 +- cxx-qt-gen/test_outputs/types_primitive_property.cpp | 2 +- cxx-qt-gen/test_outputs/types_primitive_property.rs | 2 +- cxx-qt-gen/test_outputs/types_qt_invokable.cpp | 2 +- cxx-qt-gen/test_outputs/types_qt_invokable.rs | 2 +- cxx-qt-gen/test_outputs/types_qt_property.cpp | 2 +- cxx-qt-gen/test_outputs/types_qt_property.rs | 2 +- examples/demo_threading/src/main.cpp | 2 +- examples/qml_extension_plugin/core/plugin.cpp | 2 +- examples/qml_features/src/main.cpp | 12 ++++++------ .../qml_features/src/tests/myobject/tst_myobject.cpp | 4 ++-- .../qml_features/src/tests/qttypes/tst_qttypes.cpp | 2 +- .../src/tests/serialisation/tst_serialisation.cpp | 2 +- examples/qml_minimal/src/main.cpp | 2 +- .../qml_minimal/src/tests/myobject/tst_myobject.cpp | 2 +- examples/qml_with_threaded_logic/src/main.cpp | 2 +- .../src/tests/website/tst_website.cpp | 2 +- tests/basic_cxx_qt/src/main.cpp | 8 ++++---- 34 files changed, 45 insertions(+), 45 deletions(-) diff --git a/cxx-qt-build/src/lib.rs b/cxx-qt-build/src/lib.rs index 95b9929c5..10b27b250 100644 --- a/cxx-qt-build/src/lib.rs +++ b/cxx-qt-build/src/lib.rs @@ -216,7 +216,7 @@ impl GeneratedCpp { if let Some(cxx_qt_generated) = &self.cxx_qt { let header_path = PathBuf::from(format!( - "{}/{}.h", + "{}/{}.cxxqt.h", include_directory_path.display(), self.module_ident )); @@ -228,7 +228,7 @@ impl GeneratedCpp { written_files.push(header_path); let cpp_path = PathBuf::from(format!( - "{}/{}.cpp", + "{}/{}.cxxqt.cpp", source_directory_path.display(), &self.module_ident )); diff --git a/cxx-qt-gen/src/gen_cpp.rs b/cxx-qt-gen/src/gen_cpp.rs index 27854561f..c538f6ba7 100644 --- a/cxx-qt-gen/src/gen_cpp.rs +++ b/cxx-qt-gen/src/gen_cpp.rs @@ -78,7 +78,7 @@ impl CppType for QtTypes { cpp_type_idents, .. } if external == &true && cpp_type_idents.len() > 2 => vec![format!( - "#include \"cxx-qt-gen/include/{}.h\"", + "#include \"cxx-qt-gen/include/{}.cxxqt.h\"", cpp_type_idents[cpp_type_idents.len() - 2] )], Self::QColor => vec!["#include ".to_owned()], @@ -1038,8 +1038,8 @@ pub fn generate_qobject_cpp(obj: &QObject) -> Result { // Generate C++ source part let source = formatdoc! {r#" - #include "cxx-qt-gen/include/{ident_snake}.h" #include "cxx-qt-gen/include/{ident_snake}.cxx.h" + #include "cxx-qt-gen/include/{ident_snake}.cxxqt.h" namespace {namespace} {{ diff --git a/cxx-qt-gen/src/gen_rs.rs b/cxx-qt-gen/src/gen_rs.rs index ef4c17de8..efca01128 100644 --- a/cxx-qt-gen/src/gen_rs.rs +++ b/cxx-qt-gen/src/gen_rs.rs @@ -521,7 +521,7 @@ pub fn generate_qobject_cxx( }; // Build the import path for the C++ header - let import_path = format!("cxx-qt-gen/include/{}.h", ident_snake); + let import_path = format!("cxx-qt-gen/include/{}.cxxqt.h", ident_snake); // Generate an enum representing all the properties that the object has let property_enum = generate_property_enum(obj); diff --git a/cxx-qt-gen/test_outputs/custom_default.rs b/cxx-qt-gen/test_outputs/custom_default.rs index 2440fdb02..df5bca857 100644 --- a/cxx-qt-gen/test_outputs/custom_default.rs +++ b/cxx-qt-gen/test_outputs/custom_default.rs @@ -8,7 +8,7 @@ mod my_object { } unsafe extern "C++" { - include!("cxx-qt-gen/include/my_object.h"); + include!("cxx-qt-gen/include/my_object.cxxqt.h"); type MyObject; diff --git a/cxx-qt-gen/test_outputs/handlers.cpp b/cxx-qt-gen/test_outputs/handlers.cpp index 7f1ec5be4..2afd65b90 100644 --- a/cxx-qt-gen/test_outputs/handlers.cpp +++ b/cxx-qt-gen/test_outputs/handlers.cpp @@ -1,5 +1,5 @@ -#include "cxx-qt-gen/include/my_object.h" #include "cxx-qt-gen/include/my_object.cxx.h" +#include "cxx-qt-gen/include/my_object.cxxqt.h" namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/handlers.rs b/cxx-qt-gen/test_outputs/handlers.rs index f5d1dcc22..8eea7d2cf 100644 --- a/cxx-qt-gen/test_outputs/handlers.rs +++ b/cxx-qt-gen/test_outputs/handlers.rs @@ -11,7 +11,7 @@ mod my_object { } unsafe extern "C++" { - include!("cxx-qt-gen/include/my_object.h"); + include!("cxx-qt-gen/include/my_object.cxxqt.h"); type MyObject; diff --git a/cxx-qt-gen/test_outputs/invokables.cpp b/cxx-qt-gen/test_outputs/invokables.cpp index 032908385..0ef3c96b0 100644 --- a/cxx-qt-gen/test_outputs/invokables.cpp +++ b/cxx-qt-gen/test_outputs/invokables.cpp @@ -1,5 +1,5 @@ -#include "cxx-qt-gen/include/my_object.h" #include "cxx-qt-gen/include/my_object.cxx.h" +#include "cxx-qt-gen/include/my_object.cxxqt.h" namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/invokables.h b/cxx-qt-gen/test_outputs/invokables.h index 58e082ad2..167c6ac87 100644 --- a/cxx-qt-gen/test_outputs/invokables.h +++ b/cxx-qt-gen/test_outputs/invokables.h @@ -4,7 +4,7 @@ #include "cxx-qt-lib/include/qt_types.h" -#include "cxx-qt-gen/include/nested_object.h" +#include "cxx-qt-gen/include/nested_object.cxxqt.h" #include #include diff --git a/cxx-qt-gen/test_outputs/invokables.rs b/cxx-qt-gen/test_outputs/invokables.rs index 1379df4aa..6a52a5026 100644 --- a/cxx-qt-gen/test_outputs/invokables.rs +++ b/cxx-qt-gen/test_outputs/invokables.rs @@ -5,7 +5,7 @@ mod my_object { #[cxx::bridge(namespace = "cxx_qt::my_object")] mod ffi { unsafe extern "C++" { - include!("cxx-qt-gen/include/my_object.h"); + include!("cxx-qt-gen/include/my_object.cxxqt.h"); type MyObject; diff --git a/cxx-qt-gen/test_outputs/naming.cpp b/cxx-qt-gen/test_outputs/naming.cpp index bb068bb65..58cf92ddc 100644 --- a/cxx-qt-gen/test_outputs/naming.cpp +++ b/cxx-qt-gen/test_outputs/naming.cpp @@ -1,5 +1,5 @@ -#include "cxx-qt-gen/include/my_object.h" #include "cxx-qt-gen/include/my_object.cxx.h" +#include "cxx-qt-gen/include/my_object.cxxqt.h" namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/naming.rs b/cxx-qt-gen/test_outputs/naming.rs index 46dbcd5e9..de4c18b87 100644 --- a/cxx-qt-gen/test_outputs/naming.rs +++ b/cxx-qt-gen/test_outputs/naming.rs @@ -8,7 +8,7 @@ mod my_object { } unsafe extern "C++" { - include!("cxx-qt-gen/include/my_object.h"); + include!("cxx-qt-gen/include/my_object.cxxqt.h"); type MyObject; diff --git a/cxx-qt-gen/test_outputs/passthrough.rs b/cxx-qt-gen/test_outputs/passthrough.rs index ed8ffe0ec..2dec3cce1 100644 --- a/cxx-qt-gen/test_outputs/passthrough.rs +++ b/cxx-qt-gen/test_outputs/passthrough.rs @@ -53,7 +53,7 @@ pub mod my_object { } unsafe extern "C++" { - include!("cxx-qt-gen/include/my_object.h"); + include!("cxx-qt-gen/include/my_object.cxxqt.h"); type MyObject; diff --git a/cxx-qt-gen/test_outputs/properties.cpp b/cxx-qt-gen/test_outputs/properties.cpp index 04d6a75bd..13947573d 100644 --- a/cxx-qt-gen/test_outputs/properties.cpp +++ b/cxx-qt-gen/test_outputs/properties.cpp @@ -1,5 +1,5 @@ -#include "cxx-qt-gen/include/my_object.h" #include "cxx-qt-gen/include/my_object.cxx.h" +#include "cxx-qt-gen/include/my_object.cxxqt.h" namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/properties.h b/cxx-qt-gen/test_outputs/properties.h index 7a83c4a2f..92f39a63f 100644 --- a/cxx-qt-gen/test_outputs/properties.h +++ b/cxx-qt-gen/test_outputs/properties.h @@ -4,7 +4,7 @@ #include "cxx-qt-lib/include/qt_types.h" -#include "cxx-qt-gen/include/nested_object.h" +#include "cxx-qt-gen/include/nested_object.cxxqt.h" #include namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/properties.rs b/cxx-qt-gen/test_outputs/properties.rs index 61a2320cf..6ef3335d2 100644 --- a/cxx-qt-gen/test_outputs/properties.rs +++ b/cxx-qt-gen/test_outputs/properties.rs @@ -11,7 +11,7 @@ mod my_object { } unsafe extern "C++" { - include!("cxx-qt-gen/include/my_object.h"); + include!("cxx-qt-gen/include/my_object.cxxqt.h"); type MyObject; diff --git a/cxx-qt-gen/test_outputs/signals.cpp b/cxx-qt-gen/test_outputs/signals.cpp index bcdeb1fc9..c65d7dc91 100644 --- a/cxx-qt-gen/test_outputs/signals.cpp +++ b/cxx-qt-gen/test_outputs/signals.cpp @@ -1,5 +1,5 @@ -#include "cxx-qt-gen/include/my_object.h" #include "cxx-qt-gen/include/my_object.cxx.h" +#include "cxx-qt-gen/include/my_object.cxxqt.h" namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/signals.rs b/cxx-qt-gen/test_outputs/signals.rs index be64a3ce6..bdddf2904 100644 --- a/cxx-qt-gen/test_outputs/signals.rs +++ b/cxx-qt-gen/test_outputs/signals.rs @@ -5,7 +5,7 @@ mod my_object { #[cxx::bridge(namespace = "cxx_qt::my_object")] mod ffi { unsafe extern "C++" { - include!("cxx-qt-gen/include/my_object.h"); + include!("cxx-qt-gen/include/my_object.cxxqt.h"); type MyObject; include!("cxx-qt-lib/include/qt_types.h"); diff --git a/cxx-qt-gen/test_outputs/types_primitive_property.cpp b/cxx-qt-gen/test_outputs/types_primitive_property.cpp index 8fee78b31..747e25120 100644 --- a/cxx-qt-gen/test_outputs/types_primitive_property.cpp +++ b/cxx-qt-gen/test_outputs/types_primitive_property.cpp @@ -1,5 +1,5 @@ -#include "cxx-qt-gen/include/my_object.h" #include "cxx-qt-gen/include/my_object.cxx.h" +#include "cxx-qt-gen/include/my_object.cxxqt.h" namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/types_primitive_property.rs b/cxx-qt-gen/test_outputs/types_primitive_property.rs index 3c4773acd..ab36601ab 100644 --- a/cxx-qt-gen/test_outputs/types_primitive_property.rs +++ b/cxx-qt-gen/test_outputs/types_primitive_property.rs @@ -16,7 +16,7 @@ mod my_object { } unsafe extern "C++" { - include!("cxx-qt-gen/include/my_object.h"); + include!("cxx-qt-gen/include/my_object.cxxqt.h"); type MyObject; diff --git a/cxx-qt-gen/test_outputs/types_qt_invokable.cpp b/cxx-qt-gen/test_outputs/types_qt_invokable.cpp index f50924079..09edb24c8 100644 --- a/cxx-qt-gen/test_outputs/types_qt_invokable.cpp +++ b/cxx-qt-gen/test_outputs/types_qt_invokable.cpp @@ -1,5 +1,5 @@ -#include "cxx-qt-gen/include/my_object.h" #include "cxx-qt-gen/include/my_object.cxx.h" +#include "cxx-qt-gen/include/my_object.cxxqt.h" namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/types_qt_invokable.rs b/cxx-qt-gen/test_outputs/types_qt_invokable.rs index 8d72abb4e..40068c4fd 100644 --- a/cxx-qt-gen/test_outputs/types_qt_invokable.rs +++ b/cxx-qt-gen/test_outputs/types_qt_invokable.rs @@ -4,7 +4,7 @@ mod my_object { #[cxx::bridge(namespace = "cxx_qt::my_object")] mod ffi { unsafe extern "C++" { - include!("cxx-qt-gen/include/my_object.h"); + include!("cxx-qt-gen/include/my_object.cxxqt.h"); type MyObject; diff --git a/cxx-qt-gen/test_outputs/types_qt_property.cpp b/cxx-qt-gen/test_outputs/types_qt_property.cpp index 56a24e511..1db8142a9 100644 --- a/cxx-qt-gen/test_outputs/types_qt_property.cpp +++ b/cxx-qt-gen/test_outputs/types_qt_property.cpp @@ -1,5 +1,5 @@ -#include "cxx-qt-gen/include/my_object.h" #include "cxx-qt-gen/include/my_object.cxx.h" +#include "cxx-qt-gen/include/my_object.cxxqt.h" namespace cxx_qt::my_object { diff --git a/cxx-qt-gen/test_outputs/types_qt_property.rs b/cxx-qt-gen/test_outputs/types_qt_property.rs index 3ce6b45d9..2ed5dbad9 100644 --- a/cxx-qt-gen/test_outputs/types_qt_property.rs +++ b/cxx-qt-gen/test_outputs/types_qt_property.rs @@ -20,7 +20,7 @@ mod my_object { } unsafe extern "C++" { - include!("cxx-qt-gen/include/my_object.h"); + include!("cxx-qt-gen/include/my_object.cxxqt.h"); type MyObject; diff --git a/examples/demo_threading/src/main.cpp b/examples/demo_threading/src/main.cpp index aafee52a1..a52bf772d 100644 --- a/examples/demo_threading/src/main.cpp +++ b/examples/demo_threading/src/main.cpp @@ -7,7 +7,7 @@ #include #include -#include "cxx-qt-gen/include/energy_usage.h" +#include "cxx-qt-gen/include/energy_usage.cxxqt.h" int main(int argc, char* argv[]) diff --git a/examples/qml_extension_plugin/core/plugin.cpp b/examples/qml_extension_plugin/core/plugin.cpp index d725da1fd..7a086b3a6 100644 --- a/examples/qml_extension_plugin/core/plugin.cpp +++ b/examples/qml_extension_plugin/core/plugin.cpp @@ -9,7 +9,7 @@ #include #include -#include "cxx-qt-gen/include/my_object.h" +#include "cxx-qt-gen/include/my_object.cxxqt.h" class CoreQmlpluginPlugin : public QQmlExtensionPlugin { diff --git a/examples/qml_features/src/main.cpp b/examples/qml_features/src/main.cpp index e30058c7a..bf3ae013f 100644 --- a/examples/qml_features/src/main.cpp +++ b/examples/qml_features/src/main.cpp @@ -8,12 +8,12 @@ #include #include -#include "cxx-qt-gen/include/data_struct_properties.h" -#include "cxx-qt-gen/include/handler_property_change.h" -#include "cxx-qt-gen/include/my_object.h" -#include "cxx-qt-gen/include/serialisation.h" -#include "cxx-qt-gen/include/sub_object.h" -#include "cxx-qt-gen/include/types.h" +#include "cxx-qt-gen/include/data_struct_properties.cxxqt.h" +#include "cxx-qt-gen/include/handler_property_change.cxxqt.h" +#include "cxx-qt-gen/include/my_object.cxxqt.h" +#include "cxx-qt-gen/include/serialisation.cxxqt.h" +#include "cxx-qt-gen/include/sub_object.cxxqt.h" +#include "cxx-qt-gen/include/types.cxxqt.h" int main(int argc, char* argv[]) diff --git a/examples/qml_features/src/tests/myobject/tst_myobject.cpp b/examples/qml_features/src/tests/myobject/tst_myobject.cpp index fb8bba534..cbc9042cb 100644 --- a/examples/qml_features/src/tests/myobject/tst_myobject.cpp +++ b/examples/qml_features/src/tests/myobject/tst_myobject.cpp @@ -9,8 +9,8 @@ #include #include -#include "cxx-qt-gen/include/my_object.h" -#include "cxx-qt-gen/include/sub_object.h" +#include "cxx-qt-gen/include/my_object.cxxqt.h" +#include "cxx-qt-gen/include/sub_object.cxxqt.h" class Setup : public QObject { diff --git a/examples/qml_features/src/tests/qttypes/tst_qttypes.cpp b/examples/qml_features/src/tests/qttypes/tst_qttypes.cpp index 359f73b27..93758bf3c 100644 --- a/examples/qml_features/src/tests/qttypes/tst_qttypes.cpp +++ b/examples/qml_features/src/tests/qttypes/tst_qttypes.cpp @@ -9,7 +9,7 @@ #include #include -#include "cxx-qt-gen/include/mock_qt_types.h" +#include "cxx-qt-gen/include/mock_qt_types.cxxqt.h" class Setup : public QObject { diff --git a/examples/qml_features/src/tests/serialisation/tst_serialisation.cpp b/examples/qml_features/src/tests/serialisation/tst_serialisation.cpp index d9ccbe636..7039a62c6 100644 --- a/examples/qml_features/src/tests/serialisation/tst_serialisation.cpp +++ b/examples/qml_features/src/tests/serialisation/tst_serialisation.cpp @@ -9,7 +9,7 @@ #include #include -#include "cxx-qt-gen/include/serialisation.h" +#include "cxx-qt-gen/include/serialisation.cxxqt.h" class Setup : public QObject { diff --git a/examples/qml_minimal/src/main.cpp b/examples/qml_minimal/src/main.cpp index f7c15bd81..3791bc8d7 100644 --- a/examples/qml_minimal/src/main.cpp +++ b/examples/qml_minimal/src/main.cpp @@ -11,7 +11,7 @@ #include // ANCHOR: book_cpp_include -#include "cxx-qt-gen/include/my_object.h" +#include "cxx-qt-gen/include/my_object.cxxqt.h" // ANCHOR_END: book_cpp_include int diff --git a/examples/qml_minimal/src/tests/myobject/tst_myobject.cpp b/examples/qml_minimal/src/tests/myobject/tst_myobject.cpp index 3b48a99e5..2d2ce39d0 100644 --- a/examples/qml_minimal/src/tests/myobject/tst_myobject.cpp +++ b/examples/qml_minimal/src/tests/myobject/tst_myobject.cpp @@ -9,7 +9,7 @@ #include #include -#include "cxx-qt-gen/include/my_object.h" +#include "cxx-qt-gen/include/my_object.cxxqt.h" class Setup : public QObject { diff --git a/examples/qml_with_threaded_logic/src/main.cpp b/examples/qml_with_threaded_logic/src/main.cpp index 4def07b0b..4bd6376b3 100644 --- a/examples/qml_with_threaded_logic/src/main.cpp +++ b/examples/qml_with_threaded_logic/src/main.cpp @@ -8,7 +8,7 @@ #include #include -#include "cxx-qt-gen/include/website.h" +#include "cxx-qt-gen/include/website.cxxqt.h" int main(int argc, char* argv[]) diff --git a/examples/qml_with_threaded_logic/src/tests/website/tst_website.cpp b/examples/qml_with_threaded_logic/src/tests/website/tst_website.cpp index 03d9fccc5..c1f0e3469 100644 --- a/examples/qml_with_threaded_logic/src/tests/website/tst_website.cpp +++ b/examples/qml_with_threaded_logic/src/tests/website/tst_website.cpp @@ -9,7 +9,7 @@ #include #include -#include "cxx-qt-gen/include/website.h" +#include "cxx-qt-gen/include/website.cxxqt.h" class Setup : public QObject { diff --git a/tests/basic_cxx_qt/src/main.cpp b/tests/basic_cxx_qt/src/main.cpp index 20a764576..3a71bde3b 100644 --- a/tests/basic_cxx_qt/src/main.cpp +++ b/tests/basic_cxx_qt/src/main.cpp @@ -12,10 +12,10 @@ #define DOCTEST_CONFIG_IMPLEMENT #include "doctest.h" -#include "cxx-qt-gen/include/my_data.h" -#include "cxx-qt-gen/include/my_object.h" -#include "cxx-qt-gen/include/my_types.h" -#include "cxx-qt-gen/include/sub_object.h" +#include "cxx-qt-gen/include/my_data.cxxqt.h" +#include "cxx-qt-gen/include/my_object.cxxqt.h" +#include "cxx-qt-gen/include/my_types.cxxqt.h" +#include "cxx-qt-gen/include/sub_object.cxxqt.h" int main(int argc, char** argv) From 899525d8b43f6903ab8a4a870ec5076c5c500456 Mon Sep 17 00:00:00 2001 From: Be Wilson Date: Fri, 15 Jul 2022 18:16:41 -0500 Subject: [PATCH 3/4] add command line tool for C++ code generation --- CMakeLists.txt | 1 + cxx-qt-cli/Cargo.toml | 19 +++++++++++++++++++ cxx-qt-cli/src/main.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 cxx-qt-cli/Cargo.toml create mode 100644 cxx-qt-cli/src/main.rs diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fae09468..47e97ed3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -171,6 +171,7 @@ add_test_cargo(cxx_qt "${CMAKE_CURRENT_SOURCE_DIR}/cxx-qt/Cargo.toml" DOCTESTS_O add_test_cargo(cxx_qt_build "${CMAKE_CURRENT_SOURCE_DIR}/cxx-qt-build/Cargo.toml" DOCTESTS_ON) add_test_cargo(cxx_qt_gen "${CMAKE_CURRENT_SOURCE_DIR}/cxx-qt-gen/Cargo.toml" DOCTESTS_ON) add_test_cargo(cxx_qt_lib "${CMAKE_CURRENT_SOURCE_DIR}/cxx-qt-lib/Cargo.toml" DOCTESTS_ON) +add_test_cargo(cxx_qt_cli "${CMAKE_CURRENT_SOURCE_DIR}/cxx-qt-cli/Cargo.toml" DOCTESTS_OFF) # Ensure test inputs and outputs are formatted file(GLOB CXX_QT_GEN_TEST_INPUTS ${CMAKE_CURRENT_SOURCE_DIR}/cxx-qt-gen/test_inputs/*.rs) diff --git a/cxx-qt-cli/Cargo.toml b/cxx-qt-cli/Cargo.toml new file mode 100644 index 000000000..37c5bcc7a --- /dev/null +++ b/cxx-qt-cli/Cargo.toml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company +# SPDX-FileContributor: Be Wilson +# SPDX-License-Identifier: MIT OR Apache-2.0 + +[package] +name = "cxx-qt-cli" +authors = ["Be Wilson "] +version = "0.3.0" +edition = "2021" +description = "Command line tool for cxx-qt's C++ code generation step for integration into C++ build systems" +repository = "https://github.com/KDAB/cxx-qt/" + +[[bin]] +name = "cxxqtbridge" +path = "src/main.rs" + +[dependencies] +cxx-qt-build = { path = "../cxx-qt-build" } +clap = { version = "^3.2.12", features = [ "derive" ] } diff --git a/cxx-qt-cli/src/main.rs b/cxx-qt-cli/src/main.rs new file mode 100644 index 000000000..a04eb5a73 --- /dev/null +++ b/cxx-qt-cli/src/main.rs @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company +// SPDX-FileContributor: Be Wilson +// SPDX-License-Identifier: MIT OR Apache-2.0 + +use clap::Parser; +use cxx_qt_build::GeneratedCpp; +use std::path::PathBuf; + +#[derive(Parser)] +#[clap(author, version, about, long_about = None)] +struct Cli { + /// path to Rust file containing module with #[cxx_qt::bridge] attribute macro + #[clap(short, long, value_parser)] + input: PathBuf, + + /// directory to output generated C++ files + #[clap(short, long, value_parser)] + output: PathBuf, +} + +fn main() { + let cli = Cli::parse(); + + let generated_code = GeneratedCpp::new(&cli.input); + let output_file_paths = generated_code.write_to_directory(&cli.output); + + for output_file_path in output_file_paths { + println!("{}", output_file_path.display()); + } +} From 5f069a1f16f9a704df599dbde71722d4cc76c8de Mon Sep 17 00:00:00 2001 From: Be Wilson Date: Fri, 15 Jul 2022 22:31:32 -0500 Subject: [PATCH 4/4] cxx-qt-cli: add feature for outputting absolute paths --- CMakeLists.txt | 4 ++-- cxx-qt-cli/Cargo.toml | 6 ++++++ cxx-qt-cli/src/main.rs | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47e97ed3d..7234f8e1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,14 +152,14 @@ add_subdirectory(examples) # Create helper method which adds relevent cargo tests for a given manifest function(add_test_cargo TEST_NAME_PREFIX MANIFEST_PATH ADD_DOCTESTS) # Add cargo as a test - add_test(NAME ${TEST_NAME_PREFIX}_cargo_tests COMMAND cargo test --all-targets --all-features --manifest-path ${MANIFEST_PATH}) + add_test(NAME ${TEST_NAME_PREFIX}_cargo_tests COMMAND cargo test --all-targets --manifest-path ${MANIFEST_PATH}) # Check if we should enable doc tests if (${ADD_DOCTESTS} STREQUAL "DOCTESTS_ON") # Add cargo docs as a test add_test(NAME ${TEST_NAME_PREFIX}_cargo_doc_tests COMMAND cargo test --doc --manifest-path ${MANIFEST_PATH}) endif() # Add clippy as a test - add_test(NAME ${TEST_NAME_PREFIX}_cargo_clippy COMMAND cargo clippy --all-targets --all-features --manifest-path ${MANIFEST_PATH} -- -D warnings) + add_test(NAME ${TEST_NAME_PREFIX}_cargo_clippy COMMAND cargo clippy --all-targets --manifest-path ${MANIFEST_PATH} -- -D warnings) # Add rustfmt as a test add_test(NAME ${TEST_NAME_PREFIX}_cargo_fmt COMMAND cargo fmt --manifest-path ${MANIFEST_PATH} -- --check) endfunction() diff --git a/cxx-qt-cli/Cargo.toml b/cxx-qt-cli/Cargo.toml index 37c5bcc7a..eaeb2ce37 100644 --- a/cxx-qt-cli/Cargo.toml +++ b/cxx-qt-cli/Cargo.toml @@ -17,3 +17,9 @@ path = "src/main.rs" [dependencies] cxx-qt-build = { path = "../cxx-qt-build" } clap = { version = "^3.2.12", features = [ "derive" ] } + +[features] +# Requires nightly compiler until std::path::absolute is stabilized +# https://github.com/rust-lang/rust/issues/92750 +# TODO: enable by default when stabilized +absolute-paths = [] diff --git a/cxx-qt-cli/src/main.rs b/cxx-qt-cli/src/main.rs index a04eb5a73..bc88a35a3 100644 --- a/cxx-qt-cli/src/main.rs +++ b/cxx-qt-cli/src/main.rs @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company // SPDX-FileContributor: Be Wilson // SPDX-License-Identifier: MIT OR Apache-2.0 +#![cfg_attr(feature = "absolute-paths", feature(absolute_path))] use clap::Parser; use cxx_qt_build::GeneratedCpp; @@ -25,6 +26,9 @@ fn main() { let output_file_paths = generated_code.write_to_directory(&cli.output); for output_file_path in output_file_paths { + #[cfg(feature = "absolute-paths")] + let output_file_path = std::path::absolute(output_file_path).unwrap(); + println!("{}", output_file_path.display()); } }