From 2c301277741674c681c1ddc34973daa7c41de964 Mon Sep 17 00:00:00 2001 From: Alexandre Plateau Date: Sat, 23 Mar 2024 18:50:03 +0100 Subject: [PATCH] feat(cli): --version and --help now output the version with the commit hash --- CHANGELOG.md | 1 + CMakeLists.txt | 7 +++++++ include/Ark/Constants.hpp.in | 9 ++++----- src/arkreactor/VM/State.cpp | 3 ++- src/arkscript/main.cpp | 28 +++++++++++----------------- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc31e8b36..1be5ca0a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - new parser, new syntax for imports: `(import package.sub.file)` - allow nodes to be empty when dumping the AST to JSON - macros can be declared inside a begin block within a cond macro and used in the scope surrounding the cond macro +- `arkscript --version` and `arkscript --help` now output ArkScript version with the commit hash ### Removed - removed unused `NodeType::Closure` diff --git a/CMakeLists.txt b/CMakeLists.txt index b32bf240a..8c6c1a69c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,13 @@ set(ARK_VERSION_MAJOR 4) set(ARK_VERSION_MINOR 0) set(ARK_VERSION_PATCH 0) +execute_process( + COMMAND git rev-parse --short=8 HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE) +set(ARK_COMMIT ${GIT_COMMIT_HASH}) + include(cmake/link_time_optimization.cmake) include(cmake/sanitizers.cmake) include(GNUInstallDirs) # Uses GNU Install directory variables diff --git a/include/Ark/Constants.hpp.in b/include/Ark/Constants.hpp.in index 948b90209..45883c069 100644 --- a/include/Ark/Constants.hpp.in +++ b/include/Ark/Constants.hpp.in @@ -2,10 +2,10 @@ * @file Constants.hpp * @author Alexandre Plateau (lexplt.dev@gmail.com) * @brief Constants used by ArkScript - * @version 0.1 + * @version 0.2 * @date 2020-10-27 * - * @copyright Copyright (c) 2020 + * @copyright Copyright (c) 2020-2024 * */ @@ -17,10 +17,9 @@ constexpr int ARK_VERSION_MAJOR = @ARK_VERSION_MAJOR@; constexpr int ARK_VERSION_MINOR = @ARK_VERSION_MINOR@; constexpr int ARK_VERSION_PATCH = @ARK_VERSION_PATCH@; // clang-format on -constexpr int ARK_VERSION = (ARK_VERSION_MAJOR << 16) + (ARK_VERSION_MINOR << 8) + ARK_VERSION_PATCH; -constexpr char ARK_VERSION_STR[4] = { ARK_VERSION_MAJOR + '0', ARK_VERSION_MINOR + '0', ARK_VERSION_PATCH + '0', 0x00 }; +constexpr std::string_view ARK_VERSION { "@ARK_VERSION_MAJOR@.@ARK_VERSION_MINOR@.@ARK_VERSION_PATCH@" }; +constexpr std::string_view ARK_FULL_VERSION { "@ARK_VERSION_MAJOR@.@ARK_VERSION_MINOR@.@ARK_VERSION_PATCH@-@ARK_COMMIT@" }; -#define ARK_COMPILATION_OPTIONS "@CMAKE_CXX_FLAGS@" #define ARK_COMPILER "@CMAKE_CXX_COMPILER_ID@" #define ARK_CACHE_DIRNAME "__arkscript__" #define ARK_NO_NAME_FILE "FILE" diff --git a/src/arkreactor/VM/State.cpp b/src/arkreactor/VM/State.cpp index cc4192c60..b23403067 100644 --- a/src/arkreactor/VM/State.cpp +++ b/src/arkreactor/VM/State.cpp @@ -11,6 +11,7 @@ #include #include +#include namespace Ark { @@ -177,7 +178,7 @@ namespace Ark std::string str_version = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(patch); - throwStateError("Compiler and VM versions don't match: " + str_version + " and " + ARK_VERSION_STR); + throwStateError(fmt::format("Compiler and VM versions don't match: got {} while running {}", str_version, ARK_VERSION)); } using timestamp_t = unsigned long long; diff --git a/src/arkscript/main.cpp b/src/arkscript/main.cpp index 6ff3b7dea..e2419a8b7 100644 --- a/src/arkscript/main.cpp +++ b/src/arkscript/main.cpp @@ -117,6 +117,10 @@ int main(int argc, char** argv) .split_alternatives(true) // split usage into several lines for large alternatives .merge_alternative_flags_with_common_prefix(true) // [-fok] [-fno-ok] becomes [-f(ok|no-ok)] ; + const auto man_page = make_man_page(cli, "arkscript", fmt) + .prepend_section("DESCRIPTION", " ArkScript programming language") + .append_section("VERSION", fmt::format(" {}", ARK_FULL_VERSION)) + .append_section("LICENSE", " Mozilla Public License 2.0"); if (parse(argc, argv, cli) && wrong.empty()) { @@ -145,22 +149,17 @@ int main(int argc, char** argv) switch (selected) { case mode::help: - // clipp only supports streams - std::cout << make_man_page(cli, "arkscript", fmt) - .prepend_section("DESCRIPTION", " ArkScript programming language") - .append_section("VERSION", fmt::format(" {}.{}.{}", ARK_VERSION_MAJOR, ARK_VERSION_MINOR, ARK_VERSION_PATCH)) - .append_section("LICENSE", " Mozilla Public License 2.0") - << std::endl; + std::cout << man_page << std::endl; break; case mode::version: - std::cout << fmt::format("Version {}.{}.{}\n", ARK_VERSION_MAJOR, ARK_VERSION_MINOR, ARK_VERSION_PATCH); + std::cout << fmt::format("{}\n", ARK_FULL_VERSION); break; case mode::dev_info: { std::cout << fmt::format( - "Have been compiled with {}, options: {}\n\n" + "Have been compiled with {}\n\n" "sizeof(Ark::Value) = {}B\n" " sizeof(Value_t) = {}B\n" " sizeof(ValueType) = {}B\n" @@ -176,7 +175,7 @@ int main(int argc, char** argv) " sizeof(vector) = {}B\n" " sizeof(char) = {}B\n" "\nsizeof(Node) = {}B\n", - ARK_COMPILER, ARK_COMPILATION_OPTIONS, + ARK_COMPILER, // value sizeof(Ark::Value), sizeof(Ark::Value::Value_t), @@ -287,14 +286,9 @@ int main(int argc, char** argv) else { for (const auto& arg : wrong) - std::cerr << "'" << arg.c_str() << "' ins't a valid argument\n"; - - // clipp only supports streams - std::cout << make_man_page(cli, "arkscript", fmt) - .prepend_section("DESCRIPTION", " ArkScript programming language") - .append_section("VERSION", fmt::format(" {}.{}.{}", ARK_VERSION_MAJOR, ARK_VERSION_MINOR, ARK_VERSION_PATCH)) - .append_section("LICENSE", " Mozilla Public License 2.0") - << std::endl; + std::cerr << "'" << arg.c_str() << "' isn't a valid argument\n"; + + std::cout << man_page << std::endl; } return 0;