Skip to content

Commit bc5c508

Browse files
committed
Merge branch 'feature/support_rsource_mconf' into 'master'
Support rsource in old kconfig See merge request espressif/esp-idf!9982
2 parents 8a9dc46 + f77eeb3 commit bc5c508

File tree

16 files changed

+83
-13
lines changed

16 files changed

+83
-13
lines changed

tools/kconfig/kconfig-language.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ end a menu entry:
259259
- menu/endmenu
260260
- if/endif
261261
- source
262+
- rsource
262263
The first five also start the definition of a menu entry.
263264

264265
config:
@@ -333,6 +334,14 @@ source:
333334

334335
This reads the specified configuration file. This file is always parsed.
335336

337+
rsource:
338+
339+
"rsource" <prompt>
340+
341+
This reads the specified configuration file relative to the current file. This file is always parsed.
342+
343+
344+
336345
mainmenu:
337346

338347
"mainmenu" <prompt>

tools/kconfig/lkc.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ void zconfdump(FILE *out);
7272
void zconf_starthelp(void);
7373
FILE *zconf_fopen(const char *name);
7474
void zconf_initscan(const char *name);
75-
void zconf_nextfile(const char *name);
76-
void zconf_nextfiles(const char *name);
75+
void zconf_nextfile(const char *name, bool relative);
76+
void zconf_nextfiles(const char *name, bool relative);
7777
int zconf_lineno(void);
7878
const char *zconf_curname(void);
79+
const char *zconf_curdir(void);
7980

8081
/* confdata.c */
8182
const char *conf_get_configname(void);
@@ -112,7 +113,7 @@ void menu_finalize(struct menu *parent);
112113
void menu_set_type(int type);
113114

114115
/* util.c */
115-
struct file *file_lookup(const char *name);
116+
struct file *file_lookup(const char *name, bool relative);
116117
int file_write_dep(const char *name);
117118
void *xmalloc(size_t size);
118119
void *xcalloc(size_t nmemb, size_t size);

tools/kconfig/util.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,28 @@
88
#include <stdarg.h>
99
#include <stdlib.h>
1010
#include <string.h>
11+
#include <limits.h>
12+
#include <libgen.h>
1113
#include "lkc.h"
1214

