summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2022-06-28 11:00:47 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2022-06-29 15:36:20 +0200
commit16a61d5c4b1faff9571a3f02ebaeecc7684603af (patch)
tree7a93f7976d8a1d9a4e33ac2318ee741dc82a9aaa /src
parent39cab886df1a50ea8e70504dff83cc77c6140bcb (diff)
downloadjustbuild-16a61d5c4b1faff9571a3f02ebaeecc7684603af.tar.gz
Use a more meaningful abbreviation of expression values
... in error messages. The outer structure is usually more important than the the details of the first element.
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/build_engine/expression/configuration.hpp2
-rw-r--r--src/buildtool/build_engine/expression/expression.cpp3
-rw-r--r--src/buildtool/build_engine/expression/expression.hpp1
3 files changed, 5 insertions, 1 deletions
diff --git a/src/buildtool/build_engine/expression/configuration.hpp b/src/buildtool/build_engine/expression/configuration.hpp
index 5d0b9c2a..3306d293 100644
--- a/src/buildtool/build_engine/expression/configuration.hpp
+++ b/src/buildtool/build_engine/expression/configuration.hpp
@@ -47,10 +47,10 @@ class Configuration {
size_t actual_width = width - prefix.size();
for (auto const& [key, value] : expr_->Map()) {
std::string key_str = Expression{key}.ToString();
- std::string val_str = value->ToString();
if (actual_width > key_str.size() + 3) {
ss << prefix << key_str << " : ";
size_t remain = actual_width - key_str.size() - 3;
+ std::string val_str = value->ToAbbrevString(remain);
if (val_str.size() >= remain) {
ss << val_str.substr(0, remain - 3) << "...";
}
diff --git a/src/buildtool/build_engine/expression/expression.cpp b/src/buildtool/build_engine/expression/expression.cpp
index 6891d7ab..65077efe 100644
--- a/src/buildtool/build_engine/expression/expression.cpp
+++ b/src/buildtool/build_engine/expression/expression.cpp
@@ -147,6 +147,9 @@ auto Expression::ToString() const -> std::string {
return ToJson().dump();
}
+[[nodiscard]] auto Expression::ToAbbrevString(size_t len) const -> std::string {
+ return AbbreviateJson(ToJson(), len);
+}
// NOLINTNEXTLINE(misc-no-recursion)
auto Expression::ToHash() const noexcept -> std::string {
return hash_.SetOnceAndGet([this] { return ComputeHash(); });
diff --git a/src/buildtool/build_engine/expression/expression.hpp b/src/buildtool/build_engine/expression/expression.hpp
index 68dddb10..334dfb0d 100644
--- a/src/buildtool/build_engine/expression/expression.hpp
+++ b/src/buildtool/build_engine/expression/expression.hpp
@@ -212,6 +212,7 @@ class Expression {
-> nlohmann::json;
[[nodiscard]] auto IsCacheable() const -> bool;
[[nodiscard]] auto ToString() const -> std::string;
+ [[nodiscard]] auto ToAbbrevString(size_t len) const -> std::string;
[[nodiscard]] auto ToHash() const noexcept -> std::string;
[[nodiscard]] auto ToIdentifier() const noexcept -> std::string {
return ToHexString(ToHash());