From 1f18f0f44c25fb86b3a7e6166420a3453bb6d6b5 Mon Sep 17 00:00:00 2001 From: leanid Date: Thu, 4 Dec 2014 17:25:12 +0300 Subject: [PATCH] fix all jrosdahl commentes on previous patch, and test on windows ndk with clang, g++ --- ccache.c | 63 ++++++++++++------------------------------------------- ccache.h | 2 ++ execute.c | 24 ++++++++++++++------- util.c | 8 +++---- 4 files changed, 34 insertions(+), 63 deletions(-) diff --git a/ccache.c b/ccache.c index b6afe844e..c05c5c212 100644 --- a/ccache.c +++ b/ccache.c @@ -802,20 +802,9 @@ to_cache(struct args *args) char *tmp_stderr2; tmp_stderr2 = format("%s.2", tmp_stderr); -#ifdef _WIN32 - // on Windows file descriptor should be closed before rename - int prev_stderr_fd = tmp_stderr_fd; - close(tmp_stderr_fd); -#endif - int rename_result = x_rename(tmp_stderr, tmp_stderr2); -#ifdef _WIN32 - tmp_stderr_fd = create_tmp_fd(&tmp_stderr); - assert(prev_stderr_fd == tmp_stderr_fd); -#endif - if (rename_result) { - const char* err_str = strerror(errno); + if (x_rename(tmp_stderr, tmp_stderr2)) { cc_log("Failed to rename %s to %s: %s", tmp_stderr, tmp_stderr2, - err_str); + strerror(errno)); failed(); } fd_cpp_stderr = open(cpp_stderr, O_RDONLY | O_BINARY); @@ -981,6 +970,7 @@ get_object_name_from_cpp(struct args *args, struct mdfour *hash) char *path_stdout, *path_stderr; int status, path_stderr_fd; struct file_hash *result; + int path_stdout_fd = -1; /* ~/hello.c -> tmp.hello.123.i limit the basename to 10 @@ -1001,8 +991,6 @@ get_object_name_from_cpp(struct args *args, struct mdfour *hash) time_of_compilation = time(NULL); - int path_stdout_fd = -1; - if (direct_i_file) { /* We are compiling a .i or .ii file - that means we can skip the cpp stage * and directly form the correct i_tmpfile. */ @@ -1058,21 +1046,7 @@ get_object_name_from_cpp(struct args *args, struct mdfour *hash) /* i_tmpfile needs the proper cpp_extension for the compiler to do its * thing correctly. */ i_tmpfile = format("%s.%s", path_stdout, conf->cpp_extension); -#ifdef _WIN32 - // on Windows rename only if file descriptor closed - if (path_stdout_fd != -1) - { - close(path_stdout_fd); - } -#endif x_rename(path_stdout, i_tmpfile); -#ifdef _WIN32 - if (path_stdout_fd != -1) - { - int tmp_fd = create_tmp_fd(&path_stdout); - assert(tmp_fd == path_stdout_fd); - } -#endif add_pending_tmp_file(i_tmpfile); } @@ -1157,6 +1131,8 @@ compiler_is_gcc(struct args *args) return is; } + + /* * Update a hash sum with information common for the direct and preprocessor * modes. @@ -1176,32 +1152,19 @@ calculate_common_hash(struct args *args, struct mdfour *hash) hash_delimiter(hash, "ext"); hash_string(hash, conf->cpp_extension); + const char* full_path = args->argv[0]; #ifdef _WIN32 - const char* ext = strchr(args->argv[0], '.'); - char full_path_win_ext[MAX_PATH] = {0}; - strncat(full_path_win_ext, args->argv[0], MAX_PATH); - if (!ext - || (strcmp(".exe", ext) != 0 - && strcmp(".bat", ext) != 0 - && strcmp(".EXE", ext) != 0 - && strcmp(".BAT", ext) != 0 - ) - ) - { - strncat(full_path_win_ext, ".exe", MAX_PATH); - } - if (stat(full_path_win_ext, &st) != 0) { - cc_log("Couldn't stat compiler %s: %s", args->argv[0], strerror(errno)); - stats_update(STATS_COMPILER); - failed(); - } -#else - if (stat(args->argv[0], &st) != 0) { + const char* ext = strrchr(args->argv[0], '.'); + char full_path_win_ext[MAX_PATH + 1] = {0}; + add_exe_ext_if_no_to_fullpath(full_path_win_ext, MAX_PATH, ext, + args->argv[0]); + full_path = full_path_win_ext; +#endif + if (stat(full_path, &st) != 0) { cc_log("Couldn't stat compiler %s: %s", args->argv[0], strerror(errno)); stats_update(STATS_COMPILER); failed(); } -#endif /* * Hash information about the compiler. diff --git a/ccache.h b/ccache.h index 461831360..4dc94ee72 100644 --- a/ccache.h +++ b/ccache.h @@ -252,6 +252,8 @@ char *win32argvtos(char *prefix, char **argv); char *win32getshell(char *path); int win32execute(char *path, char **argv, int doreturn, int fd_stdout, int fd_stderr); +void add_exe_ext_if_no_to_fullpath(char *full_path_win_ext, size_t max_size, + const char* ext, char* path); # ifndef _WIN32_WINNT # define _WIN32_WINNT 0x0501 # endif diff --git a/execute.c b/execute.c index 52a9b9897..5af0cf3e2 100644 --- a/execute.c +++ b/execute.c @@ -117,6 +117,18 @@ win32getshell(char *path) return sh; } +void add_exe_ext_if_no_to_fullpath(char *full_path_win_ext, size_t max_size, + const char* ext, char* path) { + strncat(full_path_win_ext, path, max_size); + if (!ext + || (!str_eq(".exe", ext) + && !str_eq(".bat", ext) + && !str_eq(".EXE", ext) + && !str_eq(".BAT", ext))) { + strncat(full_path_win_ext, ".exe", max_size); + } +} + int win32execute(char *path, char **argv, int doreturn, int fd_stdout, int fd_stderr) @@ -149,17 +161,13 @@ win32execute(char *path, char **argv, int doreturn, } args = win32argvtos(sh, argv); - const char* ext = strchr(path, '.'); + const char* ext = strrchr(path, '.'); char full_path_win_ext[MAX_PATH] = { 0 }; - strncat(full_path_win_ext, path, MAX_PATH); - if (!ext - || (strcmp(".exe", ext) != 0 && strcmp(".bat", ext) != 0 - && strcmp(".EXE", ext) != 0 && strcmp(".BAT", ext) != 0)) { - strncat(full_path_win_ext, ".exe", MAX_PATH); - } - + add_exe_ext_if_no_to_fullpath(full_path_win_ext, MAX_PATH, ext, path); ret = CreateProcess(full_path_win_ext, args, NULL, NULL, 1, 0, NULL, NULL, &si, &pi); + close(fd_stdout); + close(fd_stderr); free(args); if (ret == 0) { LPVOID lpMsgBuf; diff --git a/util.c b/util.c index 72e641f98..e360afd77 100644 --- a/util.c +++ b/util.c @@ -519,7 +519,7 @@ get_hostname(void) if (err != 0) { /* Tell the user that we could not find a usable */ /* Winsock DLL. */ - cc_log("WSAStartup failed with error: %d\n", err); + cc_log("WSAStartup failed with error: %d", err); return hostname; } @@ -532,8 +532,7 @@ get_hostname(void) } int result = gethostname(hostname, sizeof(hostname)-1); - if (result != 0) - { + if (result != 0) { int last_error = WSAGetLastError(); LPVOID lpMsgBuf; LPVOID lpDisplayBuf; @@ -1377,8 +1376,7 @@ x_rename(const char *oldpath, const char *newpath) /* Windows' rename() refuses to overwrite an existing file. */ unlink(newpath); /* not x_unlink, as x_unlink calls x_rename */ /*If the function succeeds, the return value is nonzero.*/ - if (MoveFileA(oldpath, newpath) == 0) - { + if (MoveFileA(oldpath, newpath) == 0) { LPVOID lpMsgBuf; LPVOID lpDisplayBuf; DWORD dw = GetLastError(); -- 2.47.2