build: transition from experimental filesystem

This commit is contained in:
Danny Robson 2018-12-05 19:12:03 +11:00
parent f3f59e1f37
commit 1a82e4fe76
27 changed files with 71 additions and 71 deletions

View File

@ -38,7 +38,7 @@ processor::add (std::string token, std::unique_ptr<directive> handler)
//-----------------------------------------------------------------------------
void
processor::process (std::ostream &os, const std::experimental::filesystem::path &src) const
processor::process (std::ostream &os, const std::filesystem::path &src) const
{
const auto data = cruft::slurp<char> (src);
context ctx;
@ -148,7 +148,7 @@ include::process (std::ostream &os,
cruft::view<cruft::tokeniser<const char*>::iterator> lines) const
{
const auto name = lines.begin ()->slice (strlen("#include '"), -2);
std::experimental::filesystem::path fragment { name.begin (), name.end () };
std::filesystem::path fragment { name.begin (), name.end () };
const auto target = ctx.source.top ().parent_path () / fragment;
const auto data = cruft::slurp<char> (target);

14
cpp.hpp
View File

@ -12,7 +12,7 @@
#include "string.hpp"
#include "view.hpp"
#include <experimental/filesystem>
#include <filesystem>
#include <string>
#include <map>
#include <stdexcept>
@ -21,7 +21,7 @@
namespace cruft::cpp {
///////////////////////////////////////////////////////////////////////////
struct context {
std::stack<std::experimental::filesystem::path> source;
std::stack<std::filesystem::path> source;
std::map<std::string,std::string> defines;
};
@ -52,10 +52,10 @@ namespace cruft::cpp {
processor ();
void add (std::string token, std::unique_ptr<directive>);
void process (std::ostream&, const std::experimental::filesystem::path&) const;
void process (std::ostream&, const std::filesystem::path&) const;
std::experimental::filesystem::path
resolve (const std::experimental::filesystem::path&) const;
std::filesystem::path
resolve (const std::filesystem::path&) const;
cruft::tokeniser<const char*>::iterator
process (std::ostream&,
@ -111,7 +111,7 @@ namespace cruft::cpp {
public:
include (processor &_parent);
void add (const std::experimental::filesystem::path&);
void add (const std::filesystem::path&);
virtual cruft::tokeniser<const char*>::iterator
process (std::ostream&,
@ -120,7 +120,7 @@ namespace cruft::cpp {
private:
processor &m_parent;
std::vector<std::experimental::filesystem::path> m_paths;
std::vector<std::filesystem::path> m_paths;
};
};

View File

@ -9,11 +9,11 @@
#ifndef __UTIL_EXE_HPP
#define __UTIL_EXE_HPP
#include <experimental/filesystem>
#include <filesystem>
namespace cruft {
/// Returns a path to the current executable.
std::experimental::filesystem::path image_path (void);
std::filesystem::path image_path (void);
}
#endif

View File

@ -5,7 +5,7 @@
#include <sys/types.h>
#include <sys/sysctl.h>
std::experimental::filesystem::path
std::filesystem::path
cruft::image_path (void)
{
int name[] = {
@ -21,5 +21,5 @@ cruft::image_path (void)
auto err = sysctl (name, elems (name), data, &len, nullptr, 0);
errno_error::try_code (err);
return std::experimental::filesystem::path (std::cbegin (data), std::cbegin (data) + len);
return std::filesystem::path (std::cbegin (data), std::cbegin (data) + len);
}

View File

@ -12,13 +12,13 @@
#include "posix/except.hpp"
#include <vector>
#include <experimental/filesystem>
#include <filesystem>
#include <unistd.h>
///////////////////////////////////////////////////////////////////////////////
std::experimental::filesystem::path
std::filesystem::path
cruft::image_path (void)
{
static const char PROC_SELF[] = "/proc/self/exe";
@ -38,6 +38,6 @@ retry:
goto retry;
}
return std::experimental::filesystem::path (resolved.data (), resolved.data () + written);
return std::filesystem::path (resolved.data (), resolved.data () + written);
}

View File

@ -11,12 +11,12 @@
#include "win32/except.hpp"
#include "win32/windows.hpp"
#include <experimental/filesystem>
#include <filesystem>
#include <vector>
///////////////////////////////////////////////////////////////////////////////
std::experimental::filesystem::path
std::filesystem::path
cruft::image_path (void)
{
std::vector<char> resolved (256);
@ -31,5 +31,5 @@ retry:
goto retry;
}
return std::experimental::filesystem::path (resolved.data (), resolved.data () + written);
return std::filesystem::path (resolved.data (), resolved.data () + written);
}

View File

@ -15,7 +15,7 @@
#include <sys/stat.h>
#include <unistd.h>
namespace ns = std::experimental::filesystem;
namespace ns = std::filesystem;
///////////////////////////////////////////////////////////////////////////////

View File

@ -12,7 +12,7 @@
#include <string>
///////////////////////////////////////////////////////////////////////////////
namespace std::experimental::filesystem {
namespace std::filesystem {
class path {
public:
using value_type = char;

View File

@ -16,7 +16,7 @@
#include <array>
#include <cstddef>
#include <cstdint>
#include <experimental/filesystem>
#include <filesystem>
#include <ostream>
#include <string>
#include <tuple>
@ -60,7 +60,7 @@ namespace cruft {
CLANG_WORKAROUND(const char*, const_cstring, "cstring")
CLANG_WORKAROUND(char*, cstring, "cstring")
CLANG_WORKAROUND(std::string, string, "string")
CLANG_WORKAROUND(std::experimental::filesystem::path, path, "path");
CLANG_WORKAROUND(std::filesystem::path, path, "path");
CLANG_WORKAROUND(std::byte, byte, "byte");

16
io.cpp
View File

@ -18,7 +18,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <experimental/filesystem>
#include <filesystem>
#include <stdexcept>
@ -28,7 +28,7 @@ using namespace cruft;
//////////////////////////////////////////////////////////////////////////////
template <typename T>
std::vector<T>
cruft::slurp (const std::experimental::filesystem::path &path)
cruft::slurp (const std::filesystem::path &path)
{
posix::fd out (path, O_RDONLY | O_BINARY);
@ -63,10 +63,10 @@ cruft::slurp (const std::experimental::filesystem::path &path)
//-----------------------------------------------------------------------------
template std::vector<char> cruft::slurp (const std::experimental::filesystem::path&);
template std::vector<unsigned char> cruft::slurp (const std::experimental::filesystem::path&);
template std::vector<std::byte> cruft::slurp (const std::experimental::filesystem::path&);
template std::vector<uint32_t> cruft::slurp (const std::experimental::filesystem::path&);
template std::vector<char> cruft::slurp (const std::filesystem::path&);
template std::vector<unsigned char> cruft::slurp (const std::filesystem::path&);
template std::vector<std::byte> cruft::slurp (const std::filesystem::path&);
template std::vector<uint32_t> cruft::slurp (const std::filesystem::path&);
///////////////////////////////////////////////////////////////////////////////
@ -231,14 +231,14 @@ scoped_cwd::~scoped_cwd ()
///////////////////////////////////////////////////////////////////////////////
path_error::path_error (const std::experimental::filesystem::path &_path):
path_error::path_error (const std::filesystem::path &_path):
runtime_error (to_string (format::printf ("Unknown path: %!", m_path))),
m_path (_path)
{ ; }
//-----------------------------------------------------------------------------
const std::experimental::filesystem::path&
const std::filesystem::path&
path_error::path (void) const noexcept
{
return m_path;

10
io.hpp
View File

@ -15,7 +15,7 @@
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <experimental/filesystem>
#include <filesystem>
#include <vector>
#include <streambuf>
@ -30,7 +30,7 @@ namespace cruft {
/// Reads an entire file into memory in one operation.
template <typename T = std::byte>
std::vector<T>
slurp (const std::experimental::filesystem::path&);
slurp (std::filesystem::path const&);
///------------------------------------------------------------------------
@ -135,12 +135,12 @@ namespace cruft {
//-------------------------------------------------------------------------
class path_error : public std::runtime_error {
public:
explicit path_error (const std::experimental::filesystem::path &path);
explicit path_error (std::filesystem::path const &path);
const std::experimental::filesystem::path& path (void) const noexcept;
std::filesystem::path const& path (void) const noexcept;
private:
const std::experimental::filesystem::path m_path;
std::filesystem::path const m_path;
};
class stream_error : public std::exception {

View File

@ -19,7 +19,7 @@ using cruft::detail::posix::mapped_file;
//////////////////////////////////////////////////////////////////////////////
mapped_file::mapped_file (const std::experimental::filesystem::path &path,
mapped_file::mapped_file (const std::filesystem::path &path,
int fflags,
int mflags):
mapped_file (cruft::posix::fd (path, fflags), mflags)

View File

@ -14,7 +14,7 @@
#include "view.hpp"
#include <type_traits>
#include <experimental/filesystem>
#include <filesystem>
#include <sys/mman.h>
#include <fcntl.h>
@ -36,7 +36,7 @@ namespace cruft {
using difference_type = std::iterator_traits<iterator>::difference_type;
using size_type = size_t;
mapped_file (const std::experimental::filesystem::path&,
mapped_file (const std::filesystem::path&,
int fflags = O_RDONLY | O_BINARY,
int mflags = PROT_READ);
mapped_file (const cruft::posix::fd&,

View File

@ -114,7 +114,7 @@ mapped_file::mapped_file (::cruft::win32::handle &&src,
//-----------------------------------------------------------------------------
mapped_file::mapped_file (
std::experimental::filesystem::path const &path,
std::filesystem::path const &path,
int fflags,
int mflags
)

View File

@ -17,7 +17,7 @@
#include "view.hpp"
#include <cstdint>
#include <experimental/filesystem>
#include <filesystem>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
@ -59,7 +59,7 @@ namespace cruft {
mapped_file (::cruft::win32::handle &&,
int fflags = O_RDONLY,
int mflags = PROT_READ);
mapped_file (const std::experimental::filesystem::path &path,
mapped_file (const std::filesystem::path &path,
int fflags = O_RDONLY,
int mflags = PROT_READ);
mapped_file (cruft::posix::fd const&,

View File

@ -15,7 +15,7 @@ using cruft::detail::library_posix;
///////////////////////////////////////////////////////////////////////////////
library_posix::library_posix (const std::experimental::filesystem::path &path):
library_posix::library_posix (const std::filesystem::path &path):
m_handle (dlopen (path.c_str (), RTLD_NOW))
{
if (!m_handle)

View File

@ -9,7 +9,7 @@
#ifndef __UTIL_LIBRARY_POSIX_HPP
#define __UTIL_LIBRARY_POSIX_HPP
#include <experimental/filesystem>
#include <filesystem>
#include <dlfcn.h>
@ -17,7 +17,7 @@ namespace cruft {
namespace detail {
class library_posix {
public:
explicit library_posix (const std::experimental::filesystem::path&);
explicit library_posix (const std::filesystem::path&);
library_posix (library_posix&&) noexcept;
~library_posix ();

View File

@ -14,7 +14,7 @@ using cruft::detail::win32::library;
///////////////////////////////////////////////////////////////////////////////
library::library (const std::experimental::filesystem::path &path):
library::library (const std::filesystem::path &path):
m_handle (LoadLibraryA (path.u8string ().c_str ()))
{
if (!m_handle)

View File

@ -13,13 +13,13 @@
#include <cruft/util/cast.hpp>
#include <experimental/filesystem>
#include <filesystem>
namespace cruft {
namespace detail::win32 {
class library {
public:
explicit library (const std::experimental::filesystem::path&);
explicit library (const std::filesystem::path&);
library (library const&) = delete;
library& operator=(library const&) = delete;
library (library&&);

View File

@ -14,7 +14,7 @@ using cruft::posix::dir;
///////////////////////////////////////////////////////////////////////////////
dir::dir (const std::experimental::filesystem::path &p):
dir::dir (const std::filesystem::path &p):
m_handle (::opendir (p.u8string ().c_str ()))
{
if (!m_handle)

View File

@ -15,13 +15,13 @@
#include <dirent.h>
#include <functional>
#include <experimental/filesystem>
#include <filesystem>
namespace cruft::posix {
struct dir {
public:
explicit dir (const std::experimental::filesystem::path&);
explicit dir (const std::filesystem::path&);
~dir ();
operator DIR* (void);

View File

@ -19,13 +19,13 @@ using cruft::posix::fd;
///////////////////////////////////////////////////////////////////////////////
fd::fd (const std::experimental::filesystem::path &path, int flags):
fd::fd (const std::filesystem::path &path, int flags):
fd (path, flags, 0666)
{ ; }
//-----------------------------------------------------------------------------
fd::fd (const std::experimental::filesystem::path &path, int flags, mode_t mode):
fd::fd (const std::filesystem::path &path, int flags, mode_t mode):
m_fd (error::try_value (::open (path.u8string ().c_str (), flags, mode)))
{
// You always want binary mode. Always.

View File

@ -12,7 +12,7 @@
#include "../debug.hpp"
#include "../view.hpp"
#include <experimental/filesystem>
#include <filesystem>
#include <sys/types.h>
#include <sys/stat.h>
@ -33,8 +33,8 @@ namespace cruft::posix {
// If you are using a system which delineates between binary/text mode
// for descriptors the behaviour is undefined if you don't set the
// necessary flags for binary mode.
fd (const std::experimental::filesystem::path &path, int flags);
fd (const std::experimental::filesystem::path &path, int flags, mode_t);
fd (const std::filesystem::path &path, int flags);
fd (const std::filesystem::path &path, int flags, mode_t);
fd (fd &&) noexcept;
fd& operator= (fd &&) noexcept;

View File

@ -10,7 +10,7 @@
#include "string.hpp"
#include <experimental/filesystem>
#include <filesystem>
#include <cstdlib>
#include <stdexcept>
@ -24,14 +24,14 @@ const graphics graphics::RESET (0);
//
// throws an exception if not found
static
std::experimental::filesystem::path
find_terminfo_path (const std::experimental::filesystem::path &dir,
std::filesystem::path
find_terminfo_path (const std::filesystem::path &dir,
const std::string &key)
{
const char letter[2] = { key[0], '\0' };
auto candidate = dir / letter / key;
if (!std::experimental::filesystem::is_directory (candidate))
if (!std::filesystem::is_directory (candidate))
throw std::runtime_error ("path not found");
return candidate;
@ -43,10 +43,10 @@ find_terminfo_path (const std::experimental::filesystem::path &dir,
//
// throws an exception if not found
static
std::experimental::filesystem::path
std::filesystem::path
find_terminfo_path [[gnu::unused]] (const std::string &key)
{
static const std::experimental::filesystem::path DEFAULT_SEARCH_DIR = "/usr/share/terminfo";
static const std::filesystem::path DEFAULT_SEARCH_DIR = "/usr/share/terminfo";
// check if the path is explicitly listed. must not fall through.
if (const char *dir = getenv ("TERMINFO")) {
@ -55,7 +55,7 @@ find_terminfo_path [[gnu::unused]] (const std::string &key)
// check if we have a path at $HOME. falls through.
if (const char *home = getenv ("HOME")) {
std::experimental::filesystem::path HOME (home);
std::filesystem::path HOME (home);
try {
return find_terminfo_path (HOME / ".terminfo", key);
} catch (...) { }
@ -70,7 +70,7 @@ find_terminfo_path [[gnu::unused]] (const std::string &key)
return find_terminfo_path (
i.empty () ?
DEFAULT_SEARCH_DIR :
std::experimental::filesystem::path (i.cbegin (), i.cend ()), key
std::filesystem::path (i.cbegin (), i.cend ()), key
);
} catch (...) { }
}

View File

@ -2,7 +2,7 @@
#include "../exe.hpp"
#include <experimental/filesystem>
#include <filesystem>
///////////////////////////////////////////////////////////////////////////////
@ -18,7 +18,7 @@ main (int, char **argv)
// so we compare the filename instead under the assumption that it should
// be stable across path styles.
auto const query = cruft::image_path ();
auto const truth = std::experimental::filesystem::path (argv[0]);
auto const truth = std::filesystem::path (argv[0]);
tap.expect_eq (
query.stem (),
truth.stem (),

View File

@ -15,11 +15,11 @@
#include "io.hpp"
#include <experimental/filesystem>
#include <filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
namespace fs = std::filesystem;
///////////////////////////////////////////////////////////////////////////////

View File

@ -20,7 +20,7 @@ enum {
#if 0
///////////////////////////////////////////////////////////////////////////////
void process (std::ostream &dst, const std::experimental::filesystem::path&);
void process (std::ostream &dst, const std::filesystem::path&);
///////////////////////////////////////////////////////////////////////////////
@ -42,7 +42,7 @@ struct include {
///////////////////////////////////////////////////////////////////////////////
void
process (std::ostream &dst, const std::experimental::filesystem::path &src)
process (std::ostream &dst, const std::filesystem::path &src)
{
auto data = cruft::slurp<char> (src);
include handler;
@ -68,7 +68,7 @@ main (const int argc, const char **argv)
return EXIT_FAILURE;
}
std::experimental::filesystem::path src = argv[ARG_SRC];
std::filesystem::path src = argv[ARG_SRC];
if (argc == 3) {
std::ofstream dst (argv[ARG_DST]);