]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
- don't need CCACHE_PATH on non-linux now
authorAndrew Tridgell <tridge@samba.org>
Wed, 27 Mar 2002 01:29:53 +0000 (02:29 +0100)
committerAndrew Tridgell <tridge@samba.org>
Wed, 27 Mar 2002 01:29:53 +0000 (02:29 +0100)
- faster handling of error case

README
ccache.c
ccache.h

diff --git a/README b/README
index 91f0ee5693942bc40c560b43622aa65f5b38f15d..cf0775f8c519ddc459b674a11d1dd538ef491068 100644 (file)
--- a/README
+++ b/README
@@ -29,11 +29,6 @@ This will work as long as /usr/local/bin comes before the path to gcc
 (which is usually in /usr/bin). After installing you may wish to run
 "rehash; type gcc" to make sure that the correct link is being used.
 
-If you are installing on a system that doesn't have a /proc/self/exe
-link (ie. most non-Linux systems) then you also also need to set the
-CCACHE_PATH environment variable. 
-
-
 Configuration
 -------------
 
@@ -56,12 +51,10 @@ will be fine.
 
    CCACHE_PATH
 
-   You need to set the CCACHE_PATH environment variable on systems
-   that don't have a Linux-like /proc filesystem. It should be set to
-   a colon separated list of directories where ccache will look for
-   the real compilers. On Linux this is not needed because ccache can
-   use /proc/self/exe and the normal PATH variable to find the
-   compiler. 
+   You can optionally set CCACHE_PATH to a colon separated path where ccache will
+   look for the real compilers. If you don't do this then ccache will
+   look for the first executable in the normal PATH that isn't a link
+   to ccache itself.
 
 
 Differences
index 87c17a071b62caf38c18a1af2d321c3f772da8ac..7b30ff2d8d83336dda224115e71aaa068f3c3eeb 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -57,24 +57,34 @@ static void to_cache(ARGS *args)
        status = execute(args->argv, tmp_stdout, tmp_stderr);
        args->argc -= 2;
 
-       if (status != 0) {
-               cc_log("compile of %s gave status = %d\n", output_file, status);
+       if (stat(tmp_stdout, &st) != 0 || st.st_size != 0) {
+               cc_log("compiler produced stdout for %s\n", output_file);
                unlink(tmp_stdout);
                unlink(tmp_stderr);
                unlink(tmp_hashname);
                failed();
        }
+       unlink(tmp_stdout);
 
-       if (stat(tmp_stdout, &st) != 0 || st.st_size != 0) {
-               cc_log("compiler produced stdout for %s\n", output_file);
-               unlink(tmp_stdout);
+       if (status != 0) {
+               int fd;
+               cc_log("compile of %s gave status = %d\n", output_file, status);
+
+               fd = open(tmp_stderr, O_RDONLY);
+               if (fd != -1 && 
+                   (rename(tmp_hashname, output_file) == 0 || errno == ENOENT)) {
+                       /* we can use a quick method of getting the failed output */
+                       copy_fd(fd, 2);
+                       close(fd);
+                       unlink(tmp_stderr);
+                       exit(status);
+               }
+               
                unlink(tmp_stderr);
                unlink(tmp_hashname);
                failed();
        }
 
-       unlink(tmp_stdout);
-
        x_asprintf(&path_stderr, "%s.stderr", hashname);
 
        if (rename(tmp_hashname, hashname) != 0 ||
@@ -253,6 +263,7 @@ static char *find_compiler(const char *argv0)
        char *base;
        char *path, *tok;
        struct stat st1, st2;
+       int found_one = 0;
 
        p = strrchr(argv0, '/');
        if (p) {
@@ -261,16 +272,14 @@ static char *find_compiler(const char *argv0)
                base = x_strdup(argv0);
        }
 
-       /* we compare size, device and inode. On non-Linux systems
-          we rely on CCACHE_PATH being set and end up just using the first 
-          executable we find in the path
-       */
-       if (stat("/proc/self/exe", &st1) != 0) {
-               if (!getenv("CCACHE_PATH")) {
-                       cc_log("You must set CCACHE_PATH\n");
-                       exit(1);
-               }
-               memset(&st1, 0, sizeof(st1));
+       /* try to find ourselves the linux way */
+       if (stat("/proc/self/exe", &st1) == 0) {
+               found_one = 1;
+       }
+
+       /* they might have given a full path ... */
+       if (!found_one && strchr(argv0, '/') && stat(argv0, &st1) == 0) {
+               found_one = 1;
        }
 
        path = getenv("CCACHE_PATH");
@@ -293,6 +302,13 @@ static char *find_compiler(const char *argv0)
                if (access(fname, X_OK) == 0 &&
                    stat(fname, &st2) == 0 &&
                    S_ISREG(st2.st_mode)) {
+                       /* we have a candidate */
+                       if (!found_one) {
+                               st1 = st2;
+                               found_one = 1;
+                               continue;
+                       }
+
                        if (st1.st_size != st2.st_size ||
                            st1.st_dev != st2.st_dev ||
                            st1.st_ino != st2.st_ino) {
index 285b2196430f2e6f75e9389587a074167b6f6575..4720a2ad42b3ca4d514c8f612563deae0396b9d7 100644 (file)
--- a/ccache.h
+++ b/ccache.h
@@ -54,5 +54,3 @@ typedef struct {
 
 ARGS *args_init(void);
 void args_add(ARGS *args, const char *s);
-
-