diff options
author | Leah Neukirchen <leah@vuxu.org> | 2018-07-08 23:49:57 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2018-07-08 23:49:57 +0200 |
commit | b7d9335f082b6fa33ef6238c312dade88d4f3af0 (patch) | |
tree | c43e20bb5c8f7e5942eebd5beea9fcb60f1a43d5 | |
parent | 2dba720f9783cc678b6f54b7aa55394f0d835a57 (diff) | |
download | redo-c-b7d9335f082b6fa33ef6238c312dade88d4f3af0.tar.gz redo-c-b7d9335f082b6fa33ef6238c312dade88d4f3af0.tar.xz redo-c-b7d9335f082b6fa33ef6238c312dade88d4f3af0.zip |
compute proper relative paths when default.do is run from a directory above v0.1
-rw-r--r-- | redo.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/redo.c b/redo.c index 792c43c..cdd7a82 100644 --- a/redo.c +++ b/redo.c @@ -521,13 +521,32 @@ find_job(pid_t pid) return 0; } +char uprel[PATH_MAX]; + +void +compute_uprel() +{ + char *u = uprel; + char *dp = getenv("REDO_DIRPREFIX"); + + *u = 0; + while (dp && *dp) { + *u++ = '.'; + *u++ = '.'; + *u++ = '/'; + *u = 0; + dp = strchr(dp + 1, '/'); + } +} + static int write_dep(int dep_fd, char *file) { int fd = open(file, O_RDONLY); if (fd < 0) return 0; - dprintf(dep_fd, "=%s %s %s\n", hashfile(fd), datefile(fd), file); + dprintf(dep_fd, "=%s %s %s%s\n", + hashfile(fd), datefile(fd), (*file == '/' ? "" : uprel), file); close(fd); return 0; } @@ -648,6 +667,11 @@ run_script(char *target, int implicit) snprintf(rel_target, sizeof rel_target, "%s%s%s", dirprefix, "/"+(*dirprefix ? 0 : 1), target); + if (dirprefix) + setenv("REDO_DIRPREFIX", dirprefix, 1); + else + unsetenv("REDO_DIRPREFIX"); + pid = fork(); if (pid < 0) { perror("fork"); @@ -875,12 +899,12 @@ record_deps(int targetc, char *targetv[]) return; fchdir(dir_fd); + compute_uprel(); for (targeti = 0; targeti < targetc; targeti++) { fd = open(targetv[targeti], O_RDONLY); if (fd < 0) continue; - // here, we write out the unmodified target name! write_dep(dep_fd, targetv[targeti]); close(fd); } |