file->compiled = maybe_temp_file(ctx, "", keep, file->fullname);
if (!compile_and_link(ctx, file->fullname, ccan_dir,
obj_list(m, file),
- "", lib_list(m), file->compiled, output)) {
+ compiler, cflags,
+ lib_list(m), file->compiled, output)) {
+ /* Don't keep failures. */
+ if (keep)
+ unlink(file->compiled);
talloc_free(file->compiled);
file->compiled = NULL;
return false;
bool in_function = false, fake_function = false, has_main = false;
unsigned int i;
- ret = talloc_strdup(m, "/* Prepend a heap of headers. */\n"
- "#include <assert.h>\n"
- "#include <err.h>\n"
- "#include <errno.h>\n"
- "#include <fcntl.h>\n"
- "#include <limits.h>\n"
- "#include <stdbool.h>\n"
- "#include <stdint.h>\n"
- "#include <stdio.h>\n"
- "#include <stdlib.h>\n"
- "#include <string.h>\n"
- "#include <sys/stat.h>\n"
- "#include <sys/types.h>\n"
- "#include <unistd.h>\n");
- ret = talloc_asprintf_append(ret, "/* Include header from module. */\n"
- "#include <ccan/%s/%s.h>\n",
- m->basename, m->basename);
+ ret = talloc_asprintf(m,
+ "/* Include header from module. */\n"
+ "#include <ccan/%s/%s.h>\n"
+ "/* Prepend a heap of headers. */\n"
+ "#include <assert.h>\n"
+ "#include <err.h>\n"
+ "#include <errno.h>\n"
+ "#include <fcntl.h>\n"
+ "#include <limits.h>\n"
+ "#include <stdbool.h>\n"
+ "#include <stdint.h>\n"
+ "#include <stdio.h>\n"
+ "#include <stdlib.h>\n"
+ "#include <string.h>\n"
+ "#include <sys/stat.h>\n"
+ "#include <sys/types.h>\n"
+ "#include <unistd.h>\n",
+ m->basename, m->basename);
ret = talloc_asprintf_append(ret, "/* Useful dummy functions. */\n"
"extern int somefunc(void);\n"
prev = lines[j];
score->score++;
warnings = true;
- score->error = "Compiling extracted example"
- " gave warnings";
- error = talloc_asprintf(score,
- "Example:\n"
- "%s\n"
- "Compiler:\n"
- "%s",
- get_ccan_file_contents(file[j]),
- err[j]);
- score_file_error(score, file[j], 0, error);
+ score_file_error(score, file[j], 0,
+ "Compiling extracted example"
+ " gave warnings:\n"
+ "Example:\n"
+ "%s\n"
+ "Compiler:\n"
+ "%s",
+ get_ccan_file_contents(file[j]),
+ err[j]);
goto next;
}
}
score->pass = false;
- score->error = "Compiling extracted examples failed";
if (!verbose) {
if (num == 3)
- error = "Standalone, adding headers, "
+ error = "Compiling standalone, adding headers, "
"and including previous "
"example all failed";
else
err[1]);
}
}
- score_file_error(score, i, 0, error);
+ score_file_error(score, i, 0, "%s", error);
/* This didn't work, so not a candidate for combining. */
prev = NULL;
}
struct ccanlint examples_compile = {
- .key = "examples-compile",
+ .key = "examples_compile",
.name = "Module examples compile",
.check = build_examples,
.can_run = can_run,
+ .needs = "examples_exist module_builds"
};
-REGISTER_TEST(examples_compile, &has_examples, &build, NULL);
+REGISTER_TEST(examples_compile);