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 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); const auto data = cruft::slurp<char> (src);
context ctx; context ctx;
@ -148,7 +148,7 @@ include::process (std::ostream &os,
cruft::view<cruft::tokeniser<const char*>::iterator> lines) const cruft::view<cruft::tokeniser<const char*>::iterator> lines) const
{ {
const auto name = lines.begin ()->slice (strlen("#include '"), -2); 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 target = ctx.source.top ().parent_path () / fragment;
const auto data = cruft::slurp<char> (target); const auto data = cruft::slurp<char> (target);

14
cpp.hpp
View File

@ -12,7 +12,7 @@
#include "string.hpp" #include "string.hpp"
#include "view.hpp" #include "view.hpp"
#include <experimental/filesystem> #include <filesystem>
#include <string> #include <string>
#include <map> #include <map>
#include <stdexcept> #include <stdexcept>
@ -21,7 +21,7 @@
namespace cruft::cpp { namespace cruft::cpp {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
struct context { struct context {
std::stack<std::experimental::filesystem::path> source; std::stack<std::filesystem::path> source;
std::map<std::string,std::string> defines; std::map<std::string,std::string> defines;
}; };
@ -52,10 +52,10 @@ namespace cruft::cpp {
processor (); processor ();
void add (std::string token, std::unique_ptr<directive>); 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 std::filesystem::path
resolve (const std::experimental::filesystem::path&) const; resolve (const std::filesystem::path&) const;
cruft::tokeniser<const char*>::iterator cruft::tokeniser<const char*>::iterator
process (std::ostream&, process (std::ostream&,
@ -111,7 +111,7 @@ namespace cruft::cpp {
public: public:
include (processor &_parent); include (processor &_parent);
void add (const std::experimental::filesystem::path&); void add (const std::filesystem::path&);
virtual cruft::tokeniser<const char*>::iterator virtual cruft::tokeniser<const char*>::iterator
process (std::ostream&, process (std::ostream&,
@ -120,7 +120,7 @@ namespace cruft::cpp {
private: private:
processor &m_parent; 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 #ifndef __UTIL_EXE_HPP
#define __UTIL_EXE_HPP #define __UTIL_EXE_HPP
#include <experimental/filesystem> #include <filesystem>
namespace cruft { namespace cruft {
/// Returns a path to the current executable. /// Returns a path to the current executable.
std::experimental::filesystem::path image_path (void); std::filesystem::path image_path (void);
} }
#endif #endif

View File

@ -5,7 +5,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
std::experimental::filesystem::path std::filesystem::path
cruft::image_path (void) cruft::image_path (void)
{ {
int name[] = { int name[] = {
@ -21,5 +21,5 @@ cruft::image_path (void)
auto err = sysctl (name, elems (name), data, &len, nullptr, 0); auto err = sysctl (name, elems (name), data, &len, nullptr, 0);
errno_error::try_code (err); 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 "posix/except.hpp"
#include <vector> #include <vector>
#include <experimental/filesystem> #include <filesystem>
#include <unistd.h> #include <unistd.h>
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
std::experimental::filesystem::path std::filesystem::path
cruft::image_path (void) cruft::image_path (void)
{ {
static const char PROC_SELF[] = "/proc/self/exe"; static const char PROC_SELF[] = "/proc/self/exe";
@ -38,6 +38,6 @@ retry:
goto 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/except.hpp"
#include "win32/windows.hpp" #include "win32/windows.hpp"
#include <experimental/filesystem> #include <filesystem>
#include <vector> #include <vector>
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
std::experimental::filesystem::path std::filesystem::path
cruft::image_path (void) cruft::image_path (void)
{ {
std::vector<char> resolved (256); std::vector<char> resolved (256);
@ -31,5 +31,5 @@ retry:
goto 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 <sys/stat.h>
#include <unistd.h> #include <unistd.h>
namespace ns = std::experimental::filesystem; namespace ns = std::filesystem;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

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

View File

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

16
io.cpp
View File

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

10
io.hpp
View File

@ -15,7 +15,7 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include <experimental/filesystem> #include <filesystem>
#include <vector> #include <vector>
#include <streambuf> #include <streambuf>
@ -30,7 +30,7 @@ namespace cruft {
/// Reads an entire file into memory in one operation. /// Reads an entire file into memory in one operation.
template <typename T = std::byte> template <typename T = std::byte>
std::vector<T> 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 { class path_error : public std::runtime_error {
public: 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: private:
const std::experimental::filesystem::path m_path; std::filesystem::path const m_path;
}; };
class stream_error : public std::exception { 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 fflags,
int mflags): int mflags):
mapped_file (cruft::posix::fd (path, fflags), mflags) mapped_file (cruft::posix::fd (path, fflags), mflags)

View File

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

View File

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

View File

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

View File

@ -9,7 +9,7 @@
#ifndef __UTIL_LIBRARY_POSIX_HPP #ifndef __UTIL_LIBRARY_POSIX_HPP
#define __UTIL_LIBRARY_POSIX_HPP #define __UTIL_LIBRARY_POSIX_HPP
#include <experimental/filesystem> #include <filesystem>
#include <dlfcn.h> #include <dlfcn.h>
@ -17,7 +17,7 @@ namespace cruft {
namespace detail { namespace detail {
class library_posix { class library_posix {
public: public:
explicit library_posix (const std::experimental::filesystem::path&); explicit library_posix (const std::filesystem::path&);
library_posix (library_posix&&) noexcept; library_posix (library_posix&&) noexcept;
~library_posix (); ~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 ())) m_handle (LoadLibraryA (path.u8string ().c_str ()))
{ {
if (!m_handle) if (!m_handle)

View File

@ -13,13 +13,13 @@
#include <cruft/util/cast.hpp> #include <cruft/util/cast.hpp>
#include <experimental/filesystem> #include <filesystem>
namespace cruft { namespace cruft {
namespace detail::win32 { namespace detail::win32 {
class library { class library {
public: public:
explicit library (const std::experimental::filesystem::path&); explicit library (const std::filesystem::path&);
library (library const&) = delete; library (library const&) = delete;
library& operator=(library const&) = delete; library& operator=(library const&) = delete;
library (library&&); 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 ())) m_handle (::opendir (p.u8string ().c_str ()))
{ {
if (!m_handle) if (!m_handle)

View File

@ -15,13 +15,13 @@
#include <dirent.h> #include <dirent.h>
#include <functional> #include <functional>
#include <experimental/filesystem> #include <filesystem>
namespace cruft::posix { namespace cruft::posix {
struct dir { struct dir {
public: public:
explicit dir (const std::experimental::filesystem::path&); explicit dir (const std::filesystem::path&);
~dir (); ~dir ();
operator DIR* (void); 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 (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))) m_fd (error::try_value (::open (path.u8string ().c_str (), flags, mode)))
{ {
// You always want binary mode. Always. // You always want binary mode. Always.

View File

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

View File

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

View File

@ -2,7 +2,7 @@
#include "../exe.hpp" #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 // so we compare the filename instead under the assumption that it should
// be stable across path styles. // be stable across path styles.
auto const query = cruft::image_path (); 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 ( tap.expect_eq (
query.stem (), query.stem (),
truth.stem (), truth.stem (),

View File

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

View File

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