diff --git a/.gitignore b/.gitignore index 306c9d2f5409bdf2a003e63b795885f268af391a..a14ac887e7f573d4e37d483bf9b33e7de42970e6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,11 @@ -# general +# general .cache # C++ Build build*/ install*/ cppcheck-result.xml +include/aidge/core_version.h # VSCode .vscode diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a1dc22b43ce8326e295f2dce3db52c98c07d2d7..62051da26211a3dc54f12dc34bd14ab66a0883b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,17 +3,29 @@ set(CXX_STANDARD 14) file(STRINGS "${CMAKE_SOURCE_DIR}/version.txt" version) +# Parse version.txt to retrieve Major, Minor and Path +string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" _ MATCHES ${version}) +set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1}) +set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2}) +set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_3}) + +# Retrieve latest git commit +execute_process( + COMMAND git rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET +) + project(aidge_core VERSION ${version} DESCRIPTION "Core algorithms for operators and graph of the AIDGE framework" LANGUAGES CXX) -message(STATUS "Project name: ${CMAKE_PROJECT_NAME}") -message(STATUS "Project version: ${version}") -add_definitions(-DPROJECT_VERSION="${version}") message(STATUS "Project name: ${CMAKE_PROJECT_NAME}") message(STATUS "Project version: ${version}") - +message(STATUS "Latest git commit: ${GIT_COMMIT_HASH}") # helper for LSP users set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -29,7 +41,6 @@ option(TEST "Enable tests" ON) option(COVERAGE "Enable coverage" OFF) option(ENABLE_ASAN "Enable ASan (AddressSanitizer) for runtime analysis of memory use (over/underflow, memory leak, ...)" OFF) - ############################################## # Import utils CMakeLists set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") @@ -168,6 +179,13 @@ if(NOT $ENV{AIDGE_INSTALL} STREQUAL "") message(WARNING "CMAKE_INSTALL_PREFIX set to env variable AIDGE_INSTALL by default = ${CMAKE_INSTALL_PREFIX}") endif() +message(STATUS "Creating ${CMAKE_CURRENT_SOURCE_DIR}/include/aidge/core_version.h") +# Generate version.h file from config file version.h.in +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/include/aidge/version.h.in" + "${CMAKE_CURRENT_SOURCE_DIR}/include/aidge/core_version.h" +) + include(GNUInstallDirs) set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${CMAKE_PROJECT_NAME}) diff --git a/aidge_core/__init__.py b/aidge_core/__init__.py index 32042125ed6ecb1d935e240837afe6516706dbcb..0832de2c472d15e2ce1667cae66e4f09303a5add 100644 --- a/aidge_core/__init__.py +++ b/aidge_core/__init__.py @@ -13,4 +13,3 @@ import aidge_core.utils from aidge_core.aidge_export_aidge import serialize_to_cpp from aidge_core.show_graphview import gview_to_json from aidge_core.mem_info import * -from ._version import * diff --git a/include/aidge/aidge.hpp b/include/aidge/aidge.hpp index a06202696951a888284f1e0a50b6c25b677fe7f3..d65a46378c01b070d998b72d5d2e272b7d8f7def 100644 --- a/include/aidge/aidge.hpp +++ b/include/aidge/aidge.hpp @@ -11,6 +11,7 @@ #ifndef AIDGE_IMPORTS_H_ #define AIDGE_IMPORTS_H_ +#include "aidge/core_version.h" #include "aidge/backend/OperatorImpl.hpp" #include "aidge/backend/TensorImpl.hpp" @@ -92,5 +93,6 @@ #include "aidge/utils/Random.hpp" #include "aidge/utils/Registrar.hpp" #include "aidge/utils/Types.h" +#include "aidge/utils/sys_info/CoreVersionInfo.hpp" #endif /* AIDGE_IMPORTS_H_ */ diff --git a/include/aidge/utils/sys_info/CoreVersionInfo.hpp b/include/aidge/utils/sys_info/CoreVersionInfo.hpp new file mode 100644 index 0000000000000000000000000000000000000000..648998ede84a886315be9f26dfde68e7abddd345 --- /dev/null +++ b/include/aidge/utils/sys_info/CoreVersionInfo.hpp @@ -0,0 +1,37 @@ +#ifndef AIDGE_UTILS_SYS_INFO_CORE_VERSION_INFO_H +#define AIDGE_UTILS_SYS_INFO_CORE_VERSION_INFO_H + +#include "aidge/utils/Log.hpp" +#include "aidge/core_version.h" + +namespace Aidge { + +constexpr inline const char * getCoreProjectVersion(){ + return PROJECT_VERSION; +} + +constexpr inline const char * getCoreGitHash(){ + return PROJECT_GIT_HASH; +} + +void showCoreVersion() { + Log::info("Aidge core: {} ({}), {} {}", getCoreProjectVersion(), getCoreGitHash(), __DATE__, __TIME__); + // Compiler version + #if defined(__clang__) + /* Clang/LLVM. ---------------------------------------------- */ + Log::info("Clang/LLVM compiler version: {}.{}.{}\n", __clang_major__ , __clang_minor__, __clang_patchlevel__); + #elif defined(__ICC) || defined(__INTEL_COMPILER) + /* Intel ICC/ICPC. ------------------------------------------ */ + Log::info("Intel ICC/ICPC compiler version: {}\n", __INTEL_COMPILER); + #elif defined(__GNUC__) || defined(__GNUG__) + /* GNU GCC/G++. --------------------------------------------- */ + Log::info("GNU GCC/G++ compiler version: {}.{}.{}", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); + #elif defined(_MSC_VER) + /* Microsoft Visual Studio. --------------------------------- */ + Log::info("Microsoft Visual Studio compiler version: {}\n", _MSC_VER); + #else + Log::info("Unknown compiler\n"); + #endif +} +} // namespace Aidge +#endif // AIDGE_UTILS_SYS_INFO_CORE_VERSION_INFO_H diff --git a/include/aidge/version.h.in b/include/aidge/version.h.in new file mode 100644 index 0000000000000000000000000000000000000000..4b876f63002972c1f8f1340b70cdecdace911012 --- /dev/null +++ b/include/aidge/version.h.in @@ -0,0 +1,11 @@ +#ifndef VERSION_H +#define VERSION_H + +namespace Aidge { +static constexpr const int PROJECT_VERSION_MAJOR = @PROJECT_VERSION_MAJOR@; +static constexpr const int PROJECT_VERSION_MINOR = @PROJECT_VERSION_MINOR@; +static constexpr const int PROJECT_VERSION_PATCH = @PROJECT_VERSION_PATCH@; +static constexpr const char * PROJECT_VERSION = "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@"; +static constexpr const char * PROJECT_GIT_HASH = "@GIT_COMMIT_HASH@"; +} +#endif // VERSION_H diff --git a/pyproject.toml b/pyproject.toml index b838aca5ee100d182ba88b79f23f3a2ebff9acf3..c5c8a0600dda804ce13dfb8d4c6874ae967e87e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,6 @@ [project] -name = "aidge_core" +name="aidge_core" + description="Core algorithms for operators and graph of the AIDGE framework" dependencies = [ "numpy>=1.21.6", @@ -8,11 +9,18 @@ dependencies = [ requires-python = ">= 3.7" readme = "README.md" license = { file = "LICENSE" } -classifiers = [ +classifiers = [ "Development Status :: 2 - Pre-Alpha", "Programming Language :: Python :: 3" ] -dynamic = ["version"] # defined in tool.setuptools_scm +dynamic = ["version"] # defined by pbr + +[project.urls] +Homepage = "https://www.deepgreen.ai/en/platform" +Documentation = "https://eclipse-aidge.readthedocs.io/en/latest/" +Repository = "https://gitlab.eclipse.org/eclipse/aidge/aidge_core" +Issues = "https://gitlab.eclipse.org/eclipse/aidge/aidge_core/-/issues/" +Changelog = "https://gitlab.eclipse.org/eclipse/aidge/aidge_core/-/releases" [project.optional-dependencies] test = [ @@ -22,8 +30,8 @@ test = [ [build-system] requires = [ "setuptools>=64", - "setuptools_scm[toml]==7.1.0", - "cmake>=3.18.4.post1" + "cmake>=3.18.4.post1", + "pbr" ] build-backend = "setuptools.build_meta" @@ -40,11 +48,7 @@ exclude = [ # exclude packages matching these glob patterns (empty by default) ".unit_tests.static", ".aidge_export_aidge.__pycache__", ".aidge_export_aidge.utils.__pycache__", -] - -# SETUPTOOLS_SCM -[tool.setuptools_scm] -write_to = "aidge_core/_version.py" +] ##################################################### # CIBUILDWHEEL diff --git a/python_binding/pybind_core.cpp b/python_binding/pybind_core.cpp index f572c024d3cf69a1a06cd9be3e60cc7106fccfe3..eccbebd2f0db7fd45484f114e4ae3dea8b2e5451 100644 --- a/python_binding/pybind_core.cpp +++ b/python_binding/pybind_core.cpp @@ -16,6 +16,7 @@ namespace py = pybind11; namespace Aidge { +void init_CoreSysInfo(py::module&); void init_Random(py::module&); void init_Data(py::module&); void init_Database(py::module&); @@ -104,6 +105,7 @@ void init_TensorUtils(py::module&); void init_Filler(py::module&); void init_Aidge(py::module& m) { + init_CoreSysInfo(m); init_Random(m); init_Data(m); diff --git a/python_binding/utils/sys_info/pybind_CoreVersionInfo.cpp b/python_binding/utils/sys_info/pybind_CoreVersionInfo.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b498e86ed31adad57de4dbd57fa8f358b188f499 --- /dev/null +++ b/python_binding/utils/sys_info/pybind_CoreVersionInfo.cpp @@ -0,0 +1,11 @@ +#include <pybind11/pybind11.h> +#include "aidge/utils/sys_info/CoreVersionInfo.hpp" + +namespace py = pybind11; +namespace Aidge { +void init_CoreSysInfo(py::module& m){ + m.def("show_version", &showCoreVersion); + m.def("get_project_version", &getCoreProjectVersion); + m.def("get_git_hash", &getCoreGitHash); +} +} diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000000000000000000000000000000000000..bd90e50b282a1e1c08e0b2acaaddae940b0b4ac5 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +# pbr file +[metadata] +name = file: project_name.txt +version = file: version.txt diff --git a/setup.py b/setup.py index 4f2e21711f193eb7d5c37ace7b5ad83ac63d3635..2fb84a991e416c41da709845f44c1cd6042a278d 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,11 @@ from setuptools import setup, Extension from setuptools.command.build_ext import build_ext -PROJECT_NAME = "aidge_core" +def get_project_name() -> str: + return open(pathlib.Path().absolute() / "project_name.txt", "r").read().strip() + + +PROJECT_NAME = get_project_name() SETUP_DIR = pathlib.Path(__file__).parent