From 4178308e964e174260bf7aebb8ee2aee9ab194be Mon Sep 17 00:00:00 2001 From: Robert Bendun Date: Sat, 14 Jan 2023 22:48:15 +0100 Subject: [PATCH] make version info available --- CHANGELOG.md | 1 + config.mk | 13 ++++++++++++- musique/main.cc | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 155fbc7..d35e530 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Builtin function documentation generation from C++ Musique implementation source code - New builtins: digits - Negative numbers! +- Version command via `:version` in REPL or `--version`, `-v` in command line. ### Removed diff --git a/config.mk b/config.mk index dd14879..86cb27a 100644 --- a/config.mk +++ b/config.mk @@ -1,7 +1,18 @@ MAKEFLAGS="-j $(grep -c ^processor /proc/cpuinfo)" +MAJOR := 0 +MINOR := 3 +PATCH := 1 +COMMIT := gc$(shell git rev-parse --short HEAD 2>/dev/null) + +ifeq ($(COMMIT),gc) + COMMIT = "gcunknown" +endif + +VERSION := $(MAJOR).$(MINOR).$(PATCH)-dev+$(COMMIT) + CXXFLAGS:=$(CXXFLAGS) -std=c++20 -Wall -Wextra -Werror=switch -Werror=return-type -Werror=unused-result -CPPFLAGS:=$(CPPFLAGS) -Ilib/expected/ -I. -Ilib/bestline/ -Ilib/rtmidi/ +CPPFLAGS:=$(CPPFLAGS) -Ilib/expected/ -I. -Ilib/bestline/ -Ilib/rtmidi/ -DMusique_Version='"$(VERSION)"' LDFLAGS=-flto LDLIBS= -lpthread diff --git a/musique/main.cc b/musique/main.cc index 3ae5fc7..7721c56 100644 --- a/musique/main.cc +++ b/musique/main.cc @@ -84,6 +84,9 @@ static T pop(std::span &span) " --ast\n" " prints ast for given code\n" "\n" + " -v,--version\n" + " prints Musique interpreter version\n" + "\n" "Thanks to:\n" " Sy Brand, https://sybrand.ink/, creator of tl::expected https://github.com/TartanLlama/expected\n" " Justine Tunney, https://justinetunney.com, creator of bestline readline library https://github.com/jart/bestline\n" @@ -289,6 +292,12 @@ static Result handle_repl_session_commands(std::string_view input, Runner std::exit(0); } }, + Command { "version", + +[](Runner&, std::optional) -> std::optional { + std::cout << Musique_Version << std::endl; + return {}; + }, + }, Command { "clear", +[](Runner&, std::optional) -> std::optional { std::cout << "\x1b[1;1H\x1b[2J" << std::flush; @@ -424,6 +433,11 @@ static std::optional Main(std::span args) continue; } + if (arg == "--version" || arg == "-v") { + std::cout << Musique_Version << std::endl; + return {}; + } + if (arg == "-o" || arg == "--output") { if (args.empty()) { std::cerr << "musique: error: option " << arg << " requires an argument" << std::endl;