From 2c86cf3d33f65055836cb4a600daf24b960229db Mon Sep 17 00:00:00 2001 From: Philippe Gras Date: Tue, 21 Jan 2025 23:43:23 +0100 Subject: [PATCH] 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. --- src/CodeTree.cpp | 9 ++++----- test/TestInheritance/A.h | 10 +++++++++- test/TestInheritance/TestInheritance.wit | 3 +++ test/TestInheritance/runTestInheritance.jl | 6 ++++++ test/WrapitTestSetup.cmake | 6 ++++-- test/make.rules | 6 +++--- 6 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/CodeTree.cpp b/src/CodeTree.cpp index ab3f87b..3e1e6f2 100644 --- a/src/CodeTree.cpp +++ b/src/CodeTree.cpp @@ -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; } @@ -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; } } diff --git a/test/TestInheritance/A.h b/test/TestInheritance/A.h index 50294b4..bfedbff 100644 --- a/test/TestInheritance/A.h +++ b/test/TestInheritance/A.h @@ -13,6 +13,7 @@ struct A1{ struct A2{ int f2() { return 2; } + virtual ~A2(){} }; struct B: public A1, A2, C { @@ -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;} +}; diff --git a/test/TestInheritance/TestInheritance.wit b/test/TestInheritance/TestInheritance.wit index 212a3bf..9d7067a 100644 --- a/test/TestInheritance/TestInheritance.wit +++ b/test/TestInheritance/TestInheritance.wit @@ -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:" ] \ No newline at end of file diff --git a/test/TestInheritance/runTestInheritance.jl b/test/TestInheritance/runTestInheritance.jl index 7f81b89..e611144 100644 --- a/test/TestInheritance/runTestInheritance.jl +++ b/test/TestInheritance/runTestInheritance.jl @@ -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 diff --git a/test/WrapitTestSetup.cmake b/test/WrapitTestSetup.cmake index c8241f0..5036baa 100644 --- a/test/WrapitTestSetup.cmake +++ b/test/WrapitTestSetup.cmake @@ -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 ) @@ -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() diff --git a/test/make.rules b/test/make.rules index 23c5073..d06604e 100644 --- a/test/make.rules +++ b/test/make.rules @@ -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