Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
grasph committed Jan 21, 2025
1 parent 14eb9a6 commit 2c86cf3
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
9 changes: 4 additions & 5 deletions src/CodeTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ CodeTree::getParentClassForWrapper(CXCursor cursor) const{
}
//FIXME: handling of parent namespace?
if(data.preferred_parent.size() == 0
|| str(clang_getTypeSpelling(clang_getCursorType(data.c)))
|| str(clang_getTypeSpelling(clang_getCursorType(cursor)))
== data.preferred_parent){
data.c = cursor;
}
Expand All @@ -164,11 +164,10 @@ CodeTree::getParentClassForWrapper(CXCursor cursor) const{
clang_visitChildren(cursor, visitor, &data);

if(clang_Cursor_isNull(data.c) && !clang_Cursor_isNull(data.first_parent)){
std::cerr << "Inheritance preference" << clazz << ":" << data.preferred_parent
std::cerr << "Inheritance preference " << clazz << ":" << data.preferred_parent
<< " cannot be fulfilled as there is no such inheritance. "
<< "Inheritance from class "
<< clang_getCursorType(data.first_parent) << " is mapped into "
<< " Julia.\n";
<< "Super type of " << clazz << " will be "
<< clang_getCursorType(data.first_parent) << " in Julia.\n";
data.c = data.first_parent;
}
}
Expand Down
10 changes: 9 additions & 1 deletion test/TestInheritance/A.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct A1{

struct A2{
int f2() { return 2; }
virtual ~A2(){}
};

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

struct B2: public A1, A2, C {
int f7(){ return 7; }
};

struct E: public D {
int f6(){ return 6; }
};

A1* new_B(){
return new B();
}
};

struct F: public A1{
int f7(){ return 7;}
};
3 changes: 3 additions & 0 deletions test/TestInheritance/TestInheritance.wit
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ cxx-std = "c++17"

# all generated code in a single file:
n_classes_per_file = 0

# test inheritance map
inheritances = [ "B2:A2", "F:" ]
6 changes: 6 additions & 0 deletions test/TestInheritance/runTestInheritance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ function runtest()
s = TestInheritance.String("Hello")
s_with_underscore = f(s)
@test s_with_underscore == s * "_"

@test supertype(TestInheritance.F) == Any
@test f7(TestInheritance.F()) == 7

@test supertype(TestInheritance.B2) == TestInheritance.A2
@test f2(TestInheritance.B2()) == 2
end
end

Expand Down
6 changes: 4 additions & 2 deletions test/WrapitTestSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ endif()

if("${CXXWRAP_REQUESTED_VERSION}" STREQUAL "")
execute_process(
COMMAND ${JULIA} --project=${CMAKE_BINARY_DIR} -e "import Pkg; Pkg.add(\"CxxWrap\"); Pkg.resolve(); import CxxWrap; print(pkgversion(CxxWrap));"
#note: we don't use Pkg.pkgversion because it is not supported for Julia < 1.9
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\"]);"
OUTPUT_VARIABLE CXXWRAP_INSTALLED_VERSION
RESULT_VARIABLE result
)
Expand All @@ -78,7 +79,8 @@ if("${CXXWRAP_REQUESTED_VERSION}" STREQUAL "")
message(STATUS ${WRAPIT})
else()
execute_process(
COMMAND ${JULIA} --project=${CMAKE_BINARY_DIR} -e "import Pkg; Pkg.add(name=\"CxxWrap\", version=\"${CXXWRAP_REQUESTED_VERSION}\"); Pkg.resolve(); import CxxWrap; print(pkgversion(CxxWrap));"
#note: we don't use Pkg.pkgversion because it is not supported for Julia < 1.9
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\"]);"
OUTPUT_VARIABLE CXXWRAP_INSTALLED_VERSION
RESULT_VARIABLE result)
endif()
Expand Down
6 changes: 3 additions & 3 deletions test/make.rules
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ WRAPIT = $(shell which wrapit)
WIT_FILE = $(MODULE_NAME).wit

ifeq ($(CXXWRAP_VERSION),)
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())")
CXXWRAP_VERSION=$(shell julia -e "import CxxWrap; print(pkgversion(CxxWrap));")
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())")
CXXWRAP_VERSION:=$(shell julia --project=$(BUILD_DIR) -e "import CxxWrap,TOML; print(TOML.parsefile(joinpath(pkgdir(CxxWrap), \"Project.toml\"))[\"version\"]);")
WRAPIT_OPT=--add-cfg cxxwrap_version=\"$(CXXWRAP_VERSION)\"
else
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())")
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())")
endif

WRAPIT_PRODUCTS+=jl$(MODULE_NAME).cxx
Expand Down

0 comments on commit 2c86cf3

Please sign in to comment.