From: Joel Rosdahl Date: Tue, 6 Jul 2021 19:19:57 +0000 (+0200) Subject: Remove system.hpp, including what’s needed instead X-Git-Tag: v4.4~146 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ca9ec9cfa8af99eb1e5c39c9dffdc1c611ed235c;p=thirdparty%2Fccache.git Remove system.hpp, including what’s needed instead This is the next step after a57f70eda32e99221de56f5499079b4f00dc2bc5. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index dd1e76e61..d37342296 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,10 +84,6 @@ include(GNUInstallDirs) include(GenerateConfigurationFile) include(GenerateVersionFile) -if(HAVE_SYS_MMAN_H AND HAVE_PTHREAD_MUTEXATTR_SETPSHARED) - set(INODE_CACHE_SUPPORTED 1) -endif() - # # Third party # diff --git a/cmake/GenerateConfigurationFile.cmake b/cmake/GenerateConfigurationFile.cmake index 244a5c585..30d50c10d 100644 --- a/cmake/GenerateConfigurationFile.cmake +++ b/cmake/GenerateConfigurationFile.cmake @@ -98,5 +98,9 @@ endif() # alias set(MTR_ENABLED "${ENABLE_TRACING}") +if(HAVE_SYS_MMAN_H AND HAVE_PTHREAD_MUTEXATTR_SETPSHARED) + set(INODE_CACHE_SUPPORTED 1) +endif() + configure_file(${CMAKE_SOURCE_DIR}/cmake/config.h.in ${CMAKE_BINARY_DIR}/config.h @ONLY) diff --git a/cmake/config.h.in b/cmake/config.h.in index ed2e19d49..957118f32 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -64,8 +64,6 @@ #cmakedefine _WIN32_WINNT @_WIN32_WINNT@ // clang-format on -#define SYSCONFDIR "@CMAKE_INSTALL_FULL_SYSCONFDIR@" - #ifdef __clang__ # pragma clang diagnostic pop #endif @@ -184,11 +182,41 @@ #endif #ifdef _WIN32 +# define NOMINMAX 1 +# define STDIN_FILENO 0 +# define STDOUT_FILENO 1 +# define STDERR_FILENO 2 + # ifdef _MSC_VER +# define PATH_MAX MAX_PATH typedef unsigned __int32 mode_t; typedef int pid_t; + +# ifndef __MINGW32__ +typedef __int64 ssize_t; +# endif # endif #endif // _WIN32 +// GCC version of a couple of standard C++ attributes. +#ifdef __GNUC__ +# define nodiscard gnu::warn_unused_result +# define maybe_unused gnu::unused +#endif + +// O_BINARY is needed when reading binary data on Windows, so use it everywhere +// with a compatibility define for Unix platforms. +#if !defined(_WIN32) && !defined(O_BINARY) +# define O_BINARY 0 +#endif + +#ifndef ESTALE +# define ESTALE -1 +#endif + +#define SYSCONFDIR "@CMAKE_INSTALL_FULL_SYSCONFDIR@" + +#cmakedefine INODE_CACHE_SUPPORTED + // Buffer size for I/O operations. Should be a multiple of 4 KiB. #define CCACHE_READ_BUFFER_SIZE 65536 diff --git a/src/Args.hpp b/src/Args.hpp index 48fb77df5..a93d1881b 100644 --- a/src/Args.hpp +++ b/src/Args.hpp @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include "NonCopyable.hpp" #include "Util.hpp" diff --git a/src/ArgsInfo.hpp b/src/ArgsInfo.hpp index 4d9eaf394..6e9ea823b 100644 --- a/src/ArgsInfo.hpp +++ b/src/ArgsInfo.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include "Args.hpp" #include diff --git a/src/AtomicFile.hpp b/src/AtomicFile.hpp index 118c310b4..9dba4181f 100644 --- a/src/AtomicFile.hpp +++ b/src/AtomicFile.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,8 +18,8 @@ #pragma once -#include "system.hpp" - +#include +#include #include #include diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ed64aaa1a..9b60b2109 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,11 +12,11 @@ set( Counters.cpp Decompressor.cpp Depfile.cpp + Fd.cpp Hash.cpp Lockfile.cpp Logging.cpp Manifest.cpp - MiniTrace.cpp NullCompressor.cpp NullDecompressor.cpp ProgressBar.cpp @@ -48,6 +48,10 @@ if(INODE_CACHE_SUPPORTED) list(APPEND source_files InodeCache.cpp) endif() +if(MTR_ENABLED) + list(APPEND source_files MiniTrace.cpp) +endif() + if(WIN32) list(APPEND source_files Win32Util.cpp) endif() diff --git a/src/CacheEntryReader.hpp b/src/CacheEntryReader.hpp index 37db80f5e..ba98a66e5 100644 --- a/src/CacheEntryReader.hpp +++ b/src/CacheEntryReader.hpp @@ -18,12 +18,12 @@ #pragma once -#include "system.hpp" - #include "Checksum.hpp" #include "Decompressor.hpp" #include "Util.hpp" +#include +#include #include // This class knows how to read a cache entry with a common header and a diff --git a/src/CacheEntryWriter.hpp b/src/CacheEntryWriter.hpp index dc9226f61..ccbbdff7d 100644 --- a/src/CacheEntryWriter.hpp +++ b/src/CacheEntryWriter.hpp @@ -18,12 +18,12 @@ #pragma once -#include "system.hpp" - #include "Checksum.hpp" #include "Compressor.hpp" #include "Util.hpp" +#include +#include #include // This class knows how to write a cache entry with a common header and a diff --git a/src/CacheFile.hpp b/src/CacheFile.hpp index 1cea40880..8993f5bec 100644 --- a/src/CacheFile.hpp +++ b/src/CacheFile.hpp @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include "Stat.hpp" #include "third_party/nonstd/optional.hpp" diff --git a/src/Checksum.hpp b/src/Checksum.hpp index e2c6274f3..ee8bcc23b 100644 --- a/src/Checksum.hpp +++ b/src/Checksum.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,14 +18,14 @@ #pragma once -#include "system.hpp" - #ifdef USE_XXH_DISPATCH # include "third_party/xxh_x86dispatch.h" #else # include "third_party/xxhash.h" #endif +#include + class Checksum { public: diff --git a/src/Compression.hpp b/src/Compression.hpp index 24e1746bb..42721e979 100644 --- a/src/Compression.hpp +++ b/src/Compression.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,8 +18,7 @@ #pragma once -#include "system.hpp" - +#include #include class Config; diff --git a/src/Compressor.hpp b/src/Compressor.hpp index 3295874c5..5588dada1 100644 --- a/src/Compressor.hpp +++ b/src/Compressor.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,10 +18,10 @@ #pragma once -#include "system.hpp" - #include "Compression.hpp" +#include +#include #include class Compressor diff --git a/src/Config.cpp b/src/Config.cpp index 7eed171f1..937663e01 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -27,11 +27,16 @@ #include "exceptions.hpp" #include "fmtmacros.hpp" +#include #include #include #include "third_party/fmt/core.h" +#ifdef HAVE_UNISTD_H +# include +#endif + #include #include #include @@ -43,6 +48,14 @@ using nonstd::nullopt; using nonstd::optional; +#if defined(_MSC_VER) +# define DLLIMPORT __declspec(dllimport) +#else +# define DLLIMPORT +#endif + +DLLIMPORT extern char** environ; + namespace { enum class ConfigItem { diff --git a/src/Config.hpp b/src/Config.hpp index 06069bd18..e3b822944 100644 --- a/src/Config.hpp +++ b/src/Config.hpp @@ -18,13 +18,12 @@ #pragma once -#include "system.hpp" - #include "NonCopyable.hpp" #include "Util.hpp" #include "third_party/nonstd/optional.hpp" +#include #include #include #include diff --git a/src/Context.cpp b/src/Context.cpp index d61a68b41..ff5ce1241 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -24,8 +24,13 @@ #include "Util.hpp" #include "hashutil.hpp" +#include #include +#ifdef HAVE_UNISTD_H +# include +#endif + #include #include #include diff --git a/src/Context.hpp b/src/Context.hpp index 856428b4e..d0a7e8f45 100644 --- a/src/Context.hpp +++ b/src/Context.hpp @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include "Args.hpp" #include "ArgsInfo.hpp" #include "Config.hpp" @@ -39,6 +37,7 @@ #include "third_party/nonstd/optional.hpp" #include "third_party/nonstd/string_view.hpp" +#include #include #include #include diff --git a/src/Counters.hpp b/src/Counters.hpp index d19227b5b..cb2837fbb 100644 --- a/src/Counters.hpp +++ b/src/Counters.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2010-2020 Joel Rosdahl and other contributors +// Copyright (C) 2010-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,12 +18,12 @@ #pragma once -#include "system.hpp" +#include "Statistic.hpp" +#include +#include #include -enum class Statistic; - // A simple wrapper around a vector of integers used for the statistics // counters. class Counters diff --git a/src/Decompressor.hpp b/src/Decompressor.hpp index 59558898b..44a2ae8e6 100644 --- a/src/Decompressor.hpp +++ b/src/Decompressor.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,10 +18,9 @@ #pragma once -#include "system.hpp" - #include "Compression.hpp" +#include #include class Decompressor diff --git a/src/Digest.hpp b/src/Digest.hpp index d219d5174..189b53769 100644 --- a/src/Digest.hpp +++ b/src/Digest.hpp @@ -18,12 +18,11 @@ #pragma once -#include "system.hpp" - #include "Util.hpp" #include "third_party/fmt/core.h" +#include #include // Digest represents the binary form of the final digest (AKA hash or checksum) diff --git a/src/Fd.cpp b/src/Fd.cpp new file mode 100644 index 000000000..082825819 --- /dev/null +++ b/src/Fd.cpp @@ -0,0 +1,31 @@ +// Copyright (C) 2021 Joel Rosdahl and other contributors +// +// See doc/AUTHORS.adoc for a complete list of contributors. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 51 +// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +#include "Fd.hpp" + +#include + +#ifdef HAVE_UNISTD_H +# include +#endif + +bool +Fd::close() +{ + return m_fd != -1 && ::close(release()) == 0; +} diff --git a/src/Fd.hpp b/src/Fd.hpp index 6316e45ce..3a47278c0 100644 --- a/src/Fd.hpp +++ b/src/Fd.hpp @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include "NonCopyable.hpp" #include "assertions.hpp" @@ -87,12 +85,6 @@ Fd::operator=(Fd&& other_fd) noexcept return *this; } -inline bool -Fd::close() -{ - return m_fd != -1 && ::close(release()) == 0; -} - inline int Fd::release() { diff --git a/src/File.hpp b/src/File.hpp index f8f6c0be4..fe3206f48 100644 --- a/src/File.hpp +++ b/src/File.hpp @@ -18,10 +18,9 @@ #pragma once -#include "system.hpp" - #include "NonCopyable.hpp" +#include #include class File : public NonCopyable diff --git a/src/Finalizer.hpp b/src/Finalizer.hpp index 74f6b781f..c5d2033c1 100644 --- a/src/Finalizer.hpp +++ b/src/Finalizer.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include class Finalizer diff --git a/src/FormatNonstdStringView.hpp b/src/FormatNonstdStringView.hpp index 0770a9012..4834dc41e 100644 --- a/src/FormatNonstdStringView.hpp +++ b/src/FormatNonstdStringView.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include "third_party/fmt/core.h" #include "third_party/nonstd/string_view.hpp" diff --git a/src/Hash.cpp b/src/Hash.cpp index 61cc5a3e7..2eb491dc9 100644 --- a/src/Hash.cpp +++ b/src/Hash.cpp @@ -22,6 +22,16 @@ #include "Logging.hpp" #include "fmtmacros.hpp" +#include + +#include +#include +#include + +#ifdef HAVE_UNISTD_H +# include +#endif + using nonstd::string_view; const string_view HASH_DELIMITER("\000cCaChE\000", 8); diff --git a/src/Hash.hpp b/src/Hash.hpp index d2686aff2..02c5a4d12 100644 --- a/src/Hash.hpp +++ b/src/Hash.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,13 +18,14 @@ #pragma once -#include "system.hpp" - #include "Digest.hpp" #include "third_party/blake3/blake3.h" #include "third_party/nonstd/string_view.hpp" +#include +#include + // This class represents a hash state. class Hash { diff --git a/src/InodeCache.cpp b/src/InodeCache.cpp index 34f5577d4..815e6aba6 100644 --- a/src/InodeCache.cpp +++ b/src/InodeCache.cpp @@ -19,6 +19,7 @@ #include "InodeCache.hpp" #include "Config.hpp" +#include "Digest.hpp" #include "Fd.hpp" #include "Finalizer.hpp" #include "Hash.hpp" @@ -28,8 +29,10 @@ #include "Util.hpp" #include "fmtmacros.hpp" +#include #include #include +#include #include #include @@ -63,7 +66,7 @@ const uint32_t k_num_entries = 4; static_assert(Digest::size() == 20, "Increment version number if size of digest is changed."); -static_assert(IS_TRIVIALLY_COPYABLE(Digest), +static_assert(std::is_trivially_copyable::value, "Digest is expected to be trivially copyable."); static_assert( diff --git a/src/InodeCache.hpp b/src/InodeCache.hpp index 9ef330afa..a4a272972 100644 --- a/src/InodeCache.hpp +++ b/src/InodeCache.hpp @@ -18,10 +18,7 @@ #pragma once -#include "system.hpp" - -#include "config.h" - +#include #include #include diff --git a/src/Lockfile.cpp b/src/Lockfile.cpp index 209b0aac1..b0e2a82d2 100644 --- a/src/Lockfile.cpp +++ b/src/Lockfile.cpp @@ -20,18 +20,27 @@ #include "Logging.hpp" #include "Util.hpp" +#include "Win32Util.hpp" #include "fmtmacros.hpp" -#ifdef _WIN32 -# include "Win32Util.hpp" -#endif +#include #include "third_party/fmt/core.h" +#ifdef HAVE_UNISTD_H +# include +#endif + #include #include #include +// AIX/PASE does not properly define usleep within its headers. However, the +// function is available in libc.a. +#ifdef _AIX +extern "C" int usleep(useconds_t); +#endif + namespace { #ifndef _WIN32 @@ -221,3 +230,13 @@ Lockfile::~Lockfile() #endif } } + +bool +Lockfile::acquired() const +{ +#ifndef _WIN32 + return m_acquired; +#else + return m_handle != INVALID_HANDLE_VALUE; +#endif +} diff --git a/src/Lockfile.hpp b/src/Lockfile.hpp index 78baed81e..309c0c4aa 100644 --- a/src/Lockfile.hpp +++ b/src/Lockfile.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,8 +18,7 @@ #pragma once -#include "system.hpp" - +#include #include class Lockfile @@ -40,16 +39,6 @@ private: #ifndef _WIN32 bool m_acquired = false; #else - HANDLE m_handle = nullptr; + void* m_handle = nullptr; #endif }; - -inline bool -Lockfile::acquired() const -{ -#ifndef _WIN32 - return m_acquired; -#else - return m_handle != INVALID_HANDLE_VALUE; -#endif -} diff --git a/src/Logging.cpp b/src/Logging.cpp index c6590d88e..45a785a95 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -22,10 +22,17 @@ #include "Config.hpp" #include "File.hpp" #include "Util.hpp" +#include "Win32Util.hpp" #include "exceptions.hpp" #include "execute.hpp" #include "fmtmacros.hpp" +#include + +#ifdef HAVE_UNISTD_H +# include +#endif + #ifdef HAVE_SYSLOG_H # include #endif @@ -39,12 +46,6 @@ # endif #endif -#ifdef _WIN32 -# include -# include -# include -#endif - using nonstd::string_view; namespace { diff --git a/src/Logging.hpp b/src/Logging.hpp index 5c780ec15..7ed70faef 100644 --- a/src/Logging.hpp +++ b/src/Logging.hpp @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include "FormatNonstdStringView.hpp" #include "third_party/fmt/core.h" diff --git a/src/Manifest.hpp b/src/Manifest.hpp index addf17ec4..0230c707a 100644 --- a/src/Manifest.hpp +++ b/src/Manifest.hpp @@ -18,10 +18,11 @@ #pragma once -#include "system.hpp" - #include "third_party/nonstd/optional.hpp" +#include +#include +#include #include #include diff --git a/src/MiniTrace.cpp b/src/MiniTrace.cpp index f593caa99..07f495ad7 100644 --- a/src/MiniTrace.cpp +++ b/src/MiniTrace.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -16,50 +16,53 @@ // this program; if not, write to the Free Software Foundation, Inc., 51 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -#include "system.hpp" +#include "MiniTrace.hpp" -#ifdef MTR_ENABLED +#include "ArgsInfo.hpp" +#include "TemporaryFile.hpp" +#include "Util.hpp" +#include "fmtmacros.hpp" -# include "ArgsInfo.hpp" -# include "MiniTrace.hpp" -# include "TemporaryFile.hpp" -# include "Util.hpp" -# include "fmtmacros.hpp" +#include -# ifdef HAVE_SYS_TIME_H -# include -# endif +#ifdef HAVE_SYS_TIME_H +# include +#endif + +#ifdef HAVE_UNISTD_H +# include +#endif namespace { std::string get_system_tmp_dir() { -# ifndef _WIN32 +#ifndef _WIN32 const char* tmpdir = getenv("TMPDIR"); if (tmpdir) { return tmpdir; } -# else +#else static char dirbuf[PATH_MAX]; DWORD retval = GetTempPath(PATH_MAX, dirbuf); if (retval > 0 && retval < PATH_MAX) { return dirbuf; } -# endif +#endif return "/tmp"; } double time_seconds() { -# ifdef HAVE_GETTIMEOFDAY +#ifdef HAVE_GETTIMEOFDAY struct timeval tv; gettimeofday(&tv, nullptr); return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0; -# else +#else return (double)time(nullptr); -# endif +#endif } } // namespace @@ -89,5 +92,3 @@ MiniTrace::~MiniTrace() } Util::unlink_tmp(m_tmp_trace_file); } - -#endif diff --git a/src/MiniTrace.hpp b/src/MiniTrace.hpp index 25d886458..76aae3810 100644 --- a/src/MiniTrace.hpp +++ b/src/MiniTrace.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,13 +18,9 @@ #pragma once -#include "system.hpp" - #include "third_party/minitrace.h" -#ifdef MTR_ENABLED - -# include +#include struct ArgsInfo; @@ -40,5 +36,3 @@ private: std::string m_tmp_trace_file; std::string m_start_time; }; - -#endif diff --git a/src/NullCompressor.hpp b/src/NullCompressor.hpp index 9a4fcd16d..e7abe29f8 100644 --- a/src/NullCompressor.hpp +++ b/src/NullCompressor.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,11 +18,11 @@ #pragma once -#include "system.hpp" - #include "Compressor.hpp" #include "NonCopyable.hpp" +#include + // A compressor of an uncompressed stream. class NullCompressor : public Compressor, NonCopyable { diff --git a/src/NullDecompressor.hpp b/src/NullDecompressor.hpp index 514ed7d7c..68ccf8822 100644 --- a/src/NullDecompressor.hpp +++ b/src/NullDecompressor.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,11 +18,11 @@ #pragma once -#include "system.hpp" - #include "Decompressor.hpp" #include "NonCopyable.hpp" +#include + // A decompressor of an uncompressed stream. class NullDecompressor : public Decompressor, NonCopyable { diff --git a/src/ProgressBar.cpp b/src/ProgressBar.cpp index c7b219e02..99a37a088 100644 --- a/src/ProgressBar.cpp +++ b/src/ProgressBar.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -20,9 +20,12 @@ #include "fmtmacros.hpp" +#include + #include "third_party/fmt/core.h" -#ifndef _WIN32 +#ifdef _WIN32 +#else # include #endif @@ -30,6 +33,10 @@ # include #endif +#ifdef HAVE_UNISTD_H +# include +#endif + #include namespace { diff --git a/src/ProgressBar.hpp b/src/ProgressBar.hpp index 8aefa897d..1be38020a 100644 --- a/src/ProgressBar.hpp +++ b/src/ProgressBar.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,8 +18,8 @@ #pragma once -#include "system.hpp" - +#include +#include #include class ProgressBar diff --git a/src/Result.cpp b/src/Result.cpp index 4fd15483e..a5c66fc58 100644 --- a/src/Result.cpp +++ b/src/Result.cpp @@ -32,8 +32,17 @@ #include "exceptions.hpp" #include "fmtmacros.hpp" +#include #include +#include +#include +#include + +#ifdef HAVE_UNISTD_H +# include +#endif + #include // Result data format diff --git a/src/Result.hpp b/src/Result.hpp index 7fcfc95b6..67032c58f 100644 --- a/src/Result.hpp +++ b/src/Result.hpp @@ -18,11 +18,10 @@ #pragma once -#include "system.hpp" - #include "third_party/nonstd/expected.hpp" #include "third_party/nonstd/optional.hpp" +#include #include #include #include diff --git a/src/ResultDumper.hpp b/src/ResultDumper.hpp index 85602d61f..c48d2ab59 100644 --- a/src/ResultDumper.hpp +++ b/src/ResultDumper.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,10 +18,11 @@ #pragma once -#include "system.hpp" - #include "Result.hpp" +#include +#include + // This class dumps information about the result entry to `stream`. class ResultDumper : public Result::Reader::Consumer { diff --git a/src/ResultExtractor.cpp b/src/ResultExtractor.cpp index e18ae5160..b46f3000c 100644 --- a/src/ResultExtractor.cpp +++ b/src/ResultExtractor.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -21,6 +21,12 @@ #include "Util.hpp" #include "fmtmacros.hpp" +#include + +#include +#include +#include + ResultExtractor::ResultExtractor(const std::string& directory) : m_directory(directory) { diff --git a/src/ResultExtractor.hpp b/src/ResultExtractor.hpp index f4b8f3bed..0e801ff4a 100644 --- a/src/ResultExtractor.hpp +++ b/src/ResultExtractor.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include "Fd.hpp" #include "Result.hpp" diff --git a/src/ResultRetriever.cpp b/src/ResultRetriever.cpp index 0218877c3..9eff7125a 100644 --- a/src/ResultRetriever.cpp +++ b/src/ResultRetriever.cpp @@ -22,6 +22,16 @@ #include "Depfile.hpp" #include "Logging.hpp" +#include + +#include +#include +#include + +#ifdef HAVE_UNISTD_H +# include +#endif + using Result::FileType; ResultRetriever::ResultRetriever(Context& ctx, bool rewrite_dependency_target) diff --git a/src/ResultRetriever.hpp b/src/ResultRetriever.hpp index 609f15f91..a2ab43941 100644 --- a/src/ResultRetriever.hpp +++ b/src/ResultRetriever.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include "Fd.hpp" #include "Result.hpp" diff --git a/src/SignalHandler.cpp b/src/SignalHandler.cpp index 8a07cc7e1..9051eeb0d 100644 --- a/src/SignalHandler.cpp +++ b/src/SignalHandler.cpp @@ -24,6 +24,9 @@ # include "assertions.hpp" # include // NOLINT: sigaddset et al are defined in signal.h +# include +# include +# include namespace { diff --git a/src/SignalHandler.hpp b/src/SignalHandler.hpp index 3ef88479d..603dbe213 100644 --- a/src/SignalHandler.hpp +++ b/src/SignalHandler.hpp @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - class Context; class SignalHandler diff --git a/src/Stat.cpp b/src/Stat.cpp index 244fd6f5a..ffd11843d 100644 --- a/src/Stat.cpp +++ b/src/Stat.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,14 +18,15 @@ #include "Stat.hpp" -#ifdef _WIN32 -# include "Win32Util.hpp" - -# include "third_party/win32/winerror_to_errno.h" -#endif - #include "Finalizer.hpp" #include "Logging.hpp" +#include "Win32Util.hpp" + +#include + +#ifdef _WIN32 +# include +#endif namespace { diff --git a/src/Stat.hpp b/src/Stat.hpp index 5a046d2ab..9cf9a210b 100644 --- a/src/Stat.hpp +++ b/src/Stat.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,12 +18,43 @@ #pragma once -#include "system.hpp" - #include "exceptions.hpp" +#include +#include + #include +#ifdef _WIN32 +# ifndef S_IFIFO +# define S_IFIFO 0x1000 +# endif +# ifndef S_IFBLK +# define S_IFBLK 0x6000 +# endif +# ifndef S_IFLNK +# define S_IFLNK 0xA000 +# endif +# ifndef S_ISREG +# define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) +# endif +# ifndef S_ISDIR +# define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) +# endif +# ifndef S_ISFIFO +# define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO) +# endif +# ifndef S_ISCHR +# define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR) +# endif +# ifndef S_ISLNK +# define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK) +# endif +# ifndef S_ISBLK +# define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK) +# endif +#endif + class Stat { public: diff --git a/src/Statistics.hpp b/src/Statistics.hpp index 6e5917b43..ef7087900 100644 --- a/src/Statistics.hpp +++ b/src/Statistics.hpp @@ -18,15 +18,12 @@ #pragma once -#include "system.hpp" - #include "Counters.hpp" -#include "Statistic.hpp" // Any reasonable use of Statistics requires the Statistic enum. #include "third_party/nonstd/optional.hpp" +#include #include -#include #include class Config; diff --git a/src/ThreadPool.hpp b/src/ThreadPool.hpp index 5eee38182..fa4653825 100644 --- a/src/ThreadPool.hpp +++ b/src/ThreadPool.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include #include #include diff --git a/src/UmaskScope.hpp b/src/UmaskScope.hpp index a641c1f35..2a2f85a74 100644 --- a/src/UmaskScope.hpp +++ b/src/UmaskScope.hpp @@ -18,10 +18,11 @@ #pragma once -#include "system.hpp" - #include "third_party/nonstd/optional.hpp" +#include +#include + // This class sets a new (process-global) umask and restores the previous umask // when destructed. class UmaskScope diff --git a/src/Util.cpp b/src/Util.cpp index fd701eadc..e40729960 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -24,14 +24,26 @@ #include "FormatNonstdStringView.hpp" #include "Logging.hpp" #include "TemporaryFile.hpp" +#include "Win32Util.hpp" #include "fmtmacros.hpp" +#include #include extern "C" { #include "third_party/base32hex.h" } +#ifdef HAVE_DIRENT_H +# include +#endif + +#ifdef HAVE_UNISTD_H +# include +#endif + +#include + #include #include @@ -47,6 +59,12 @@ extern "C" { # include #endif +#ifdef HAVE_UTIME_H +# include +#elif defined(HAVE_SYS_UTIME_H) +# include +#endif + #ifdef HAVE_LINUX_FS_H # include # include @@ -55,10 +73,6 @@ extern "C" { # include #endif -#ifdef _WIN32 -# include "Win32Util.hpp" -#endif - #ifdef __linux__ # ifdef HAVE_SYS_IOCTL_H # include diff --git a/src/Util.hpp b/src/Util.hpp index d31657c79..0c8328aa2 100644 --- a/src/Util.hpp +++ b/src/Util.hpp @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include "CacheFile.hpp" #include @@ -28,6 +26,7 @@ #include "third_party/nonstd/string_view.hpp" #include +#include #include #include #include diff --git a/src/Win32Util.hpp b/src/Win32Util.hpp index 0a2f1a133..ceeab576a 100644 --- a/src/Win32Util.hpp +++ b/src/Win32Util.hpp @@ -18,9 +18,19 @@ #pragma once -#include "system.hpp" +#ifdef _WIN32 -#include +# include + +# include + +void usleep(int64_t usec); +struct tm* localtime_r(time_t* _clock, struct tm* _result); + +# ifdef _MSC_VER +int gettimeofday(struct timeval* tp, struct timezone* tzp); +int asprintf(char** strp, const char* fmt, ...); +# endif namespace Win32Util { @@ -44,3 +54,5 @@ std::string error_message(DWORD error_code); NTSTATUS get_last_ntstatus(); } // namespace Win32Util + +#endif diff --git a/src/ZstdCompressor.hpp b/src/ZstdCompressor.hpp index 58ca45342..2551d1326 100644 --- a/src/ZstdCompressor.hpp +++ b/src/ZstdCompressor.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,13 +18,13 @@ #pragma once -#include "system.hpp" - #include "Compressor.hpp" #include "NonCopyable.hpp" #include +#include + // A compressor of a Zstandard stream. class ZstdCompressor : public Compressor, NonCopyable { diff --git a/src/ZstdDecompressor.hpp b/src/ZstdDecompressor.hpp index 4c79886b4..2868982b0 100644 --- a/src/ZstdDecompressor.hpp +++ b/src/ZstdDecompressor.hpp @@ -18,13 +18,11 @@ #pragma once -#include "system.hpp" - #include "Decompressor.hpp" #include -#include +#include // A decompressor of a Zstandard stream. class ZstdDecompressor : public Decompressor diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp index 839e4538a..62c4716db 100644 --- a/src/argprocessing.cpp +++ b/src/argprocessing.cpp @@ -26,6 +26,12 @@ #include "fmtmacros.hpp" #include "language.hpp" +#include + +#ifdef HAVE_UNISTD_H +# include +#endif + #include using nonstd::nullopt; @@ -94,7 +100,8 @@ bool color_output_possible() { const char* term_env = getenv("TERM"); - return isatty(STDERR_FILENO) && term_env && strcasecmp(term_env, "DUMB") != 0; + return isatty(STDERR_FILENO) && term_env + && Util::to_lowercase(term_env) != "dumb"; } bool diff --git a/src/assertions.hpp b/src/assertions.hpp index 040c3a5f6..d88cb10f5 100644 --- a/src/assertions.hpp +++ b/src/assertions.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,7 +18,7 @@ #pragma once -#include "system.hpp" +#include #ifdef _MSC_VER # define CCACHE_FUNCTION __func__ diff --git a/src/ccache.cpp b/src/ccache.cpp index 65daa54a2..69534f1e3 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -44,6 +44,7 @@ #include "TemporaryFile.hpp" #include "UmaskScope.hpp" #include "Util.hpp" +#include "Win32Util.hpp" #include "argprocessing.hpp" #include "cleanup.hpp" #include "compopt.hpp" @@ -55,6 +56,7 @@ #include "language.hpp" #include +#include #include #include "third_party/fmt/core.h" @@ -71,8 +73,10 @@ extern "C" { } #endif -#ifdef _WIN32 -# include "Win32Util.hpp" +#include + +#ifdef HAVE_UNISTD_H +# include #endif #include diff --git a/src/ccache.hpp b/src/ccache.hpp index da1f342e7..e4fb11607 100644 --- a/src/ccache.hpp +++ b/src/ccache.hpp @@ -19,8 +19,6 @@ #pragma once -#include "system.hpp" - #include "Config.hpp" #include "third_party/nonstd/string_view.hpp" diff --git a/src/cleanup.hpp b/src/cleanup.hpp index 053eb53e0..97d5cb75c 100644 --- a/src/cleanup.hpp +++ b/src/cleanup.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,10 +18,9 @@ #pragma once -#include "system.hpp" - #include "Util.hpp" +#include #include class Config; diff --git a/src/compopt.cpp b/src/compopt.cpp index 5e5f143f2..8cc516e0b 100644 --- a/src/compopt.cpp +++ b/src/compopt.cpp @@ -45,6 +45,8 @@ // The option only affects compilation; not passed to the preprocessor. #define AFFECTS_COMP (1 << 6) +#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) + struct CompOpt { const char* name; diff --git a/src/compopt.hpp b/src/compopt.hpp index a0169280a..29a3354b0 100644 --- a/src/compopt.hpp +++ b/src/compopt.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2010-2020 Joel Rosdahl and other contributors +// Copyright (C) 2010-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include bool compopt_short(bool (*fn)(const std::string& option), diff --git a/src/compress.cpp b/src/compress.cpp index 70c711762..4a26de784 100644 --- a/src/compress.cpp +++ b/src/compress.cpp @@ -32,8 +32,14 @@ #include "assertions.hpp" #include "fmtmacros.hpp" +#include + #include "third_party/fmt/core.h" +#ifdef HAVE_UNISTD_H +# include +#endif + #include #include #include diff --git a/src/compress.hpp b/src/compress.hpp index 91eb04d1b..dd1670b18 100644 --- a/src/compress.hpp +++ b/src/compress.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include "Util.hpp" #include "third_party/nonstd/optional.hpp" diff --git a/src/core/wincompat.hpp b/src/core/wincompat.hpp new file mode 100644 index 000000000..4bc2d16aa --- /dev/null +++ b/src/core/wincompat.hpp @@ -0,0 +1,103 @@ +// Copyright (C) 2021 Joel Rosdahl and other contributors +// +// See doc/AUTHORS.adoc for a complete list of contributors. +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program; if not, write to the Free Software Foundation, Inc., 51 +// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +#pragma once + +#ifdef _WIN32 + +# include + +# ifndef __MINGW32__ +typedef __int64 ssize_t; +# endif + +// From: +// http://mesos.apache.org/api/latest/c++/3rdparty_2stout_2include_2stout_2windows_8hpp_source.html +# ifdef _MSC_VER +const mode_t S_IRUSR = mode_t(_S_IREAD); +const mode_t S_IWUSR = mode_t(_S_IWRITE); +# endif + +# ifndef S_IFIFO +# define S_IFIFO 0x1000 +# endif + +# ifndef S_IFBLK +# define S_IFBLK 0x6000 +# endif + +# ifndef S_IFLNK +# define S_IFLNK 0xA000 +# endif + +# ifndef S_ISREG +# define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) +# endif +# ifndef S_ISDIR +# define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) +# endif +# ifndef S_ISFIFO +# define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO) +# endif +# ifndef S_ISCHR +# define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR) +# endif +# ifndef S_ISLNK +# define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK) +# endif +# ifndef S_ISBLK +# define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK) +# endif + +# include +# include +# include +# include +# define NOMINMAX 1 +# define WIN32_NO_STATUS +// clang-format off +# include +# include // NTSTATUS +# include // struct timeval +// clang-format on +# undef WIN32_NO_STATUS +# include +# define mkdir(a, b) _mkdir(a) + +// Protect against incidental use of MinGW execv. +# define execv(a, b) do_not_call_execv_on_windows + +# ifdef _MSC_VER +# define PATH_MAX MAX_PATH +# endif + +# ifdef _MSC_VER +# define DLLIMPORT __declspec(dllimport) +# else +# define DLLIMPORT +# endif + +# define STDIN_FILENO 0 +# define STDOUT_FILENO 1 +# define STDERR_FILENO 2 + +# ifndef O_BINARY +# define O_BINARY 0 +# endif + +#endif // _WIN32 diff --git a/src/exceptions.hpp b/src/exceptions.hpp index 6f7ccb32f..65c4e2e86 100644 --- a/src/exceptions.hpp +++ b/src/exceptions.hpp @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include "FormatNonstdStringView.hpp" #include "third_party/fmt/core.h" diff --git a/src/execute.cpp b/src/execute.cpp index 4f7a9a6bd..6dac76440 100644 --- a/src/execute.cpp +++ b/src/execute.cpp @@ -27,13 +27,22 @@ #include "Stat.hpp" #include "TemporaryFile.hpp" #include "Util.hpp" +#include "Win32Util.hpp" #include "fmtmacros.hpp" +#include #include +#ifdef HAVE_UNISTD_H +# include +#endif + +#ifdef HAVE_SYS_WAIT_H +# include +#endif + #ifdef _WIN32 # include "Finalizer.hpp" -# include "Win32Util.hpp" #endif using nonstd::string_view; diff --git a/src/execute.hpp b/src/execute.hpp index 628ceb327..8e4922639 100644 --- a/src/execute.hpp +++ b/src/execute.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include "Fd.hpp" #include diff --git a/src/hashutil.cpp b/src/hashutil.cpp index 7378c02fa..73350e33a 100644 --- a/src/hashutil.cpp +++ b/src/hashutil.cpp @@ -25,18 +25,25 @@ #include "Logging.hpp" #include "Sloppiness.hpp" #include "Stat.hpp" +#include "Win32Util.hpp" #include "execute.hpp" #include "fmtmacros.hpp" #include "macroskip.hpp" -#include "third_party/blake3/blake3_cpu_supports_avx2.h" +#include #ifdef INODE_CACHE_SUPPORTED # include "InodeCache.hpp" #endif -#ifdef _WIN32 -# include "Win32Util.hpp" +#include "third_party/blake3/blake3_cpu_supports_avx2.h" + +#ifdef HAVE_UNISTD_H +# include +#endif + +#ifdef HAVE_SYS_WAIT_H +# include #endif #ifdef HAVE_AVX2 diff --git a/src/hashutil.hpp b/src/hashutil.hpp index 51ac36af7..b3f1756d7 100644 --- a/src/hashutil.hpp +++ b/src/hashutil.hpp @@ -18,10 +18,9 @@ #pragma once -#include "system.hpp" - #include "third_party/nonstd/string_view.hpp" +#include #include class Config; diff --git a/src/language.hpp b/src/language.hpp index 99bf386e0..74be7aaf6 100644 --- a/src/language.hpp +++ b/src/language.hpp @@ -18,8 +18,6 @@ #pragma once -#include "system.hpp" - #include "Config.hpp" #include diff --git a/src/macroskip.hpp b/src/macroskip.hpp index f15932346..5cacba87f 100644 --- a/src/macroskip.hpp +++ b/src/macroskip.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2010-2020 Joel Rosdahl and other contributors +// Copyright (C) 2010-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,7 +18,7 @@ #pragma once -#include "system.hpp" +#include // A Boyer-Moore-Horspool skip table used for searching for the strings // "__TIME__", "__DATE__" and "__TIMESTAMP__". diff --git a/src/storage/primary/PrimaryStorage.cpp b/src/storage/primary/PrimaryStorage.cpp index df8d7b6aa..027f2bff8 100644 --- a/src/storage/primary/PrimaryStorage.cpp +++ b/src/storage/primary/PrimaryStorage.cpp @@ -27,10 +27,15 @@ #include #include #include +#include #include #include #include +#ifdef HAVE_UNISTD_H +# include +#endif + namespace storage { namespace primary { diff --git a/src/system.hpp b/src/system.hpp deleted file mode 100644 index df71a6d1a..000000000 --- a/src/system.hpp +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright (C) 2010-2021 Joel Rosdahl and other contributors -// -// See doc/AUTHORS.adoc for a complete list of contributors. -// -// This program is free software; you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the Free -// Software Foundation; either version 3 of the License, or (at your option) -// any later version. -// -// This program is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -// more details. -// -// You should have received a copy of the GNU General Public License along with -// this program; if not, write to the Free Software Foundation, Inc., 51 -// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -#pragma once - -#ifdef HAVE_SYS_FILE_H -# include -#endif - -#ifdef HAVE_SYS_MMAN_H -# include -#endif -#include -#include -#ifdef HAVE_SYS_WAIT_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_DIRENT_H -# include -#endif - -#include - -#ifdef HAVE_STRINGS_H -# include -#endif - -#ifdef HAVE_UNISTD_H -# include -#endif - -#ifdef HAVE_UTIME_H -# include -#elif defined(HAVE_SYS_UTIME_H) -# include -#endif - -#ifdef HAVE_VARARGS_H -# include -#endif - -// AIX/PASE does not properly define usleep within its headers. However, the -// function is available in libc.a. This extern define ensures that it is -// usable within the ccache code base. -#ifdef _AIX -extern "C" int usleep(useconds_t); -#endif - -#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) - -#ifndef ESTALE -# define ESTALE -1 -#endif - -#ifdef _WIN32 -# ifndef _WIN32_WINNT -// _WIN32_WINNT is set in the generated header config.h -# error _WIN32_WINNT is undefined -# endif - -# ifndef __MINGW32__ -typedef int64_t ssize_t; -# endif - -// Defined in Win32Util.cpp -void usleep(int64_t usec); -struct tm* localtime_r(time_t* _clock, struct tm* _result); - -# ifdef _MSC_VER -int gettimeofday(struct timeval* tp, struct timezone* tzp); -int asprintf(char** strp, const char* fmt, ...); -# endif - -// From: -// http://mesos.apache.org/api/latest/c++/3rdparty_2stout_2include_2stout_2windows_8hpp_source.html -# ifdef _MSC_VER -const mode_t S_IRUSR = mode_t(_S_IREAD); -const mode_t S_IWUSR = mode_t(_S_IWRITE); -# endif - -# ifndef S_IFIFO -# define S_IFIFO 0x1000 -# endif - -# ifndef S_IFBLK -# define S_IFBLK 0x6000 -# endif - -# ifndef S_IFLNK -# define S_IFLNK 0xA000 -# endif - -# ifndef S_ISREG -# define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) -# endif -# ifndef S_ISDIR -# define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) -# endif -# ifndef S_ISFIFO -# define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO) -# endif -# ifndef S_ISCHR -# define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR) -# endif -# ifndef S_ISLNK -# define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK) -# endif -# ifndef S_ISBLK -# define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK) -# endif - -# include -# include -# include -# define NOMINMAX 1 -# define WIN32_NO_STATUS -// clang-format off -# include -# include // NTSTATUS -# include // struct timeval -// clang-format on -# undef WIN32_NO_STATUS -# include -# define mkdir(a, b) _mkdir(a) -# define execv(a, b) \ - do_not_call_execv_on_windows // to protect against incidental use of MinGW - // execv -# define strncasecmp _strnicmp -# define strcasecmp _stricmp - -# ifdef _MSC_VER -# define PATH_MAX MAX_PATH -# endif - -# ifdef _MSC_VER -# define DLLIMPORT __declspec(dllimport) -# else -# define DLLIMPORT -# endif - -# define STDIN_FILENO 0 -# define STDOUT_FILENO 1 -# define STDERR_FILENO 2 -#else -# define DLLIMPORT -#endif - -DLLIMPORT extern char** environ; - -// Work with silly DOS binary open. -#ifndef O_BINARY -# define O_BINARY 0 -#endif - -#if defined(HAVE_SYS_MMAN_H) && defined(HAVE_PTHREAD_MUTEXATTR_SETPSHARED) -# define INODE_CACHE_SUPPORTED -#endif - -// Workaround for missing std::is_trivially_copyable in GCC < 5. -#if __GNUG__ && __GNUC__ < 5 -# define IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T) -#else -# define IS_TRIVIALLY_COPYABLE(T) std::is_trivially_copyable::value -#endif - -// GCC version of a couple of standard C++ attributes -#ifdef __GNUC__ -# define nodiscard gnu::warn_unused_result -# define maybe_unused gnu::unused -#endif diff --git a/unittest/TestUtil.cpp b/unittest/TestUtil.cpp index fa8f7f01b..615f8bcb9 100644 --- a/unittest/TestUtil.cpp +++ b/unittest/TestUtil.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -22,6 +22,12 @@ #include "../src/exceptions.hpp" #include "../src/fmtmacros.hpp" +#include + +#ifdef HAVE_UNISTD_H +# include +#endif + namespace TestUtil { size_t TestContext::m_subdir_counter = 0; diff --git a/unittest/TestUtil.hpp b/unittest/TestUtil.hpp index 0f06d3ee3..6be4969b2 100644 --- a/unittest/TestUtil.hpp +++ b/unittest/TestUtil.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -18,8 +18,7 @@ #pragma once -#include "system.hpp" - +#include #include #ifdef _MSC_VER diff --git a/unittest/test_Lockfile.cpp b/unittest/test_Lockfile.cpp index 7a01512ea..d95cb3d1b 100644 --- a/unittest/test_Lockfile.cpp +++ b/unittest/test_Lockfile.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2020 Joel Rosdahl and other contributors +// Copyright (C) 2020-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -20,8 +20,14 @@ #include "../src/Stat.hpp" #include "TestUtil.hpp" +#include + #include "third_party/doctest.h" +#ifdef HAVE_UNISTD_H +# include +#endif + TEST_SUITE_BEGIN("LockFile"); using TestUtil::TestContext; diff --git a/unittest/test_NullCompression.cpp b/unittest/test_NullCompression.cpp index 22da2f55f..9ea78afef 100644 --- a/unittest/test_NullCompression.cpp +++ b/unittest/test_NullCompression.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -24,6 +24,8 @@ #include "third_party/doctest.h" +#include + using TestUtil::TestContext; TEST_SUITE_BEGIN("NullCompression"); diff --git a/unittest/test_Stat.cpp b/unittest/test_Stat.cpp index e5b6eeb83..c67673299 100644 --- a/unittest/test_Stat.cpp +++ b/unittest/test_Stat.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -21,6 +21,8 @@ #include "../src/Util.hpp" #include "TestUtil.hpp" +#include + #include "third_party/doctest.h" #ifdef HAVE_UNISTD_H diff --git a/unittest/test_Util.cpp b/unittest/test_Util.cpp index 4720c8ba5..cd40e8d8f 100644 --- a/unittest/test_Util.cpp +++ b/unittest/test_Util.cpp @@ -22,9 +22,17 @@ #include "../src/fmtmacros.hpp" #include "TestUtil.hpp" +#include + #include "third_party/doctest.h" #include "third_party/nonstd/optional.hpp" +#include + +#ifdef HAVE_UNISTD_H +# include +#endif + #include using doctest::Approx; diff --git a/unittest/test_ZstdCompression.cpp b/unittest/test_ZstdCompression.cpp index a72f59e56..834350346 100644 --- a/unittest/test_ZstdCompression.cpp +++ b/unittest/test_ZstdCompression.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2020 Joel Rosdahl and other contributors +// Copyright (C) 2019-2021 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -24,6 +24,8 @@ #include "third_party/doctest.h" +#include + using TestUtil::TestContext; TEST_SUITE_BEGIN("ZstdCompression"); diff --git a/unittest/test_argprocessing.cpp b/unittest/test_argprocessing.cpp index aa4c0550a..8ac228b5e 100644 --- a/unittest/test_argprocessing.cpp +++ b/unittest/test_argprocessing.cpp @@ -25,6 +25,8 @@ #include "TestUtil.hpp" #include "argprocessing.hpp" +#include + #include "third_party/doctest.h" #include diff --git a/unittest/test_bsdmkstemp.cpp b/unittest/test_bsdmkstemp.cpp index 6ded67403..5a8dd6d18 100644 --- a/unittest/test_bsdmkstemp.cpp +++ b/unittest/test_bsdmkstemp.cpp @@ -20,6 +20,8 @@ #include "../src/Finalizer.hpp" #include "TestUtil.hpp" +#include + #include "third_party/doctest.h" #include "third_party/win32/mktemp.h" diff --git a/unittest/test_ccache.cpp b/unittest/test_ccache.cpp index 3236a4883..a09a316e7 100644 --- a/unittest/test_ccache.cpp +++ b/unittest/test_ccache.cpp @@ -22,9 +22,15 @@ #include "../src/fmtmacros.hpp" #include "TestUtil.hpp" +#include + #include "third_party/doctest.h" #include "third_party/nonstd/optional.hpp" +#ifdef HAVE_UNISTD_H +# include +#endif + #ifdef MYNAME # define CCACHE_NAME MYNAME #else