Report file name and line number on all macro file errors and warnings
Report file name and/or line number on macro errors if %__file_name and/or %__file_lineno macros are defined, arrange them to be appropriately defined when loading macro files. Drop the former per-file failure counting as its no longer useful. Add a testcase.
This commit is contained in:
parent
3a87f969d3
commit
20797ad209
|
@ -305,7 +305,12 @@ static void mbErr(MacroBuf mb, int error, const char *fmt, ...)
|
|||
va_end(ap);
|
||||
|
||||
if (n >= -1) {
|
||||
rpmlog(error ? RPMLOG_ERR : RPMLOG_WARNING, "%s", emsg);
|
||||
/* XXX should have an non-locking version for this */
|
||||
char *pfx = rpmExpand("%{?__file_name:%{__file_name}: }",
|
||||
"%{?__file_lineno:line %{__file_lineno}: }",
|
||||
NULL);
|
||||
rpmlog(error ? RPMLOG_ERR : RPMLOG_WARNING, "%s%s", pfx, emsg);
|
||||
free(pfx);
|
||||
}
|
||||
|
||||
if (error)
|
||||
|
@ -1602,32 +1607,38 @@ static int loadMacroFile(rpmMacroContext mc, const char * fn)
|
|||
char *buf = xmalloc(blen);
|
||||
int rc = -1;
|
||||
int nfailed = 0;
|
||||
int lineno = 0;
|
||||
int nlines = 0;
|
||||
|
||||
if (fd == NULL)
|
||||
goto exit;
|
||||
|
||||
buf[0] = '\0';
|
||||
while (rdcl(buf, blen, fd) > 0) {
|
||||
char c, *n;
|
||||
pushMacro(mc, "__file_name", NULL, fn, RMIL_MACROFILES, ME_NONE);
|
||||
|
||||
buf[0] = '\0';
|
||||
while ((nlines = rdcl(buf, blen, fd)) > 0) {
|
||||
char c, *n;
|
||||
char lnobuf[16];
|
||||
|
||||
lineno += nlines;
|
||||
n = buf;
|
||||
SKIPBLANK(n, c);
|
||||
|
||||
if (c != '%')
|
||||
continue;
|
||||
n++; /* skip % */
|
||||
|
||||
snprintf(lnobuf, sizeof(lnobuf), "%d", lineno);
|
||||
pushMacro(mc, "__file_lineno", NULL, lnobuf, RMIL_MACROFILES, ME_NONE);
|
||||
if (defineMacro(mc, n, RMIL_MACROFILES))
|
||||
nfailed++;
|
||||
popMacro(mc, "__file_lineno");
|
||||
}
|
||||
fclose(fd);
|
||||
popMacro(mc, "__file_name");
|
||||
|
||||
rc = (nfailed > 0);
|
||||
|
||||
if (nfailed) {
|
||||
rpmlog(rc ? RPMLOG_ERR : RPMLOG_WARNING,
|
||||
_("file %s: %d invalid macro definitions\n"), fn, nfailed);
|
||||
}
|
||||
|
||||
exit:
|
||||
_free(buf);
|
||||
return rc;
|
||||
|
|
|
@ -490,3 +490,27 @@ ccc0
|
|||
ccc1
|
||||
])
|
||||
AT_CLEANUP
|
||||
|
||||
AT_SETUP([macro file errors])
|
||||
AT_KEYWORDS([macros])
|
||||
AT_CHECK([
|
||||
cat << EOF > macros.bad
|
||||
%_i foo
|
||||
|
||||
%multi \\
|
||||
line\\
|
||||
thing
|
||||
|
||||
%foo bar
|
||||
%bad-name 123
|
||||
EOF
|
||||
|
||||
run rpm --macros "macros.bad" --eval "%foo"
|
||||
],
|
||||
[0],
|
||||
[bar
|
||||
],
|
||||
[error: macros.bad: line 1: Macro %_i has illegal name (%define)
|
||||
warning: macros.bad: line 8: Macro %bad needs whitespace before body
|
||||
])
|
||||
AT_CLEANUP
|
||||
|
|
Loading…
Reference in New Issue