]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Clean up slightly after ea433578
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 20 Mar 2021 19:07:43 +0000 (20:07 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 26 Mar 2021 07:34:52 +0000 (08:34 +0100)
src/Win32Util.hpp
src/ccache.cpp
src/execute.cpp

index 7e02a4b2a2e9ebd6f83c6d59dab86261721fe838..d6fc57595a10c8839f13c5971a8ef768d01694a1 100644 (file)
@@ -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.
 //
@@ -29,9 +29,9 @@ namespace Win32Util {
 std::string add_exe_suffix(const std::string& program);
 
 // Recreate a Windows command line string based on `argv`. If `prefix` is
-// non-empty, add it as the first argument.
-// If escape_backslashes is true, emit additional backslash for each backslash
-// which is not preceding '"' and is not at the end of argv[i] either.
+// non-empty, add it as the first argument. If `escape_backslashes` is true,
+// emit an additional backslash for each backslash that is not preceding '"' and
+// is not at the end of `argv[i]` either.
 std::string argv_to_string(const char* const* argv,
                            const std::string& prefix,
                            bool escape_backslashes = false);
index b4c039e3597116f8575db7073496316075366faa..7d39e5bbc273f5cc03efcd6f2fcb72190983ef08 100644 (file)
@@ -2326,7 +2326,7 @@ cache_compilation(int argc, const char* const* argv)
       saved_orig_args = std::move(ctx.orig_args);
       auto execv_argv = saved_orig_args.to_argv();
       LOG("Executing {}", Util::format_argv_for_logging(execv_argv.data()));
-      // Run execute_noreturn below after ctx and finalizer have been
+      // Execute the original command below after ctx and finalizer have been
       // destructed.
     }
   }
@@ -2336,8 +2336,7 @@ cache_compilation(int argc, const char* const* argv)
       umask(*original_umask);
     }
     auto execv_argv = saved_orig_args.to_argv();
-    execute_noreturn(const_cast<char* const*>(execv_argv.data()),
-                     saved_temp_dir);
+    execute_noreturn(execv_argv.data(), saved_temp_dir);
     throw Fatal(
       "execute_noreturn of {} failed: {}", execv_argv[0], strerror(errno));
   }
index 326d17bce000af4c76e7649b280181dd69b6a711..ebcf2becbeab1c6372e0a98e28a9126845e7e962 100644 (file)
@@ -1,5 +1,5 @@
 // Copyright (C) 2002 Andrew Tridgell
-// Copyright (C) 2011-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2011-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -30,6 +30,7 @@
 #include "fmtmacros.hpp"
 
 #ifdef _WIN32
+#  include "Finalizer.hpp"
 #  include "Win32Util.hpp"
 #endif
 
@@ -127,13 +128,20 @@ win32execute(const char* path,
   std::string args = Win32Util::argv_to_string(argv, sh);
   std::string full_path = Win32Util::add_exe_suffix(path);
   std::string tmp_file_path;
+
+  Finalizer tmp_file_remover([&tmp_file_path] {
+    if (!tmp_file_path.empty()) {
+      Util::unlink_tmp(tmp_file_path);
+    }
+  });
+
   if (args.length() > 8192) {
     TemporaryFile tmp_file(FMT("{}/cmd_args", temp_dir));
     args = Win32Util::argv_to_string(argv + 1, sh, true);
     Util::write_fd(*tmp_file.fd, args.data(), args.length());
     args = FMT("{} @{}", full_path, tmp_file.path);
     tmp_file_path = tmp_file.path;
-    LOG("args from file {}", tmp_file.path);
+    LOG("Arguments from {}", tmp_file.path);
   }
   BOOL ret = CreateProcess(full_path.c_str(),
                            const_cast<char*>(args.c_str()),
@@ -155,17 +163,10 @@ win32execute(const char* path,
         full_path,
         Win32Util::error_message(error),
         error);
-    if (!tmp_file_path.empty()) {
-      Util::unlink_tmp(tmp_file_path);
-    }
     return -1;
   }
   WaitForSingleObject(pi.hProcess, INFINITE);
 
-  if (!tmp_file_path.empty()) {
-    Util::unlink_tmp(tmp_file_path);
-  }
-
   DWORD exitcode;
   GetExitCodeProcess(pi.hProcess, &exitcode);
   CloseHandle(pi.hProcess);
@@ -229,7 +230,7 @@ execute(Context& ctx, const char* const* argv, Fd&& fd_out, Fd&& fd_err)
 }
 
 void
-execute_noreturn(const char* const* argv, const std::string& /* unused */)
+execute_noreturn(const char* const* argv, const std::string& /*temp_dir*/)
 {
   execv(argv[0], const_cast<char* const*>(argv));
 }