shithub: mc

Download patch

ref: de4bc34a527fc33a86e862d7462ab9c8f02ddfcb
parent: ff6e3444ff9cb3f8877f9d4c2653236609bae4f2
author: Ori Bernstein <[email protected]>
date: Thu Sep 5 09:00:33 EDT 2013

Add basic loop detection to myrbuild.

--- a/myrbuild/myrbuild.c
+++ b/myrbuild/myrbuild.c
@@ -43,6 +43,7 @@
 
 regex_t usepat;
 Htab *compiled;
+Htab *loopdetect;
 
 static void usage(char *prog)
 {
@@ -198,6 +199,9 @@
 
     if (hthas(compiled, file))
         return;
+    if (hthas(loopdetect, file))
+        die("Cycle in dependency graph, involving %s\n", file);
+    htput(loopdetect, file, file);
     if (hassuffix(file, ".myr")) {
         swapsuffix(use, sizeof use, file, ".myr", ".use");
         swapsuffix(obj, sizeof obj, file, ".myr", ".o");
@@ -212,9 +216,9 @@
             }
         }
         if (isfresh(file, use))
-            return;
+            goto done;
         if (isfresh(file, obj))
-            return;
+            goto done;
         gencmd(&cmd, &ncmd, muse, file, NULL, 0);
         run(cmd);
 
@@ -223,13 +227,15 @@
     } else if (hassuffix(file, ".s")) {
         swapsuffix(obj, sizeof obj, file, ".s", ".o");
         if (isfresh(file, obj))
-            return;
+            goto done;
         extra[2] = obj;
         gencmd(&cmd, &ncmd, as, file, extra, 3);
         run(cmd);
     }
+done:
     s = strdup(file);
     htput(compiled, s, s);
+    htdel(loopdetect, file);
 }
 
 void mergeuse(char **files, size_t nfiles)
@@ -390,6 +396,7 @@
         die("Can't specify both library and binary names");
 
     compiled = mkht(strhash, streq);
+    loopdetect = mkht(strhash, streq);
     regcomp(&usepat, "^[[:space:]]*use[[:space:]]+([^[:space:]]+)", REG_EXTENDED);
     for (i = optind; i < argc; i++)
         compile(argv[i]);