#include <string.h>
#include <ctype.h>
-static bool has_dep(struct manifest *m, const char *depname)
+static bool has_dep(struct manifest *m, bool test_depend, const char *depname)
{
struct manifest *i;
if (streq(i->basename, depname))
return true;
}
+
+ if (test_depend) {
+ list_for_each(&m->test_deps, i, list) {
+ if (streq(i->basename, depname))
+ return true;
+ }
+ }
+
return false;
}
+static void check_dep_includes(struct manifest *m, struct score *score,
+ struct ccan_file *f, bool test_depend)
+{
+ unsigned int i;
+ char **lines = get_ccan_file_lines(f);
+ struct line_info *li = get_ccan_line_info(f);
+
+ for (i = 0; lines[i]; i++) {
+ char *mod;
+ if (!strreg(f, lines[i],
+ "^[ \t]*#[ \t]*include[ \t]*[<\"]"
+ "ccan/+([^/]+)/", &mod))
+ continue;
+
+ if (has_dep(m, test_depend, mod))
+ continue;
+
+ /* FIXME: we can't be sure about
+ * conditional includes, so don't
+ * complain. */
+ if (!li[i].cond) {
+ score_file_error(score, f, i+1,
+ "%s not listed in _info", mod);
+ }
+ }
+}
+
static void check_depends_accurate(struct manifest *m,
unsigned int *timeleft, struct score *score)
{
struct list_head *list;
- foreach_ptr(list, &m->c_files, &m->h_files,
- &m->run_tests, &m->api_tests,
+ foreach_ptr(list, &m->c_files, &m->h_files) {
+ struct ccan_file *f;
+
+ list_for_each(list, f, list)
+ check_dep_includes(m, score, f, false);
+ }
+
+ foreach_ptr(list, &m->run_tests, &m->api_tests,
&m->compile_ok_tests, &m->compile_fail_tests,
&m->other_test_c_files) {
struct ccan_file *f;
- list_for_each(list, f, list) {
- unsigned int i;
- char **lines = get_ccan_file_lines(f);
- struct line_info *li = get_ccan_line_info(f);
-
- for (i = 0; lines[i]; i++) {
- char *mod;
- if (!strreg(f, lines[i],
- "^[ \t]*#[ \t]*include[ \t]*[<\"]"
- "ccan/+([^/]+)/", &mod))
- continue;
-
- if (has_dep(m, mod))
- continue;
-
- /* FIXME: we can't be sure about
- * conditional includes, so don't
- * complain. */
- if (!li[i].cond) {
- score_file_error(score, f, i+1,
- "%s not listed in _info",
- mod);
- }
- }
- }
+ list_for_each(list, f, list)
+ check_dep_includes(m, score, f, true);
}
if (!score->error) {
.key = "depends_accurate",
.name = "Module's CCAN dependencies are the only CCAN files #included",
.check = check_depends_accurate,
- .needs = "depends_exist"
+ .needs = "depends_exist test_depends_exist"
};
REGISTER_TEST(depends_accurate);
#include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h>
#include <ccan/talloc/talloc.h>
+#include <ccan/foreach/foreach.h>
#include <ccan/str/str.h>
#include <sys/types.h>
#include <sys/stat.h>
static void check_depends_built(struct manifest *m,
unsigned int *timeleft, struct score *score)
{
- struct manifest *i;
-
- list_for_each(&m->deps, i, list) {
- char *errstr = build_submodule(i, cflags, COMPILE_NORMAL);
-
- if (errstr) {
- score->error = talloc_asprintf(score,
- "Dependency %s"
- " did not build:\n%s",
- i->basename, errstr);
- return;
+ struct list_head *list;
+
+ foreach_ptr(list, &m->deps, &m->test_deps) {
+ struct manifest *i;
+ list_for_each(list, i, list) {
+ char *errstr;
+
+ errstr = build_submodule(i, cflags, COMPILE_NORMAL);
+
+ if (errstr) {
+ score->error = talloc_asprintf(score,
+ "Dependency %s"
+ " did not"
+ " build:\n%s",
+ i->basename,
+ errstr);
+ return;
+ }
}
}
.name = "Module's CCAN dependencies can be found or built",
.check = check_depends_built,
.can_run = can_build,
- .needs = "depends_exist"
+ .needs = "depends_exist test_depends_exist"
};
REGISTER_TEST(depends_build);
#include <tools/tools.h>
#include <ccan/talloc/talloc.h>
#include <ccan/str/str.h>
+#include <ccan/foreach/foreach.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
unsigned int *timeleft,
struct score *score)
{
+ struct list_head *list;
struct manifest *i;
char *flags;
flags = talloc_asprintf(score, "%s %s", cflags,
REDUCE_FEATURES_FLAGS);
- list_for_each(&m->deps, i, list) {
- char *errstr = build_submodule(i, flags, COMPILE_NOFEAT);
+ foreach_ptr(list, &m->deps, &m->test_deps) {
+ list_for_each(list, i, list) {
+ char *errstr = build_submodule(i, flags,
+ COMPILE_NOFEAT);
- if (errstr) {
- score->error = talloc_asprintf(score,
- "Dependency %s"
- " did not build:\n%s",
- i->basename, errstr);
- return;
+ if (errstr) {
+ score->error = talloc_asprintf(score,
+ "Dependency %s"
+ " did not"
+ " build:\n%s",
+ i->basename,
+ errstr);
+ return;
+ }
}
}
#include <string.h>
#include <ctype.h>
-static bool add_dep(struct manifest *m, const char *dep, struct score *score)
+static bool have_dep(struct manifest *m, const char *dep)
+{
+ struct manifest *i;
+
+ list_for_each(&m->deps, i, list)
+ if (streq(i->basename, dep + strlen("ccan/")))
+ return true;
+
+ return false;
+}
+
+static bool add_dep(struct manifest *m,
+ struct list_head *deplist,
+ const char *dep, struct score *score)
{
struct stat st;
struct manifest *subm;
return false;
}
subm = get_manifest(m, dir);
- list_add_tail(&m->deps, &subm->list);
+ list_add_tail(deplist, &subm->list);
return true;
}
{
unsigned int i;
char **deps;
- char *updir = talloc_strdup(m, m->dir);
- bool needs_tap;
- if (strrchr(updir, '/'))
- *strrchr(updir, '/') = '\0';
+ if (safe_mode)
+ deps = get_safe_ccan_deps(m, m->dir, "depends", true);
+ else
+ deps = get_deps(m, m->dir, "depends", true,
+ get_or_compile_info);
+
+ for (i = 0; deps[i]; i++) {
+ if (!strstarts(deps[i], "ccan/"))
+ continue;
+
+ if (!add_dep(m, &m->deps, deps[i], score))
+ return;
+ }
+
+ score->pass = true;
+ score->score = score->total;
+}
+
+static void check_test_depends_exist(struct manifest *m,
+ unsigned int *timeleft,
+ struct score *score)
+{
+ unsigned int i;
+ char **deps;
+ bool needs_tap;
/* We may need libtap for testing, unless we're "tap" */
if (streq(m->basename, "tap")) {
}
if (safe_mode)
- deps = get_safe_ccan_deps(m, m->dir, "depends", true);
+ deps = get_safe_ccan_deps(m, m->dir, "testdepends", true);
else
- deps = get_deps(m, m->dir, "depends", true,
+ deps = get_deps(m, m->dir, "testdepends", true,
get_or_compile_info);
for (i = 0; deps[i]; i++) {
if (!strstarts(deps[i], "ccan/"))
continue;
- if (!add_dep(m, deps[i], score))
+ /* Don't add dependency twice: we can only be on one list! */
+ if (!have_dep(m, deps[i])
+ && !add_dep(m, &m->test_deps, deps[i], score))
return;
if (streq(deps[i], "ccan/tap")) {
}
}
- if (needs_tap && !add_dep(m, "ccan/tap", score)) {
+ if (needs_tap && !have_dep(m, "ccan/tap")
+ && !add_dep(m, &m->test_deps, "ccan/tap", score)) {
return;
}
};
REGISTER_TEST(depends_exist);
+
+struct ccanlint test_depends_exist = {
+ .key = "test_depends_exist",
+ .name = "Module's CCAN test dependencies can be found",
+ .compulsory = false,
+ .check = check_test_depends_exist,
+ .needs = "depends_exist"
+};
+
+REGISTER_TEST(test_depends_exist);
list = talloc_asprintf_append(list, " %s",
i->compiled[own_ctype]);
- /* Other ccan modules. */
+ /* Other ccan modules (normal depends). */
list_for_each(&m->deps, subm, list) {
if (subm->compiled[ctype])
list = talloc_asprintf_append(list, " %s",
subm->compiled[ctype]);
}
+ /* Other ccan modules (test depends). */
+ list_for_each(&m->test_deps, subm, list) {
+ if (subm->compiled[ctype])
+ list = talloc_asprintf_append(list, " %s",
+ subm->compiled[ctype]);
+ }
+
return list;
}
-char *lib_list(const struct manifest *m, enum compile_type ctype)
+char *test_lib_list(const struct manifest *m, enum compile_type ctype)
{
unsigned int i;
char **libs;
char *ret = talloc_strdup(m, "");
- libs = get_libs(m, m->dir, "depends", get_or_compile_info);
+ libs = get_libs(m, m->dir, "testdepends", get_or_compile_info);
for (i = 0; libs[i]; i++)
ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
return ret;
if (!compile_and_link(ctx, file->fullname, ccan_dir,
test_obj_list(m, link_with_module,
ctype, ctype),
- compiler, flags, lib_list(m, ctype), fname,
+ compiler, flags, test_lib_list(m, ctype), fname,
output)) {
talloc_free(fname);
return false;
compile_and_link_async(file, time_ms, file->fullname, ccan_dir,
test_obj_list(m, link_with_module, ctype, ctype),
- compiler, flags, lib_list(m, ctype),
+ compiler, flags, test_lib_list(m, ctype),
file->compiled[ctype]);
}
char *test_obj_list(const struct manifest *m, bool link_with_module,
enum compile_type ctype, enum compile_type own_ctype);
/* Library list as specified by ctype variant of _info. */
-char *lib_list(const struct manifest *m, enum compile_type ctype);
+char *test_lib_list(const struct manifest *m, enum compile_type ctype);
COMPILE_NORMAL,
COMPILE_COVERAGE),
compiler, flags,
- lib_list(m, COMPILE_NORMAL),
+ test_lib_list(m, COMPILE_NORMAL),
file->compiled[COMPILE_COVERAGE]);
}
list_head_init(&m->examples);
list_head_init(&m->mangled_examples);
list_head_init(&m->deps);
+ list_head_init(&m->test_deps);
len = strlen(m->dir);
while (len && m->dir[len-1] == '/')
/* From tests/check_depends_exist.c */
struct list_head deps;
+ struct list_head test_deps;
/* From tests/license_exists.c */
enum license license;