Now have proper xification of dependencies even if main file hasn't changed
authorNick Downing <downing.nick@gmail.com>
Sun, 22 Jan 2017 00:21:05 +0000 (11:21 +1100)
committerNick Downing <downing.nick@gmail.com>
Sun, 22 Jan 2017 00:21:05 +0000 (11:21 +1100)
xify/cc.c
xify/xify

index 59db51a..e2ec3a7 100644 (file)
--- a/xify/cc.c
+++ b/xify/cc.c
@@ -88,6 +88,7 @@ int in_queue_tail;
 
 char   in_path[BUFSIZ];
 char   out_path[BUFSIZ];
+char   err_path[BUFSIZ];
 #endif
 
 #define        cunlink(s)      if (s) unlink(s)
@@ -559,9 +560,6 @@ char *setsuf(as, ch) char *as; int ch; {
 int xify_file(in_name, in_mtime) char *in_name; struct timespec *in_mtime; {
        int i;
        struct stat out_statbuf;
-       int t, status;
-       char **cpp;
-       int fds[3];
        FILE *err_fp;
        char err_line[BUFSIZ];
        int e;
@@ -572,56 +570,36 @@ int xify_file(in_name, in_mtime) char *in_name; struct timespec *in_mtime; {
        bcopy(in_name, out_path, i);
        strcpy(out_path + i, ".xify/x_");
        strcat(out_path + i, in_name + i);
+
+       strcpy(err_path, out_path);
+       strcat(err_path, ".deps");
+       
        if (
-               stat(out_path, &out_statbuf) == 0 && (
-                       out_statbuf.st_mtim.tv_sec > in_mtime->tv_sec || (
-                               out_statbuf.st_mtim.tv_sec == in_mtime->tv_sec &&
-                               out_statbuf.st_mtim.tv_nsec >= in_mtime->tv_nsec
-                       )
+               stat(out_path, &out_statbuf) ||
+               out_statbuf.st_mtim.tv_sec < in_mtime->tv_sec || (
+                       out_statbuf.st_mtim.tv_sec == in_mtime->tv_sec &&
+                       out_statbuf.st_mtim.tv_nsec < in_mtime->tv_nsec
                )
                
-       )
-               return 0;
+       ) {
+               out_path[i + 5] = 0;
+               if (mkdir(out_path, 0777) == -1 && errno != EEXIST) {
+                       error("can't mkdir: %s\n", out_path);
+                       return 1;
+               }
+               out_path[i + 5] = '/';
 
-       out_path[i + 5] = 0;
-       if (mkdir(out_path, 0777) == -1 && errno != EEXIST) {
-               error("can't mkdir: %s\n", out_path);
-               return 1;
+               av[0] = "xify"; av[1] = in_name; av[2] = out_path; av[3] = err_path; av[4] = 0;
+               if (callsys(xify, av))
+                       return 1;
        }
-       out_path[i + 5] = '/';
-
-       av[0] = "xify"; av[1] = in_name; av[2] = out_path; av[3] = 0;
-       /*return callsys(xify, av);*/
 
-       if (debug) {
-               fprintf(stderr, "%s:", xify);
-               for (cpp = av; *cpp != 0; cpp++)
-                       fprintf(stderr, " %s", *cpp);
-               fprintf(stderr, "\n");
-       }
-       if (
-               pipe(fds) ||
-               (err_fp = fdopen(fds[0], "r")) == 0 ||
-               (fds[2] = dup(2)) == -1
-       ) {
-               fprintf(stderr, "Can't create pipe\n");
-               return (100);
-       }
-       dup2(fds[1], 2);
-       close(fds[1]);
-       t = vfork();
-       if (t == -1) {
-               printf("No more processes\n");
-               return (100);
-       }
-       if (t == 0) {
-               execv(xify, av);
-               printf("Can't find %s\n", xify);
-               fflush(stdout);
-               _exit(100);
+ /*fprintf(stderr, "reading deps: %s\n", err_path);*/
+       err_fp = fopen(err_path, "r");
+       if (err_fp == 0) {
+               error("can't find deps: %s", err_path);
+               return 1;
        }
-       dup2(fds[2], 2);
-       close(fds[2]);
        while (fgets(err_line, BUFSIZ, err_fp))
                if (err_line[0] == '"') {
                        e = '"';
@@ -635,25 +613,17 @@ int xify_file(in_name, in_mtime) char *in_name; struct timespec *in_mtime; {
                                        goto garbage;
                        }
                        err_line[i] = 0;
+ /*fprintf(stderr, "found dep: %s\n", err_line);*/
                        if (xify_include(err_line + 1, err_line[0] == '"' ? in_name : 0))
                                break;
                }
                else {
                garbage:
-                       fprintf(stderr, "Garbage from filter\n");
+                       error("garbage in deps: %s\n", err_path);
                        break;
                }
        fclose(err_fp);
-       while (t != wait(&status))
-               ;
-       if ((t=(status&0377)) != 0 && t!=14) {
-               if (t!=2) {
-                       printf("Fatal error in %s\n", xify);
-                       eflag = 8;
-               }
-               dexit();
-       }
-       return ((status>>8) & 0377);
+       return 0;
 }
 
 int xify_include(in_name, prev_name) char *in_name; char *prev_name; {
@@ -667,30 +637,30 @@ int xify_include(in_name, prev_name) char *in_name; char *prev_name; {
                strcpy(in_path + i, in_name);
                if (stat(in_path, &statbuf) == 0) {
                        i = -1;
-                       goto found_local;
+                       goto found_relative;
                }
        }
-       for (int i = 0; i < np; ++i)
+       for (i = 0; i < np; ++i)
                if (/*plist[i][0] == '-' &&*/ plist[i][1] == 'I') {
                        j = strlen(plist[i] + 2) - 5; /* remove ".xify" */      
                        bcopy(plist[i] + 2, in_path, j);
                        strcpy(in_path + j, in_name);
                        if (stat(in_path, &statbuf) == 0)
-                               goto found_system;
+                               goto found_in_path;
                }
        error("not found: %s\n", in_name);
        return 1;
 
-found_system:
+found_in_path:
        /* see if it requires extra mkdir */
        for (; in_path[j]; ++j)
                if (in_path[j] == '/')
-                       goto found_local;
+                       goto found_relative;
 
        /* it does not require extra mkdir */
        i = -1;
 
-found_local:
+found_relative:
        for (j = 0; j < in_queue_tail; ++j)
                if (strcmp(in_queue[j].path, in_path) == 0)
                        return 0;
index 178c278..3b733ef 100755 (executable)
--- a/xify/xify
+++ b/xify/xify
@@ -22,5 +22,5 @@ typedef uint32_t x_unsigned_long;
 
 #endif
 EOF
-  "`dirname "$0"`/xifyfilt" <$1 |sed -e 's/\(extern\|register\|static\) x_int x_\(datum\|off_t\|time_t\|u_int\|u_short\|u_long\)/\1 x_\2/g; s/va_arg(x_argp, x_\(unsigned_\)\?\(short\|int\|long\))/_va_arg_\1\2(x_argp)/g'
+  "`dirname "$0"`/xifyfilt" <$1 2>$3 |sed -e 's/\(extern\|register\|static\) x_int x_\(datum\|off_t\|time_t\|u_int\|u_short\|u_long\)/\1 x_\2/g; s/va_arg(x_argp, x_\(unsigned_\)\?\(short\|int\|long\))/_va_arg_\1\2(x_argp)/g'
 ) >$2