1315
/* file already present in list? If not add it */
14-
struct file *file_lookup(const char *name)
16+
struct file *file_lookup(const char *name, bool relative)
1517
{
1618
struct file *file;
17-
const char *file_name = sym_expand_string_value(name);
19+
char fullname[PATH_MAX + 1] = { 0 };
20+
21+
if (relative) {
22+
char *last_bslash = strrchr(zconf_curname(), '\\');
23+
char *last_fslash = strrchr(zconf_curname(), '/');
24+
char *last_slash = last_bslash ? last_bslash : last_fslash;
25+
strncpy(fullname, zconf_curname(), last_slash - zconf_curname());
26+
strcat(fullname, last_bslash ? "\\" : "/");
27+
strcat(fullname, name);
28+
} else {
29+
sprintf(fullname, "%s", name);
30+
}
31+
32+
const char *file_name = sym_expand_string_value(fullname);
1833

1934
for (file = file_list; file; file = file->next) {
2035
if (!strcmp(name, file->name)) {

tools/kconfig/zconf.gperf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mainmenu, T_MAINMENU, TF_COMMAND
1414
menu, T_MENU, TF_COMMAND
1515
endmenu, T_ENDMENU, TF_COMMAND
1616
source, T_SOURCE, TF_COMMAND
17+
rsource, T_RSOURCE, TF_COMMAND
1718
choice, T_CHOICE, TF_COMMAND
1819
endchoice, T_ENDCHOICE, TF_COMMAND
1920
comment, T_COMMENT, TF_COMMAND

tools/kconfig/zconf.l

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ FILE *zconf_fopen(const char *name)
281281
FILE *f;
282282

283283
f = fopen(name, "r");
284+
284285
if (!f && name != NULL && name[0] != '/') {
285286
env = getenv(SRCTREE);
286287
if (env) {
@@ -302,14 +303,14 @@ void zconf_initscan(const char *name)
302303
current_buf = xmalloc(sizeof(*current_buf));
303304
memset(current_buf, 0, sizeof(*current_buf));
304305

305-
current_file = file_lookup(name);
306+
current_file = file_lookup(name, false);
306307
current_file->lineno = 1;
307308
}
308309

309-
void zconf_nextfile(const char *name)
310+
void zconf_nextfile(const char *name, bool relative)
310311
{
311312
struct file *iter;
312-
struct file *file = file_lookup(name);
313+
struct file *file = file_lookup(name, relative);
313314
struct buffer *buf = xmalloc(sizeof(*buf));
314315
memset(buf, 0, sizeof(*buf));
315316

@@ -348,7 +349,7 @@ void zconf_nextfile(const char *name)
348349
current_file = file;
349350
}
350351

351-
void zconf_nextfiles(const char *expression)
352+
void zconf_nextfiles(const char *expression, bool relative)
352353
{
353354
/* Expand environment variables in 'expression' */
354355
char* str = expand_environment(expression, zconf_curname(), zconf_lineno());
@@ -364,13 +365,13 @@ void zconf_nextfiles(const char *expression)
364365
if(*pos == ' ') {
365366
*pos = '\0'; // split buffer into multiple c-strings
366367
if (strlen(pos + 1)) {
367-
zconf_nextfile(pos + 1);
368+
zconf_nextfile(pos + 1, relative);
368369
}
369370
}
370371
}
371372

372373
if (strlen(str)) { // re-check as first character may have been a space
373-
zconf_nextfile(str);
374+
zconf_nextfile(str, relative);
374375
}
375376
}
376377

@@ -401,4 +402,4 @@ int zconf_lineno(void)
401402
const char *zconf_curname(void)
402403
{
403404
return current_pos.file ? current_pos.file->name : "<none>";
404-
}
405+
}

tools/kconfig/zconf.y

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static struct menu *current_menu, *current_entry;
4848
%token <id>T_MENU
4949
%token <id>T_ENDMENU
5050
%token <id>T_SOURCE
51+
%token <id>T_RSOURCE
5152
%token <id>T_CHOICE
5253
%token <id>T_ENDCHOICE
5354
%token <id>T_COMMENT
@@ -135,6 +136,7 @@ common_stmt:
135136
| config_stmt
136137
| menuconfig_stmt
137138
| source_stmt
139+
| rsource_stmt
138140
;
139141

140142
option_error:
@@ -395,7 +397,13 @@ menu_block:
395397
source_stmt: T_SOURCE prompt T_EOL
396398
{
397399
printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
398-
zconf_nextfiles($2);
400+
zconf_nextfiles($2, false);
401+
};
402+
403+
rsource_stmt: T_RSOURCE prompt T_EOL
404+
{
405+
printd(DEBUG_PARSE, "%s:%d:rsource %s\n", zconf_curname(), zconf_lineno(), $2);
406+
zconf_nextfiles($2, true);
399407
};
400408

401409
/* comment entry */
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# The following lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.5)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
project(rsource_test)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
menu "RSOURCE test"
2+
config RSOURCE_EXTRA_CONFIG
3+
bool "rsource extra config"
4+
default y
5+
endmenu
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
3+
# project subdirectory.
4+
#
5+
6+
PROJECT_NAME := rsource_test
7+
8+
include $(IDF_PATH)/make/project.mk
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This project tests that use of rsource in Kconfig files. The main component will source a Kconfig file depending on the target (IDF_TARGET), which in turn will source a Kconfig file in the project directory -- all specified via relative paths.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
idf_component_register(SRCS "test_main.c"
2+
INCLUDE_DIRS ".")
3+
4+
if(NOT CONFIG_RSOURCE_EXTRA_CONFIG)
5+
message(FATAL_ERROR "RSOURCE config not included")
6+
endif()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rsource "port/$IDF_TARGET/Kconfig"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ifndef CONFIG_RSOURCE_EXTRA_CONFIG
2+
$(error RSOURCE config not included)
3+
endif
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rsource "../../../Kconfig.extra"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rsource "../../../Kconfig.extra"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
void app_main(void)
2+
{
3+
}

0 commit comments

Comments
 (0)