summaryrefslogtreecommitdiff
path: root/parse/use.c
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-02-17 22:21:41 -0800
committerOri Bernstein <ori@eigenstate.org>2017-02-17 23:32:19 -0800
commit61a91a2cc9be621ee517b2cb4114922bd5da351f (patch)
tree2dbf60c0c0d4b03c65c59146f44e4f7c8f1c9cb2 /parse/use.c
parent210b24e9cf07baef21fb0fd943f81f38a3196945 (diff)
downloadmc-61a91a2cc9be621ee517b2cb4114922bd5da351f.tar.gz
Search for usefiles relative to the output.
For most uses, this is equivalent to compiler cwd, but supports out of tree builds better. It also means that builds behave the same way regardless of the directory that the compiler is run from, which is convenient for testing. This also drops support for `.use` suffixes on local uses.
Diffstat (limited to 'parse/use.c')
-rw-r--r--parse/use.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/parse/use.c b/parse/use.c
index 70cd299..28132bd 100644
--- a/parse/use.c
+++ b/parse/use.c
@@ -1031,18 +1031,18 @@ void readuse(Node *use, Stab *st, Vis vis)
char *t, *p;
char buf[512];
- /* local (quoted) uses are always relative to the cwd */
+ /* local (quoted) uses are always relative to the output */
fd = NULL;
p = NULL;
if (use->use.islocal) {
- if (hassuffix(use->use.name, ".use"))
- snprintf(buf, sizeof buf, "%s", use->use.name);
- else
- snprintf(buf,sizeof buf, "%s.use", use->use.name);
-
+ snprintf(buf,sizeof buf, "%s/%s.use", localincpath, use->use.name);
p = strdup(buf);
fd = fopen(p, "r");
- /* nonlocal (barename) uses are always searched on the include path */
+ if (!fd) {
+ fprintf(stderr, "could not open usefile %s\n", buf);
+ exit(1);
+ }
+ /* nonlocal (barename) uses are always searched on the include path */
} else {
for (i = 0; i < nincpaths; i++) {
snprintf(buf, sizeof buf, "lib%s.use", use->use.name);
@@ -1064,12 +1064,12 @@ void readuse(Node *use, Stab *st, Vis vis)
}
free(p);
}
- }
- if (!fd) {
- fprintf(stderr, "could not open usefile %s in search path:\n", use->use.name);
- for (i = 0; i < nincpaths; i++)
- fprintf(stderr, "\t%s\n", incpaths[i]);
- exit(1);
+ if (!fd) {
+ fprintf(stderr, "could not open usefile %s in search path:\n", use->use.name);
+ for (i = 0; i < nincpaths; i++)
+ fprintf(stderr, "\t%s\n", incpaths[i]);
+ exit(1);
+ }
}
if (!loaduse(p, fd, st, vis))