mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2] scripts: imx: report file where error occurred
Date: Thu, 28 Nov 2019 17:37:08 +0100	[thread overview]
Message-ID: <20191128163707.6055-1-a.fatoum@pengutronix.de> (raw)

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>
---
 scripts/imx/imx.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/scripts/imx/imx.c b/scripts/imx/imx.c
index b3e8d62ba8b6..b8d939a43177 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;
 }
-- 
2.24.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2019-11-28 16:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-28 16:37 Ahmad Fatoum [this message]
2019-12-02  8:59 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191128163707.6055-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox