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

summaryrefslogtreecommitdiffhomepage
path: root/tools/ThirdPartyMain.cpp
diff options
context:
space:
mode:
authorLeitwolf112026-11-01 22:58:30 +0300
committerLeitwolf112026-11-01 22:58:30 +0300
commite66db1cf17714be2ebfeab37670ef3d8965fc7cc (patch)
tree88a8b55a14e9bc6152608662d062c1624c2863cf /tools/ThirdPartyMain.cpp
parente32c9d107274f42b9cca700475404c80e96533c5 (diff)
downloadcatch3-e66db1cf17714be2ebfeab37670ef3d8965fc7cc.tar.gz
Answer the review of the tools
repo_info starts Git in the checkout with fixed commands, so a shell never reads a path, reports an unknown state as null rather than clean, and counts only files it can start. third_party reads every archive before it changes a file and refuses two modes. version checks that the sources make a distribution, computes every place before writing any, and release_notes finds a three-number heading for a version with D = 0.
Diffstat (limited to 'tools/ThirdPartyMain.cpp')
-rw-r--r--tools/ThirdPartyMain.cpp29
1 files changed, 20 insertions, 9 deletions
diff --git a/tools/ThirdPartyMain.cpp b/tools/ThirdPartyMain.cpp
index 6223e85f..796c6182 100644
--- a/tools/ThirdPartyMain.cpp
+++ b/tools/ThirdPartyMain.cpp
@@ -11,6 +11,7 @@
#include <memory>
#include <string>
#include <string_view>
+#include <utility>
#include <vector>
#include "rules_cc/cc/runfiles/runfiles.h"
@@ -24,11 +25,13 @@ main(int argc, char **argv)
std::vector<std::string_view> files;
std::string_view mode;
+ bool usable = true;
for (int index = 1; index < argc; ++index)
{
const std::string_view argument{ argv[index] };
if (argument == "--check" || argument == "--update")
{
+ usable = usable && mode.empty();
mode = argument;
}
else if (argument.find('=') != std::string_view::npos)
@@ -37,11 +40,10 @@ main(int argc, char **argv)
}
else
{
- mode = {};
- break;
+ usable = false;
}
}
- if (mode.empty())
+ if (!usable || mode.empty())
{
std::cerr << "usage: bazelisk run //tools:third_party -- "
"--check|--update\n";
@@ -63,16 +65,25 @@ main(int argc, char **argv)
return 2;
}
Problems problems;
+ // Every archive is read before any file changes.
+ std::vector<std::pair<std::string_view, std::string>> archived;
for (const auto file : files)
{
const auto separator = file.find('=');
- const auto vendored = file.substr(0, separator);
- const auto archived = ReadOrReport(
- runfiles->Rlocation(std::string{ file.substr(separator + 1) }),
- problems);
+ archived.emplace_back(file.substr(0, separator),
+ ReadOrReport(runfiles->Rlocation(std::string{
+ file.substr(separator + 1) }),
+ problems));
+ }
+ if (!problems.empty())
+ {
+ return Finish(problems);
+ }
+ for (const auto &[vendored, text] : archived)
+ {
if (mode == "--check")
{
- if (ReadText(*root / vendored) != archived)
+ if (ReadText(*root / vendored) != text)
{
problems.push_back(std::string{ vendored }
+ " differs from its pinned archive: run "
@@ -80,7 +91,7 @@ main(int argc, char **argv)
"--update");
}
}
- else if (!WriteText(*root / vendored, archived))
+ else if (!WriteText(*root / vendored, text))
{
problems.push_back("cannot write " + std::string{ vendored });
}