From aabf0866d6f62ad8fa45c4213268e15d8a44d22b Mon Sep 17 00:00:00 2001 From: saumyaj3 Date: Wed, 9 Oct 2024 12:42:09 +0200 Subject: [PATCH] Update version numbers and add commit hash support Updated version numbers across various files to "0.2.1". Added commit hash retrieval and binding for better tracking of builds. NP-349 --- CMakeLists.txt | 15 +++++++++++---- DulcificumJS/cpp/DulcificumJS.cpp | 20 +++++++++++++++++++- DulcificumJS/package-lock.json | 4 ++-- DulcificumJS/package.json | 2 +- DulcificumJS/src/index.ts | 7 +++++++ conanfile.py | 10 ++++++++++ include/dulcificum.h | 2 +- pyDulcificum/pyDulcificum.cpp | 4 ++-- 8 files changed, 53 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92f622a..58c28b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,18 +8,21 @@ option(WITH_APPS "Build with apps" ON) option(WITH_JS_BINDINGS "Build with JavaScript Emscripten bindings" OFF) if(WITH_APPS) - set(APP_VERSION "0.1.0" CACHE STRING "Version of the translator app" ) + set(APP_VERSION "0.2.1" CACHE STRING "Version of the translator app" ) message(STATUS "Configuring translator app version: ${APP_VERSION}") endif () option(WITH_PYTHON_BINDINGS "Build with Python bindings: `pyDulcificum`" ON) if(WITH_PYTHON_BINDINGS) - set(PYDULCIFICUM_VERSION "0.1.0" CACHE STRING "Version of the pyDulcificum python bindings" ) + set(PYDULCIFICUM_VERSION "0.2.1" CACHE STRING "Version of the pyDulcificum python bindings" ) message(STATUS "Configuring pyDulcificum version: ${PYDULCIFICUM_VERSION}") endif () -set(DULCIFICUM_VERSION "0.1.0" CACHE STRING "Version of the dulcificum library" ) +if(NOT DEFINED DULCIFICUM_VERSION) + message(FATAL_ERROR "DULCIFICUM_VERSION is not defined!") +endif() message(STATUS "Configuring Dulcificum version: ${DULCIFICUM_VERSION}") +message(STATUS "Configuring Dulcificum hash: ${GIT_COMMIT_HASH}") find_package(nlohmann_json REQUIRED) find_package(spdlog REQUIRED) @@ -52,7 +55,11 @@ target_include_directories(dulcificum $ ) -target_compile_definitions(dulcificum PRIVATE DULCIFICUM_VERSION="${DULCIFICUM_VERSION}") +target_compile_definitions(dulcificum + PUBLIC + DULCIFICUM_VERSION="${DULCIFICUM_VERSION}" + DULCIFICUM_HASH="${GIT_COMMIT_HASH}" +) if (NOT WITH_JS_BINDINGS) use_threads(dulcificum) diff --git a/DulcificumJS/cpp/DulcificumJS.cpp b/DulcificumJS/cpp/DulcificumJS.cpp index b4ecfd4..e254b7e 100644 --- a/DulcificumJS/cpp/DulcificumJS.cpp +++ b/DulcificumJS/cpp/DulcificumJS.cpp @@ -1,7 +1,25 @@ #include #include +struct info_t +{ + std::string dulcificum_version; + std::string dulcificum_hash; +}; + +info_t get_info() +{ + return { DULCIFICUM_VERSION, DULCIFICUM_HASH }; +} + EMSCRIPTEN_BINDINGS(dulcificum) { emscripten::function("gcode_2_miracle_jtp", &dulcificum::GCode2Miracle_JTP); -} \ No newline at end of file + // Binding for info_t structure + emscripten::value_object("info_t") + .field("dulcificum_version", &info_t::dulcificum_version) + .field("dulcificum_hash", &info_t::dulcificum_hash); + + // Binding for get_info function + emscripten::function("dulcificum_info", &get_info); +} diff --git a/DulcificumJS/package-lock.json b/DulcificumJS/package-lock.json index 0fe3735..25f968b 100644 --- a/DulcificumJS/package-lock.json +++ b/DulcificumJS/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ultimaker/dulcificumjs", - "version": "0.1.0-alpha.6", + "version": "0.1.0-alpha.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@ultimaker/dulcificumjs", - "version": "0.1.0-alpha.6", + "version": "0.1.0-alpha.8", "dependencies": { "emscripten": "^0.0.2-beta" }, diff --git a/DulcificumJS/package.json b/DulcificumJS/package.json index 0bbefba..22f00e2 100644 --- a/DulcificumJS/package.json +++ b/DulcificumJS/package.json @@ -1,6 +1,6 @@ { "name": "@ultimaker/dulcificumjs", - "version": "0.1.0-alpha.7", + "version": "0.1.0-alpha.8", "description": "DulcificumJS is a TS component to run Dulcificum in a browser", "main": "dist/index.js", "scripts": { diff --git a/DulcificumJS/src/index.ts b/DulcificumJS/src/index.ts index 01ca2a9..a83a812 100644 --- a/DulcificumJS/src/index.ts +++ b/DulcificumJS/src/index.ts @@ -18,3 +18,10 @@ export function gcode_2_miracle_jtp(input: string): string { } return mod.gcode_2_miracle_jtp(input); } + +export function dulcificum_info(): dulcificum.info_t { + if (mod == null) { + return { dulcificum_version: "", dulcificum_hash: "" }; + } + return mod.dulcificum_info(); +} diff --git a/conanfile.py b/conanfile.py index a2ef945..75c5579 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,4 +1,5 @@ import os +import subprocess from conan import ConanFile from conan.errors import ConanInvalidConfiguration @@ -129,6 +130,7 @@ def generate(self): tc.variables["ENABLE_TESTS"] = self._run_tests tc.variables["EXTENSIVE_WARNINGS"] = self.options.enable_extensive_warnings tc.variables["DULCIFICUM_VERSION"] = self.version + tc.variables["GIT_COMMIT_HASH"] = self._get_git_commit_hash() tc.variables["WITH_APPS"] = self.options.with_apps if self.options.with_apps: @@ -176,6 +178,14 @@ def generate(self): if len(dep.cpp_info.bindirs) > 0: copy(self, "*.dll", dep.cpp_info.bindirs[0], os.path.join(self.build_folder, "tests")) + def _get_git_commit_hash(self): + try: + result = subprocess.run(["git", "rev-parse", "HEAD"], cwd=self.recipe_folder, capture_output=True, + check=True, text=True) + return result.stdout.strip() + except subprocess.CalledProcessError: + return "unknown" + def build(self): cmake = CMake(self) cmake.configure() diff --git a/include/dulcificum.h b/include/dulcificum.h index cd3665b..c734dcb 100644 --- a/include/dulcificum.h +++ b/include/dulcificum.h @@ -3,7 +3,7 @@ #include #ifndef DULCIFICUM_VERSION -#define DULCIFICUM_VERSION "0.1.0" +#define DULCIFICUM_VERSION "0.2.1" #endif #include "dulcificum/gcode/gcode_to_command.h" diff --git a/pyDulcificum/pyDulcificum.cpp b/pyDulcificum/pyDulcificum.cpp index a9174be..a37a5ca 100644 --- a/pyDulcificum/pyDulcificum.cpp +++ b/pyDulcificum/pyDulcificum.cpp @@ -6,7 +6,7 @@ #include #ifndef PYDULCIFICUM_VERSION -#define PYDULCIFICUM_VERSION "0.1.0" +#define PYDULCIFICUM_VERSION "0.2.1" #endif namespace py = pybind11; @@ -44,4 +44,4 @@ PYBIND11_MODULE(pyDulcificum, module) "Writes a given string to a file."); module.def("gcode_2_miracle_jtp", &dulcificum::GCode2Miracle_JTP, "Converts GGode to Miracle JSON Toolpaths", py::arg("content")); -} \ No newline at end of file +}