Skip to content

Commit 4fe8ce3

Browse files
committed
cxx-qt-build: consider the folders in rust path
Closes #855
1 parent 8b809e8 commit 4fe8ce3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+80
-67
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3535
- File name is used for CXX bridges rather than module name to match upstream
3636
- `#[qobject]` attribute is now optional on types in `extern "RustQt"`
3737
- `#[qobject]` attribute is now required on types in `extern "C++Qt"`
38+
- Rust bridges which are in folders are now considered by `CxxQtBuilder`
3839

3940
### Fixed
4041

crates/cxx-qt-build/src/lib.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ struct GeneratedCpp {
6161

6262
impl GeneratedCpp {
6363
/// Generate QObject and cxx header/source C++ file contents
64-
pub fn new(rust_file_path: impl AsRef<Path>) -> Result<Self, Diagnostic> {
64+
pub fn new(
65+
rust_file_path: impl AsRef<Path>,
66+
relative_path: impl AsRef<Path>,
67+
) -> Result<Self, Diagnostic> {
6568
let to_diagnostic = |err| Diagnostic::new(rust_file_path.as_ref().to_owned(), err);
6669

6770
let rust_file_path = rust_file_path.as_ref();
@@ -91,15 +94,16 @@ impl GeneratedCpp {
9194
rust_file_path.display());
9295
}
9396

94-
// Match upstream where they use the file name as the ident
95-
//
96-
// TODO: what happens if there are folders?
97+
// Match upstream where they use the file name and folders as the ident
9798
//
9899
// TODO: ideally CXX-Qt would also use the file name
99100
// https://github.com/KDAB/cxx-qt/pull/200/commits/4861c92e66c3a022d3f0dedd9f8fd20db064b42b
100-
file_ident = rust_file_path
101-
.file_stem()
102-
.unwrap()
101+
//
102+
// We need the relative path here as we want the folders
103+
file_ident = relative_path
104+
.as_ref()
105+
// Remove the .rs extension
106+
.with_extension("")
103107
.to_str()
104108
.unwrap()
105109
.to_owned();
@@ -210,6 +214,10 @@ impl GeneratedCpp {
210214
header_directory.display(),
211215
self.file_ident
212216
));
217+
if let Some(directory) = header_path.parent() {
218+
std::fs::create_dir_all(directory)
219+
.expect("Could not create directory to write cxx-qt generated header files");
220+
}
213221
let mut header = File::create(header_path).expect("Could not create cxx header file");
214222
header
215223
.write_all(&self.cxx.header)
@@ -220,6 +228,10 @@ impl GeneratedCpp {
220228
cpp_directory.display(),
221229
self.file_ident
222230
));
231+
if let Some(directory) = cpp_path.parent() {
232+
std::fs::create_dir_all(directory)
233+
.expect("Could not create directory to write cxx-qt generated source files");
234+
}
223235
let mut cpp = File::create(&cpp_path).expect("Could not create cxx source file");
224236
cpp.write_all(&self.cxx.implementation)
225237
.expect("Could not write cxx source file");
@@ -242,7 +254,7 @@ fn generate_cxxqt_cpp_files(
242254
let path = format!("{manifest_dir}/{}", rs_path.as_ref().display());
243255
println!("cargo:rerun-if-changed={path}");
244256

245-
let generated_code = match GeneratedCpp::new(&path) {
257+
let generated_code = match GeneratedCpp::new(&path, rs_path) {
246258
Ok(v) => v,
247259
Err(diagnostic) => {
248260
diagnostic.report();

crates/cxx-qt-gen/src/writer/cpp/header.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub fn write_cpp_header(generated: &GeneratedCppBlocks) -> String {
185185
{includes}
186186
187187
{forward_declare}
188-
#include "cxx-qt-gen/{cxx_file_stem}.cxx.h"
188+
#include "{cxx_file_stem}.cxx.h"
189189
190190
{extern_cxx_qt}
191191
{qobjects}

crates/cxx-qt-gen/src/writer/cpp/source.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn write_cpp_source(generated: &GeneratedCppBlocks) -> String {
6060
.join("\n");
6161

6262
formatdoc! {r#"
63-
#include "cxx-qt-gen/{cxx_file_stem}.cxxqt.h"
63+
#include "{cxx_file_stem}.cxxqt.h"
6464
6565
{extern_cxx_qt}
6666
{qobjects}

crates/cxx-qt-gen/test_outputs/inheritance.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cxx-qt-gen/inheritance.cxxqt.h"
1+
#include "inheritance.cxxqt.h"
22

33
QVariant
44
MyObject::data(QModelIndex const& _index, ::std::int32_t _role) const

crates/cxx-qt-gen/test_outputs/inheritance.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class MyObject;
88

9-
#include "cxx-qt-gen/inheritance.cxx.h"
9+
#include "inheritance.cxx.h"
1010

1111
class MyObject
1212
: public QAbstractItemModel

crates/cxx-qt-gen/test_outputs/invokables.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cxx-qt-gen/ffi.cxxqt.h"
1+
#include "ffi.cxxqt.h"
22

33
namespace cxx_qt::my_object {
44
void

crates/cxx-qt-gen/test_outputs/invokables.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using MyObjectCxxQtThread = ::rust::cxxqt1::CxxQtThread<MyObject>;
1010

1111
} // namespace cxx_qt::my_object
1212

13-
#include "cxx-qt-gen/ffi.cxx.h"
13+
#include "ffi.cxx.h"
1414

1515
namespace cxx_qt::my_object {
1616
class MyObject

crates/cxx-qt-gen/test_outputs/passthrough_and_naming.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cxx-qt-gen/multi_object.cxxqt.h"
1+
#include "multi_object.cxxqt.h"
22

33
// Define namespace otherwise we hit a GCC bug
44
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480

crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ using ExternObjectCxxQtSignalHandlererrorOccurred =
5353
struct ExternObjectCxxQtSignalParamserrorOccurred*>;
5454
} // namespace mynamespace::rust::cxxqtgen1
5555

56-
#include "cxx-qt-gen/multi_object.cxx.h"
56+
#include "multi_object.cxx.h"
5757

5858
namespace rust::cxxqtgen1 {
5959
::QMetaObject::Connection

crates/cxx-qt-gen/test_outputs/properties.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cxx-qt-gen/ffi.cxxqt.h"
1+
#include "ffi.cxxqt.h"
22

33
// Define namespace otherwise we hit a GCC bug
44
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480

crates/cxx-qt-gen/test_outputs/properties.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using MyObjectCxxQtSignalHandlertrivialChanged = ::rust::cxxqt1::SignalHandler<
2121
struct MyObjectCxxQtSignalParamstrivialChanged*>;
2222
} // namespace cxx_qt::my_object::rust::cxxqtgen1
2323

24-
#include "cxx-qt-gen/ffi.cxx.h"
24+
#include "ffi.cxx.h"
2525

2626
namespace cxx_qt::my_object::rust::cxxqtgen1 {
2727
::QMetaObject::Connection

crates/cxx-qt-gen/test_outputs/qenum.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cxx-qt-gen/ffi.cxxqt.h"
1+
#include "ffi.cxxqt.h"
22

33
namespace cxx_qt::my_object {
44
void

crates/cxx-qt-gen/test_outputs/qenum.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ enum class MyOtherNamespacedEnum : ::std::int32_t
5353
Q_ENUM_NS(MyOtherNamespacedEnum)
5454
} // namespace other_namespace
5555

56-
#include "cxx-qt-gen/ffi.cxx.h"
56+
#include "ffi.cxx.h"
5757

5858
namespace cxx_qt::my_object {
5959
class MyObject

crates/cxx-qt-gen/test_outputs/signals.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cxx-qt-gen/ffi.cxxqt.h"
1+
#include "ffi.cxxqt.h"
22

33
// Define namespace otherwise we hit a GCC bug
44
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56480

crates/cxx-qt-gen/test_outputs/signals.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using QTimerCxxQtSignalHandlertimeout =
3030
::rust::cxxqt1::SignalHandler<struct QTimerCxxQtSignalParamstimeout*>;
3131
} // namespace cxx_qt::my_object::rust::cxxqtgen1
3232

33-
#include "cxx-qt-gen/ffi.cxx.h"
33+
#include "ffi.cxx.h"
3434

3535
namespace cxx_qt::my_object::rust::cxxqtgen1 {
3636
::QMetaObject::Connection

examples/demo_threading/cpp/helpers/energyusageproxymodel.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <QtCore/QAbstractListModel>
1313
#include <QtCore/QVector>
1414

15-
#include "cxx-qt-gen/energy_usage.cxxqt.h"
15+
#include "cxx-qt-gen/src/energy_usage.cxxqt.h"
1616

1717
class EnergyUsageProxyModel : public QAbstractListModel
1818
{

tests/basic_cxx_only/cpp/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// SPDX-License-Identifier: MIT OR Apache-2.0
88
#include <QtTest/QTest>
99

10-
#include "cxx-qt-gen/lib.cxx.h"
10+
#include "cxx-qt-gen/src/lib.cxx.h"
1111
#include "cxx_test.h"
1212

1313
class CxxTest : public QObject

tests/basic_cxx_qt/cpp/main.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
#include <QtTest/QSignalSpy>
1111
#include <QtTest/QTest>
1212

13-
#include "cxx-qt-gen/empty.cxxqt.h"
14-
#include "cxx-qt-gen/locking.cxxqt.h"
15-
#include "cxx-qt-gen/my_data.cxxqt.h"
16-
#include "cxx-qt-gen/my_object.cxxqt.h"
17-
#include "cxx-qt-gen/my_types.cxxqt.h"
13+
#include "cxx-qt-gen/src/empty.cxxqt.h"
14+
#include "cxx-qt-gen/src/locking.cxxqt.h"
15+
#include "cxx-qt-gen/src/my_data.cxxqt.h"
16+
#include "cxx-qt-gen/src/my_object.cxxqt.h"
17+
#include "cxx-qt-gen/src/my_types.cxxqt.h"
1818

1919
class LockingWorkerThread : public QThread
2020
{

tests/qt_types_standalone/cpp/qbytearray.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <QtCore/QByteArray>
1010
#include <QtTest/QTest>
1111

12-
#include "cxx-qt-gen/qbytearray.cxx.h"
12+
#include "cxx-qt-gen/src/qbytearray.cxx.h"
1313

1414
class QByteArrayTest : public QObject
1515
{

tests/qt_types_standalone/cpp/qcoreapplication.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <QtCore/QCoreApplication>
1010
#include <QtTest/QTest>
1111

12-
#include "cxx-qt-gen/qcoreapplication.cxx.h"
12+
#include "cxx-qt-gen/src/qcoreapplication.cxx.h"
1313

1414
class QCoreApplicationTest : public QObject
1515
{

tests/qt_types_standalone/cpp/qdate.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <QtCore/QDate>
1010
#include <QtTest/QTest>
1111

12-
#include "cxx-qt-gen/qdate.cxx.h"
12+
#include "cxx-qt-gen/src/qdate.cxx.h"
1313

1414
class QDateTest : public QObject
1515
{

tests/qt_types_standalone/cpp/qdatetime.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <QtCore/QDateTime>
1010
#include <QtTest/QTest>
1111

12-
#include "cxx-qt-gen/qdatetime.cxx.h"
12+
#include "cxx-qt-gen/src/qdatetime.cxx.h"
1313

1414
class QDateTimeTest : public QObject
1515
{

tests/qt_types_standalone/cpp/qguiapplication.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <QtGui/QGuiApplication>
1010
#include <QtTest/QTest>
1111

12-
#include "cxx-qt-gen/qguiapplication.cxx.h"
12+
#include "cxx-qt-gen/src/qguiapplication.cxx.h"
1313

1414
class QGuiApplicationTest : public QObject
1515
{

tests/qt_types_standalone/cpp/qhash.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <QtCore/QVariant>
1111
#include <QtTest/QTest>
1212

13-
#include "cxx-qt-gen/qhash.cxx.h"
13+
#include "cxx-qt-gen/src/qhash.cxx.h"
1414

1515
class QHashTest : public QObject
1616
{

tests/qt_types_standalone/cpp/qline.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <QtCore/QLine>
1010
#include <QtTest/QTest>
1111

12-
#include "cxx-qt-gen/qline.cxx.h"
12+
#include "cxx-qt-gen/src/qline.cxx.h"
1313

1414
class QLineTest : public QObject
1515
{

tests/qt_types_standalone/cpp/qlinef.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <QtCore/QLineF>
1010
#include <QtTest/QTest>
1111

12-
#include "cxx-qt-gen/qlinef.cxx.h"
12+
#include "cxx-qt-gen/src/qlinef.cxx.h"
1313

1414
class QLineFTest : public QObject
1515
{

tests/qt_types_standalone/cpp/qlist.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <QtCore/QList>
1010
#include <QtTest/QTest>
1111

12-
#include "cxx-qt-gen/qlist.cxx.h"
12+
#include "cxx-qt-gen/src/qlist.cxx.h"
1313

1414
class QListTest : public QObject
1515
{

tests/qt_types_standalone/cpp/qmap.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <QtCore/QVariant>
1111
#include <QtTest/QTest>
1212

13-
#include "cxx-qt-gen/qmap.cxx.h"
13+
#include "cxx-qt-gen/src/qmap.cxx.h"
1414

1515
class QMapTest : public QObject
1616
{

tests/qt_types_standalone/cpp/qmargins.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <QtCore/QMargins>
1010
#include <QtTest/QTest>
1111

12-
#include "cxx-qt-gen/qmargins.cxx.h"
12+
#include "cxx-qt-gen/src/qmargins.cxx.h"
1313

1414
class QMarginsTest : public QObject
1515
{

tests/qt_types_standalone/cpp/qmarginsf.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <QtCore/QMarginsF>
1010
#include <QtTest/QTest>
1111

12-
#include "cxx-qt-gen/qmarginsf.cxx.h"
12+
#include "cxx-qt-gen/src/qmarginsf.cxx.h"
1313

1414
class QMarginsFTest : public QObject
1515
{

tests/qt_types_standalone/cpp/qmetaobjectconnection.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <QtTest/QTest>
1212
#include <qobjectdefs.h>
1313

14-
#include "cxx-qt-gen/qmetaobjectconnection.cxx.h"
14+
#include "cxx-qt-gen/src/qmetaobjectconnection.cxx.h"
1515

1616
class MyObject : public QObject
1717
{

tests/qt_types_standalone/cpp/qmodelindex.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <QtCore/QStringListModel>
1212
#include <QtTest/QTest>
1313

14-
#include "cxx-qt-gen/qmodelindex.cxx.h"
14+
#include "cxx-qt-gen/src/qmodelindex.cxx.h"
1515

1616
// We subclass from QAbstractListModel to have a valid model to use for
1717
// access to createIndex();

tests/qt_types_standalone/cpp/qpen.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <QtGui/QPen>
1010
#include <QtTest/QTest>
1111

12-
#include "cxx-qt-gen/qpen.cxx.h"
12+
#include "cxx-qt-gen/src/qpen.cxx.h"
1313

1414
class QPenTest : public QObject
1515
{

tests/qt_types_standalone/cpp/qpersistentmodelindex.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <QtGui/QStandardItemModel>
1212
#include <QtTest/QTest>
1313

14-
#include "cxx-qt-gen/qpersistentmodelindex.cxx.h"
14+
#include "cxx-qt-gen/src/qpersistentmodelindex.cxx.h"
1515

1616
class QPersistentModelIndexTest : public QObject
1717
{

tests/qt_types_standalone/cpp/qpoint.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <QtCore/QPoint>
1010
#include <QtTest/QTest>
1111

12-
#include "cxx-qt-gen/qpoint.cxx.h"
12+
#include "cxx-qt-gen/src/qpoint.cxx.h"
1313

1414
class QPointTest : public QObject
1515
{

tests/qt_types_standalone/cpp/qpointf.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <QtCore/QPointF>
1010
#include <QtTest/QTest>
1111

12-
#include "cxx-qt-gen/qpointf.cxx.h"
12+
#include "cxx-qt-gen/src/qpointf.cxx.h"
1313

1414
class QPointFTest : public QObject
1515
{

tests/qt_types_standalone/cpp/qpolygon.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <QtGui/QPolygon>
1010
#include <QtTest/QTest>
1111

12-
#include "cxx-qt-gen/qpolygon.cxx.h"
12+
#include "cxx-qt-gen/src/qpolygon.cxx.h"
1313

1414
class QPolygonTest : public QObject
1515
{

tests/qt_types_standalone/cpp/qpolygonf.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <QtGui/QPolygonF>
1010
#include <QtTest/QTest>
1111

12-
#include "cxx-qt-gen/qpolygonf.cxx.h"
12+
#include "cxx-qt-gen/src/qpolygonf.cxx.h"
1313

1414
class QPolygonFTest : public QObject
1515
{

0 commit comments

Comments
 (0)