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