aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/build.c32
-rw-r--r--src/build.h1
-rw-r--r--src/redo.c3
3 files changed, 25 insertions, 11 deletions
diff --git a/src/build.c b/src/build.c
index 01f8314..c79cf73 100644
--- a/src/build.c
+++ b/src/build.c
@@ -182,11 +182,11 @@ static int build_target(dep_info *dep) {
}
free(dep2.path);
- add_prereq(doscripts->chosen, dep->target, 'c');
+ add_prereq_path(doscripts->chosen, dep->target, 'c');
/* redo-ifcreate on specific if general was chosen */
if (doscripts->general == doscripts->chosen)
- add_prereq(doscripts->specific, dep->target, 'e');
+ add_prereq_path(doscripts->specific, dep->target, 'e');
free(temp_output);
exit:
@@ -340,7 +340,13 @@ static char *get_dep_path(const char *target) {
return dep_path;
}
-/* Declare that `parent` depends on `target`. */
+/* Declare that parent depends on target in the specific way ident.
+ * Parent must be a path pointing to a (maybe non-existent) file in a valid,
+ * exisiting directory. Target can be any string.
+ * This relation is saved in the dependency store like this:
+ * .redo/{abs,rel}/<parent>.prereq:
+ * <ident>:<target>
+ */
void add_prereq(const char *target, const char *parent, int ident) {
char *base_path = get_dep_path(parent);
char *dep_path = concat(2, base_path, ".prereq");
@@ -349,27 +355,35 @@ void add_prereq(const char *target, const char *parent, int ident) {
if (fd < 0)
fatal("redo: failed to open %s", dep_path);
- char *reltarget = get_relpath(target);
- size_t bufsize = strlen(reltarget)*2 + 3;
+ size_t bufsize = strlen(target)*2 + 3;
char *buf = xmalloc(bufsize);
buf[0] = ident;
buf[1] = ':';
- size_t encoded_len = encode_string(buf+2, reltarget);
- buf[encoded_len+2] = '\n';
+ size_t encoded_len = encode_string(buf+2, target) + 3;
+ buf[encoded_len-1] = '\n';
- if (write(fd, buf, encoded_len+3) < (ssize_t) encoded_len+3)
+ if (write(fd, buf, encoded_len) < (ssize_t) encoded_len)
fatal("redo: failed to write to %s", dep_path);
if (close(fd))
fatal("redo: failed to close %s", dep_path);
free(buf);
- free(reltarget);
free(dep_path);
free(base_path);
}
+/* Works like add_prereq(), except that it uses the relative path of target to
+ * REDO_ROOT instead of just the target. Target must be a path pointing to a
+ * (maybe non-existant) file in a valid existing directory.
+ */
+void add_prereq_path(const char *target, const char *parent, int ident) {
+ char *reltarget = get_relpath(target);
+ add_prereq(reltarget, parent, ident);
+ free(reltarget);
+}
+
/* Hash the target file, returning a pointer to the heap allocated hash. */
static unsigned char *hash_file(FILE *fp) {
unsigned char *hash = xmalloc(20);
diff --git a/src/build.h b/src/build.h
index 2611479..24367a4 100644
--- a/src/build.h
+++ b/src/build.h
@@ -12,6 +12,7 @@
#include <stdbool.h>
extern void add_prereq(const char *target, const char *parent, int ident);
+extern void add_prereq_path(const char *target, const char *parent, int ident);
extern int update_target(const char *target, int ident);
#endif
diff --git a/src/redo.c b/src/redo.c
index 7f69949..e28f8fa 100644
--- a/src/redo.c
+++ b/src/redo.c
@@ -94,8 +94,7 @@ int main(int argc, char *argv[]) {
} while (!*temp);
update_target(*temp, ident);
- add_prereq(*temp, xbasename(parent), ident);
-
+ add_prereq_path(*temp, xbasename(parent), ident);
*temp = NULL;
}
}