[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

@@ -4,8 +4,8 @@
#include "frc/Notifier.h" // NOLINT(build/include_order)
#include <fmt/core.h>
#include <gtest/gtest.h>
#include <wpi/print.h>
#include "frc/Timer.h"
@@ -20,13 +20,13 @@ TEST(NotifierTest, StartPeriodicAndStop) {
notifier.Stop();
EXPECT_EQ(10u, counter) << "Received " << counter
<< " notifications in 10.5 seconds\n";
fmt::print("Received {} notifications in 10.5 seconds\n", counter);
wpi::print("Received {} notifications in 10.5 seconds\n", counter);
frc::Wait(3_s);
EXPECT_EQ(10u, counter) << "Received " << counter - 10
<< " notifications in 3 seconds\n";
fmt::print("Received {} notifications in 3 seconds\n", counter - 10);
wpi::print("Received {} notifications in 3 seconds\n", counter - 10);
}
TEST(NotifierTest, StartSingle) {
@@ -39,5 +39,5 @@ TEST(NotifierTest, StartSingle) {
EXPECT_EQ(1u, counter) << "Received " << counter
<< " notifications in 10.5 seconds\n";
fmt::print("Received {} notifications in 10.5 seconds\n", counter);
wpi::print("Received {} notifications in 10.5 seconds\n", counter);
}

View File

@@ -5,9 +5,9 @@
#include <cstdlib>
#include <thread>
#include <fmt/core.h>
#include <gtest/gtest.h>
#include <hal/HAL.h>
#include <wpi/print.h>
#include "frc/DriverStation.h"
#include "frc/livewindow/LiveWindow.h"
@@ -29,7 +29,7 @@ class TestEnvironment : public testing::Environment {
m_alreadySetUp = true;
if (!HAL_Initialize(500, 0)) {
fmt::print(stderr, "FATAL ERROR: HAL could not be initialized\n");
wpi::print(stderr, "FATAL ERROR: HAL could not be initialized\n");
std::exit(-1);
}
@@ -42,7 +42,7 @@ class TestEnvironment : public testing::Environment {
HAL_ObserveUserProgramStarting();
frc::LiveWindow::SetEnabled(false);
fmt::print("Started coms\n");
wpi::print("Started coms\n");
int enableCounter = 0;
frc::DriverStation::RefreshData();
@@ -50,13 +50,13 @@ class TestEnvironment : public testing::Environment {
if (enableCounter > 50) {
// Robot did not enable properly after 5 seconds.
// Force exit
fmt::print(stderr, " Failed to enable. Aborting\n");
wpi::print(stderr, " Failed to enable. Aborting\n");
std::terminate();
}
std::this_thread::sleep_for(100ms);
fmt::print("Waiting for enable: {}\n", enableCounter++);
wpi::print("Waiting for enable: {}\n", enableCounter++);
frc::DriverStation::RefreshData();
}
}

View File

@@ -8,16 +8,16 @@
#include <string_view>
#include <fmt/core.h>
#include <hal/cpp/fpga_clock.h>
#include <wpi/Logger.h>
#include <wpi/SmallVector.h>
#include <wpi/print.h>
#include <wpinet/UDPClient.h>
static void LoggerFunc(unsigned int level, const char* file, unsigned int line,
const char* msg) {
if (level == 20) {
fmt::print(stderr, "DS: {}\n", msg);
wpi::print(stderr, "DS: {}\n", msg);
return;
}
@@ -31,7 +31,7 @@ static void LoggerFunc(unsigned int level, const char* file, unsigned int line,
} else {
return;
}
fmt::print(stderr, "DS: {}: {} ({}:{})\n", levelmsg, msg, file, line);
wpi::print(stderr, "DS: {}: {} ({}:{})\n", levelmsg, msg, file, line);
}
static void generateEnabledDsPacket(wpi::SmallVectorImpl<uint8_t>& data,