diff --git a/doc/config.md b/doc/config.md index 603749f..c543662 100644 --- a/doc/config.md +++ b/doc/config.md @@ -112,6 +112,19 @@ fields_and_variables = true # given class. # inheritances = [ "" ] + +# List of customized C++-to-Julia name mapping. Each element of the list must +# be a string with format -> . +# +# E. g., ["TDirectoryFile::Get -> Get_", "TDirectory::Get -> Get_" ] will +# request to name `Get_` the Julia bindings to the `Get` methods of C++ classes +# `TDirectoryFile` and `TDirectory`. +# +# This feature is useful to customize a julia binding: changing the name +# of a function, for instance by appending an underscore as in the above +# example, allows the implementation in Julia of a wrapper with the original +# function name, that can make the required customization. +julia_names = [ ] ``` ### Extra options for the julia module code generation diff --git a/src/CodeTree.cpp b/src/CodeTree.cpp index 8f30ef2..ab3f87b 100644 --- a/src/CodeTree.cpp +++ b/src/CodeTree.cpp @@ -843,7 +843,7 @@ CodeTree::generate_accessor_cxx(std::ostream& o, const TypeRcd* type_rcd, const CXCursor& cursor, bool getter_only, int nindents){ - FunctionWrapper helper(MethodRcd(cursor), type_rcd, type_map_, + FunctionWrapper helper(cxx_to_julia_, MethodRcd(cursor), type_rcd, type_map_, cxxwrap_version_, "", "", nindents); int ngens = 0; @@ -971,7 +971,7 @@ CodeTree::method_cxx_decl(std::ostream& o, const MethodRcd& method, TypeRcd* pTypeRcd = find_class_of_method(method.cursor); - FunctionWrapper wrapper(method, pTypeRcd, type_map_, cxxwrap_version_, varname, + FunctionWrapper wrapper(cxx_to_julia_, method, pTypeRcd, type_map_, cxxwrap_version_, varname, classname, nindents, templated); //FIXME: check that code below is needed. Should now be vetoed upstream @@ -1278,7 +1278,7 @@ CodeTree::visit_global_function(CXCursor cursor){ } - FunctionWrapper wrapper(MethodRcd(cursor), nullptr, type_map_, cxxwrap_version_); + FunctionWrapper wrapper(cxx_to_julia_, MethodRcd(cursor), nullptr, type_map_, cxxwrap_version_); if(in_veto_list(wrapper.signature())){ // if(std::find(veto_list_.begin(), veto_list_.end(), wrapper.signature()) != veto_list_.end()){ if(verbose > 0){ @@ -1732,7 +1732,7 @@ CodeTree::visit_member_function(CXCursor cursor){ TypeRcd* pTypeRcd = find_class_of_method(cursor); - FunctionWrapper wrapper(MethodRcd(cursor), pTypeRcd, type_map_, cxxwrap_version_); + FunctionWrapper wrapper(cxx_to_julia_, MethodRcd(cursor), pTypeRcd, type_map_, cxxwrap_version_); if(in_veto_list(wrapper.signature())){ // if(std::find(veto_list_.begin(), veto_list_.end(), wrapper.signature()) != veto_list_.end()){ @@ -1830,8 +1830,8 @@ CodeTree::inform_missing_types(std::vector missing_types, }; if(verbose > 0){ - std::string funcname = FunctionWrapper(methodRcd, classRcd, type_map_, - cxxwrap_version_).signature(); + std::string funcname = FunctionWrapper(cxx_to_julia_, methodRcd, classRcd, + type_map_, cxxwrap_version_).signature(); std::cerr << "Warning: missing definition of type " << (missing_types.size() > 1 ? "s" : "") << " " @@ -1930,7 +1930,7 @@ CodeTree::visit_class_constructor(CXCursor cursor){ TypeRcd* pTypeRcd = find_class_of_method(cursor); - FunctionWrapper wrapper(MethodRcd(cursor), pTypeRcd, type_map_, + FunctionWrapper wrapper(cxx_to_julia_, MethodRcd(cursor), pTypeRcd, type_map_, cxxwrap_version_); if(in_veto_list(wrapper.signature())){ @@ -3031,3 +3031,15 @@ void CodeTree::generate_project_file(std::ostream& o, "CxxWrap = \"" << version_int_to_string(cxxwrap_version_, version_depth) << "\"\n"; } + +void CodeTree::set_julia_names(const std::vector& name_map){ + cxx_to_julia_.clear(); + std::regex re("\\s*->\\s"); + for(const std::string& m: name_map){ + std::sregex_token_iterator it{m.begin(), m.end(), re, -1}; + std::vector tokens{it, {}}; + if(tokens.size() > 1){ + cxx_to_julia_[tokens[0]] = tokens[1]; + } + } +} diff --git a/src/CodeTree.h b/src/CodeTree.h index 7e81f7a..96d757f 100644 --- a/src/CodeTree.h +++ b/src/CodeTree.h @@ -18,6 +18,7 @@ #include #include #include +#include //#include "Entity.h" #include "TypeRcd.h" @@ -82,7 +83,7 @@ namespace codetree{ std::vector files_to_wrap_; std::vector files_to_wrap_fullpaths_; std::vector wrapped_methods_; - + int n_classes_per_file_; std::string out_cxx_dir_; std::string out_jl_dir_; @@ -275,6 +276,8 @@ namespace codetree{ void set_force_mode(bool forced){ out_open_mode_ = forced ? std::ios_base::out : std::ios_base::app; } + void set_julia_names(const std::vector& name_map); + protected: enum class accessor_mode_t {none, getter, both }; @@ -463,6 +466,7 @@ namespace codetree{ bool is_natively_supported(const std::string& type_fqn, int* nparams = nullptr) const; + private: std::string clang_resource_dir_; @@ -476,6 +480,8 @@ namespace codetree{ std::string header_file_path_; + std::map cxx_to_julia_; + std::string module_name_; std::ios_base::openmode out_open_mode_; diff --git a/src/FunctionWrapper.cpp b/src/FunctionWrapper.cpp index e0b1ac2..0534253 100644 --- a/src/FunctionWrapper.cpp +++ b/src/FunctionWrapper.cpp @@ -480,13 +480,15 @@ FunctionWrapper::arg_decl(int iarg, bool argtypes_only) const{ } -FunctionWrapper::FunctionWrapper(const MethodRcd& method, +FunctionWrapper::FunctionWrapper(const std::map& name_map, + const MethodRcd& method, const TypeRcd* pTypeRcd, const TypeMapper& type_map, long cxxwrap_version, std::string varname, std::string classname, int nindents, bool templated): method(method), + // name_map_(name_map), varname_(varname), classname(classname), cxxwrap_version_(cxxwrap_version), @@ -528,8 +530,6 @@ FunctionWrapper::FunctionWrapper(const MethodRcd& method, name_cxx = fully_qualified_name(cursor); } - std::string name_jl_suffix = jl_type_name(name_cxx); - is_static_ = clang_Cursor_getStorageClass(cursor) == CX_SC_Static; if(name_cxx == "operator new" || name_cxx == "operator delete" @@ -540,38 +540,35 @@ FunctionWrapper::FunctionWrapper(const MethodRcd& method, varname_ = is_static_ ? "module_" : "t"; } - static std::regex opregex("(^|.*::)operator[[:space:]]*(.*)$"); - std::cmatch m; override_base_ = false; //number of args including the implicit "this" //of non-statis method int noperands = clang_getNumArgTypes(method_type); if((this->classname.size()) != 0 && !is_static_) noperands += 1; - - if(std::regex_match(name_cxx.c_str(), m, opregex)){ - name_jl_suffix = m[2]; - } - - //FIXME: check that julia = operator is not already mapped to c++ operator= - //by CxxWrap. In that case we won't need to define an assign function - if(name_jl_suffix == "="){ - name_jl_suffix = "assign"; - } - if(name_jl_suffix == "*" && noperands == 1){ - name_jl_suffix = "getindex"; //Deferencing operator, *x -> x[] - override_base_ = true; - } - - if(name_jl_suffix == "[]"){ - name_jl_suffix = "getindex"; - override_base_ = true; + +//-------- + + auto full_name = class_prefix + name_cxx; + auto it = name_map.find(full_name); + + std::string name_jl_suffix; + if(it != name_map.end()){ //custom name mapping + name_jl_suffix = it->second; + if(verbose > 0){ + std::cerr << "Info name mapping: " << full_name << " mapped to " << name_jl_ << "\n"; + } + } else{// automatic name mapping + if(verbose > 4){ + std::cerr << "Info name mapping: no name customization for " << full_name + << ", standard naming rules will be used.\n"; + } + name_jl_suffix = get_name_jl_suffix(name_cxx, noperands); } - if(name_jl_suffix == "+"){ - //Base.+ can take an arbitrary number of arguments - //including zero, case that corrsponds to the prefix operator + + if(name_jl_suffix == "getindex" || name_jl_suffix == "+"){ override_base_ = true; } @@ -584,8 +581,8 @@ FunctionWrapper::FunctionWrapper(const MethodRcd& method, } static std::vector infix_base_ops = { "-", "*", "/", - "%", "[]", "&", "|", "^", ">>", ">>>", "<<", ">", "<", "<=", ">=", - "==", "!=", "<=>"}; + "%", "[]", "&", "|", "xor", ">>", ">>>", "<<", ">", "<", "<=", ">=", + "==", "!=", "cmp"}; if(noperands == 2 && std::find(infix_base_ops.begin(), infix_base_ops.end(), @@ -593,42 +590,19 @@ FunctionWrapper::FunctionWrapper(const MethodRcd& method, override_base_ = true; } - //TODO map cast operator to convert - //T A::operator R(); - - //C++ -> Julia operation name map for operators65;6203;1c - //When not in the list, operatorOP() is mapped to Base.OP() - std::vector> op_map = { - {"()", "paren"}, - {"+=", "add!"}, - {"-=", "sub!"}, - {"*=", "mult!"}, - {"/=", "fdiv!"}, - {"%=", "rem!"}, - {"^=", "xor!"}, - {"|=", "or!"}, - {"&=", "and!"}, - {"<<=", "lshit!"}, - {">>=", "rshit!"}, - {"^", "xor"}, - {"->", "arrow"}, - {"->*", "arrowstar"}, - {",", "comma"}, - {"<=>", "cmp"}, - {"--", "dec!"}, - {"++", "inc!"}, - {"&&", "logicaland"},//&& and ||, to which short-circuit evalution is applied - {"||", "logicalor"},//cannot be overloaded in Julia. - }; - - for(const auto& m: op_map){ - if(name_jl_suffix == m.first){ - name_jl_suffix = m.second; + if(is_static_){ + if(templated_){ + name_jl_ = jl_type_name(pTypeRcd->type_name + "::") + name_jl_suffix; + } else{ + name_jl_ = jl_type_name(class_prefix) + name_jl_suffix; } + } else{ + //FIXME: Add prefix. The namespace? + name_jl_ = name_jl_suffix; } - + + setindex_ = getindex_ = false; - if(name_cxx == "operator[]"){ getindex_ = true; @@ -637,17 +611,6 @@ FunctionWrapper::FunctionWrapper(const MethodRcd& method, setindex_ = true; } } - - if(is_static_){ - if(templated_){ - name_jl_ = jl_type_name(pTypeRcd->type_name + "::") + name_jl_suffix; - } else{ - name_jl_ = jl_type_name(class_prefix) + name_jl_suffix; - } - } else{ - //FIXME: Add prefix. The namespace? - name_jl_ = name_jl_suffix; - } bool argtype_mapped; build_arg_lists(argtype_mapped); @@ -789,3 +752,68 @@ std::string FunctionWrapper::fix_template_type(std::string type_name) const{ return fixed; } + +std::string FunctionWrapper::get_name_jl_suffix(const std::string& cxx_name, + int noperands) const{ + auto name_jl_suffix = jl_type_name(name_cxx); + + + static std::regex opregex("(^|.*::)operator[[:space:]]*(.*)$"); + std::cmatch m; + + if(std::regex_match(name_cxx.c_str(), m, opregex)){ + name_jl_suffix = m[2]; + } + + //FIXME: check that julia = operator is not already mapped to c++ operator= + //by CxxWrap. In that case we won't need to define an assign function + if(name_jl_suffix == "="){ + name_jl_suffix = "assign"; + } + + if(name_jl_suffix == "*" && noperands == 1){ + name_jl_suffix = "getindex"; //Deferencing operator, *x -> x[] + } + + if(name_jl_suffix == "getindex"){ + name_jl_suffix = "getindex"; + } + + if(name_jl_suffix == "+"){ + //Base.+ can take an arbitrary number of arguments + //including zero, case that corrsponds to the prefix operator + } + + + //C++ -> Julia operation name map for operators + //When not in the list, operatorOP() is mapped to Base.OP() + std::vector> op_map = { + {"()", "paren"}, + {"+=", "add!"}, + {"-=", "sub!"}, + {"*=", "mult!"}, + {"/=", "fdiv!"}, + {"%=", "rem!"}, + {"^=", "xor!"}, + {"|=", "or!"}, + {"&=", "and!"}, + {"<<=", "lshit!"}, + {">>=", "rshit!"}, + {"^", "xor"}, + {"->", "arrow"}, + {"->*", "arrowstar"}, + {",", "comma"}, + {"<=>", "cmp"}, + {"--", "dec!"}, + {"++", "inc!"}, + {"&&", "logicaland"},//&& and ||, to which short-circuit evalution is applied + {"||", "logicalor"},//cannot be overloaded in Julia. + }; + + for(const auto& m: op_map){ + if(name_jl_suffix == m.first){ + name_jl_suffix = m.second; + } + } + return name_jl_suffix; +} diff --git a/src/FunctionWrapper.h b/src/FunctionWrapper.h index 76c70f1..f74c076 100644 --- a/src/FunctionWrapper.h +++ b/src/FunctionWrapper.h @@ -11,7 +11,7 @@ #include "TypeRcd.h" #include #include - +#include class TypeMapper; @@ -26,7 +26,8 @@ class TypeMapper; // class FunctionWrapper{ public: - FunctionWrapper(const MethodRcd& method, + FunctionWrapper(const std::map& name_map, + const MethodRcd& method, const TypeRcd* pTypeRcd, const TypeMapper& type_mapper, long cxxwrap_version, @@ -134,6 +135,9 @@ class FunctionWrapper{ std::string arg_decl(int iarg, bool argtype_only) const; + std::string get_name_jl_suffix(const std::string& cxx_name, + int noperands) const; + private: long cxxwrap_version_; @@ -148,6 +152,7 @@ class FunctionWrapper{ CXCursor cursor; CXType method_type; + // std::map name_map_; CXType return_type_; bool is_variadic; const TypeRcd* pTypeRcd; diff --git a/src/main.cpp b/src/main.cpp index a519d94..44e3229 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "toml.hpp" using namespace std::string_view_literals; @@ -86,7 +87,7 @@ void append_to_table(toml::table& dest, toml::table& src){ int main(int argc, char* argv[]){ - srand(time(nullptr)); + srand(time(nullptr) ^ ~getpid()); cxxopts::Options option_list("wrapit", "Generates wrappers from a c++ header file for Cxx.jl.\n"); @@ -244,7 +245,7 @@ int main(int argc, char* argv[]){ auto n_classes_per_file = toml_config["n_classes_per_file"].value_or(-1); - + auto julia_names = read_vstring("julia_names"); auto veto_list = toml_config["veto_list"].value_or(""sv); @@ -375,6 +376,8 @@ int main(int argc, char* argv[]){ tree.set_cxxwrap_version(cxxwrap_version); + tree.set_julia_names(julia_names); + tree.add_std_option(cxx_std); tree.auto_veto(auto_veto); diff --git a/src/uuid_utils.cpp b/src/uuid_utils.cpp index 933045e..5befae2 100644 --- a/src/uuid_utils.cpp +++ b/src/uuid_utils.cpp @@ -1,6 +1,6 @@ #include "uuid_utils.h" - #include + std::string gen_uuid(){ const char* v = "0123456789abcdef"; //3fb17ebc-bc38-4939-bc8b-74f2443281d4 @@ -9,6 +9,7 @@ std::string gen_uuid(){ s.resize(36); for(int i = 0; i < 36; ++i) { if(i != 8 && i != 13 && i != 18 && i != 23){ + //s[i] = v[arc4random()%16]; //not working on Ubuntu, requires to install an extra package s[i] = v[rand()%16]; } else{ s[i] = '-'; diff --git a/test/TestAccessAndDelete/TestAccessAndDelete.wit b/test/TestAccessAndDelete/TestAccessAndDelete.wit index f8148e2..860b17c 100644 --- a/test/TestAccessAndDelete/TestAccessAndDelete.wit +++ b/test/TestAccessAndDelete/TestAccessAndDelete.wit @@ -1,4 +1,5 @@ module_name = "TestAccessAndDelete" +uuid = "b84a21c7-7db1-4fd8-bb99-b65182dd0d09" include_dirs = [ "." ] @@ -10,5 +11,3 @@ export = "all" # all generated code in a single file: n_classes_per_file = 0 - -#cxxwrap_version = "0.15.0" diff --git a/test/TestAccessAndDelete/runTestAccessAndDelete.jl b/test/TestAccessAndDelete/runTestAccessAndDelete.jl index 8b5e003..b171c28 100644 --- a/test/TestAccessAndDelete/runTestAccessAndDelete.jl +++ b/test/TestAccessAndDelete/runTestAccessAndDelete.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestAccessAndDelete") using TestAccessAndDelete diff --git a/test/TestAutoAdd/TestAutoAdd.wit b/test/TestAutoAdd/TestAutoAdd.wit index 3045e07..0165c2d 100644 --- a/test/TestAutoAdd/TestAutoAdd.wit +++ b/test/TestAutoAdd/TestAutoAdd.wit @@ -1,4 +1,5 @@ module_name = "TestAutoAdd" +uuid = "21166305-f8c1-4e69-baf1-f0db5e7eeaa1" include_dirs = [ "." ] diff --git a/test/TestAutoAdd/runTestAutoAdd.jl b/test/TestAutoAdd/runTestAutoAdd.jl index 126ab82..2b3dff7 100644 --- a/test/TestAutoAdd/runTestAutoAdd.jl +++ b/test/TestAutoAdd/runTestAutoAdd.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestAutoAdd") using TestAutoAdd diff --git a/test/TestCtorDefVal/TestCtorDefVal.wit b/test/TestCtorDefVal/TestCtorDefVal.wit index 5996c59..839d889 100644 --- a/test/TestCtorDefVal/TestCtorDefVal.wit +++ b/test/TestCtorDefVal/TestCtorDefVal.wit @@ -1,4 +1,5 @@ module_name = "TestCtorDefVal" +uuid = "6adbae56-dcac-43a4-a141-f1a93695edd0" include_dirs = [ "." ] diff --git a/test/TestCtorDefVal/runTestCtorDefVal.jl b/test/TestCtorDefVal/runTestCtorDefVal.jl index 9d709a0..46035a3 100644 --- a/test/TestCtorDefVal/runTestCtorDefVal.jl +++ b/test/TestCtorDefVal/runTestCtorDefVal.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestCtorDefVal") using TestCtorDefVal diff --git a/test/TestEmptyClass/TestEmptyClass.wit b/test/TestEmptyClass/TestEmptyClass.wit index 0c11d85..00597e9 100644 --- a/test/TestEmptyClass/TestEmptyClass.wit +++ b/test/TestEmptyClass/TestEmptyClass.wit @@ -1,4 +1,5 @@ module_name = "TestEmptyClass" +uuid = "2f673fc7-f88b-4edc-83bf-90277445a7d5" include_dirs = [ "." ] diff --git a/test/TestEmptyClass/runTestEmptyClass.jl b/test/TestEmptyClass/runTestEmptyClass.jl index e1434a6..61864fb 100644 --- a/test/TestEmptyClass/runTestEmptyClass.jl +++ b/test/TestEmptyClass/runTestEmptyClass.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestEmptyClass") using TestEmptyClass diff --git a/test/TestEnum/TestEnum.wit b/test/TestEnum/TestEnum.wit index 8bae44d..ebde26a 100644 --- a/test/TestEnum/TestEnum.wit +++ b/test/TestEnum/TestEnum.wit @@ -1,4 +1,5 @@ module_name="TestEnum" +uuid = "28eb9369-de4c-45bd-ac6f-8997959d6fdf" input = [ "A.h" ] diff --git a/test/TestEnum/runTestEnum.jl b/test/TestEnum/runTestEnum.jl index 01b795e..db09421 100644 --- a/test/TestEnum/runTestEnum.jl +++ b/test/TestEnum/runTestEnum.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestEnum") using TestEnum diff --git a/test/TestIncompleteArray/TestIncompleteArray.wit b/test/TestIncompleteArray/TestIncompleteArray.wit index 0c48c99..0aeb89c 100644 --- a/test/TestIncompleteArray/TestIncompleteArray.wit +++ b/test/TestIncompleteArray/TestIncompleteArray.wit @@ -1,4 +1,5 @@ module_name = "TestIncompleteArray" +uuid = "ccef8bff-c5fb-42fc-a1e7-2ad4b6b12870" include_dirs = [ "." ] diff --git a/test/TestInheritance/TestInheritance.wit b/test/TestInheritance/TestInheritance.wit index d3e165c..212a3bf 100644 --- a/test/TestInheritance/TestInheritance.wit +++ b/test/TestInheritance/TestInheritance.wit @@ -1,10 +1,10 @@ module_name = "TestInheritance" +uuid = "e64be293-bed8-4ae4-84f8-1bc3a2c4f291" include_dirs = [ "." ] input = [ "A.h", "D.h", "MyString.h" ] - cxx-std = "c++17" # all generated code in a single file: diff --git a/test/TestInheritance/runTestInheritance.jl b/test/TestInheritance/runTestInheritance.jl index 4bbcfef..7f81b89 100644 --- a/test/TestInheritance/runTestInheritance.jl +++ b/test/TestInheritance/runTestInheritance.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestInheritance") using TestInheritance diff --git a/test/TestNamespace/TestNamespace.wit b/test/TestNamespace/TestNamespace.wit index 67db44f..1d6b194 100644 --- a/test/TestNamespace/TestNamespace.wit +++ b/test/TestNamespace/TestNamespace.wit @@ -1,4 +1,5 @@ module_name="TestNamespace" +uuid = "9105eb7d-8b5e-4e93-a689-47fa8b474c60" input = [ "A.h" ] diff --git a/test/TestNamespace/runTestNamespace.jl b/test/TestNamespace/runTestNamespace.jl index 550b508..abb39df 100644 --- a/test/TestNamespace/runTestNamespace.jl +++ b/test/TestNamespace/runTestNamespace.jl @@ -3,7 +3,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestNamespace") using TestNamespace diff --git a/test/TestNoFinalizer/TestNoFinalizer.wit b/test/TestNoFinalizer/TestNoFinalizer.wit index 1fcd381..9dd4a95 100644 --- a/test/TestNoFinalizer/TestNoFinalizer.wit +++ b/test/TestNoFinalizer/TestNoFinalizer.wit @@ -1,4 +1,5 @@ module_name = "TestNoFinalizer" +uuid = "9b3b33f9-5f5a-4340-99f2-99014b361dcb" include_dirs = [ "." ] diff --git a/test/TestNoFinalizer/runTestNoFinalizer.jl b/test/TestNoFinalizer/runTestNoFinalizer.jl index 9f2ed56..23416a1 100644 --- a/test/TestNoFinalizer/runTestNoFinalizer.jl +++ b/test/TestNoFinalizer/runTestNoFinalizer.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestNoFinalizer") using TestNoFinalizer diff --git a/test/TestOperators/TestOperators.wit b/test/TestOperators/TestOperators.wit index 63e214e..ff59898 100644 --- a/test/TestOperators/TestOperators.wit +++ b/test/TestOperators/TestOperators.wit @@ -1,4 +1,5 @@ module_name = "TestOperators" +uuid = "eac3d17b-fe75-474e-abb4-ffee6697f022" include_dirs = [ "." ] diff --git a/test/TestOperators/runTestOperators.jl b/test/TestOperators/runTestOperators.jl index 0573c69..e99664f 100644 --- a/test/TestOperators/runTestOperators.jl +++ b/test/TestOperators/runTestOperators.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestOperators") using TestOperators diff --git a/test/TestOrder/TestOrder.wit b/test/TestOrder/TestOrder.wit index a8fef4d..7a441a8 100644 --- a/test/TestOrder/TestOrder.wit +++ b/test/TestOrder/TestOrder.wit @@ -1,4 +1,5 @@ module_name = "TestOrder" +uuid = "ebb94d09-d965-41ab-bedb-1b43446a2abc" include_dirs = [ "." ] diff --git a/test/TestOrder/runTestOrder.jl b/test/TestOrder/runTestOrder.jl index 06621b7..c97e5cd 100644 --- a/test/TestOrder/runTestOrder.jl +++ b/test/TestOrder/runTestOrder.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestOrder") if "-s" in ARGS #Serialize mode diff --git a/test/TestPointers/TestPointers.wit b/test/TestPointers/TestPointers.wit index 4103175..fd79b7d 100644 --- a/test/TestPointers/TestPointers.wit +++ b/test/TestPointers/TestPointers.wit @@ -1,4 +1,5 @@ module_name = "TestPointers" +uuid = "349e78bd-0c7e-4b4e-b557-74e6dbc0705f" include_dirs = [ "." ] diff --git a/test/TestPointers/runTestPointers.jl b/test/TestPointers/runTestPointers.jl index ddce675..3fe8383 100644 --- a/test/TestPointers/runTestPointers.jl +++ b/test/TestPointers/runTestPointers.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestPointers") using TestPointers diff --git a/test/TestPropagation/Makefile b/test/TestPropagation/Makefile index 7b28fe8..71a1b72 100644 --- a/test/TestPropagation/Makefile +++ b/test/TestPropagation/Makefile @@ -10,7 +10,7 @@ LDFLAGS += $(shell $(JL_SHARE)/julia-config.jl --ldflags) LDLIBS += $(shell $(JL_SHARE)/julia-config.jl --ldlibs) -CXXWRAP_PREFIX=$(shell julia -e 'import Pkg; haskey(Pkg.dependencies(), Base.UUID("1f15a43c-97ca-5a2a-ae31-89f07a497df4")) || Pkg.add("CxxWrap"); using CxxWrap; print(CxxWrap.prefix_path())') +CXXWRAP_PREFIX:=$(shell julia --project=${BUILD_DIR} -e 'import Pkg; haskey(Pkg.dependencies(), Base.UUID("1f15a43c-97ca-5a2a-ae31-89f07a497df4")) || Pkg.add("CxxWrap"); using CxxWrap; print(CxxWrap.prefix_path())') CXXWRAP_VERSION:=$(shell julia --project=${BUILD_DIR} -e "import CxxWrap; print(pkgversion(CxxWrap));") WRAPIT_OPT=--add-cfg cxxwrap_version=\"$(CXXWRAP_VERSION)\" diff --git a/test/TestPropagation/TestPropagation1.wit b/test/TestPropagation/TestPropagation1.wit index a806e37..63f1ec1 100644 --- a/test/TestPropagation/TestPropagation1.wit +++ b/test/TestPropagation/TestPropagation1.wit @@ -1,4 +1,5 @@ module_name="TestPropagation1" +uuid = "dcafd7d8-bc61-4afa-8d46-2a065f56244d" propagation_mode = "types" diff --git a/test/TestPropagation/TestPropagation2.wit b/test/TestPropagation/TestPropagation2.wit index f9003d9..0a63502 100644 --- a/test/TestPropagation/TestPropagation2.wit +++ b/test/TestPropagation/TestPropagation2.wit @@ -1,4 +1,5 @@ module_name="TestPropagation2" +uuid = "9d9b0f37-9d0a-4dc4-a44d-0b7f029205ea" propagation_mode = "types" diff --git a/test/TestPropagation/TestPropagation3.wit b/test/TestPropagation/TestPropagation3.wit index 49581ea..e01c709 100644 --- a/test/TestPropagation/TestPropagation3.wit +++ b/test/TestPropagation/TestPropagation3.wit @@ -1,4 +1,5 @@ module_name="TestPropagation3" +uuid = "ac2b7bf6-f4d9-4534-bf49-445754912cc0" propagation_mode = "methods" diff --git a/test/TestPropagation/runTestPropagation1.jl b/test/TestPropagation/runTestPropagation1.jl index 1438f3c..c84581f 100644 --- a/test/TestPropagation/runTestPropagation1.jl +++ b/test/TestPropagation/runTestPropagation1.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestPropagation1") import TestPropagation1 diff --git a/test/TestPropagation/runTestPropagation2.jl b/test/TestPropagation/runTestPropagation2.jl index 066b8b0..0598f23 100644 --- a/test/TestPropagation/runTestPropagation2.jl +++ b/test/TestPropagation/runTestPropagation2.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestPropagation2") import TestPropagation2 diff --git a/test/TestPropagation/runTestPropagation3.jl b/test/TestPropagation/runTestPropagation3.jl index cfdb675..5da97c6 100644 --- a/test/TestPropagation/runTestPropagation3.jl +++ b/test/TestPropagation/runTestPropagation3.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestPropagation3") import TestPropagation3 diff --git a/test/TestSizet/TestSizet.wit b/test/TestSizet/TestSizet.wit index 0852a65..7f46134 100644 --- a/test/TestSizet/TestSizet.wit +++ b/test/TestSizet/TestSizet.wit @@ -1,4 +1,5 @@ module_name = "TestSizet" +uuid = "2c12789d-13f2-429a-adac-3a38cadcc931" include_dirs = [ "." ] diff --git a/test/TestSizet/runTestSizet.jl b/test/TestSizet/runTestSizet.jl index 7ee9a21..b971ced 100644 --- a/test/TestSizet/runTestSizet.jl +++ b/test/TestSizet/runTestSizet.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestSizet") using TestSizet diff --git a/test/TestStdString/TestStdString.wit b/test/TestStdString/TestStdString.wit index 232e741..79c8f7f 100644 --- a/test/TestStdString/TestStdString.wit +++ b/test/TestStdString/TestStdString.wit @@ -1,4 +1,5 @@ module_name = "TestStdString" +uuid = "0f352689-3a91-449f-b356-09037dc0014d" include_dirs = [ "." ] @@ -10,3 +11,7 @@ export = "all" # all generated code in a single file: n_classes_per_file = 0 + +# not working with CxxWrap 0.16 on MacOS and with 0.15 on both Linux and MacOS +# forcing version to 0.14 +cxxwrap_version = "0.14" diff --git a/test/TestStdString/runTestStdString.jl b/test/TestStdString/runTestStdString.jl index 0a29000..2b9e6c0 100644 --- a/test/TestStdString/runTestStdString.jl +++ b/test/TestStdString/runTestStdString.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestStdString") using TestStdString diff --git a/test/TestStdVector/TestStdVector.wit b/test/TestStdVector/TestStdVector.wit index 76a3f3c..f53a5ef 100644 --- a/test/TestStdVector/TestStdVector.wit +++ b/test/TestStdVector/TestStdVector.wit @@ -1,4 +1,5 @@ module_name = "TestStdVector" +uuid = "e3f6a139-b70f-4986-83d9-6831a1366ac5" include_dirs = [ "." ] @@ -10,8 +11,10 @@ export = "all" fields_and_variables = false -# Currently not working with CxxWrap 0.15.0, use 0.14.x -cxxwrap_version = "0.14" - # all generated code in a single file: #n_classes_per_file = 0 + +# not working with CxxWrap 0.16 on MacOS and with 0.15 on both Linux and MacOS +# forcing version to 0.14 +cxxwrap_version = "0.14" + diff --git a/test/TestStdVector/runTestStdVector.jl b/test/TestStdVector/runTestStdVector.jl index 8815574..6ac6721 100644 --- a/test/TestStdVector/runTestStdVector.jl +++ b/test/TestStdVector/runTestStdVector.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestStdVector") using TestStdVector diff --git a/test/TestStringView/TestStringView.wit b/test/TestStringView/TestStringView.wit index 308f626..4424659 100644 --- a/test/TestStringView/TestStringView.wit +++ b/test/TestStringView/TestStringView.wit @@ -1,4 +1,5 @@ module_name = "TestStringView" +uuid = "e57441ec-fdf1-4fed-8052-68b2b6ada888" include_dirs = [ "." ] diff --git a/test/TestStringView/runTestStringView.jl b/test/TestStringView/runTestStringView.jl index b32ea23..c3e608b 100644 --- a/test/TestStringView/runTestStringView.jl +++ b/test/TestStringView/runTestStringView.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestStringView") using TestStringView diff --git a/test/TestTemplate1/TestTemplate1.wit b/test/TestTemplate1/TestTemplate1.wit index 148ee8e..eaa427b 100644 --- a/test/TestTemplate1/TestTemplate1.wit +++ b/test/TestTemplate1/TestTemplate1.wit @@ -1,4 +1,5 @@ module_name="TestTemplate1" +uuid = "75b462a2-300d-4e17-8fef-26b5867f20b8" input = [ "A.h" ] diff --git a/test/TestTemplate1/runTestTemplate1.jl b/test/TestTemplate1/runTestTemplate1.jl index 18a13f3..4e6f96a 100644 --- a/test/TestTemplate1/runTestTemplate1.jl +++ b/test/TestTemplate1/runTestTemplate1.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path=joinpath(@__DIR__, "build", "TestTemplate1")) using TestTemplate1 diff --git a/test/TestTemplate2/TestTemplate2.wit b/test/TestTemplate2/TestTemplate2.wit index 546af4c..3cf5b0b 100644 --- a/test/TestTemplate2/TestTemplate2.wit +++ b/test/TestTemplate2/TestTemplate2.wit @@ -1,4 +1,5 @@ module_name = "TestTemplate2" +uuid = "f6352dd4-e1f8-479c-b32e-3de4d6ebae5d" input = [ "A.h" ] diff --git a/test/TestTemplate2/runTestTemplate2.jl b/test/TestTemplate2/runTestTemplate2.jl index 8a596f0..46e0eef 100644 --- a/test/TestTemplate2/runTestTemplate2.jl +++ b/test/TestTemplate2/runTestTemplate2.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestTemplate2") using TestTemplate2 diff --git a/test/TestUsingType/TestUsingType.wit b/test/TestUsingType/TestUsingType.wit index 1ff991b..cb84941 100644 --- a/test/TestUsingType/TestUsingType.wit +++ b/test/TestUsingType/TestUsingType.wit @@ -1,4 +1,5 @@ module_name = "TestUsingType" +uuid = "0ba2e2b8-09e1-4537-a510-6ba872e04e29" include_dirs = [ "." ] @@ -12,10 +13,9 @@ export = "all" auto_veto = true -# Currently not working with CxxWrap 0.15.0, use 0.14.x -cxxwrap_version = "0.14" - - # all generated code in a single file: n_classes_per_file = 0 +# not working with CxxWrap 0.16 on MacOS +# forcing version to 0.14 +cxxwrap_version = "0.14" diff --git a/test/TestUsingType/runTestUsingType.jl b/test/TestUsingType/runTestUsingType.jl index 32de2a2..4a4d5aa 100644 --- a/test/TestUsingType/runTestUsingType.jl +++ b/test/TestUsingType/runTestUsingType.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestUsingType") using TestUsingType diff --git a/test/TestVarField/TestVarFieldOff.wit b/test/TestVarField/TestVarFieldOff.wit index 94d3c87..3bee44f 100644 --- a/test/TestVarField/TestVarFieldOff.wit +++ b/test/TestVarField/TestVarFieldOff.wit @@ -1,4 +1,5 @@ module_name = "TestVarFieldOff" +uuid = "d452198e-6ce7-4520-8180-a0cb7a6fd7a6" input = [ "A.h" ] diff --git a/test/TestVarField/TestVarFieldOn.wit b/test/TestVarField/TestVarFieldOn.wit index a523aad..4d6a8de 100644 --- a/test/TestVarField/TestVarFieldOn.wit +++ b/test/TestVarField/TestVarFieldOn.wit @@ -1,4 +1,5 @@ module_name = "TestVarFieldOn" +uuid = "dd714936-ccd5-4eb9-b517-eb27dc33182c" input = [ "A.h" ] @@ -13,4 +14,4 @@ n_classes_per_file = 0 fields_and_variables = true -auto_veto = false \ No newline at end of file +auto_veto = false diff --git a/test/TestVarField/runTestVarFieldOff.jl b/test/TestVarField/runTestVarFieldOff.jl index 41c209b..c0e174d 100644 --- a/test/TestVarField/runTestVarFieldOff.jl +++ b/test/TestVarField/runTestVarFieldOff.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestVarFieldOff") using TestVarFieldOff diff --git a/test/TestVarField/runTestVarFieldOn.jl b/test/TestVarField/runTestVarFieldOn.jl index 229070a..4ddba6f 100644 --- a/test/TestVarField/runTestVarFieldOn.jl +++ b/test/TestVarField/runTestVarFieldOn.jl @@ -2,7 +2,7 @@ using Test using Serialization import Pkg -Pkg.activate(;temp=true) +Pkg.activate("$(@__DIR__)/build") Pkg.develop(path="$(@__DIR__)/build/TestVarFieldOn") using TestVarFieldOn diff --git a/test/WrapitTestSetup.cmake b/test/WrapitTestSetup.cmake index 6e5261c..c8241f0 100644 --- a/test/WrapitTestSetup.cmake +++ b/test/WrapitTestSetup.cmake @@ -68,7 +68,7 @@ endif() if("${CXXWRAP_REQUESTED_VERSION}" STREQUAL "") execute_process( - COMMAND ${JULIA} --project=${CMAKE_BINARY_DIR} -e "import Pkg; Pkg.add(\"CxxWrap\"); import CxxWrap; print(pkgversion(CxxWrap));" + COMMAND ${JULIA} --project=${CMAKE_BINARY_DIR} -e "import Pkg; Pkg.add(\"CxxWrap\"); Pkg.resolve(); import CxxWrap; print(pkgversion(CxxWrap));" OUTPUT_VARIABLE CXXWRAP_INSTALLED_VERSION RESULT_VARIABLE result ) @@ -78,7 +78,7 @@ if("${CXXWRAP_REQUESTED_VERSION}" STREQUAL "") message(STATUS ${WRAPIT}) else() execute_process( - COMMAND ${JULIA} --project=${CMAKE_BINARY_DIR} -e "import Pkg; import CxxWrap; Pkg.add(name=\"CxxWrap\", version=\"${CXXWRAP_REQUESTED_VERSION}\"); Pkg.resolve(); print(pkgversion(CxxWrap));" + COMMAND ${JULIA} --project=${CMAKE_BINARY_DIR} -e "import Pkg; Pkg.add(name=\"CxxWrap\", version=\"${CXXWRAP_REQUESTED_VERSION}\"); Pkg.resolve(); import CxxWrap; print(pkgversion(CxxWrap));" OUTPUT_VARIABLE CXXWRAP_INSTALLED_VERSION RESULT_VARIABLE result) endif() diff --git a/test/runtests.jl b/test/runtests.jl index 9a2be04..a8f2337 100755 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,10 +8,10 @@ tests = [ "TestSizet", "TestCtorDefVal", "TestAccessAndDelete", "TestNoFinalizer "TestOrder", "TestAutoAdd" ] -#Switch to test examples +# Switch to test examples testExamples = true -#List of test can also be specified on the command line +# List of test can also be specified on the command line if length(ARGS) > 0 tests = replace.(filter(x->x ≠ "examples", ARGS), r"/$" => "") if length(ARGS) == length(tests) @@ -19,9 +19,13 @@ if length(ARGS) > 0 end end -#Number of CPU cores to use to compile the code +# Number of CPU cores to use to compile the code ncores=Sys.CPU_THREADS +# Clean the module load path for spwaneed julia process to reduce test dependency +# on the installation the test is run on (remove "@#.#") +ENV["LOAD_PATH"] = "@:@stdlib" + @testset verbose=true "Tests" begin for t in tests @testset "$t" begin @@ -35,6 +39,7 @@ ncores=Sys.CPU_THREADS #cmake based build # Configure and build with CMake run(`cmake --fresh -S $source_dir -B $build_dir`) + run(`cmake --build $build_dir -t clean`) run(`cmake --build $build_dir -j $ncores`) else println("source_dir:", source_dir)