mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +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,7 +8,7 @@
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/print.h>
|
||||
|
||||
#include "AnalogInternal.h"
|
||||
#include "HALInitializer.h"
|
||||
@@ -194,7 +194,7 @@ void HAL_CalibrateAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
|
||||
if (*status != 0) {
|
||||
return;
|
||||
}
|
||||
fmt::print("Calibrating analog gyro for {} seconds.\n",
|
||||
wpi::print("Calibrating analog gyro for {} seconds.\n",
|
||||
kCalibrationSampleTime);
|
||||
Wait(kCalibrationSampleTime);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/print.h>
|
||||
|
||||
#include "AnalogInternal.h"
|
||||
#include "ConstantsInternal.h"
|
||||
@@ -737,7 +737,7 @@ enum HAL_DMAReadStatus HAL_ReadDMADirect(void* dmaPointer,
|
||||
&remainingBytes, status);
|
||||
|
||||
if ((remainingBytes % dma->captureStore.captureSize) != 0) {
|
||||
fmt::print(
|
||||
wpi::print(
|
||||
"Remaining bytes {} is not a multiple of capture size {}. This is "
|
||||
"likely a "
|
||||
"bug in WPILib. Please report this issue with a copy of your code.\n",
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <wpi/StringExtras.h>
|
||||
#include <wpi/fs.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/print.h>
|
||||
#include <wpi/timestamp.h>
|
||||
|
||||
#include "FPGACalls.h"
|
||||
@@ -500,14 +501,14 @@ static bool killExistingProgram(int timeout, int mode) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(timeout));
|
||||
if (kill(pid, 0) == 0) {
|
||||
// still not successful
|
||||
fmt::print(
|
||||
wpi::print(
|
||||
"FRC pid {} did not die within {} ms. Force killing with kill -9\n",
|
||||
pid, timeout);
|
||||
// Force kill -9
|
||||
auto forceKill = kill(pid, SIGKILL);
|
||||
if (forceKill != 0) {
|
||||
auto errorMsg = std::strerror(forceKill);
|
||||
fmt::print("Kill -9 error: {}\n", errorMsg);
|
||||
wpi::print("Kill -9 error: {}\n", errorMsg);
|
||||
}
|
||||
// Give a bit of time for the kill to take place
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
||||
@@ -533,20 +534,20 @@ static bool SetupNowRio(void) {
|
||||
Dl_info info;
|
||||
status = dladdr(reinterpret_cast<void*>(tHMB::create), &info);
|
||||
if (status == 0) {
|
||||
fmt::print(stderr, "Failed to call dladdr on chipobject {}\n", dlerror());
|
||||
wpi::print(stderr, "Failed to call dladdr on chipobject {}\n", dlerror());
|
||||
return false;
|
||||
}
|
||||
|
||||
void* chipObjectLibrary = dlopen(info.dli_fname, RTLD_LAZY);
|
||||
if (chipObjectLibrary == nullptr) {
|
||||
fmt::print(stderr, "Failed to call dlopen on chipobject {}\n", dlerror());
|
||||
wpi::print(stderr, "Failed to call dlopen on chipobject {}\n", dlerror());
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<tHMB> hmb;
|
||||
hmb.reset(tHMB::create(&status));
|
||||
if (hmb == nullptr) {
|
||||
fmt::print(stderr, "Failed to open HMB on chipobject {}\n", status);
|
||||
wpi::print(stderr, "Failed to open HMB on chipobject {}\n", status);
|
||||
dlclose(chipObjectLibrary);
|
||||
return false;
|
||||
}
|
||||
@@ -609,7 +610,7 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
|
||||
|
||||
HAL_InitializeHMB(&status);
|
||||
if (status != 0) {
|
||||
fmt::print(stderr, "Failed to open HAL HMB, status code {}\n", status);
|
||||
wpi::print(stderr, "Failed to open HAL HMB, status code {}\n", status);
|
||||
return false;
|
||||
}
|
||||
hmbBuffer = HAL_GetHMBBuffer();
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/print.h>
|
||||
|
||||
#include "DigitalInternal.h"
|
||||
#include "HALInitializer.h"
|
||||
@@ -65,7 +65,7 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
|
||||
}
|
||||
int handle = open("/dev/i2c-2", O_RDWR);
|
||||
if (handle < 0) {
|
||||
fmt::print("Failed to open onboard i2c bus: {}\n", std::strerror(errno));
|
||||
wpi::print("Failed to open onboard i2c bus: {}\n", std::strerror(errno));
|
||||
return;
|
||||
}
|
||||
i2COnBoardHandle = handle;
|
||||
@@ -88,7 +88,7 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
|
||||
digitalSystem->readEnableMXPSpecialFunction(status) | 0xC000, status);
|
||||
int handle = open("/dev/i2c-1", O_RDWR);
|
||||
if (handle < 0) {
|
||||
fmt::print("Failed to open MXP i2c bus: {}\n", std::strerror(errno));
|
||||
wpi::print("Failed to open MXP i2c bus: {}\n", std::strerror(errno));
|
||||
return;
|
||||
}
|
||||
i2CMXPHandle = handle;
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <wpi/condition_variable.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/print.h>
|
||||
|
||||
#include "HALInitializer.h"
|
||||
#include "HALInternal.h"
|
||||
@@ -164,12 +164,12 @@ HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status) {
|
||||
notifierThreadPriority, status);
|
||||
if (*status == HAL_THREAD_PRIORITY_ERROR) {
|
||||
*status = 0;
|
||||
fmt::print("{}: HAL Notifier thread\n",
|
||||
wpi::print("{}: HAL Notifier thread\n",
|
||||
HAL_THREAD_PRIORITY_ERROR_MESSAGE);
|
||||
}
|
||||
if (*status == HAL_THREAD_PRIORITY_RANGE_ERROR) {
|
||||
*status = 0;
|
||||
fmt::print("{}: HAL Notifier thread\n",
|
||||
wpi::print("{}: HAL Notifier thread\n",
|
||||
HAL_THREAD_PRIORITY_RANGE_ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/print.h>
|
||||
|
||||
#include "DigitalInternal.h"
|
||||
#include "HALInitializer.h"
|
||||
@@ -125,7 +125,7 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
|
||||
// CS0 is not a DIO port, so nothing to allocate
|
||||
handle = open("/dev/spidev0.0", O_RDWR);
|
||||
if (handle < 0) {
|
||||
fmt::print("Failed to open SPI port {}: {}\n",
|
||||
wpi::print("Failed to open SPI port {}: {}\n",
|
||||
static_cast<int32_t>(port), std::strerror(errno));
|
||||
CommonSPIPortFree();
|
||||
return;
|
||||
@@ -147,7 +147,7 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
|
||||
}
|
||||
handle = open("/dev/spidev0.1", O_RDWR);
|
||||
if (handle < 0) {
|
||||
fmt::print("Failed to open SPI port {}: {}\n",
|
||||
wpi::print("Failed to open SPI port {}: {}\n",
|
||||
static_cast<int32_t>(port), std::strerror(errno));
|
||||
CommonSPIPortFree();
|
||||
HAL_FreeDIOPort(digitalHandles[0]);
|
||||
@@ -170,7 +170,7 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
|
||||
}
|
||||
handle = open("/dev/spidev0.2", O_RDWR);
|
||||
if (handle < 0) {
|
||||
fmt::print("Failed to open SPI port {}: {}\n",
|
||||
wpi::print("Failed to open SPI port {}: {}\n",
|
||||
static_cast<int32_t>(port), std::strerror(errno));
|
||||
CommonSPIPortFree();
|
||||
HAL_FreeDIOPort(digitalHandles[1]);
|
||||
@@ -193,7 +193,7 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
|
||||
}
|
||||
handle = open("/dev/spidev0.3", O_RDWR);
|
||||
if (handle < 0) {
|
||||
fmt::print("Failed to open SPI port {}: {}\n",
|
||||
wpi::print("Failed to open SPI port {}: {}\n",
|
||||
static_cast<int32_t>(port), std::strerror(errno));
|
||||
CommonSPIPortFree();
|
||||
HAL_FreeDIOPort(digitalHandles[2]);
|
||||
@@ -240,7 +240,7 @@ void HAL_InitializeSPI(HAL_SPIPort port, int32_t* status) {
|
||||
digitalSystem->readEnableMXPSpecialFunction(status) | 0x00F0, status);
|
||||
handle = open("/dev/spidev1.0", O_RDWR);
|
||||
if (handle < 0) {
|
||||
fmt::print("Failed to open SPI port {}: {}\n",
|
||||
wpi::print("Failed to open SPI port {}: {}\n",
|
||||
static_cast<int32_t>(port), std::strerror(errno));
|
||||
HAL_FreeDIOPort(digitalHandles[5]); // free the first port allocated
|
||||
HAL_FreeDIOPort(digitalHandles[6]); // free the second port allocated
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/print.h>
|
||||
|
||||
#include "hal/HALBase.h"
|
||||
|
||||
@@ -20,7 +20,7 @@ fpga_clock::time_point fpga_clock::now() noexcept {
|
||||
int32_t status = 0;
|
||||
uint64_t currentTime = HAL_GetFPGATime(&status);
|
||||
if (status != 0) {
|
||||
fmt::print(
|
||||
wpi::print(
|
||||
stderr,
|
||||
"Call to HAL_GetFPGATime failed in fpga_clock::now() with status {}. "
|
||||
"Initialization might have failed. Time will not be correct\n",
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/SmallVector.h>
|
||||
#include <wpi/StringExtras.h>
|
||||
#include <wpi/fs.h>
|
||||
#include <wpi/print.h>
|
||||
#include <wpi/spinlock.h>
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
@@ -55,7 +55,7 @@ extern "C" {
|
||||
|
||||
int HAL_LoadOneExtension(const char* library) {
|
||||
int rc = 1; // It is expected and reasonable not to find an extra simulation
|
||||
fmt::print("HAL Extensions: Attempting to load: {}\n",
|
||||
wpi::print("HAL Extensions: Attempting to load: {}\n",
|
||||
fs::path{library}.stem().string());
|
||||
std::fflush(stdout);
|
||||
HTYPE handle = DLOPEN(library);
|
||||
@@ -66,14 +66,14 @@ int HAL_LoadOneExtension(const char* library) {
|
||||
#else
|
||||
auto libraryName = fmt::format("lib{}.so", library);
|
||||
#endif
|
||||
fmt::print("HAL Extensions: Load failed: {}\nTrying modified name: {}\n",
|
||||
wpi::print("HAL Extensions: Load failed: {}\nTrying modified name: {}\n",
|
||||
DLERROR, fs::path{libraryName}.stem().string());
|
||||
std::fflush(stdout);
|
||||
handle = DLOPEN(libraryName.c_str());
|
||||
}
|
||||
#endif
|
||||
if (!handle) {
|
||||
fmt::print("HAL Extensions: Failed to load library: {}\n", DLERROR);
|
||||
wpi::print("HAL Extensions: Failed to load library: {}\n", DLERROR);
|
||||
std::fflush(stdout);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <cstdio>
|
||||
#include <thread>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/print.h>
|
||||
#include <wpi/timestamp.h>
|
||||
|
||||
#include "MockHooksInternal.h"
|
||||
@@ -84,7 +84,7 @@ void HALSIM_WaitForProgramStart(void) {
|
||||
int count = 0;
|
||||
while (!programStarted) {
|
||||
count++;
|
||||
fmt::print("Waiting for program start signal: {}\n", count);
|
||||
wpi::print("Waiting for program start signal: {}\n", count);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user