From d0d0d61ea9955bad17f3f7512aca7b23f57ced5d Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 12 Feb 2010 13:40:25 -0500 Subject: [PATCH] Lemon now deletes its output on failure. This is to fix the build system. Previously, a Makefile would abort when lemon fails, but on the next run it would see a newer (incorrect/incomplete) output file, and assume it succeeded previously, with disastrous effects for later steps in the build process. --- misc/lemon.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/misc/lemon.c b/misc/lemon.c index 3814e314..73278bc0 100644 --- a/misc/lemon.c +++ b/misc/lemon.c @@ -40,6 +40,27 @@ extern int access(); #define MAXRHS 1000 #endif +#if __MOJOSHADER__ +static const char **made_files = NULL; +static int made_files_count = 0; +static void lemon_exit(const int status) +{ + /* if we failed, delete (most) files we made, to unconfuse build tools. */ + int i; + for (i = 0; i < made_files_count; i++) { + if (status != 0) { + remove(made_files[i]); + } + free((void *) made_files[i]); + } + free(made_files); + made_files_count = 0; + made_files = NULL; + exit(status); +} +#define exit(x) lemon_exit(x) +#endif + static char *msort(char*,char**,int(*)(const char*,const char*)); /* @@ -2833,6 +2854,22 @@ char *mode; lemp->errorcnt++; return 0; } +#if __MOJOSHADER__ + /* don't include .out files: 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; + } +#endif return fp; }