Commit 1f45ec04 authored by Rusty Russell's avatar Rusty Russell

ccanlint: -k should not pollute module directory.

It leads to numerous problems, such as the next ccanlint getting confused
trying to compile examples, and "-k examples_compile -k examples_exist"
giving bogus errors.

So instead we leave the temporary dir lying around and delete
individual files which aren't marked "keep".
parent 020f8ef4
......@@ -292,12 +292,21 @@ static void init_tests(void)
}
}
static int show_tmpdir(char *dir)
{
printf("You can find ccanlint working files in '%s'\n", dir);
return 0;
}
static char *keep_test(const char *testname, void *unused)
{
struct ccanlint *i = find_test(testname);
if (!i)
errx(1, "No test %s to --keep", testname);
i->keep_results = true;
/* Don't automatically destroy temporary dir. */
talloc_set_destructor(temp_dir(NULL), show_tmpdir);
return NULL;
}
......@@ -495,6 +504,10 @@ int main(int argc, char *argv[])
" of CCAN modules.",
"This usage message");
/* We move into temporary directory, so gcov dumps its files there. */
if (chdir(temp_dir(talloc_autofree_context())) != 0)
err(1, "Error changing to %s temporary dir", temp_dir(NULL));
opt_parse(&argc, argv, opt_log_stderr_exit);
if (dir[0] != '/')
......@@ -508,10 +521,6 @@ int main(int argc, char *argv[])
if (verbose >= 4)
tools_verbose = true;
/* We move into temporary directory, so gcov dumps its files there. */
if (chdir(temp_dir(talloc_autofree_context())) != 0)
err(1, "Error changing to %s temporary dir", temp_dir(NULL));
m = get_manifest(talloc_autofree_context(), dir);
/* Create a symlink from temp dir back to src dir's test directory. */
......
......@@ -122,6 +122,9 @@ static bool compile(const void *ctx,
if (!compile_and_link(ctx, file->fullname, ccan_dir,
obj_list(m, file),
"", lib_list(m), file->compiled, output)) {
/* Don't keep failures. */
if (keep)
unlink(file->compiled);
talloc_free(file->compiled);
file->compiled = NULL;
return false;
......
......@@ -127,15 +127,26 @@ static void do_run_coverage_tests(struct manifest *m,
unsigned int *timeleft, struct score *score)
{
struct ccan_file *i;
char *cmdout;
char *cmdout, *outdir;
char *covcmd;
bool full_gcov = (verbose > 1);
struct list_head *list;
/* This tells gcov where we put those .gcno files. */
outdir = talloc_dirname(score, m->info_file->compiled);
covcmd = talloc_asprintf(m, "gcov %s -o %s",
full_gcov ? "" : "-n",
talloc_dirname(score, m->info_file->compiled));
outdir);
/* Unlink these files afterwards. */
if (!keep) {
talloc_set_destructor(talloc_asprintf(score,
"%s/run.gcno", outdir),
unlink_file_destructor);
talloc_set_destructor(talloc_asprintf(score,
"%s/run.gcda", outdir),
unlink_file_destructor);
}
/* Run them all. */
foreach_ptr(list, &m->run_tests, &m->api_tests) {
......
......@@ -210,6 +210,12 @@ char *temp_dir(const void *ctx)
return tmpdir;
}
int unlink_file_destructor(char *filename)
{
unlink(filename);
return 0;
}
char *maybe_temp_file(const void *ctx, const char *extension, bool keep,
const char *srcname)
{
......@@ -218,11 +224,7 @@ char *maybe_temp_file(const void *ctx, const char *extension, bool keep,
struct stat st;
unsigned int count = 0;
if (!keep)
srcname = talloc_basename(ctx, srcname);
else
assert(srcname[0] == '/');
srcname = talloc_basename(ctx, srcname);
if (strrchr(srcname, '.'))
baselen = strrchr(srcname, '.') - srcname;
else
......@@ -230,7 +232,7 @@ char *maybe_temp_file(const void *ctx, const char *extension, bool keep,
do {
f = talloc_asprintf(ctx, "%s/%.*s%s%s",
keep ? "" : temp_dir(ctx),
temp_dir(ctx),
baselen, srcname,
suffix, extension);
talloc_free(suffix);
......@@ -238,7 +240,10 @@ char *maybe_temp_file(const void *ctx, const char *extension, bool keep,
} while (lstat(f, &st) == 0);
if (tools_verbose)
printf("Creating file %s\n", f);
printf("Creating %sfile %s\n", keep ? "" : "temporary ", f);
if (!keep)
talloc_set_destructor(f, unlink_file_destructor);
talloc_free(suffix);
return f;
......
......@@ -72,4 +72,7 @@ char *maybe_temp_file(const void *ctx, const char *extension, bool in_pwd,
/* Default wait for run_command. Should never time out. */
extern const unsigned int default_timeout_ms;
/* Talloc destructor which unlinks file. */
int unlink_file_destructor(char *filename);
#endif /* CCAN_TOOLS_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment