[wpiutil] Replace llvm filesystem with C++17 filesystem (#3401)

Use ghc::filesystem as fill on older GCC (e.g. RoboRIO).
This can be removed once all GCC platforms have upgraded to 8.1 or later.

File open functionality has been retained from LLVM but moved to "fs" namespace
and tweaked for improved consistency with std::filesystem (e.g. error_code is
passed by reference instead of returned).

Also update WPILibC's Filesystem functions to return std::string.
This commit is contained in:
Peter Johnson
2021-06-01 21:50:35 -07:00
committed by GitHub
parent 01dc0249de
commit fe570e000c
25 changed files with 6757 additions and 3538 deletions

View File

@@ -4,9 +4,9 @@
#include "LoggerImpl.h"
#include <wpi/Path.h>
#include <wpi/SmallString.h>
#include <wpi/StringRef.h>
#include <wpi/fs.h>
#include <wpi/raw_ostream.h>
using namespace nt;
@@ -70,13 +70,12 @@ unsigned int LoggerImpl::GetMinLevel() {
void LoggerImpl::Log(unsigned int level, const char* file, unsigned int line,
const char* msg) {
// this is safe because it's null terminated and always the end
const char* filename = wpi::sys::path::filename(file).data();
auto filename = fs::path{file}.filename();
{
auto thr = GetThread();
if (!thr || thr->m_listeners.empty()) {
DefaultLogger(level, filename, line, msg);
DefaultLogger(level, filename.string().c_str(), line, msg);
}
}
Send(UINT_MAX, 0, level, filename, line, msg);
Send(UINT_MAX, 0, level, filename.string().c_str(), line, msg);
}

View File

@@ -6,10 +6,10 @@
#include <string>
#include <wpi/Base64.h>
#include <wpi/FileSystem.h>
#include <wpi/Format.h>
#include <wpi/SmallString.h>
#include <wpi/StringExtras.h>
#include <wpi/fs.h>
#include <wpi/raw_ostream.h>
#include "Log.h"
@@ -209,7 +209,7 @@ const char* Storage::SavePersistent(const wpi::Twine& filename,
// start by writing to temporary file
std::error_code ec;
wpi::raw_fd_ostream os(tmp, ec, wpi::sys::fs::F_Text);
wpi::raw_fd_ostream os(tmp, ec, fs::F_Text);
if (ec.value() != 0) {
err = "could not open file";
goto done;
@@ -266,7 +266,7 @@ const char* Storage::SaveEntries(const wpi::Twine& filename,
// start by writing to temporary file
std::error_code ec;
wpi::raw_fd_ostream os(tmp, ec, wpi::sys::fs::F_Text);
wpi::raw_fd_ostream os(tmp, ec, fs::F_Text);
if (ec.value() != 0) {
return "could not open file";
}