include(GenerateConfigurationFile)
include(GenerateVersionFile)
-if(HAVE_SYS_MMAN_H AND HAVE_PTHREAD_MUTEXATTR_SETPSHARED)
- set(INODE_CACHE_SUPPORTED 1)
-endif()
-
#
# Third party
#
# 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)
#cmakedefine _WIN32_WINNT @_WIN32_WINNT@
// clang-format on
-#define SYSCONFDIR "@CMAKE_INSTALL_FULL_SYSCONFDIR@"
-
#ifdef __clang__
# pragma clang diagnostic pop
#endif
#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
#pragma once
-#include "system.hpp"
-
#include "NonCopyable.hpp"
#include "Util.hpp"
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "Args.hpp"
#include <string>
-// 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.
//
#pragma once
-#include "system.hpp"
-
+#include <cstdint>
+#include <cstdio>
#include <string>
#include <vector>
Counters.cpp
Decompressor.cpp
Depfile.cpp
+ Fd.cpp
Hash.cpp
Lockfile.cpp
Logging.cpp
Manifest.cpp
- MiniTrace.cpp
NullCompressor.cpp
NullDecompressor.cpp
ProgressBar.cpp
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()
#pragma once
-#include "system.hpp"
-
#include "Checksum.hpp"
#include "Decompressor.hpp"
#include "Util.hpp"
+#include <cstdint>
+#include <cstdio>
#include <memory>
// This class knows how to read a cache entry with a common header and a
#pragma once
-#include "system.hpp"
-
#include "Checksum.hpp"
#include "Compressor.hpp"
#include "Util.hpp"
+#include <cstdint>
+#include <cstdio>
#include <memory>
// This class knows how to write a cache entry with a common header and a
#pragma once
-#include "system.hpp"
-
#include "Stat.hpp"
#include "third_party/nonstd/optional.hpp"
-// 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.
//
#pragma once
-#include "system.hpp"
-
#ifdef USE_XXH_DISPATCH
# include "third_party/xxh_x86dispatch.h"
#else
# include "third_party/xxhash.h"
#endif
+#include <cstdint>
+
class Checksum
{
public:
-// 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.
//
#pragma once
-#include "system.hpp"
-
+#include <cstdint>
#include <string>
class Config;
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "Compression.hpp"
+#include <cstdint>
+#include <cstdio>
#include <memory>
class Compressor
#include "exceptions.hpp"
#include "fmtmacros.hpp"
+#include <core/wincompat.hpp>
#include <util/path_utils.hpp>
#include <util/string_utils.hpp>
#include "third_party/fmt/core.h"
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
#include <algorithm>
#include <cassert>
#include <fstream>
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 {
#pragma once
-#include "system.hpp"
-
#include "NonCopyable.hpp"
#include "Util.hpp"
#include "third_party/nonstd/optional.hpp"
+#include <cstdint>
#include <functional>
#include <limits>
#include <string>
#include "Util.hpp"
#include "hashutil.hpp"
+#include <core/wincompat.hpp>
#include <util/path_utils.hpp>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
#include <algorithm>
#include <string>
#include <vector>
#pragma once
-#include "system.hpp"
-
#include "Args.hpp"
#include "ArgsInfo.hpp"
#include "Config.hpp"
#include "third_party/nonstd/optional.hpp"
#include "third_party/nonstd/string_view.hpp"
+#include <ctime>
#include <string>
#include <unordered_map>
#include <vector>
-// 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.
//
#pragma once
-#include "system.hpp"
+#include "Statistic.hpp"
+#include <cstddef>
+#include <cstdint>
#include <vector>
-enum class Statistic;
-
// A simple wrapper around a vector of integers used for the statistics
// counters.
class Counters
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "Compression.hpp"
+#include <cstdio>
#include <memory>
class Decompressor
#pragma once
-#include "system.hpp"
-
#include "Util.hpp"
#include "third_party/fmt/core.h"
+#include <cstdint>
#include <string>
// Digest represents the binary form of the final digest (AKA hash or checksum)
--- /dev/null
+// 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 <core/wincompat.hpp>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+bool
+Fd::close()
+{
+ return m_fd != -1 && ::close(release()) == 0;
+}
#pragma once
-#include "system.hpp"
-
#include "NonCopyable.hpp"
#include "assertions.hpp"
return *this;
}
-inline bool
-Fd::close()
-{
- return m_fd != -1 && ::close(release()) == 0;
-}
-
inline int
Fd::release()
{
#pragma once
-#include "system.hpp"
-
#include "NonCopyable.hpp"
+#include <cstdio>
#include <string>
class File : public NonCopyable
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include <functional>
class Finalizer
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "third_party/fmt/core.h"
#include "third_party/nonstd/string_view.hpp"
#include "Logging.hpp"
#include "fmtmacros.hpp"
+#include <core/wincompat.hpp>
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
using nonstd::string_view;
const string_view HASH_DELIMITER("\000cCaChE\000", 8);
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "Digest.hpp"
#include "third_party/blake3/blake3.h"
#include "third_party/nonstd/string_view.hpp"
+#include <cstdint>
+#include <cstdio>
+
// This class represents a hash state.
class Hash
{
#include "InodeCache.hpp"
#include "Config.hpp"
+#include "Digest.hpp"
#include "Fd.hpp"
#include "Finalizer.hpp"
#include "Hash.hpp"
#include "Util.hpp"
#include "fmtmacros.hpp"
+#include <fcntl.h>
#include <libgen.h>
#include <sys/mman.h>
+#include <unistd.h>
#include <atomic>
#include <type_traits>
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<Digest>::value,
"Digest is expected to be trivially copyable.");
static_assert(
#pragma once
-#include "system.hpp"
-
-#include "config.h"
-
+#include <cstdint>
#include <functional>
#include <string>
#include "Logging.hpp"
#include "Util.hpp"
+#include "Win32Util.hpp"
#include "fmtmacros.hpp"
-#ifdef _WIN32
-# include "Win32Util.hpp"
-#endif
+#include <core/wincompat.hpp>
#include "third_party/fmt/core.h"
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
#include <algorithm>
#include <sstream>
#include <thread>
+// 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
#endif
}
}
+
+bool
+Lockfile::acquired() const
+{
+#ifndef _WIN32
+ return m_acquired;
+#else
+ return m_handle != INVALID_HANDLE_VALUE;
+#endif
+}
-// 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.
//
#pragma once
-#include "system.hpp"
-
+#include <cstdint>
#include <string>
class Lockfile
#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
-}
#include "Config.hpp"
#include "File.hpp"
#include "Util.hpp"
+#include "Win32Util.hpp"
#include "exceptions.hpp"
#include "execute.hpp"
#include "fmtmacros.hpp"
+#include <core/wincompat.hpp>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
#ifdef HAVE_SYSLOG_H
# include <syslog.h>
#endif
# endif
#endif
-#ifdef _WIN32
-# include <psapi.h>
-# include <sys/locking.h>
-# include <tchar.h>
-#endif
-
using nonstd::string_view;
namespace {
#pragma once
-#include "system.hpp"
-
#include "FormatNonstdStringView.hpp"
#include "third_party/fmt/core.h"
#pragma once
-#include "system.hpp"
-
#include "third_party/nonstd/optional.hpp"
+#include <cstdint>
+#include <cstdio>
+#include <ctime>
#include <string>
#include <unordered_map>
-// 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.
//
// 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 <core/wincompat.hpp>
-# ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
-# endif
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#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
}
Util::unlink_tmp(m_tmp_trace_file);
}
-
-#endif
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "third_party/minitrace.h"
-#ifdef MTR_ENABLED
-
-# include <string>
+#include <string>
struct ArgsInfo;
std::string m_tmp_trace_file;
std::string m_start_time;
};
-
-#endif
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "Compressor.hpp"
#include "NonCopyable.hpp"
+#include <cstdio>
+
// A compressor of an uncompressed stream.
class NullCompressor : public Compressor, NonCopyable
{
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "Decompressor.hpp"
#include "NonCopyable.hpp"
+#include <cstdio>
+
// A decompressor of an uncompressed stream.
class NullDecompressor : public Decompressor, NonCopyable
{
-// 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.
//
#include "fmtmacros.hpp"
+#include <core/wincompat.hpp>
+
#include "third_party/fmt/core.h"
-#ifndef _WIN32
+#ifdef _WIN32
+#else
# include <sys/ioctl.h>
#endif
# include <termios.h>
#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
#include <algorithm>
namespace {
-// 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.
//
#pragma once
-#include "system.hpp"
-
+#include <cstddef>
+#include <cstdint>
#include <string>
class ProgressBar
#include "exceptions.hpp"
#include "fmtmacros.hpp"
+#include <core/wincompat.hpp>
#include <util/path_utils.hpp>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
#include <algorithm>
// Result data format
#pragma once
-#include "system.hpp"
-
#include "third_party/nonstd/expected.hpp"
#include "third_party/nonstd/optional.hpp"
+#include <cstdint>
#include <map>
#include <string>
#include <vector>
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "Result.hpp"
+#include <cstdint>
+#include <cstdio>
+
// This class dumps information about the result entry to `stream`.
class ResultDumper : public Result::Reader::Consumer
{
-// 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.
//
#include "Util.hpp"
#include "fmtmacros.hpp"
+#include <core/wincompat.hpp>
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
ResultExtractor::ResultExtractor(const std::string& directory)
: m_directory(directory)
{
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "Fd.hpp"
#include "Result.hpp"
#include "Depfile.hpp"
#include "Logging.hpp"
+#include <core/wincompat.hpp>
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
using Result::FileType;
ResultRetriever::ResultRetriever(Context& ctx, bool rewrite_dependency_target)
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "Fd.hpp"
#include "Result.hpp"
# include "assertions.hpp"
# include <signal.h> // NOLINT: sigaddset et al are defined in signal.h
+# include <sys/types.h>
+# include <sys/wait.h>
+# include <unistd.h>
namespace {
#pragma once
-#include "system.hpp"
-
class Context;
class SignalHandler
-// 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.
//
#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 <core/wincompat.hpp>
+
+#ifdef _WIN32
+# include <third_party/win32/winerror_to_errno.h>
+#endif
namespace {
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "exceptions.hpp"
+#include <sys/stat.h>
+#include <sys/types.h>
+
#include <string>
+#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:
#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 <ctime>
#include <functional>
-#include <sstream>
#include <string>
class Config;
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include <condition_variable>
#include <functional>
#include <limits>
#pragma once
-#include "system.hpp"
-
#include "third_party/nonstd/optional.hpp"
+#include <sys/stat.h>
+#include <sys/types.h>
+
// This class sets a new (process-global) umask and restores the previous umask
// when destructed.
class UmaskScope
#include "FormatNonstdStringView.hpp"
#include "Logging.hpp"
#include "TemporaryFile.hpp"
+#include "Win32Util.hpp"
#include "fmtmacros.hpp"
+#include <core/wincompat.hpp>
#include <util/path_utils.hpp>
extern "C" {
#include "third_party/base32hex.h"
}
+#ifdef HAVE_DIRENT_H
+# include <dirent.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#include <fcntl.h>
+
#include <algorithm>
#include <fstream>
# include <sys/time.h>
#endif
+#ifdef HAVE_UTIME_H
+# include <utime.h>
+#elif defined(HAVE_SYS_UTIME_H)
+# include <sys/utime.h>
+#endif
+
#ifdef HAVE_LINUX_FS_H
# include <linux/magic.h>
# include <sys/statfs.h>
# include <sys/param.h>
#endif
-#ifdef _WIN32
-# include "Win32Util.hpp"
-#endif
-
#ifdef __linux__
# ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#pragma once
-#include "system.hpp"
-
#include "CacheFile.hpp"
#include <util/Tokenizer.hpp>
#include "third_party/nonstd/string_view.hpp"
#include <algorithm>
+#include <cstdint>
#include <functional>
#include <ios>
#include <memory>
#pragma once
-#include "system.hpp"
+#ifdef _WIN32
-#include <string>
+# include <core/wincompat.hpp>
+
+# include <string>
+
+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 {
NTSTATUS get_last_ntstatus();
} // namespace Win32Util
+
+#endif
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "Compressor.hpp"
#include "NonCopyable.hpp"
#include <zstd.h>
+#include <cstdint>
+
// A compressor of a Zstandard stream.
class ZstdCompressor : public Compressor, NonCopyable
{
#pragma once
-#include "system.hpp"
-
#include "Decompressor.hpp"
#include <zstd.h>
-#include <fstream>
+#include <cstdint>
// A decompressor of a Zstandard stream.
class ZstdDecompressor : public Decompressor
#include "fmtmacros.hpp"
#include "language.hpp"
+#include <core/wincompat.hpp>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
#include <cassert>
using nonstd::nullopt;
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
-// 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.
//
#pragma once
-#include "system.hpp"
+#include <cstddef>
#ifdef _MSC_VER
# define CCACHE_FUNCTION __func__
#include "TemporaryFile.hpp"
#include "UmaskScope.hpp"
#include "Util.hpp"
+#include "Win32Util.hpp"
#include "argprocessing.hpp"
#include "cleanup.hpp"
#include "compopt.hpp"
#include "language.hpp"
#include <core/types.hpp>
+#include <core/wincompat.hpp>
#include <util/path_utils.hpp>
#include "third_party/fmt/core.h"
}
#endif
-#ifdef _WIN32
-# include "Win32Util.hpp"
+#include <fcntl.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
#endif
#include <algorithm>
#pragma once
-#include "system.hpp"
-
#include "Config.hpp"
#include "third_party/nonstd/string_view.hpp"
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "Util.hpp"
+#include <cstdint>
#include <string>
class Config;
// 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;
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include <string>
bool compopt_short(bool (*fn)(const std::string& option),
#include "assertions.hpp"
#include "fmtmacros.hpp"
+#include <core/wincompat.hpp>
+
#include "third_party/fmt/core.h"
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
#include <memory>
#include <string>
#include <thread>
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "Util.hpp"
#include "third_party/nonstd/optional.hpp"
--- /dev/null
+// 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 <sys/stat.h>
+
+# 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 <direct.h>
+# include <fcntl.h>
+# include <io.h>
+# include <process.h>
+# define NOMINMAX 1
+# define WIN32_NO_STATUS
+// clang-format off
+# include <windows.h>
+# include <bcrypt.h> // NTSTATUS
+# include <winsock2.h> // struct timeval
+// clang-format on
+# undef WIN32_NO_STATUS
+# include <ntstatus.h>
+# 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
#pragma once
-#include "system.hpp"
-
#include "FormatNonstdStringView.hpp"
#include "third_party/fmt/core.h"
#include "Stat.hpp"
#include "TemporaryFile.hpp"
#include "Util.hpp"
+#include "Win32Util.hpp"
#include "fmtmacros.hpp"
+#include <core/wincompat.hpp>
#include <util/path_utils.hpp>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#ifdef HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
+
#ifdef _WIN32
# include "Finalizer.hpp"
-# include "Win32Util.hpp"
#endif
using nonstd::string_view;
-// 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.
//
#pragma once
-#include "system.hpp"
-
#include "Fd.hpp"
#include <string>
#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 <core/wincompat.hpp>
#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 <unistd.h>
+#endif
+
+#ifdef HAVE_SYS_WAIT_H
+# include <sys/wait.h>
#endif
#ifdef HAVE_AVX2
#pragma once
-#include "system.hpp"
-
#include "third_party/nonstd/string_view.hpp"
+#include <cstddef>
#include <string>
class Config;
#pragma once
-#include "system.hpp"
-
#include "Config.hpp"
#include <string>
-// 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.
//
#pragma once
-#include "system.hpp"
+#include <cstdint>
// A Boyer-Moore-Horspool skip table used for searching for the strings
// "__TIME__", "__DATE__" and "__TIMESTAMP__".
#include <Util.hpp>
#include <assertions.hpp>
#include <cleanup.hpp>
+#include <core/wincompat.hpp>
#include <exceptions.hpp>
#include <fmtmacros.hpp>
#include <util/file_utils.hpp>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
namespace storage {
namespace primary {
+++ /dev/null
-// 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 <sys/file.h>
-#endif
-
-#ifdef HAVE_SYS_MMAN_H
-# include <sys/mman.h>
-#endif
-#include <sys/stat.h>
-#include <sys/types.h>
-#ifdef HAVE_SYS_WAIT_H
-# include <sys/wait.h>
-#endif
-
-#include <cassert>
-#include <cctype>
-#include <cerrno>
-#include <cinttypes>
-#include <climits>
-#include <csignal>
-#include <cstdarg>
-#include <cstddef>
-#include <cstdint>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include <ctime>
-
-#ifdef HAVE_DIRENT_H
-# include <dirent.h>
-#endif
-
-#include <fcntl.h>
-
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-#ifdef HAVE_UTIME_H
-# include <utime.h>
-#elif defined(HAVE_SYS_UTIME_H)
-# include <sys/utime.h>
-#endif
-
-#ifdef HAVE_VARARGS_H
-# include <varargs.h>
-#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 <direct.h>
-# include <io.h>
-# include <process.h>
-# define NOMINMAX 1
-# define WIN32_NO_STATUS
-// clang-format off
-# include <windows.h>
-# include <bcrypt.h> // NTSTATUS
-# include <winsock2.h> // struct timeval
-// clang-format on
-# undef WIN32_NO_STATUS
-# include <ntstatus.h>
-# 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<T>::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
-// 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.
//
#include "../src/exceptions.hpp"
#include "../src/fmtmacros.hpp"
+#include <core/wincompat.hpp>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
namespace TestUtil {
size_t TestContext::m_subdir_counter = 0;
-// 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.
//
#pragma once
-#include "system.hpp"
-
+#include <cstddef>
#include <string>
#ifdef _MSC_VER
-// 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.
//
#include "../src/Stat.hpp"
#include "TestUtil.hpp"
+#include <core/wincompat.hpp>
+
#include "third_party/doctest.h"
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
TEST_SUITE_BEGIN("LockFile");
using TestUtil::TestContext;
-// 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.
//
#include "third_party/doctest.h"
+#include <cstring>
+
using TestUtil::TestContext;
TEST_SUITE_BEGIN("NullCompression");
-// 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.
//
#include "../src/Util.hpp"
#include "TestUtil.hpp"
+#include <core/wincompat.hpp>
+
#include "third_party/doctest.h"
#ifdef HAVE_UNISTD_H
#include "../src/fmtmacros.hpp"
#include "TestUtil.hpp"
+#include <core/wincompat.hpp>
+
#include "third_party/doctest.h"
#include "third_party/nonstd/optional.hpp"
+#include <fcntl.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
#include <algorithm>
using doctest::Approx;
-// 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.
//
#include "third_party/doctest.h"
+#include <cstring>
+
using TestUtil::TestContext;
TEST_SUITE_BEGIN("ZstdCompression");
#include "TestUtil.hpp"
#include "argprocessing.hpp"
+#include <core/wincompat.hpp>
+
#include "third_party/doctest.h"
#include <algorithm>
#include "../src/Finalizer.hpp"
#include "TestUtil.hpp"
+#include <core/wincompat.hpp>
+
#include "third_party/doctest.h"
#include "third_party/win32/mktemp.h"
#include "../src/fmtmacros.hpp"
#include "TestUtil.hpp"
+#include <core/wincompat.hpp>
+
#include "third_party/doctest.h"
#include "third_party/nonstd/optional.hpp"
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
#ifdef MYNAME
# define CCACHE_NAME MYNAME
#else