kconfig: improve handling EOF
PATCH 1/1 kconfig: improve handling EOF
The patch fixes two EOF-related issues in kconfig lexer:
1. End of file is not valid end of string token. Currently we happily accept something like
config FOO
bool "Bar
If there's EOF just after '"Bar' without newline.
2. Kconfig produces obscure error message if we miss newline at the end of file. Testcase:
% echo -n 'if FOO\nendif' >> drivers/Kconfig
% make allmodconfig
...
drivers/Kconfig:191: 'endif' in different file than 'if' drivers/Kconfig:191: location of the 'if' scripts/kconfig/Makefile:80: recipe for target 'allmodconfig' failed make[1]: *** [allmodconfig] Error 1
Makefile:558: recipe for target 'allmodconfig' failed
make: *** [allmodconfig] Error 2
We can fix it if forbid EOF form <PARAM> context.
--- kernel/Kconfig.preempt | 2 +- scripts/kconfig/zconf.l | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-)
kernel/Kconfig.preempt +1 -1
@@ -55,4 +55,4 @@ config PREEMPT endchoice config PREEMPT_COUNT - bool + bool
scripts/kconfig/zconf.l +6 -2
@@ -143,7 +143,9 @@ n [A-Za-z0-9_] \\\n current_file->lineno++; . <<EOF>> { - BEGIN(INITIAL); + printf("%s:%d: no newline at end of file\n", + zconf_curname(), zconf_lineno()); + exit(1); } }
@@ -179,7 +181,9 @@ n [A-Za-z0-9_] return T_EOL; } <<EOF>> { - BEGIN(INITIAL); + printf("%s:%d: unexpected end of file\n", + zconf_curname(), zconf_lineno()); + exit(1); } }
Signature · 1 line
2.1.3
Quoted 23 lines · Kirill A. Shutemov
The patch fixes two EOF-related issues in kconfig lexer:
1. End of file is not valid end of string token. Currently we happily accept something like
config FOO
bool "BarIf there's EOF just after '"Bar' without newline.
2.
Kconfigproduces obscure error message if we miss newline at the end of file. Testcase:% echo -n 'if FOO\nendif' >>
drivers/Kconfig
% make allmodconfig
...
drivers/Kconfig:191: 'endif' in different file than 'if'drivers/Kconfig:191: location of the 'if'scripts/kconfig/Makefile:80: recipe for target 'allmodconfig' failed make[1]: *** [allmodconfig] Error 1
Makefile:558: recipe for target 'allmodconfig' failed
make: *** [allmodconfig] Error 2
Quoted 1 line
We can fix it if forbid EOF form <PARAM> context.
s/form/in/?
Quoted 3 lines
Signed-off-by Kirill A. Shutemov <[email protected]>--- kernel/Kconfig.preempt | 2 +-
This is actually the only Kconfig file that doesn't end in a newline, isn't it?
Quoted 1 line
scripts/kconfig/zconf.l | 8 ++++++--
Could you please regenerate the _shipped file too?
kernel/Kconfig.preempt config PREEMPT · line 58
Quoted 13 lines
2 files changed, 7 insertions(+), 3 deletions(-)kernel/Kconfig.preempt +1
-1@@ -55,4 +55,4 @@ config PREEMPT endchoice config PREEMPT_COUNT - bool + bool
This hunk is not described in the commit explanation. Besides, you should do one thing per patch, so I think this should be a separate patch. Trivial as it is (and non urgent, since this apparently never broke the build.)
scripts/kconfig/zconf.l n [A-Za-z0-9_] · line 147
Quoted 11 lines
scripts/kconfig/zconf.l +2
-1@@ -143,7 +143,9 @@ n [A-Za-z0-9_] \\\n current_file->lineno++; . <<EOF>> { - BEGIN(INITIAL); + printf("%s:%d: no newline at end of file\n", + zconf_curname(), zconf_lineno());
Pet peeve of mine: warnings and errors should go to stderr.
scripts/kconfig/zconf.l n [A-Za-z0-9_] · line 148
Quoted 1 line
scripts/kconfig/zconf.l +1
-0+ exit(1);
Not all missing newline-before-EOF are currently fatal, see kernel/Kconfig.preempt above. So would this break the build even in cases like that? That would mean one ill considered commit would break the build. Perhaps we should warn and see whether we still can finish the parse instead.
scripts/kconfig/zconf.l n [A-Za-z0-9_] · line 185
Quoted 10 lines
scripts/kconfig/zconf.l +2
-1} }@@ -179,7 +181,9 @@ n [A-Za-z0-9_] return T_EOL; } <<EOF>> { - BEGIN(INITIAL); + printf("%s:%d: unexpected end of file\n", + zconf_curname(), zconf_lineno());
See above.
scripts/kconfig/zconf.l n [A-Za-z0-9_] · line 151
Quoted 4 lines
scripts/kconfig/zconf.l +1
-0+ exit(1); } }
See above.
Paul Bolle