kconfig - introduce cond-source
Hi Roman.
In a couple of cases I have had the need to include a Kconfig file only if present.
The current 'source' directive works as one would expect. It bails out if the file is missing.
Examples where I have missed cond-source:
- klibc work
- external modules
Sam
Patch below implement a cond-source.
scripts/kconfig/lkc.h +1 -0
@@ -39,6 +39,7 @@ void zconf_starthelp(void);FILE *zconf_fopen (const char *name);void zconf_initscan (const char *name);void zconf_nextfile (const char *name); +void zconf_try_nextfile (const char *name);int zconf_lineno (void );char *zconf_curname (void );
scripts/kconfig/zconf.l +24 -6
@@ -91,6 +91,7 @@ n [A-Za-z0-9_] "mainmenu" BEGIN(PARAM); return T_MAINMENU; "menu" BEGIN(PARAM); return T_MENU; "endmenu" BEGIN(PARAM); return T_ENDMENU; + "cond-source" BEGIN(PARAM); return T_CONDSOURCE; "source" BEGIN(PARAM); return T_SOURCE; "choice" BEGIN(PARAM); return T_CHOICE; "endchoice" BEGIN(PARAM); return T_ENDCHOICE;
@@ -299,18 +300,14 @@ void zconf_initscan(const char *name) current_file->flags = FILE_BUSY; } -void zconf_nextfile(const char *name) +static void zconf_switch_buffer(const char *name, FILE *filp) { struct file *file = file_lookup(name); struct buffer *buf = malloc(sizeof(*buf)); memset(buf, 0, sizeof(*buf)); current_buf->state = YY_CURRENT_BUFFER; - yyin = zconf_fopen(name); - if (!yyin) { - printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name); - exit(1); - } + yyin = filp; yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); buf->parent = current_buf; current_buf = buf;
@@ -329,6 +326,27 @@ void zconf_nextfile(const char *name) current_file = file; } +void zconf_nextfile(const char *name) +{ + FILE *filp; + + filp = zconf_fopen(name); + if (!filp) { + printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name); + exit(1); + } + zconf_switch_buffer(name, filp); +} + +void zconf_try_nextfile(const char *name) +{ + FILE *filp; + + filp = zconf_fopen(name); + if (filp) + zconf_switch_buffer(name, filp); +} + static struct buffer *zconf_endfile(void) { struct buffer *parent;
scripts/kconfig/zconf.y +11 -3
@@ -44,6 +44,7 @@ static struct menu *current_menu, *curre %token T_MENU %token T_ENDMENU %token T_SOURCE +%token T_CONDSOURCE %token T_CHOICE %token T_ENDCHOICE %token T_COMMENT
@@ -378,15 +379,22 @@ menu_block: source: T_SOURCE prompt T_EOL { - $$ = $2; printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2); + zconf_nextfile($2); }; -source_stmt: source +condsource: T_CONDSOURCE prompt T_EOL { - zconf_nextfile($1); + printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2); + zconf_try_nextfile($2); }; +source_stmt: + source + | condsource + /* empty */ +; + /* comment entry */ comment: T_COMMENT prompt T_EOL
Hi,
Quoted 4 lines · Sam Ravnborg
In a couple of cases I have had the need to include a
Kconfigfile only if present.
The current 'source' directive works as one would expect. It bails out if the file is missing.
I don't really like it, it's an open invitation to abuse. I'd rather like to see the user first, which might need it.
bye, Roman
Quoted 11 lines · Roman Zippel
Hi,
Quoted 4 lines · Sam Ravnborg
In a couple of cases I have had the need to include a
Kconfigfile only if present.
The current 'source' directive works as one would expect. It bails out if the file is missing.I don't really like it, it's an open invitation to abuse. I'd rather like to see the user first, which might need it.
Understood.
I will save this until I have a very good example where I need it.
Sam