4 #include <ccan/list/list.h>
5 #include <ccan/tal/tal.h>
6 #include <ccan/dgraph/dgraph.h>
7 #include <ccan/autodata/autodata.h>
9 #include "../doc_extract.h"
10 #include "../manifest.h"
13 AUTODATA_TYPE(ccanlint_tests, struct ccanlint);
14 #define REGISTER_TEST(test) AUTODATA(ccanlint_tests, &test)
16 /* 0 == Describe failed tests.
17 1 == Describe results for partial failures.
18 2 == One line per test, plus details of failures.
20 Mainly for debugging ccanlint:
21 3 == Describe every object built.
22 4 == Describe every action. */
25 /* Error in a particular file: stored off score->per_file_errors. */
27 struct list_node list;
28 struct ccan_file *file;
32 /* The score for an individual test. */
34 /* Starts as false: if not set to true, ccanlint exits non-zero.
35 * Thus it is usually set for compilation or other serious failures. */
37 /* Starts at 0 and 1 respectively. */
38 unsigned int score, total;
39 /* The error message to print. */
41 /* Per file errors, set by score_file_error() */
42 struct list_head per_file_errors;
46 /* More concise unique name of test. */
49 /* Unique name of test */
52 /* Can we run this test? Return string explaining why, if not. */
53 const char *(*can_run)(struct manifest *m);
55 /* Should we stop immediately if test fails? */
58 /* If timeleft is set to 0, means it timed out.
59 * score is the result, and a tal context freed after all our
60 * depends are done. */
61 void (*check)(struct manifest *m,
62 unsigned int *timeleft, struct score *score);
64 /* Can we do something about it? (NULL if not) */
65 void (*handle)(struct manifest *m, struct score *score);
67 /* Options from _info. */
69 /* If not set, we'll give an error if they try to set options. */
72 /* Space-separated list of dependency keys. */
75 /* Internal use fields: */
76 /* We are a node in a dependency graph. */
77 struct dgraph_node node;
78 /* Did we skip a dependency? If so, must skip this, too. */
80 /* Have we already run this? */
84 /* Ask the user a yes/no question: the answer is NO if there's an error. */
85 bool ask(const char *question);
88 PREPROC_LINE, /* Line starts with # */
89 CODE_LINE, /* Code (ie. not pure comment). */
90 DOC_LINE, /* Line with kernel-doc-style comment. */
91 COMMENT_LINE, /* (pure) comment line */
94 /* So far, only do simple #ifdef/#ifndef/#if defined/#if !defined tests,
95 * and #if <SYMBOL>/#if !<SYMBOL> */
96 struct pp_conditions {
97 /* We're inside another ifdef? */
98 struct pp_conditions *parent;
110 /* Preprocessor information about each line. */
112 enum line_info_type type;
114 /* Is this actually a continuation of line above? (which ends in \) */
117 /* Conditions for this line to be compiled. */
118 struct pp_conditions *cond;
121 /* Use this rather than accessing f->lines directly: loads on demand. */
122 struct line_info *get_ccan_line_info(struct ccan_file *f);
124 /* Use this rather than accessing f->simplified directly: loads on demand. */
125 const char *get_ccan_simplified(struct ccan_file *f);
133 /* Simple evaluator. If symbols are set this way, is this condition true?
134 * NULL values mean undefined, NULL symbol terminates. */
135 enum line_compiled get_ccan_line_pp(struct pp_conditions *cond,
137 const unsigned int *value, ...);
139 /* Get token if it's equal to token. */
140 bool get_token(const char **line, const char *token);
141 /* Tal copy of symbol token, or NULL. Increment line. */
142 char *get_symbol_token(void *ctx, const char **line);
144 /* Similarly for ->doc_sections */
145 struct list_head *get_ccan_file_docs(struct ccan_file *f);
147 /* Get NULL-terminated array options for this file for this test */
148 char **per_file_options(const struct ccanlint *test, struct ccan_file *f);
150 /* Append message about this file (and line, if non-zero) to the score->error */
151 void score_file_error(struct score *, struct ccan_file *f, unsigned line,
152 const char *errorfmt, ...);
154 /* Start a command in the background. */
155 void run_command_async(const void *ctx, unsigned int time_ms,
156 const char *fmt, ...);
158 /* Async version of compile_and_link. */
159 void compile_and_link_async(const void *ctx, unsigned int time_ms,
160 const char *cfile, const char *ccandir,
161 const char *objs, const char *compiler,
163 const char *libs, const char *outfile);
165 /* Get results of a command, returning ctx (and free it). */
166 void *collect_command(bool *ok, char **output);
168 /* Find manifest for this dir and return compiled _info filename. */
169 char *get_or_compile_info(const void *ctx, const char *dir);
172 extern struct ccanlint trailing_whitespace;
176 struct list_node node;
177 struct ccanlint *dependent;
180 /* Is this test excluded (cmdline or _info). */
181 bool is_excluded(const char *name);
183 /* Called to add options from _info, once it's located. */
184 void add_info_options(struct ccan_file *info);
186 /* Are we happy to compile stuff, or just non-intrusive tests? */
187 extern bool safe_mode;
189 /* Did the user want to keep all the results? */
190 extern bool keep_results;
192 /* Compiler and CFLAGS, from config.h if available. */
193 extern const char *compiler, *cflags;
195 /* Contents of config.h (or NULL if not found) */
196 extern const char *config_header;
198 /* Where is the ccan dir? */
199 extern const char *ccan_dir;
201 #endif /* CCAN_LINT_H */