diff --git a/CLAUDE.md b/CLAUDE.md index ebd7180..780c99f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -184,8 +184,11 @@ WASM target configured with `-DNAJA_SCHEMATIC_WASM_MODULE=ON` (single file, wasm inlined, `createNajaSchematic({canvas, ...})` factory, one instance per canvas), built by `.github/workflows/python-package.yml`, which also tests the wheel and publishes it to PyPI on a `v` tag (version in -`naja_schematic/__init__.py`). For local work set `NAJA_SCHEMATIC_BUNDLE` to -a locally built bundle (see `_bundle.py`). Tests: `pytest python/tests`. +`naja_schematic/__init__.py`, the project's single version: `CMakeLists.txt` +also reads it into `NAJA_SCHEMATIC_VERSION_STRING` for the C++ app's About +dialog, so a release is one edit plus a tag). For local work set +`NAJA_SCHEMATIC_BUNDLE` to a locally built bundle (see `_bundle.py`). Tests: +`pytest python/tests`. ## Architecture diff --git a/CMakeLists.txt b/CMakeLists.txt index c0e7d5a..24a8d3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,21 @@ else() endif() message(STATUS "naja-schematic commit: ${NAJA_SCHEMATIC_GIT_HASH}") +# ------------------------------------------------------------ +# naja-schematic version: single source of truth is the Python package's +# __version__ (what hatch builds the wheel from and CI checks the release +# tag against), so the app's About dialog can't drift from the release +# ------------------------------------------------------------ +file(STRINGS ${CMAKE_SOURCE_DIR}/python/naja_schematic/__init__.py + NAJA_SCHEMATIC_VERSION_LINE REGEX "^__version__ = \"[^\"]*\"") +string(REGEX REPLACE ".*\"([^\"]*)\".*" "\\1" NAJA_SCHEMATIC_VERSION + "${NAJA_SCHEMATIC_VERSION_LINE}") +if(NOT NAJA_SCHEMATIC_VERSION) + message(FATAL_ERROR + "Could not read __version__ from python/naja_schematic/__init__.py") +endif() +message(STATUS "naja-schematic version: ${NAJA_SCHEMATIC_VERSION}") + # ------------------------------------------------------------ # naja version (read from the submodule's literal, not built — needed on # both targets since both interface with naja: native links it directly, @@ -149,6 +164,7 @@ if(EMSCRIPTEN_BUILD) set_target_properties(naja-schematic PROPERTIES SUFFIX ${NAJA_SCHEMATIC_WASM_SUFFIX}) target_compile_definitions(naja-schematic PRIVATE NAJA_SCHEMATIC_GIT_HASH="${NAJA_SCHEMATIC_GIT_HASH}" + NAJA_SCHEMATIC_VERSION_STRING="${NAJA_SCHEMATIC_VERSION}" NAJA_VERSION_STRING="${NAJA_VERSION}" ) @@ -198,6 +214,7 @@ else() target_compile_definitions(naja-schematic-standalone PRIVATE NAJA_SCHEMATIC_GIT_HASH="${NAJA_SCHEMATIC_GIT_HASH}" + NAJA_SCHEMATIC_VERSION_STRING="${NAJA_SCHEMATIC_VERSION}" NAJA_VERSION_STRING="${NAJA_VERSION}" ) diff --git a/python/naja_schematic/__init__.py b/python/naja_schematic/__init__.py index 23f7619..ff38956 100644 --- a/python/naja_schematic/__init__.py +++ b/python/naja_schematic/__init__.py @@ -5,6 +5,8 @@ - From a shell: ``naja-schematic --verilog design.v --open`` serves the viewer page and opens it in a browser. """ +# Single version for the whole project: CMakeLists.txt reads this line into the +# C++ app too (NAJA_SCHEMATIC_VERSION_STRING), so keep it a plain literal. __version__ = "0.1.1" from .protocol import diagnosis_response, handle_request diff --git a/src/AppLogic.cpp b/src/AppLogic.cpp index 26439f5..dfdec57 100644 --- a/src/AppLogic.cpp +++ b/src/AppLogic.cpp @@ -26,7 +26,6 @@ using json = nlohmann::json; #include "SelectionStore.h" #include "PropertiesView.h" #include "DroidSansFont.h" -#include "Version.h" #ifndef __EMSCRIPTEN__ #include @@ -721,7 +720,7 @@ bool appFrame(AppState& state) { ImGui::Separator(); ImGui::Spacing(); - ImGui::Text("Version: %s", naja_schematic::VERSION.c_str()); + ImGui::Text("Version: %s", NAJA_SCHEMATIC_VERSION_STRING); ImGui::Text("Commit: %s", NAJA_SCHEMATIC_GIT_HASH); ImGui::Text("naja: %s", NAJA_VERSION_STRING); ImGui::Text("Project: github.com/najaeda/naja-schematic"); diff --git a/src/Version.h b/src/Version.h deleted file mode 100644 index e0155c7..0000000 --- a/src/Version.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include - -// Mirrors thirdparty/naja/src/core/NajaVersion.h: a literal MAJOR.MINOR.PATCH -// string plus helpers to split it, kept separate from the git commit hash -// (NAJA_SCHEMATIC_GIT_HASH, baked in as a compile definition by CMakeLists.txt -// since it changes every commit, unlike this literal). -namespace naja_schematic { - -namespace detail { - -inline std::string getVersionPart(const std::string& version, int index) { - std::string::size_type start = 0; - for (int i = 0; i < index; ++i) { - std::string::size_type dot = version.find('.', start); - if (dot == std::string::npos) { - return std::string {}; - } - start = dot + 1; - } - std::string::size_type end = version.find('.', start); - if (end == std::string::npos) { - end = version.size(); - } - return version.substr(start, end - start); -} - -} // namespace detail - -const std::string VERSION { "0.0.6" }; -const std::string VERSION_MAJOR { detail::getVersionPart(VERSION, 0) }; -const std::string VERSION_MINOR { detail::getVersionPart(VERSION, 1) }; -const std::string VERSION_PATCH { detail::getVersionPart(VERSION, 2) }; - -} // namespace naja_schematic