Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tools/VersionMain.cpp
diff options
context:
space:
mode:
authorLeitwolf2026-11-02 00:51:11 +0300
committerGitHub2026-11-02 00:51:11 +0300
commit268698be92962247a21a86dda4de2d4267adcf8f (patch)
tree510f7ece1750b2da6d9b4666b7c58908c8d193bb /tools/VersionMain.cpp
parent13324a043042110eba456424fa39c1334857ceaa (diff)
parent3ed0fd930371823b6d44ae64d00dbd79e421a552 (diff)
downloadcatch3-268698be92962247a21a86dda4de2d4267adcf8f.tar.gz
Merge pull request #36 from Progmasoft/feature/cpp-tools
Move the tools from Python to C++17 and Bazel
Diffstat (limited to 'tools/VersionMain.cpp')
-rw-r--r--tools/VersionMain.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/tools/VersionMain.cpp b/tools/VersionMain.cpp
new file mode 100644
index 00000000..6f1c13cb
--- /dev/null
+++ b/tools/VersionMain.cpp
@@ -0,0 +1,76 @@
+// Copyright (c) 2026 Progmasoft.
+// SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-2.0
+
+// bazelisk run //tools:version prints the current version
+// bazelisk run //tools:version -- --next moves to the next version
+// bazelisk run //tools:version -- 0.3.1.0 moves to that version
+//
+// Moving writes every place that states the version, and the amalgamation.
+
+#include <iostream>
+#include <string>
+#include <string_view>
+
+#include "tools/Amalgamation.hpp"
+#include "tools/Repository.hpp"
+#include "tools/Versions.hpp"
+
+int
+main(int argc, char **argv)
+{
+ using namespace Progmasoft::Catch3::Tools;
+
+ if (argc > 2)
+ {
+ std::cerr
+ << "usage: bazelisk run //tools:version [-- --next|<version>]\n";
+ return 2;
+ }
+ const auto root = RepositoryRoot();
+ if (!root)
+ {
+ std::cerr << "run this tool with bazelisk run\n";
+ return 2;
+ }
+ Problems problems;
+ const auto current = CurrentVersion(*root, problems);
+ if (!current)
+ {
+ return Finish(problems);
+ }
+ if (argc == 1)
+ {
+ std::cout << *current << '\n';
+ return 0;
+ }
+ const std::string_view argument{ argv[1] };
+ const auto parsed = ParseVersion(
+ argument == "--next" ? *current : std::string{ argument });
+ if (!parsed)
+ {
+ std::cerr << "not a version of three or four numbers: " << argument
+ << '\n';
+ return 2;
+ }
+ const auto version
+ = FormatVersion(argument == "--next" ? NextVersion(*parsed) : *parsed);
+ // The sources have to make a distribution before anything is changed.
+ (void)GenerateAmalgamation(*root, problems);
+ if (problems.empty())
+ {
+ SetVersion(*root, version, problems);
+ }
+ if (problems.empty())
+ {
+ const auto amalgamation = GenerateAmalgamation(*root, problems);
+ if (problems.empty())
+ {
+ WriteAmalgamation(*root, amalgamation, problems);
+ }
+ }
+ if (problems.empty())
+ {
+ std::cout << *current << " -> " << version << '\n';
+ }
+ return Finish(problems);
+}