Skip to content

Commit 2c86cf3

Browse files
committed
Bug fixes
- Fix support of 'inheritances' configuration parameter: only no-parent spec ("A:") was respected; Extend TestInheritance unit test; - Change in test make and cmake files for older Julia releases (<1.9) that do not provide the pkgversion() function. - Fix a bug in test/make.rules affecting set of CxxWrap release.
1 parent 14eb9a6 commit 2c86cf3

File tree

6 files changed

+29
-11
lines changed

6 files changed

+29
-11
lines changed

src/CodeTree.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ CodeTree::getParentClassForWrapper(CXCursor cursor) const{
145145
}
146146
//FIXME: handling of parent namespace?
147147
if(data.preferred_parent.size() == 0
148-
|| str(clang_getTypeSpelling(clang_getCursorType(data.c)))
148+
|| str(clang_getTypeSpelling(clang_getCursorType(cursor)))
149149
== data.preferred_parent){
150150
data.c = cursor;
151151
}
@@ -164,11 +164,10 @@ CodeTree::getParentClassForWrapper(CXCursor cursor) const{
164164
clang_visitChildren(cursor, visitor, &data);
165165

166166
if(clang_Cursor_isNull(data.c) && !clang_Cursor_isNull(data.first_parent)){
167-
std::cerr << "Inheritance preference" << clazz << ":" << data.preferred_parent
167+
std::cerr << "Inheritance preference " << clazz << ":" << data.preferred_parent
168168
<< " cannot be fulfilled as there is no such inheritance. "
169-
<< "Inheritance from class "
170-
<< clang_getCursorType(data.first_parent) << " is mapped into "
171-
<< " Julia.\n";
169+
<< "Super type of " << clazz << " will be "
170+
<< clang_getCursorType(data.first_parent) << " in Julia.\n";
172171
data.c = data.first_parent;
173172
}
174173
}

test/TestInheritance/A.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct A1{
1313

1414
struct A2{
1515
int f2() { return 2; }
16+
virtual ~A2(){}
1617
};
1718

1819
struct B: public A1, A2, C {
@@ -21,11 +22,18 @@ struct B: public A1, A2, C {
2122
std::string real_func(){ return std::string("B::real_func()"); }
2223
};
2324

25+
struct B2: public A1, A2, C {
26+
int f7(){ return 7; }
27+
};
28+
2429
struct E: public D {
2530
int f6(){ return 6; }
2631
};
2732

2833
A1* new_B(){
2934
return new B();
30-
}
35+
};
3136

37+
struct F: public A1{
38+
int f7(){ return 7;}
39+
};

test/TestInheritance/TestInheritance.wit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ cxx-std = "c++17"
99

1010
# all generated code in a single file:
1111
n_classes_per_file = 0
12+
13+
# test inheritance map
14+
inheritances = [ "B2:A2", "F:" ]

test/TestInheritance/runTestInheritance.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ function runtest()
2424
s = TestInheritance.String("Hello")
2525
s_with_underscore = f(s)
2626
@test s_with_underscore == s * "_"
27+
28+
@test supertype(TestInheritance.F) == Any
29+
@test f7(TestInheritance.F()) == 7
30+
31+
@test supertype(TestInheritance.B2) == TestInheritance.A2
32+
@test f2(TestInheritance.B2()) == 2
2733
end
2834
end
2935

test/WrapitTestSetup.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ endif()
6868

6969
if("${CXXWRAP_REQUESTED_VERSION}" STREQUAL "")
7070
execute_process(
71-
COMMAND ${JULIA} --project=${CMAKE_BINARY_DIR} -e "import Pkg; Pkg.add(\"CxxWrap\"); Pkg.resolve(); import CxxWrap; print(pkgversion(CxxWrap));"
71+
#note: we don't use Pkg.pkgversion because it is not supported for Julia < 1.9
72+
COMMAND ${JULIA} --project=${CMAKE_BINARY_DIR} -e "import Pkg,TOML; Pkg.add(\"CxxWrap\"); Pkg.resolve(); import CxxWrap; print(TOML.parsefile(joinpath(pkgdir(CxxWrap), \"Project.toml\"))[\"version\"]);"
7273
OUTPUT_VARIABLE CXXWRAP_INSTALLED_VERSION
7374
RESULT_VARIABLE result
7475
)
@@ -78,7 +79,8 @@ if("${CXXWRAP_REQUESTED_VERSION}" STREQUAL "")
7879
message(STATUS ${WRAPIT})
7980
else()
8081
execute_process(
81-
COMMAND ${JULIA} --project=${CMAKE_BINARY_DIR} -e "import Pkg; Pkg.add(name=\"CxxWrap\", version=\"${CXXWRAP_REQUESTED_VERSION}\"); Pkg.resolve(); import CxxWrap; print(pkgversion(CxxWrap));"
82+
#note: we don't use Pkg.pkgversion because it is not supported for Julia < 1.9
83+
COMMAND ${JULIA} --project=${CMAKE_BINARY_DIR} -e "import Pkg, TOML; Pkg.add(name=\"CxxWrap\", version=\"${CXXWRAP_REQUESTED_VERSION}\"); Pkg.resolve(); import CxxWrap; print(TOML.parsefile(joinpath(pkgdir(CxxWrap), \"Project.toml\"))[\"version\"]);"
8284
OUTPUT_VARIABLE CXXWRAP_INSTALLED_VERSION
8385
RESULT_VARIABLE result)
8486
endif()

test/make.rules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ WRAPIT = $(shell which wrapit)
1616
WIT_FILE = $(MODULE_NAME).wit
1717

1818
ifeq ($(CXXWRAP_VERSION),)
19-
CXXWRAP_PREFIX=$(shell mkdir -p $(BUILD_DIR); julia --project=$(BUILD_DIR) -e "import Pkg; Pkg.add(\"CxxWrap\"); Pkg.resolve(); import CxxWrap; print(CxxWrap.prefix_path())")
20-
CXXWRAP_VERSION=$(shell julia -e "import CxxWrap; print(pkgversion(CxxWrap));")
19+
CXXWRAP_PREFIX:=$(shell mkdir -p $(BUILD_DIR); julia --project=$(BUILD_DIR) -e "import Pkg; Pkg.add(\"CxxWrap\"); Pkg.resolve(); import CxxWrap; print(CxxWrap.prefix_path())")
20+
CXXWRAP_VERSION:=$(shell julia --project=$(BUILD_DIR) -e "import CxxWrap,TOML; print(TOML.parsefile(joinpath(pkgdir(CxxWrap), \"Project.toml\"))[\"version\"]);")
2121
WRAPIT_OPT=--add-cfg cxxwrap_version=\"$(CXXWRAP_VERSION)\"
2222
else
23-
CXXWRAP_PREFIX=$(shell mkdir -p $(BUILD_DIR); julia --project=$(BUILD_DIR) -e "import Pkg; Pkg.add(name=\"CxxWrap\", version=\"$(CXXWRAP_VERSION)\"); Pkg.resolve(); import CxxWrap; print(CxxWrap.prefix_path())")
23+
CXXWRAP_PREFIX:=$(shell mkdir -p $(BUILD_DIR); julia --project=$(BUILD_DIR) -e "import Pkg; Pkg.add(name=\"CxxWrap\", version=\"$(CXXWRAP_VERSION)\"); Pkg.resolve(); import CxxWrap; print(CxxWrap.prefix_path())")
2424
endif
2525

2626
WRAPIT_PRODUCTS+=jl$(MODULE_NAME).cxx

0 commit comments

Comments
 (0)