mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
Use std::string_view and fmtlib across all libraries (#3402)
- Twine, StringRef, Format, and NativeFormatting have been removed - Logging now uses fmtlib style formatting - Nearly all uses of wpi::outs/errs have been replaced with fmt::print() or std::puts()/std::fputs() (for unformatted strings). - A wpi/fmt/raw_ostream.h header has been added to enable fmt::print() with wpi::raw_ostream
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
@@ -16,8 +17,8 @@
|
||||
#include <FRC_NetworkCommunication/FRCComm.h>
|
||||
#include <FRC_NetworkCommunication/LoadOut.h>
|
||||
#include <FRC_NetworkCommunication/UsageReporting.h>
|
||||
#include <fmt/format.h>
|
||||
#include <wpi/mutex.h>
|
||||
#include <wpi/raw_ostream.h>
|
||||
#include <wpi/timestamp.h>
|
||||
|
||||
#include "HALInitializer.h"
|
||||
@@ -330,18 +331,19 @@ static bool killExistingProgram(int timeout, int mode) {
|
||||
// see if the pid is around, but we don't want to mess with init id=1, or
|
||||
// ourselves
|
||||
if (pid >= 2 && kill(pid, 0) == 0 && pid != getpid()) {
|
||||
wpi::outs() << "Killing previously running FRC program...\n";
|
||||
std::puts("Killing previously running FRC program...");
|
||||
kill(pid, SIGTERM); // try to kill it
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(timeout));
|
||||
if (kill(pid, 0) == 0) {
|
||||
// still not successful
|
||||
wpi::outs() << "FRC pid " << pid << " did not die within " << timeout
|
||||
<< "ms. Force killing with kill -9\n";
|
||||
fmt::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);
|
||||
wpi::outs() << "Kill -9 error: " << errorMsg << "\n";
|
||||
fmt::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));
|
||||
@@ -378,7 +380,6 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
|
||||
|
||||
setlinebuf(stdin);
|
||||
setlinebuf(stdout);
|
||||
wpi::outs().SetUnbuffered();
|
||||
|
||||
prctl(PR_SET_PDEATHSIG, SIGTERM);
|
||||
|
||||
@@ -412,11 +413,11 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
|
||||
int32_t status = 0;
|
||||
uint64_t rv = HAL_GetFPGATime(&status);
|
||||
if (status != 0) {
|
||||
wpi::errs()
|
||||
<< "Call to HAL_GetFPGATime failed in wpi::Now() with status "
|
||||
<< status
|
||||
<< ". Initialization might have failed. Time will not be correct\n";
|
||||
wpi::errs().flush();
|
||||
fmt::print(stderr,
|
||||
"Call to HAL_GetFPGATime failed in wpi::Now() with status {}. "
|
||||
"Initialization might have failed. Time will not be correct\n",
|
||||
status);
|
||||
std::fflush(stderr);
|
||||
return 0u;
|
||||
}
|
||||
return rv;
|
||||
|
||||
Reference in New Issue
Block a user