Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intialise dep_fd earlier to write negative dependencies correctly #36

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions redo.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ current bugs:
#include <sys/types.h>
#include <sys/wait.h>

#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
Expand Down Expand Up @@ -200,6 +201,47 @@ redo_ifcreate(int fd, char *target)
dprintf(fd, "-%s\n", target);
}

static int
check_tempfile(char *fname) {
return strlen(name == 14)
&& (strncmp(name, ".depend", 7) == 0 || strncmp(name, ".target", 7) == 0);
}

// TODO: Better exits (return is useless)
// TODO: actually call this function
static int
cleanup(char *path)
{
DIR *d;
struct dirent *entry;
struct stat entrystat;
char entrypath[PATH_MAX];

d = opendir(path);
if(!d)
return 1;

strcpy(entrypath, path);
strcat(entrypath, "/");
size_t baselen = strlen(entrypath);

while ((entry=readdir(d))) {
stat(entry->d_name, &entrystat);
entrypath[baselen] = 0;
strcat(entrypath, entry->d_name);

if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, ".."))
continue;

if (S_ISDIR(entrystat.st_mode))
cleanup(entrypath);

if (check_tempfile(entry->d_name)
remove(entrypath);
}
}


static char *
check_dofile(const char *fmt, ...)
{
Expand Down Expand Up @@ -629,6 +671,7 @@ run_script(char *target, int implicit)
pid_t pid;

target = targetchdir(target);
dep_fd = mkstemp(temp_depfile);

dofile = find_dofile(target);
if (!dofile) {
Expand All @@ -650,8 +693,6 @@ run_script(char *target, int implicit)
}
}

dep_fd = mkstemp(temp_depfile);

target_fd = mkstemp(temp_target_base);

fprintf(stderr, "redo%*.*s %s # %s\n", level*2, level*2, " ", orig_target, dofile);
Expand Down Expand Up @@ -903,7 +944,7 @@ record_deps(int targetc, char *targetv[])
fchdir(dir_fd);

for (targeti = 0; targeti < targetc; targeti++)
write_dep(dep_fd, targetv[targeti]);
write_dep(dep_fd, targetv[targeti]);
}

int
Expand Down