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);
|
va_end(ap);
|
||||||
|
|
||||||
if (n >= -1) {
|
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)
|
if (error)
|
||||||
|
@ -1602,32 +1607,38 @@ static int loadMacroFile(rpmMacroContext mc, const char * fn)
|
||||||
char *buf = xmalloc(blen);
|
char *buf = xmalloc(blen);
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
int nfailed = 0;
|
int nfailed = 0;
|
||||||
|
int lineno = 0;
|
||||||
|
int nlines = 0;
|
||||||
|
|
||||||
if (fd == NULL)
|
if (fd == NULL)
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
buf[0] = '\0';
|
pushMacro(mc, "__file_name", NULL, fn, RMIL_MACROFILES, ME_NONE);
|
||||||
while (rdcl(buf, blen, fd) > 0) {
|
|
||||||
char c, *n;
|
|
||||||
|
|
||||||
|
buf[0] = '\0';
|
||||||
|
while ((nlines = rdcl(buf, blen, fd)) > 0) {
|
||||||
|
char c, *n;
|
||||||
|
char lnobuf[16];
|
||||||
|
|
||||||
|
lineno += nlines;
|
||||||
n = buf;
|
n = buf;
|
||||||
SKIPBLANK(n, c);
|
SKIPBLANK(n, c);
|
||||||
|
|
||||||
if (c != '%')
|
if (c != '%')
|
||||||
continue;
|
continue;
|
||||||
n++; /* skip % */
|
n++; /* skip % */
|
||||||
|
|
||||||
|
snprintf(lnobuf, sizeof(lnobuf), "%d", lineno);
|
||||||
|
pushMacro(mc, "__file_lineno", NULL, lnobuf, RMIL_MACROFILES, ME_NONE);
|
||||||
if (defineMacro(mc, n, RMIL_MACROFILES))
|
if (defineMacro(mc, n, RMIL_MACROFILES))
|
||||||
nfailed++;
|
nfailed++;
|
||||||
|
popMacro(mc, "__file_lineno");
|
||||||
}
|
}
|
||||||
fclose(fd);
|
fclose(fd);
|
||||||
|
popMacro(mc, "__file_name");
|
||||||
|
|
||||||
rc = (nfailed > 0);
|
rc = (nfailed > 0);
|
||||||
|
|
||||||
if (nfailed) {
|
|
||||||
rpmlog(rc ? RPMLOG_ERR : RPMLOG_WARNING,
|
|
||||||
_("file %s: %d invalid macro definitions\n"), fn, nfailed);
|
|
||||||
}
|
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
_free(buf);
|
_free(buf);
|
||||||
return rc;
|
return rc;
|
||||||
|
|
|
@ -490,3 +490,27 @@ ccc0
|
||||||
ccc1
|
ccc1
|
||||||
])
|
])
|
||||||
AT_CLEANUP
|
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