summaryrefslogtreecommitdiff
path: root/myrbuild
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-09-14 23:54:27 -0400
committerOri Bernstein <ori@eigenstate.org>2014-09-14 23:54:27 -0400
commitadd4086c3f6fe23957c9d7707fc3c7720319bf21 (patch)
treeb3929427b5380e8a84593a994e4bdc9b77dfba1f /myrbuild
parent6d98d1414c11322eb919530405aebce01ee51c6f (diff)
downloadmc-add4086c3f6fe23957c9d7707fc3c7720319bf21.tar.gz
Print the stack that has a cycle when compiling.
Myrbuild now keeps track of the files being compiled, and prints a dependency stack, making it easier to puzzle out what caused a dependency loop.
Diffstat (limited to 'myrbuild')
-rw-r--r--myrbuild/myrbuild.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/myrbuild/myrbuild.c b/myrbuild/myrbuild.c
index ba7b2b8..8eb1aa9 100644
--- a/myrbuild/myrbuild.c
+++ b/myrbuild/myrbuild.c
@@ -233,7 +233,7 @@ void scrapelib(Htab *g, char *lib)
htput(g, lib, deps);
}
-void compile(char *file)
+void compile(char *file, char ***stack, size_t *nstack)
{
size_t i, ndeps;
char **cmd;
@@ -248,8 +248,12 @@ void compile(char *file)
if (hthas(compiled, file))
return;
- if (hthas(loopdetect, file))
- die("Cycle in dependency graph, involving %s\n", file);
+ if (hthas(loopdetect, file)) {
+ fprintf(stderr, "Cycle in dependency graph, involving %s. dependency stack:\n", file);
+ for (i = 0; i < *nstack; i++)
+ fprintf(stderr, "\t%s\n", (*stack)[i]);
+ exit(1);
+ }
htput(loopdetect, file, file);
if (hassuffix(file, ".myr")) {
swapsuffix(use, sizeof use, file, ".myr", ".use");
@@ -258,7 +262,9 @@ void compile(char *file)
for (i = 0; i < ndeps; i++) {
if (isquoted(deps[i])) {
localdep = usetomyr(deps[i]);
- compile(localdep);
+ lappend(stack, nstack, localdep);
+ compile(localdep, stack, nstack);
+ lpop(stack, nstack);
free(localdep);
} else {
scrapelib(libgraph, deps[i]);
@@ -452,6 +458,8 @@ int main(int argc, char **argv)
int opt;
int i;
struct utsname name;
+ char **stack;
+ size_t nstack;
if (uname(&name) == 0)
sysname = strdup(name.sysname);
@@ -489,12 +497,17 @@ int main(int argc, char **argv)
if (libname && binname)
die("Can't specify both library and binary names");
+ stack = NULL;
+ nstack = 0;
libgraph = mkht(strhash, streq);
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]);
+ for (i = optind; i < argc; i++) {
+ lappend(&stack, &nstack, argv[i]);
+ compile(argv[i], &stack, &nstack);
+ lpop(&stack, &nstack);
+ }
if (libname) {
mergeuse(&argv[optind], argc - optind);
archive(&argv[optind], argc - optind);