# include "third_party/getopt_long.h"
#endif
+#ifdef _WIN32
+# include "Win32Util.hpp"
+#endif
+
#include <algorithm>
#include <limits>
hash.hash(ctx.config.cpp_extension().c_str());
#ifdef _WIN32
- const char* ext = strrchr(args[0].c_str(), '.');
- char full_path_win_ext[MAX_PATH + 1] = {0};
- add_exe_ext_if_no_to_fullpath(
- full_path_win_ext, MAX_PATH, ext, args[0].c_str());
- const char* full_path = full_path_win_ext;
+ const std::string compiler_path = Win32Util::add_exe_suffix(args[0]);
#else
- const char* full_path = args[0].c_str();
+ const std::string compiler_path = args[0];
#endif
- auto st = Stat::stat(full_path, Stat::OnError::log);
+ auto st = Stat::stat(compiler_path, Stat::OnError::log);
if (!st) {
failed(STATS_COMPILER);
}
// Hash information about the compiler.
- hash_compiler(ctx, hash, st, args[0].c_str(), true);
+ hash_compiler(ctx, hash, st, compiler_path.c_str(), true);
// Also hash the compiler name as some compilers use hard links and behave
// differently depending on the real name.
return sh;
}
-void
-add_exe_ext_if_no_to_fullpath(char* full_path_win_ext,
- size_t max_size,
- const char* ext,
- const char* path)
-{
- if (!ext
- || (!str_eq(".exe", ext) && !str_eq(".sh", ext) && !str_eq(".bat", ext)
- && !str_eq(".EXE", ext) && !str_eq(".BAT", ext))) {
- snprintf(full_path_win_ext, max_size, "%s.exe", path);
- } else {
- snprintf(full_path_win_ext, max_size, "%s", path);
- }
-}
-
int
win32execute(const char* path,
const char* const* argv,
}
std::string args = Win32Util::argv_to_string(argv, sh);
- const char* ext = strrchr(path, '.');
- char full_path_win_ext[MAX_PATH] = {0};
- add_exe_ext_if_no_to_fullpath(full_path_win_ext, MAX_PATH, ext, path);
- BOOL ret = FALSE;
+ std::string full_path = Win32Util::add_exe_suffix(path);
+ std::string tmp_file_path;
if (args.length() > 8192) {
TemporaryFile tmp_file(path);
Util::write_fd(*tmp_file.fd, args.data(), args.length());
- std::string atfile = fmt::format("\"@{}\"", tmp_file.path);
- ret = CreateProcess(nullptr,
- const_cast<char*>(atfile.c_str()),
- nullptr,
- nullptr,
- 1,
- 0,
- nullptr,
- nullptr,
- &si,
- &pi);
- Util::unlink_tmp(tmp_file.path);
+ args = fmt::format("\"@{}\"", tmp_file.path);
+ tmp_file_path = tmp_file.path;
}
- if (!ret) {
- ret = CreateProcess(full_path_win_ext,
- const_cast<char*>(args.c_str()),
- nullptr,
- nullptr,
- 1,
- 0,
- nullptr,
- nullptr,
- &si,
- &pi);
+ BOOL ret = CreateProcess(full_path.c_str(),
+ const_cast<char*>(args.c_str()),
+ nullptr,
+ nullptr,
+ 1,
+ 0,
+ nullptr,
+ nullptr,
+ &si,
+ &pi);
+ if (!tmp_file_path.empty()) {
+ Util::unlink_tmp(tmp_file_path);
}
if (fd_stdout != -1) {
close(fd_stdout);
if (ret == 0) {
DWORD error = GetLastError();
cc_log("failed to execute %s: %s (%lu)",
- full_path_win_ext,
+ full_path.c_str(),
Win32Util::error_message(error).c_str(),
error);
return -1;