diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2019-11-28 17:37:08 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2019-12-02 09:58:38 +0100 |
commit | 9344bf77582c21c7ee086bccd4c00971b95282b8 (patch) | |
tree | 56bd8f8e29c8b77b2c6457637bfd08ab902904da /scripts | |
parent | 51f1e9c8a8d904fd3a103d9f98c8c624e60a486d (diff) | |
download | barebox-9344bf77582c21c7ee086bccd4c00971b95282b8.tar.gz barebox-9344bf77582c21c7ee086bccd4c00971b95282b8.tar.xz |
scripts: imx: report file where error occurred
Especially when using #include directives in imxcfg files, error
messages can be hard to follow because line numbers differ between
preprocessor and source files. Teach the imx image generation tool about
preprocessing line number / file name directive, so it can give more
useful error messages. Instead of:
error in line 11: Invalid argument
It now says:
$barebox/arch/arm/boards/$som/flash-header-$board.imxcfg:5: Invalid argument
No change in compiled barebox binaries.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/imx/imx.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/scripts/imx/imx.c b/scripts/imx/imx.c index b3e8d62ba8..b8d939a431 100644 --- a/scripts/imx/imx.c +++ b/scripts/imx/imx.c @@ -673,13 +673,16 @@ static char *readcmd(struct config_data *data, FILE *f) } } -int parse_config(struct config_data *data, const char *filename) +int parse_config(struct config_data *data, const char *_filename) { FILE *f; int lineno = 0; char *line = NULL, *tmp; char *argv[MAXARGS]; int nargs, i, ret = 0; + char *filename; + + filename = strdup(_filename); f = fopen(filename, "r"); if (!f) { @@ -695,8 +698,17 @@ int parse_config(struct config_data *data, const char *filename) lineno++; tmp = strchr(line, '#'); - if (tmp) - *tmp = 0; + if (tmp) { + char *endptr; + long linenum = strtol(tmp + 1, &endptr, 10); + if (strncmp(endptr, " \"", 2) == 0 && endptr[2]) { + free(filename); + lineno = linenum - 1; + filename = strdup(endptr + 2); + filename[strlen(filename) - 1] = '\0'; + } + *tmp = '\0'; + } nargs = parse_line(line, argv); if (!nargs) @@ -708,8 +720,8 @@ int parse_config(struct config_data *data, const char *filename) if (!strcmp(cmds[i].name, argv[0])) { ret = cmds[i].parse(data, nargs, argv); if (ret) { - fprintf(stderr, "error in line %d: %s\n", - lineno, strerror(-ret)); + fprintf(stderr, "%s:%d: %s\n", + filename, lineno, strerror(-ret)); goto cleanup; } break; @@ -724,5 +736,6 @@ int parse_config(struct config_data *data, const char *filename) cleanup: fclose(f); + free(filename); return ret; } |