Commit 0248fa2c authored by Rusty Russell's avatar Rusty Russell

ccanlint: fix --compiler and --cflags options to apply to _info files as well.

We weren't using the compiler and cflags options in tools/compile.
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent e0529e15
......@@ -46,10 +46,6 @@ bool keep_results = false;
static bool targeting = false;
static unsigned int timeout;
/* These are overridden at runtime if we can find config.h */
const char *compiler = NULL;
const char *cflags = NULL;
const char *config_header;
const char *ccan_dir;
......@@ -607,6 +603,7 @@ int main(int argc, char *argv[])
const char *prefix = "";
char *cwd = path_cwd(NULL), *dir;
struct dgraph_node all;
const char *override_compiler = NULL, *override_cflags = NULL;
/* Empty graph node to which we attach everything else. */
dgraph_init_node(&all);
......@@ -631,9 +628,9 @@ int main(int argc, char *argv[])
opt_register_arg("-t|--target <testname>", opt_set_target, NULL, &all,
"only run one test (and its prerequisites)");
opt_register_arg("--compiler <compiler>", opt_set_const_charp,
NULL, &compiler, "set the compiler");
NULL, &override_compiler, "set the compiler");
opt_register_arg("--cflags <flags>", opt_set_const_charp,
NULL, &cflags, "set the compiler flags");
NULL, &override_cflags, "set the compiler flags");
opt_register_noarg("-?|-h|--help", opt_usage_and_exit,
"\nA program for checking and guiding development"
" of CCAN modules.",
......@@ -668,8 +665,13 @@ int main(int argc, char *argv[])
ccan_dir = find_ccan_dir(dir);
if (!ccan_dir)
errx(1, "Cannot find ccan/ base directory in %s", dir);
config_header = read_config_header(ccan_dir, &compiler, &cflags,
verbose > 1);
config_header = read_config_header(ccan_dir, verbose > 1);
/* We do this after read_config_header has set compiler & cflags */
if (override_cflags)
cflags = override_cflags;
if (override_compiler)
compiler = override_compiler;
if (argc == 1)
pass = test_module(&all, cwd, "", summary);
......
......@@ -8,6 +8,7 @@
#include <stdbool.h>
#include "../doc_extract.h"
#include "../manifest.h"
#include "../tools.h"
#include "licenses.h"
AUTODATA_TYPE(ccanlint_tests, struct ccanlint);
......@@ -189,9 +190,6 @@ extern bool safe_mode;
/* Did the user want to keep all the results? */
extern bool keep_results;
/* Compiler and CFLAGS, from config.h if available. */
extern const char *compiler, *cflags;
/* Contents of config.h (or NULL if not found) */
extern const char *config_header;
......
#include "tools.h"
#include <stdlib.h>
#ifndef CCAN_COMPILER
#define CCAN_COMPILER DEFAULT_CCAN_COMPILER
#endif
#ifndef CCAN_CFLAGS
#define CCAN_CFLAGS DEFAULT_CCAN_CFLAGS
#endif
const char *compiler = CCAN_COMPILER;
const char *cflags = CCAN_CFLAGS;
bool compile_verbose = false;
/* Compile multiple object files into a single. Returns NULL if fails. */
......
......@@ -62,8 +62,7 @@ char *compile_info(const void *ctx, const char *dir)
compiled = temp_file(ctx, "", "info");
if (compile_and_link(ctx, info_c_file, find_ccan_dir(dir), "",
CCAN_COMPILER, CCAN_CFLAGS " -I.", "",
compiled, &output))
compiler, cflags, "", compiled, &output))
return compiled;
return NULL;
}
......
......@@ -87,9 +87,7 @@ static char *demangle_string(char *string)
return string;
}
char *read_config_header(const char *ccan_dir,
const char **compiler, const char **cflags,
bool verbose)
char *read_config_header(const char *ccan_dir, bool verbose)
{
char *fname = path_join(NULL, ccan_dir, "config.h");
char **lines;
......@@ -100,7 +98,7 @@ char *read_config_header(const char *ccan_dir,
tal_free(fname);
if (!config_header)
goto out;
return NULL;
lines = tal_strsplit(config_header, config_header, "\n", STR_EMPTY_OK);
for (i = 0; i < tal_count(lines) - 1; i++) {
......@@ -112,30 +110,23 @@ char *read_config_header(const char *ccan_dir,
if (!get_token(line, "define"))
continue;
sym = get_symbol_token(lines, line);
if (streq(sym, "CCAN_COMPILER") && !compiler) {
*compiler = demangle_string(lines[i]);
if (!*compiler)
if (streq(sym, "CCAN_COMPILER")) {
compiler = demangle_string(lines[i]);
if (!compiler)
errx(1, "%s:%u:could not parse CCAN_COMPILER",
fname, i+1);
if (verbose)
printf("%s: compiler set to '%s'\n",
fname, *compiler);
} else if (streq(sym, "CCAN_CFLAGS") && !cflags) {
*cflags = demangle_string(lines[i]);
if (!*cflags)
fname, compiler);
} else if (streq(sym, "CCAN_CFLAGS")) {
cflags = demangle_string(lines[i]);
if (!cflags)
errx(1, "%s:%u:could not parse CCAN_CFLAGS",
fname, i+1);
if (verbose)
printf("%s: compiler flags set to '%s'\n",
fname, *cflags);
fname, cflags);
}
}
out:
if (!*compiler)
*compiler = CCAN_COMPILER;
if (!*cflags)
*cflags = CCAN_CFLAGS;
return config_header;
}
......@@ -8,9 +8,7 @@ bool get_token(const char **line, const char *token);
/* Get an identifier token. */
char *get_symbol_token(void *ctx, const char **line);
/* Read config header from config_dir/config.h: set compiler/cflags. */
char *read_config_header(const char *config_dir,
const char **compiler, const char **cflags,
bool verbose);
/* Read config header from config_dir/config.h: sets compiler/cflags. */
char *read_config_header(const char *config_dir, bool verbose);
#endif /* CCAN_TOOLS_READ_CONFIG_HEADER_H */
......@@ -8,12 +8,9 @@
#include <stdlib.h>
#include <stdbool.h>
#ifndef CCAN_COMPILER
#define CCAN_COMPILER "cc"
#endif
#ifndef CCAN_CFLAGS
#define CCAN_CFLAGS "-g -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition -Werror"
#endif
/* These are the defaults. */
#define DEFAULT_CCAN_COMPILER "cc"
#define DEFAULT_CCAN_CFLAGS "-g"
#define IDENT_CHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
"abcdefghijklmnopqrstuvwxyz" \
......@@ -23,6 +20,9 @@
#define COVERAGE_CFLAGS "-fprofile-arcs -ftest-coverage"
/* Actual compiler and cflags (defaults to CCAN_COMPILER and CCAN_CFLAGS). */
extern const char *compiler, *cflags;
/* This compiles up the _info file into a temporary. */
char *compile_info(const void *ctx, const char *dir);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment