]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Convert FATAL macro to a function
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 31 Jul 2020 17:25:07 +0000 (19:25 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 31 Jul 2020 18:31:54 +0000 (20:31 +0200)
src/TemporaryFile.cpp
src/Util.cpp
src/ccache.cpp
src/exceptions.hpp
src/execute.cpp
src/hashutil.cpp
src/logging.cpp

index f7ac3ec991e8789b3d67e6c67b03a6678b216185..8dad5cf99c8a3366ab6654f04f87a54d902b9601 100644 (file)
@@ -64,12 +64,12 @@ TemporaryFile::TemporaryFile(string_view path_prefix)
   if (!initialize(path_prefix) && errno == ENOENT) {
     auto dir = Util::dir_name(path);
     if (!Util::create_dir(dir)) {
-      FATAL("Failed to create directory {}: {}", dir, strerror(errno));
+      fatal("Failed to create directory {}: {}", dir, strerror(errno));
     }
     initialize(path_prefix);
   }
   if (!fd) {
-    FATAL("Failed to create temporary file for {}: {}", path, strerror(errno));
+    fatal("Failed to create temporary file for {}: {}", path, strerror(errno));
   }
 
   set_cloexec_flag(*fd);
index d63565ecfa473c6d31aea0ffc79d5d214c7aedc1..652cf663345d9b4d1f592d4a10fcd35a7c988ae7 100644 (file)
@@ -611,7 +611,7 @@ get_home_directory()
     }
   }
 #endif
-  FATAL("Could not determine home directory from $HOME or getpwuid(3)");
+  fatal("Could not determine home directory from $HOME or getpwuid(3)");
 }
 
 const char*
index 3e8a2341fbdf8b7ae7d15953f383e7f1e9f5b18f..e2ed2ea11147f579ecb5b5c05425edeb722f40ab 100644 (file)
@@ -151,7 +151,7 @@ add_prefix(const Context& ctx, Args& args, const std::string& prefix_command)
   for (const auto& word : Util::split_into_strings(prefix_command, " ")) {
     std::string path = find_executable(ctx, word, MYNAME);
     if (path.empty()) {
-      FATAL("{}: {}", word, strerror(errno));
+      fatal("{}: {}", word, strerror(errno));
     }
 
     prefix.push_back(path);
@@ -1740,10 +1740,10 @@ find_compiler(Context& ctx, const char* const* argv)
 
   std::string compiler = find_executable(ctx, base, MYNAME);
   if (compiler.empty()) {
-    FATAL("Could not find compiler \"{}\" in PATH", base);
+    fatal("Could not find compiler \"{}\" in PATH", base);
   }
   if (compiler == argv[0]) {
-    FATAL("Recursive invocation (the name of the ccache binary must be \"{}\")",
+    fatal("Recursive invocation (the name of the ccache binary must be \"{}\")",
           MYNAME);
   }
   ctx.orig_args[0] = compiler;
@@ -1801,13 +1801,13 @@ set_up_config(Config& config)
     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(
@@ -1942,7 +1942,7 @@ cache_compilation(int argc, const char* const* argv)
     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 {} failed: {}", execv_argv[0], strerror(errno));
+    fatal("execv of {} failed: {}", execv_argv[0], strerror(errno));
   }
 }
 
index 10a959cc2c3bbbde0bbff3500a729d650a11a90c..1d70ad53db3d30151990aec71da2833fc72d4d1e 100644 (file)
 #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)
+#include <utility>
 
 // Don't throw or catch ErrorBase directly, use a subclass.
 class ErrorBase : public std::runtime_error
@@ -89,3 +83,12 @@ Failure::stat() const
 {
   return m_stat;
 }
+
+// Something went badly wrong! Print a message to stderr and exit with non-zero
+// exit code. `args` are forwarded to `fmt::format`.
+template<typename... T>
+[[noreturn]] inline void
+fatal(T&&... args)
+{
+  throw FatalError(fmt::format(std::forward<T>(args)...));
+}
index bb67fa9da08a231b58c66a07b2e2d97dc4f2b9d5..f17e52e9d346645ca13fa46e1fdd0f2ae15a36f3 100644 (file)
@@ -165,7 +165,7 @@ execute(const char* const* argv, Fd&& fd_out, Fd&& fd_err, pid_t* pid)
   }
 
   if (*pid == -1) {
-    FATAL("Failed to fork: {}", strerror(errno));
+    fatal("Failed to fork: {}", strerror(errno));
   }
 
   if (*pid == 0) {
@@ -182,7 +182,7 @@ execute(const char* const* argv, Fd&& fd_out, Fd&& fd_err, pid_t* pid)
 
   int status;
   if (waitpid(*pid, &status, 0) != *pid) {
-    FATAL("waitpid failed: {}", strerror(errno));
+    fatal("waitpid failed: {}", strerror(errno));
   }
 
   {
index f76ba7b8b16b5750bedff682fda11ce865def818..83306194dec3a43eff9f8b3c99742ee694813e74 100644 (file)
@@ -464,12 +464,12 @@ hash_command_output(Hash& hash,
 #else
   int pipefd[2];
   if (pipe(pipefd) == -1) {
-    FATAL("pipe failed: {}", strerror(errno));
+    fatal("pipe failed: {}", strerror(errno));
   }
 
   pid_t pid = fork();
   if (pid == -1) {
-    FATAL("fork failed: {}", strerror(errno));
+    fatal("fork failed: {}", strerror(errno));
   }
 
   if (pid == 0) {
index d2b62b5210c7b31b66aa80dc00310d61ff5d849c..94e55a4d02ec6e89bbc9c28a824cf527cd4f2bb7 100644 (file)
@@ -138,7 +138,7 @@ static void warn_log_fail() ATTR_NORETURN;
 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(),