[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:
Tyler Veness
2024-05-12 06:25:42 -07:00
committed by GitHub
parent 6c9dcc157e
commit d88c71ffdc
99 changed files with 1374 additions and 1130 deletions

View File

@@ -30,6 +30,7 @@
#include <wpi/fmt/raw_ostream.h>
#include <wpi/fs.h>
#include <wpi/mutex.h>
#include <wpi/print.h>
#include <wpi/raw_ostream.h>
#include "App.h"
@@ -457,21 +458,21 @@ static void ValueToCsv(wpi::raw_ostream& os, const Entry& entry,
int64_t val;
if (record.GetInteger(&val)) {
std::time_t timeval = val / 1000000;
fmt::print(os, "{:%Y-%m-%d %H:%M:%S}.{:06}", *std::localtime(&timeval),
wpi::print(os, "{:%Y-%m-%d %H:%M:%S}.{:06}", *std::localtime(&timeval),
val % 1000000);
return;
}
} else if (entry.type == "double") {
double val;
if (record.GetDouble(&val)) {
fmt::print(os, "{}", val);
wpi::print(os, "{}", val);
return;
}
} else if (entry.type == "int64" || entry.type == "int") {
// support "int" for compatibility with old NT4 datalogs
int64_t val;
if (record.GetInteger(&val)) {
fmt::print(os, "{}", val);
wpi::print(os, "{}", val);
return;
}
} else if (entry.type == "string" || entry.type == "json") {
@@ -484,31 +485,31 @@ static void ValueToCsv(wpi::raw_ostream& os, const Entry& entry,
} else if (entry.type == "boolean") {
bool val;
if (record.GetBoolean(&val)) {
fmt::print(os, "{}", val);
wpi::print(os, "{}", val);
return;
}
} else if (entry.type == "boolean[]") {
std::vector<int> val;
if (record.GetBooleanArray(&val)) {
fmt::print(os, "{}", fmt::join(val, ";"));
wpi::print(os, "{}", fmt::join(val, ";"));
return;
}
} else if (entry.type == "double[]") {
std::vector<double> val;
if (record.GetDoubleArray(&val)) {
fmt::print(os, "{}", fmt::join(val, ";"));
wpi::print(os, "{}", fmt::join(val, ";"));
return;
}
} else if (entry.type == "float[]") {
std::vector<float> val;
if (record.GetFloatArray(&val)) {
fmt::print(os, "{}", fmt::join(val, ";"));
wpi::print(os, "{}", fmt::join(val, ";"));
return;
}
} else if (entry.type == "int64[]") {
std::vector<int64_t> val;
if (record.GetIntegerArray(&val)) {
fmt::print(os, "{}", fmt::join(val, ";"));
wpi::print(os, "{}", fmt::join(val, ";"));
return;
}
} else if (entry.type == "string[]") {
@@ -527,7 +528,7 @@ static void ValueToCsv(wpi::raw_ostream& os, const Entry& entry,
return;
}
}
fmt::print(os, "<invalid>");
wpi::print(os, "<invalid>");
}
static void ExportCsvFile(InputFile& f, wpi::raw_ostream& os, int style) {
@@ -575,13 +576,13 @@ static void ExportCsvFile(InputFile& f, wpi::raw_ostream& os, int style) {
Entry* entry = entryIt->second;
if (style == 0) {
fmt::print(os, "{},\"", record.GetTimestamp() / 1000000.0);
wpi::print(os, "{},\"", record.GetTimestamp() / 1000000.0);
PrintEscapedCsvString(os, entry->name);
os << '"' << ',';
ValueToCsv(os, *entry, record);
os << '\n';
} else if (style == 1 && entry->column != -1) {
fmt::print(os, "{},", record.GetTimestamp() / 1000000.0);
wpi::print(os, "{},", record.GetTimestamp() / 1000000.0);
for (int i = 0; i < entry->column; ++i) {
os << ',';
}