mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
[wpiutil] Upgrade to fmt 10.2.1, add wpi::print (#6161)
We now use a wrapper (wpi::print) to catch exceptions since we can't patch std::print() to not throw when we ultimately migrate to it. fmtlib and std format/print throw the same exceptions and always have. We previously patched fmt::print() to not throw a write failure exception, but we can't do that for std::print(); wpi::print() is the migration plan.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <cstdio>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/print.h>
|
||||
#include <wpigui.h>
|
||||
|
||||
#include "glass/Context.h"
|
||||
@@ -31,7 +32,7 @@ Window* WindowManager::AddWindow(std::string_view id,
|
||||
return nullptr;
|
||||
}
|
||||
if (win->HasView()) {
|
||||
fmt::print(stderr, "GUI: ignoring duplicate window '{}'\n", id);
|
||||
wpi::print(stderr, "GUI: ignoring duplicate window '{}'\n", id);
|
||||
return nullptr;
|
||||
}
|
||||
win->SetView(MakeFunctionView(std::move(display)));
|
||||
@@ -46,7 +47,7 @@ Window* WindowManager::AddWindow(std::string_view id,
|
||||
return nullptr;
|
||||
}
|
||||
if (win->HasView()) {
|
||||
fmt::print(stderr, "GUI: ignoring duplicate window '{}'\n", id);
|
||||
wpi::print(stderr, "GUI: ignoring duplicate window '{}'\n", id);
|
||||
return nullptr;
|
||||
}
|
||||
win->SetView(std::move(view));
|
||||
@@ -61,7 +62,7 @@ Window* WindowManager::GetOrAddWindow(std::string_view id, bool duplicateOk,
|
||||
[](const auto& elem, std::string_view s) { return elem->GetId() < s; });
|
||||
if (it != m_windows.end() && (*it)->GetId() == id) {
|
||||
if (!duplicateOk) {
|
||||
fmt::print(stderr, "GUI: ignoring duplicate window '{}'\n", id);
|
||||
wpi::print(stderr, "GUI: ignoring duplicate window '{}'\n", id);
|
||||
return nullptr;
|
||||
}
|
||||
return it->get();
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <utility>
|
||||
|
||||
#include <fields/fields.h>
|
||||
#include <fmt/format.h>
|
||||
#include <frc/geometry/Pose2d.h>
|
||||
#include <frc/geometry/Rotation2d.h>
|
||||
#include <frc/geometry/Translation2d.h>
|
||||
@@ -30,6 +29,7 @@
|
||||
#include <wpi/StringMap.h>
|
||||
#include <wpi/fs.h>
|
||||
#include <wpi/json.h>
|
||||
#include <wpi/print.h>
|
||||
#include <wpigui.h>
|
||||
|
||||
#include "glass/Context.h"
|
||||
@@ -450,7 +450,7 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
try {
|
||||
j = wpi::json::parse(is);
|
||||
} catch (const wpi::json::parse_error& e) {
|
||||
fmt::print(stderr, "GUI: JSON: could not parse: {}\n", e.what());
|
||||
wpi::print(stderr, "GUI: JSON: could not parse: {}\n", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -465,7 +465,7 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
try {
|
||||
image = j.at("field-image").get<std::string>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
fmt::print(stderr, "GUI: JSON: could not read field-image: {}\n", e.what());
|
||||
wpi::print(stderr, "GUI: JSON: could not read field-image: {}\n", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -477,7 +477,7 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
bottom = j.at("field-corners").at("bottom-right").at(1).get<int>();
|
||||
right = j.at("field-corners").at("bottom-right").at(0).get<int>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
fmt::print(stderr, "GUI: JSON: could not read field-corners: {}\n",
|
||||
wpi::print(stderr, "GUI: JSON: could not read field-corners: {}\n",
|
||||
e.what());
|
||||
return false;
|
||||
}
|
||||
@@ -489,7 +489,7 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
width = j.at("field-size").at(0).get<float>();
|
||||
height = j.at("field-size").at(1).get<float>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
fmt::print(stderr, "GUI: JSON: could not read field-size: {}\n", e.what());
|
||||
wpi::print(stderr, "GUI: JSON: could not read field-size: {}\n", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -498,7 +498,7 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
try {
|
||||
unit = j.at("field-unit").get<std::string>();
|
||||
} catch (const wpi::json::exception& e) {
|
||||
fmt::print(stderr, "GUI: JSON: could not read field-unit: {}\n", e.what());
|
||||
wpi::print(stderr, "GUI: JSON: could not read field-unit: {}\n", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -512,7 +512,7 @@ bool FieldInfo::LoadJson(std::span<const char> is, std::string_view filename) {
|
||||
int fieldWidth = m_right - m_left;
|
||||
int fieldHeight = m_bottom - m_top;
|
||||
if (std::abs((fieldWidth / width) - (fieldHeight / height)) > 0.3) {
|
||||
fmt::print(stderr,
|
||||
wpi::print(stderr,
|
||||
"GUI: Field X and Y scaling substantially different: "
|
||||
"xscale={} yscale={}\n",
|
||||
(fieldWidth / width), (fieldHeight / height));
|
||||
@@ -553,7 +553,7 @@ void FieldInfo::LoadJsonFile(std::string_view jsonfile) {
|
||||
}
|
||||
|
||||
bool FieldInfo::LoadImageImpl(const std::string& fn) {
|
||||
fmt::print("GUI: loading field image '{}'\n", fn);
|
||||
wpi::print("GUI: loading field image '{}'\n", fn);
|
||||
auto texture = gui::Texture::CreateFromFile(fn.c_str());
|
||||
if (!texture) {
|
||||
std::puts("GUI: could not read field image");
|
||||
@@ -745,7 +745,7 @@ void ObjectInfo::LoadImage() {
|
||||
}
|
||||
|
||||
bool ObjectInfo::LoadImageImpl(const std::string& fn) {
|
||||
fmt::print("GUI: loading object image '{}'\n", fn);
|
||||
wpi::print("GUI: loading object image '{}'\n", fn);
|
||||
auto texture = gui::Texture::CreateFromFile(fn.c_str());
|
||||
if (!texture) {
|
||||
std::fputs("GUI: could not read object image\n", stderr);
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <frc/geometry/Pose2d.h>
|
||||
#include <frc/geometry/Rotation2d.h>
|
||||
#include <frc/geometry/Transform2d.h>
|
||||
@@ -24,6 +23,7 @@
|
||||
#include <portable-file-dialogs.h>
|
||||
#include <units/angle.h>
|
||||
#include <units/length.h>
|
||||
#include <wpi/print.h>
|
||||
#include <wpigui.h>
|
||||
|
||||
#include "glass/Context.h"
|
||||
@@ -126,7 +126,7 @@ void BackgroundInfo::LoadImage() {
|
||||
}
|
||||
|
||||
bool BackgroundInfo::LoadImageImpl(const std::string& fn) {
|
||||
fmt::print("GUI: loading background image '{}'\n", fn);
|
||||
wpi::print("GUI: loading background image '{}'\n", fn);
|
||||
auto texture = gui::Texture::CreateFromFile(fn.c_str());
|
||||
if (!texture) {
|
||||
std::puts("GUI: could not read background image");
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/StringExtras.h>
|
||||
#include <wpi/print.h>
|
||||
|
||||
using namespace glass;
|
||||
|
||||
@@ -36,7 +36,7 @@ void DataLogReaderThread::ReadMain() {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
auto& entryPtr = m_entriesById[data.entry];
|
||||
if (entryPtr) {
|
||||
fmt::print("...DUPLICATE entry ID, overriding\n");
|
||||
wpi::print("...DUPLICATE entry ID, overriding\n");
|
||||
}
|
||||
auto [it, isNew] = m_entriesByName.emplace(data.name, data);
|
||||
if (isNew) {
|
||||
@@ -50,7 +50,7 @@ void DataLogReaderThread::ReadMain() {
|
||||
}
|
||||
sigEntryAdded(data);
|
||||
} else {
|
||||
fmt::print("Start(INVALID)\n");
|
||||
wpi::print("Start(INVALID)\n");
|
||||
}
|
||||
} else if (record.IsFinish()) {
|
||||
int entry;
|
||||
@@ -58,13 +58,13 @@ void DataLogReaderThread::ReadMain() {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
auto it = m_entriesById.find(entry);
|
||||
if (it == m_entriesById.end()) {
|
||||
fmt::print("...ID not found\n");
|
||||
wpi::print("...ID not found\n");
|
||||
} else {
|
||||
it->second->ranges.back().m_end = recordIt;
|
||||
m_entriesById.erase(it);
|
||||
}
|
||||
} else {
|
||||
fmt::print("Finish(INVALID)\n");
|
||||
wpi::print("Finish(INVALID)\n");
|
||||
}
|
||||
} else if (record.IsSetMetadata()) {
|
||||
wpi::log::MetadataRecordData data;
|
||||
@@ -72,15 +72,15 @@ void DataLogReaderThread::ReadMain() {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
auto it = m_entriesById.find(data.entry);
|
||||
if (it == m_entriesById.end()) {
|
||||
fmt::print("...ID not found\n");
|
||||
wpi::print("...ID not found\n");
|
||||
} else {
|
||||
it->second->metadata = data.metadata;
|
||||
}
|
||||
} else {
|
||||
fmt::print("SetMetadata(INVALID)\n");
|
||||
wpi::print("SetMetadata(INVALID)\n");
|
||||
}
|
||||
} else if (record.IsControl()) {
|
||||
fmt::print("Unrecognized control record\n");
|
||||
wpi::print("Unrecognized control record\n");
|
||||
} else {
|
||||
auto it = schemaEntries.find(record.GetEntry());
|
||||
if (it != schemaEntries.end()) {
|
||||
@@ -106,14 +106,14 @@ void DataLogReaderThread::ReadMain() {
|
||||
std::string err;
|
||||
auto desc = m_structDb.Add(typeStr, schema, &err);
|
||||
if (!desc) {
|
||||
fmt::print("could not decode struct '{}' schema '{}': {}\n", name,
|
||||
wpi::print("could not decode struct '{}' schema '{}': {}\n", name,
|
||||
schema, err);
|
||||
}
|
||||
} else if (wpi::starts_with(name, "/.schema/proto:")) {
|
||||
// protobuf descriptor handling
|
||||
auto filename = wpi::drop_front(name, 15);
|
||||
if (!m_protoDb.Add(filename, data)) {
|
||||
fmt::print("could not decode protobuf '{}' filename '{}'\n", name,
|
||||
wpi::print("could not decode protobuf '{}' filename '{}'\n", name,
|
||||
filename);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user