summaryrefslogtreecommitdiff
path: root/tools/ccanlint/tests/module_builds.c
blob: cb13a0b63e6a53933705d9e3370f9237d8243238 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h>
#include <ccan/str/str.h>
#include <ccan/take/take.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <err.h>
#include <string.h>
#include <ctype.h>
#include "build.h"

static const char *can_build(struct manifest *m)
{
	if (safe_mode)
		return "Safe mode enabled";
	return NULL;
}

static char *obj_list(const struct manifest *m, enum compile_type ctype)
{
	char *list = tal_strdup(m, "");
	struct ccan_file *i;

	/* Objects from all the C files. */
	list_for_each(&m->c_files, i, list) {
		list = tal_strcat(m, take(list), i->compiled[ctype]);
		list = tal_strcat(m, take(list), " ");
	}
	return list;
}

char *build_module(struct manifest *m,
		   enum compile_type ctype, char **errstr)
{
	return link_objects(m, m->basename, obj_list(m, ctype), errstr);
}

static void do_build(struct manifest *m,
		     unsigned int *timeleft,
		     struct score *score)
{
	char *errstr;

	if (list_empty(&m->c_files)) {
		/* No files?  No score, but we "pass". */
		score->total = 0;
		score->pass = true;
		return;
	}

	m->compiled[COMPILE_NORMAL]
		= build_module(m, COMPILE_NORMAL, &errstr);
	if (!m->compiled[COMPILE_NORMAL]) {
		score_error(score, m->modname,"%s", errstr);
		return;
	}

	score->pass = true;
	score->score = score->total;
}

struct ccanlint module_builds = {
	.key = "module_builds",
	.name = "Module can be built from object files",
	.compulsory = true,
	.check = do_build,
	.can_run = can_build,
	.needs = "objects_build"
};

REGISTER_TEST(module_builds);