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".
+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;
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);
" of CCAN modules.",
"This usage message");
" 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] != '/')
opt_parse(&argc, argv, opt_log_stderr_exit);
if (dir[0] != '/')
if (verbose >= 4)
tools_verbose = true;
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. */
m = get_manifest(talloc_autofree_context(), dir);
/* Create a symlink from temp dir back to src dir's test directory. */
if (!compile_and_link(ctx, file->fullname, ccan_dir,
obj_list(m, file),
"", lib_list(m), file->compiled, output)) {
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;
talloc_free(file->compiled);
file->compiled = NULL;
return false;
unsigned int *timeleft, struct score *score)
{
struct ccan_file *i;
unsigned int *timeleft, struct score *score)
{
struct ccan_file *i;
char *covcmd;
bool full_gcov = (verbose > 1);
struct list_head *list;
/* This tells gcov where we put those .gcno files. */
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",
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) {
/* Run them all. */
foreach_ptr(list, &m->run_tests, &m->api_tests) {
+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)
{
char *maybe_temp_file(const void *ctx, const char *extension, bool keep,
const char *srcname)
{
struct stat st;
unsigned int count = 0;
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
if (strrchr(srcname, '.'))
baselen = strrchr(srcname, '.') - srcname;
else
do {
f = talloc_asprintf(ctx, "%s/%.*s%s%s",
do {
f = talloc_asprintf(ctx, "%s/%.*s%s%s",
- keep ? "" : temp_dir(ctx),
baselen, srcname,
suffix, extension);
talloc_free(suffix);
baselen, srcname,
suffix, extension);
talloc_free(suffix);
} while (lstat(f, &st) == 0);
if (tools_verbose)
} 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;
talloc_free(suffix);
return f;
/* Default wait for run_command. Should never time out. */
extern const unsigned int default_timeout_ms;
/* 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 */
#endif /* CCAN_TOOLS_H */