1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-27 20:41:58 +03:00

Delete output files if this is a failed run.

Otherwise, the fail will stop a Makefile from progressing, but if you
immediately run the build again, Make will think the output files are up to
date, since they are newer (albeit incomplete/incorrect).

FossilOrigin-Name: e38c08d9cdeb0476ac1a77cd3f29f547a8205835
This commit is contained in:
icculus
2010-02-14 05:34:42 +00:00
parent 42585cf73a
commit f5ad824071
3 changed files with 59 additions and 20 deletions

View File

@ -34,6 +34,24 @@ extern int access();
#define MAXRHS 1000
#endif
static const char **made_files = NULL;
static int made_files_count = 0;
static int successful_exit = 0;
static void LemonAtExit(void)
{
/* if we failed, delete (most) files we made, to unconfuse build tools. */
int i;
for (i = 0; i < made_files_count; i++) {
if (!successful_exit) {
remove(made_files[i]);
}
free((void *) made_files[i]);
}
free(made_files);
made_files_count = 0;
made_files = NULL;
}
static char *msort(char*,char**,int(*)(const char*,const char*));
/*
@ -1470,6 +1488,8 @@ char **argv;
int exitcode;
struct lemon lem;
atexit(LemonAtExit);
OptInit(argv,options,stderr);
if( version ){
printf("Lemon version 1.0\n");
@ -1576,6 +1596,7 @@ char **argv;
/* return 0 on success, 1 on failure. */
exitcode = ((lem.errorcnt > 0) || (lem.nconflict != lem.nexpected)) ? 1 : 0;
successful_exit = (exitcode == 0);
exit(exitcode);
return (exitcode);
}
@ -2831,6 +2852,24 @@ char *mode;
lemp->errorcnt++;
return 0;
}
/* Add files we create to a list, so we can delete them if we fail. This
** is to keep makefiles from getting confused. We don't include .out files,
** though: this is debug information, and you don't want it deleted if there
** was an error you need to track down.
*/
if(( *mode=='w' ) && (strcmp(suffix, ".out") != 0)){
const char **ptr = (const char **)
realloc(made_files, sizeof (const char **) * (made_files_count + 1));
char *fname = strdup(lemp->outname);
if ((ptr == NULL) || (fname == NULL)) {
free(ptr);
free(fname);
memory_error();
}
made_files = ptr;
made_files[made_files_count++] = fname;
}
return fp;
}