]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix all jrosdahl commentes on previous patch, and test on windows ndk with clang...
authorleanid <leanid.chaika@gmail.com>
Thu, 4 Dec 2014 14:25:12 +0000 (17:25 +0300)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 28 Jan 2015 21:33:48 +0000 (22:33 +0100)
ccache.c
ccache.h
execute.c
util.c

index b6afe844edca234ad7f0e6c21ff5f8148d23f151..c05c5c212d349d0d35ea69339d16120aa1eaa072 100644 (file)
--- 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.
index 461831360b11172df9746096ef629a5e93d6651b..4dc94ee7282429f5462edc1000b7b976b67d9f24 100644 (file)
--- 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
index 52a9b98975e773c8b8c9a94003d0b274aeb9d4bc..5af0cf3e2427d47fe2ea11eb802b86e916abe646 100644 (file)
--- 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 72e641f98eed0797f6d3d78436e5773065be1986..e360afd77ca38f0606b4eedfc37f272aa00c4629 100644 (file)
--- 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();