From f73159e35a4b992a0f156bef6213d7fa103275c0 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 23 Jul 2020 19:04:21 +0200 Subject: [PATCH 1/2] Set version of Netgen globally (for archives), interface to get version --- libsrc/core/CMakeLists.txt | 1 + libsrc/core/archive.cpp | 20 +------------------- libsrc/core/archive.hpp | 6 ------ libsrc/core/python_ngcore.hpp | 4 ++-- libsrc/core/version.cpp | 29 +++++++++++++++++++++++++++++ libsrc/core/version.hpp | 8 ++++++++ 6 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 libsrc/core/version.cpp diff --git a/libsrc/core/CMakeLists.txt b/libsrc/core/CMakeLists.txt index f0f07399..16c43a82 100644 --- a/libsrc/core/CMakeLists.txt +++ b/libsrc/core/CMakeLists.txt @@ -11,6 +11,7 @@ add_library(ngcore SHARED table.cpp taskmanager.cpp utils.cpp + version.cpp ) # Pybind11 2.3 Issue https://github.com/pybind/pybind11/issues/1604 diff --git a/libsrc/core/archive.cpp b/libsrc/core/archive.cpp index 5d968b6c..448b8f47 100644 --- a/libsrc/core/archive.cpp +++ b/libsrc/core/archive.cpp @@ -1,6 +1,6 @@ #include "archive.hpp" -#include +#include "version.hpp" #ifndef WIN32 #include @@ -8,18 +8,6 @@ namespace ngcore { - // clang-tidy should ignore this static object - static std::map library_versions; // NOLINT - std::map& Archive :: GetLibraryVersions() - { - return library_versions; - } - const VersionInfo& GetLibraryVersion(const std::string& library) - { return library_versions[library]; } - - void SetLibraryVersion(const std::string& library, const VersionInfo& version) - { library_versions[library] = version; } - // clang-tidy should ignore this static object static std::unique_ptr> type_register; // NOLINT const detail::ClassArchiveInfo& Archive :: GetArchiveRegister(const std::string& classname) @@ -45,10 +33,4 @@ namespace ngcore std::make_unique>(); return type_register->count(classname) != 0; } - - - static bool dummy = [](){ - SetLibraryVersion("netgen", NETGEN_VERSION); - return true; - }(); } // namespace ngcore diff --git a/libsrc/core/archive.hpp b/libsrc/core/archive.hpp index 22019302..ad4d5676 100644 --- a/libsrc/core/archive.hpp +++ b/libsrc/core/archive.hpp @@ -30,9 +30,6 @@ namespace pybind11 namespace ngcore { - // Libraries using this archive can store their version here to implement backwards compatibility - NGCORE_API const VersionInfo& GetLibraryVersion(const std::string& library); - NGCORE_API void SetLibraryVersion(const std::string& library, const VersionInfo& version); class NGCORE_API Archive; @@ -570,9 +567,6 @@ namespace ngcore virtual void FlushBuffer() {} - protected: - static std::map& GetLibraryVersions(); - private: template friend class RegisterClassForArchive; diff --git a/libsrc/core/python_ngcore.hpp b/libsrc/core/python_ngcore.hpp index a8ef5755..6bedabf9 100644 --- a/libsrc/core/python_ngcore.hpp +++ b/libsrc/core/python_ngcore.hpp @@ -230,7 +230,6 @@ namespace ngcore using ARCHIVE::stream; using ARCHIVE::version_map; using ARCHIVE::logger; - using ARCHIVE::GetLibraryVersions; public: PyArchive(const pybind11::object& alst = pybind11::none()) : ARCHIVE(std::make_shared()), @@ -275,10 +274,11 @@ namespace ngcore pybind11::list WriteOut() { + auto version_runtime = GetLibraryVersions(); FlushBuffer(); lst.append(pybind11::bytes(std::static_pointer_cast(stream)->str())); stream = std::make_shared(); - *this & GetLibraryVersions(); + *this & version_runtime; FlushBuffer(); lst.append(pybind11::bytes(std::static_pointer_cast(stream)->str())); stream = std::make_shared(); diff --git a/libsrc/core/version.cpp b/libsrc/core/version.cpp new file mode 100644 index 00000000..546abbf7 --- /dev/null +++ b/libsrc/core/version.cpp @@ -0,0 +1,29 @@ +#include + +#include +#include "exception.hpp" +#include "version.hpp" + +namespace ngcore +{ + // clang-tidy should ignore this static object + static std::map library_versions; // NOLINT + + const VersionInfo& GetLibraryVersion(const std::string& library) + { return library_versions[library]; } + + const std::map& GetLibraryVersions() + { return library_versions; } + + void SetLibraryVersion(const std::string& library, const VersionInfo& version) + { + if(library_versions.count(library) && (library_versions[library] != version)) + throw Exception("Failed to set library version for " + library + " to " + version.to_string() + ": version already set to " + library_versions[library].to_string()); + library_versions[library] = version; + } + + static bool dummy = [](){ + SetLibraryVersion("netgen", NETGEN_VERSION); + return true; + }(); +} // namespace ngcore diff --git a/libsrc/core/version.hpp b/libsrc/core/version.hpp index aea50bf6..3048ce5b 100644 --- a/libsrc/core/version.hpp +++ b/libsrc/core/version.hpp @@ -80,6 +80,10 @@ namespace ngcore return mayor_ == other.mayor_ && minor_ == other.minor_ && release == other.release && patch == other.patch; } + bool operator !=(const VersionInfo& other) const + { + return !(*this==other); + } bool operator >(const VersionInfo& other) const { return other < (*this); } bool operator <=(const VersionInfo& other) const { return !((*this) > other); } bool operator >=(const VersionInfo& other) const { return !((*this) < other); } @@ -89,6 +93,10 @@ namespace ngcore { return ost << version.to_string(); } + + NGCORE_API const VersionInfo& GetLibraryVersion(const std::string& library); + NGCORE_API const std::map& GetLibraryVersions(); + NGCORE_API void SetLibraryVersion(const std::string& library, const VersionInfo& version); } // namespace ngcore #endif // NETGEN_CORE_VERSION_HPP From 3305d1101a9df24b9a2aba331e9b45009abc0dfc Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 23 Jul 2020 19:04:36 +0200 Subject: [PATCH 2/2] Store Netgen version in generated mesh files --- libsrc/meshing/meshclass.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index 703109a1..ea30e5f6 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -435,6 +435,7 @@ namespace netgen int inverttets = 0; // globflags.GetDefineFlag ("inverttets"); int invertsurf = 0; // globflags.GetDefineFlag ("invertsurfacemesh"); + outfile << "# Generated by NETGEN " << GetLibraryVersion("netgen") << endl << endl; outfile << "mesh3d" << "\n";