if (!initialize(path_prefix) && errno == ENOENT) {
auto dir = Util::dir_name(path);
if (!Util::create_dir(dir)) {
- fatal("Failed to create directory %s: %s",
- std::string(dir).c_str(),
- strerror(errno));
+ FATAL("Failed to create directory {}: {}", dir, strerror(errno));
}
initialize(path_prefix);
}
if (!fd) {
- fatal("Failed to create temporary file for %s: %s",
- path.c_str(),
- strerror(errno));
+ FATAL("Failed to create temporary file for {}: {}", path, strerror(errno));
}
set_cloexec_flag(*fd);
for (const auto& word : Util::split_into_strings(prefix_command, " ")) {
std::string path = find_executable(ctx, word.c_str(), MYNAME);
if (path.empty()) {
- fatal("%s: %s", word.c_str(), strerror(errno));
+ FATAL("{}: {}", word, strerror(errno));
}
prefix.push_back(path);
std::string compiler = find_executable(ctx, base.c_str(), MYNAME);
if (compiler.empty()) {
- fatal("Could not find compiler \"%s\" in PATH", base.c_str());
+ FATAL("Could not find compiler \"{}\" in PATH", base);
}
if (compiler == argv[0]) {
- fatal("Recursive invocation (the name of the ccache binary must be \"%s\")",
+ FATAL("Recursive invocation (the name of the ccache binary must be \"{}\")",
MYNAME);
}
ctx.orig_args[0] = compiler;
MTR_END("config", "conf_read_secondary");
if (config.cache_dir().empty()) {
- fatal("configuration setting \"cache_dir\" must not be the empty string");
+ FATAL("configuration setting \"cache_dir\" must not be the empty string");
}
if ((p = getenv("CCACHE_DIR"))) {
config.set_cache_dir(p);
}
if (config.cache_dir().empty()) {
- fatal("CCACHE_DIR must not be the empty string");
+ FATAL("CCACHE_DIR must not be the empty string");
}
config.set_primary_config_path(
cc_log_argv("Executing ", execv_argv.data());
ctx.reset(); // Dump debug logs last thing before executing.
execv(execv_argv[0], const_cast<char* const*>(execv_argv.data()));
- fatal("execv of %s failed: %s", execv_argv[0], strerror(errno));
+ FATAL("execv of {} failed: {}", execv_argv[0], strerror(errno));
}
}
result_name = calculate_result_name(
ctx, args_to_hash, preprocessor_args, cpp_hash, false);
MTR_END("hash", "cpp_hash");
- if (!result_name) {
- fatal("internal error: calculate_result_name returned NULL for cpp");
- }
+
+ // calculate_result_name does not return nullopt if the last (direct_mode)
+ // argument is false.
+ assert(result_name);
ctx.set_result_name(*result_name);
if (result_name_from_manifest && result_name_from_manifest != result_name) {
#include "system.hpp"
+#include "FormatNonstdStringView.hpp"
#include "stats.hpp"
+#include "third_party/fmt/core.h"
#include "third_party/nonstd/optional.hpp"
#include <stdexcept>
+// Something went badly wrong! Print a message to stderr and exit with non-zero
+// exit code.
+#define FATAL(...) \
+ do { \
+ throw FatalError(fmt::format(__VA_ARGS__)); \
+ } while (false)
+
// Don't throw or catch ErrorBase directly, use a subclass.
class ErrorBase : public std::runtime_error
{
}
if (*pid == -1) {
- fatal("Failed to fork: %s", strerror(errno));
+ FATAL("Failed to fork: {}", strerror(errno));
}
if (*pid == 0) {
int status;
if (waitpid(*pid, &status, 0) != *pid) {
- fatal("waitpid failed: %s", strerror(errno));
+ FATAL("waitpid failed: {}", strerror(errno));
}
{
#else
int pipefd[2];
if (pipe(pipefd) == -1) {
- fatal("pipe failed");
+ FATAL("pipe failed: {}", strerror(errno));
}
pid_t pid = fork();
if (pid == -1) {
- fatal("fork failed");
+ FATAL("fork failed: {}", strerror(errno));
}
if (pid == 0) {
# include <sys/time.h>
#endif
-// Something went badly wrong!
-void
-fatal(const char* format, ...)
-{
- va_list ap;
- va_start(ap, format);
- char msg[8192];
- vsnprintf(msg, sizeof(msg), format, ap);
- va_end(ap);
-
- throw FatalError(msg);
-}
-
// Return a static string with the current hostname.
const char*
get_hostname()
}
}
#endif
- fatal("Could not determine home directory from $HOME or getpwuid(3)");
+ FATAL("Could not determine home directory from $HOME or getpwuid(3)");
}
// Return whether the argument is a full path.
#include <string>
-void fatal(const char* format, ...) ATTR_FORMAT(printf, 1, 2) ATTR_NORETURN;
-
const char* get_hostname();
void x_setenv(const char* name, const char* value);
void x_unsetenv(const char* name);
static void
warn_log_fail()
{
- // Note: Can't call fatal() since that would lead to recursion.
+ // Note: Can't call FATAL() since that would lead to recursion.
fprintf(stderr,
"ccache: error: Failed to write to %s: %s\n",
logfile_path.c_str(),