From 86d3b962d235c5a43ca34e509c57e25c1fb345df Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Fri, 7 Aug 2020 11:51:35 +0800 Subject: [PATCH 1/2] tools: support rsource in MSYS config --- tools/kconfig/kconfig-language.txt | 9 +++++++++ tools/kconfig/lkc.h | 7 ++++--- tools/kconfig/util.c | 19 +++++++++++++++++-- tools/kconfig/zconf.gperf | 1 + tools/kconfig/zconf.l | 15 ++++++++------- tools/kconfig/zconf.y | 10 +++++++++- 6 files changed, 48 insertions(+), 13 deletions(-) diff --git a/tools/kconfig/kconfig-language.txt b/tools/kconfig/kconfig-language.txt index c52856da0c..8abccb47ab 100644 --- a/tools/kconfig/kconfig-language.txt +++ b/tools/kconfig/kconfig-language.txt @@ -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" + +This reads the specified configuration file relative to the current file. This file is always parsed. + + + mainmenu: "mainmenu" diff --git a/tools/kconfig/lkc.h b/tools/kconfig/lkc.h index b1f1cc34a7..7372d3e48e 100644 --- a/tools/kconfig/lkc.h +++ b/tools/kconfig/lkc.h @@ -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); diff --git a/tools/kconfig/util.c b/tools/kconfig/util.c index 0e76042473..cb3439ece3 100644 --- a/tools/kconfig/util.c +++ b/tools/kconfig/util.c @@ -8,13 +8,28 @@ #include #include #include +#include +#include #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)) { diff --git a/tools/kconfig/zconf.gperf b/tools/kconfig/zconf.gperf index d1ede16a80..d48ae5e418 100644 --- a/tools/kconfig/zconf.gperf +++ b/tools/kconfig/zconf.gperf @@ -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 diff --git a/tools/kconfig/zconf.l b/tools/kconfig/zconf.l index b8cc8939a5..6ee27103bf 100644 --- a/tools/kconfig/zconf.l +++ b/tools/kconfig/zconf.l @@ -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 : ""; -} +} \ No newline at end of file diff --git a/tools/kconfig/zconf.y b/tools/kconfig/zconf.y index 1074d9f063..a5699c92cc 100644 --- a/tools/kconfig/zconf.y +++ b/tools/kconfig/zconf.y @@ -48,6 +48,7 @@ static struct menu *current_menu, *current_entry; %token T_MENU %token T_ENDMENU %token T_SOURCE +%token T_RSOURCE %token T_CHOICE %token T_ENDCHOICE %token 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 */ From f77eeb34d5107401ba84fd2be2f5c1b2eb708234 Mon Sep 17 00:00:00 2001 From: Renz Bagaporo Date: Fri, 7 Aug 2020 14:52:22 +0800 Subject: [PATCH 2/2] ci: add rsource test app --- tools/test_apps/build_system/rsource_test/CMakeLists.txt | 6 ++++++ tools/test_apps/build_system/rsource_test/Kconfig.extra | 5 +++++ tools/test_apps/build_system/rsource_test/Makefile | 8 ++++++++ tools/test_apps/build_system/rsource_test/README.txt | 1 + .../build_system/rsource_test/main/CMakeLists.txt | 6 ++++++ tools/test_apps/build_system/rsource_test/main/Kconfig | 1 + .../test_apps/build_system/rsource_test/main/component.mk | 3 +++ .../build_system/rsource_test/main/port/esp32/Kconfig | 1 + .../build_system/rsource_test/main/port/esp32s2/Kconfig | 1 + .../test_apps/build_system/rsource_test/main/test_main.c | 3 +++ 10 files changed, 35 insertions(+) create mode 100644 tools/test_apps/build_system/rsource_test/CMakeLists.txt create mode 100644 tools/test_apps/build_system/rsource_test/Kconfig.extra create mode 100644 tools/test_apps/build_system/rsource_test/Makefile create mode 100644 tools/test_apps/build_system/rsource_test/README.txt create mode 100644 tools/test_apps/build_system/rsource_test/main/CMakeLists.txt create mode 100644 tools/test_apps/build_system/rsource_test/main/Kconfig create mode 100644 tools/test_apps/build_system/rsource_test/main/component.mk create mode 100644 tools/test_apps/build_system/rsource_test/main/port/esp32/Kconfig create mode 100644 tools/test_apps/build_system/rsource_test/main/port/esp32s2/Kconfig create mode 100644 tools/test_apps/build_system/rsource_test/main/test_main.c diff --git a/tools/test_apps/build_system/rsource_test/CMakeLists.txt b/tools/test_apps/build_system/rsource_test/CMakeLists.txt new file mode 100644 index 0000000000..fb4e3dc6c9 --- /dev/null +++ b/tools/test_apps/build_system/rsource_test/CMakeLists.txt @@ -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) diff --git a/tools/test_apps/build_system/rsource_test/Kconfig.extra b/tools/test_apps/build_system/rsource_test/Kconfig.extra new file mode 100644 index 0000000000..39898bb615 --- /dev/null +++ b/tools/test_apps/build_system/rsource_test/Kconfig.extra @@ -0,0 +1,5 @@ +menu "RSOURCE test" + config RSOURCE_EXTRA_CONFIG + bool "rsource extra config" + default y +endmenu diff --git a/tools/test_apps/build_system/rsource_test/Makefile b/tools/test_apps/build_system/rsource_test/Makefile new file mode 100644 index 0000000000..ade5499de0 --- /dev/null +++ b/tools/test_apps/build_system/rsource_test/Makefile @@ -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 diff --git a/tools/test_apps/build_system/rsource_test/README.txt b/tools/test_apps/build_system/rsource_test/README.txt new file mode 100644 index 0000000000..4f46d42557 --- /dev/null +++ b/tools/test_apps/build_system/rsource_test/README.txt @@ -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. diff --git a/tools/test_apps/build_system/rsource_test/main/CMakeLists.txt b/tools/test_apps/build_system/rsource_test/main/CMakeLists.txt new file mode 100644 index 0000000000..60667b806e --- /dev/null +++ b/tools/test_apps/build_system/rsource_test/main/CMakeLists.txt @@ -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() diff --git a/tools/test_apps/build_system/rsource_test/main/Kconfig b/tools/test_apps/build_system/rsource_test/main/Kconfig new file mode 100644 index 0000000000..f559b62ce6 --- /dev/null +++ b/tools/test_apps/build_system/rsource_test/main/Kconfig @@ -0,0 +1 @@ +rsource "port/$IDF_TARGET/Kconfig" diff --git a/tools/test_apps/build_system/rsource_test/main/component.mk b/tools/test_apps/build_system/rsource_test/main/component.mk new file mode 100644 index 0000000000..08105c4f2c --- /dev/null +++ b/tools/test_apps/build_system/rsource_test/main/component.mk @@ -0,0 +1,3 @@ +ifndef CONFIG_RSOURCE_EXTRA_CONFIG + $(error RSOURCE config not included) +endif diff --git a/tools/test_apps/build_system/rsource_test/main/port/esp32/Kconfig b/tools/test_apps/build_system/rsource_test/main/port/esp32/Kconfig new file mode 100644 index 0000000000..c18c28fd4d --- /dev/null +++ b/tools/test_apps/build_system/rsource_test/main/port/esp32/Kconfig @@ -0,0 +1 @@ +rsource "../../../Kconfig.extra" diff --git a/tools/test_apps/build_system/rsource_test/main/port/esp32s2/Kconfig b/tools/test_apps/build_system/rsource_test/main/port/esp32s2/Kconfig new file mode 100644 index 0000000000..c18c28fd4d --- /dev/null +++ b/tools/test_apps/build_system/rsource_test/main/port/esp32s2/Kconfig @@ -0,0 +1 @@ +rsource "../../../Kconfig.extra" diff --git a/tools/test_apps/build_system/rsource_test/main/test_main.c b/tools/test_apps/build_system/rsource_test/main/test_main.c new file mode 100644 index 0000000000..cb05851571 --- /dev/null +++ b/tools/test_apps/build_system/rsource_test/main/test_main.c @@ -0,0 +1,3 @@ +void app_main(void) +{ +}