Merge branch 'feature/support_rsource_mconf' into 'master'

Support rsource in old kconfig

See merge request espressif/esp-idf!9982
This commit is contained in:
Angus Gratton 2020-08-24 15:53:22 +08:00
commit bc5c508211
16 changed files with 83 additions and 13 deletions

View File

@ -259,6 +259,7 @@ end a menu entry:
- menu/endmenu
- if/endif
- source
- rsource
The first five also start the definition of a menu entry.
config:
@ -333,6 +334,14 @@ source:
This reads the specified configuration file. This file is always parsed.
rsource:
"rsource" <prompt>
This reads the specified configuration file relative to the current file. This file is always parsed.
mainmenu:
"mainmenu" <prompt>

View File

@ -72,10 +72,11 @@ void zconfdump(FILE *out);
void zconf_starthelp(void);
FILE *zconf_fopen(const char *name);
void zconf_initscan(const char *name);
void zconf_nextfile(const char *name);
void zconf_nextfiles(const char *name);
void zconf_nextfile(const char *name, bool relative);
void zconf_nextfiles(const char *name, bool relative);
int zconf_lineno(void);
const char *zconf_curname(void);
const char *zconf_curdir(void);
/* confdata.c */
const char *conf_get_configname(void);
@ -112,7 +113,7 @@ void menu_finalize(struct menu *parent);
void menu_set_type(int type);
/* util.c */
struct file *file_lookup(const char *name);
struct file *file_lookup(const char *name, bool relative);
int file_write_dep(const char *name);
void *xmalloc(size_t size);
void *xcalloc(size_t nmemb, size_t size);

View File

@ -8,13 +8,28 @@
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <libgen.h>
#include "lkc.h"
/* file already present in list? If not add it */
struct file *file_lookup(const char *name)
struct file *file_lookup(const char *name, bool relative)
{
struct file *file;
const char *file_name = sym_expand_string_value(name);
char fullname[PATH_MAX + 1] = { 0 };
if (relative) {
char *last_bslash = strrchr(zconf_curname(), '\\');
char *last_fslash = strrchr(zconf_curname(), '/');
char *last_slash = last_bslash ? last_bslash : last_fslash;
strncpy(fullname, zconf_curname(), last_slash - zconf_curname());
strcat(fullname, last_bslash ? "\\" : "/");
strcat(fullname, name);
} else {
sprintf(fullname, "%s", name);
}
const char *file_name = sym_expand_string_value(fullname);
for (file = file_list; file; file = file->next) {
if (!strcmp(name, file->name)) {

View File

@ -14,6 +14,7 @@ mainmenu, T_MAINMENU, TF_COMMAND
menu, T_MENU, TF_COMMAND
endmenu, T_ENDMENU, TF_COMMAND
source, T_SOURCE, TF_COMMAND
rsource, T_RSOURCE, TF_COMMAND
choice, T_CHOICE, TF_COMMAND
endchoice, T_ENDCHOICE, TF_COMMAND
comment, T_COMMENT, TF_COMMAND

View File

@ -281,6 +281,7 @@ FILE *zconf_fopen(const char *name)
FILE *f;
f = fopen(name, "r");
if (!f && name != NULL && name[0] != '/') {
env = getenv(SRCTREE);
if (env) {
@ -302,14 +303,14 @@ void zconf_initscan(const char *name)
current_buf = xmalloc(sizeof(*current_buf));
memset(current_buf, 0, sizeof(*current_buf));
current_file = file_lookup(name);
current_file = file_lookup(name, false);
current_file->lineno = 1;
}
void zconf_nextfile(const char *name)
void zconf_nextfile(const char *name, bool relative)
{
struct file *iter;
struct file *file = file_lookup(name);
struct file *file = file_lookup(name, relative);
struct buffer *buf = xmalloc(sizeof(*buf));
memset(buf, 0, sizeof(*buf));
@ -348,7 +349,7 @@ void zconf_nextfile(const char *name)
current_file = file;
}
void zconf_nextfiles(const char *expression)
void zconf_nextfiles(const char *expression, bool relative)
{
/* Expand environment variables in 'expression' */
char* str = expand_environment(expression, zconf_curname(), zconf_lineno());
@ -364,13 +365,13 @@ void zconf_nextfiles(const char *expression)
if(*pos == ' ') {
*pos = '\0'; // split buffer into multiple c-strings
if (strlen(pos + 1)) {
zconf_nextfile(pos + 1);
zconf_nextfile(pos + 1, relative);
}
}
}
if (strlen(str)) { // re-check as first character may have been a space
zconf_nextfile(str);
zconf_nextfile(str, relative);
}
}
@ -401,4 +402,4 @@ int zconf_lineno(void)
const char *zconf_curname(void)
{
return current_pos.file ? current_pos.file->name : "<none>";
}
}

View File

@ -48,6 +48,7 @@ static struct menu *current_menu, *current_entry;
%token <id>T_MENU
%token <id>T_ENDMENU
%token <id>T_SOURCE
%token <id>T_RSOURCE
%token <id>T_CHOICE
%token <id>T_ENDCHOICE
%token <id>T_COMMENT
@ -135,6 +136,7 @@ common_stmt:
| config_stmt
| menuconfig_stmt
| source_stmt
| rsource_stmt
;
option_error:
@ -395,7 +397,13 @@ menu_block:
source_stmt: T_SOURCE prompt T_EOL
{
printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
zconf_nextfiles($2);
zconf_nextfiles($2, false);
};
rsource_stmt: T_RSOURCE prompt T_EOL
{
printd(DEBUG_PARSE, "%s:%d:rsource %s\n", zconf_curname(), zconf_lineno(), $2);
zconf_nextfiles($2, true);
};
/* comment entry */

View File

@ -0,0 +1,6 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(rsource_test)

View File

@ -0,0 +1,5 @@
menu "RSOURCE test"
config RSOURCE_EXTRA_CONFIG
bool "rsource extra config"
default y
endmenu

View File

@ -0,0 +1,8 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#
PROJECT_NAME := rsource_test
include $(IDF_PATH)/make/project.mk

View File

@ -0,0 +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.

View File

@ -0,0 +1,6 @@
idf_component_register(SRCS "test_main.c"
INCLUDE_DIRS ".")
if(NOT CONFIG_RSOURCE_EXTRA_CONFIG)
message(FATAL_ERROR "RSOURCE config not included")
endif()

View File

@ -0,0 +1 @@
rsource "port/$IDF_TARGET/Kconfig"

View File

@ -0,0 +1,3 @@
ifndef CONFIG_RSOURCE_EXTRA_CONFIG
$(error RSOURCE config not included)
endif

View File

@ -0,0 +1 @@
rsource "../../../Kconfig.extra"

View File

@ -0,0 +1 @@
rsource "../../../Kconfig.extra"

View File

@ -0,0 +1,3 @@
void app_main(void)
{
}