Skip to content

Commit

Permalink
feat(cli): --version and --help now output the version with the commi…
Browse files Browse the repository at this point in the history
…t hash
  • Loading branch information
SuperFola committed Mar 23, 2024
1 parent ce005b6 commit 2c30127
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions include/Ark/Constants.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @file Constants.hpp
* @author Alexandre Plateau ([email protected])
* @brief Constants used by ArkScript
* @version 0.1
* @version 0.2
* @date 2020-10-27
*
* @copyright Copyright (c) 2020
* @copyright Copyright (c) 2020-2024
*
*/

Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/arkreactor/VM/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <picosha2.h>
#include <termcolor/proxy.hpp>
#include <fmt/core.h>

namespace Ark
{
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 11 additions & 17 deletions src/arkscript/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down Expand Up @@ -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"
Expand All @@ -176,7 +175,7 @@ int main(int argc, char** argv)
" sizeof(vector<Ark::Value>) = {}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),
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2c30127

Please sign in to comment.