diff --git a/util/kconfig/conf.c b/util/kconfig/conf.c index e68da2d44f0..fd330111e88 100644 --- a/util/kconfig/conf.c +++ b/util/kconfig/conf.c @@ -553,7 +553,7 @@ static int conf_choice(struct menu *menu) print_help(child); continue; } - sym_set_choice_value(sym, child->sym); + sym_set_tristate_value(child->sym, yes); for (child = child->list; child; child = child->next) { indent += 2; conf(child); diff --git a/util/kconfig/confdata.c b/util/kconfig/confdata.c index 1300ab674fa..726a96e182f 100644 --- a/util/kconfig/confdata.c +++ b/util/kconfig/confdata.c @@ -230,6 +230,13 @@ static const char *conf_get_autoheader_name(void) return name ? name : "include/generated/autoconf.h"; } +static const char *conf_get_rustccfg_name(void) +{ + char *name = getenv("KCONFIG_RUSTCCFG"); + + return name ? name : "include/generated/rustc_cfg"; +} + static const char *conf_get_autobase_name(void) { char *name = getenv("KCONFIG_SPLITCONFIG"); @@ -632,6 +639,9 @@ static const struct comment_style comment_style_c = { static void conf_write_heading(FILE *fp, const struct comment_style *cs) { + if (!cs) + return; + fprintf(fp, "%s\n", cs->prefix); fprintf(fp, "%s Automatically generated file; DO NOT EDIT.\n", @@ -787,6 +797,65 @@ static void print_symbol_for_c(FILE *fp, struct symbol *sym) free(escaped); } +static void print_symbol_for_rustccfg(FILE *fp, struct symbol *sym) +{ + const char *val; + const char *val_prefix = ""; + char *val_prefixed = NULL; + size_t val_prefixed_len; + char *escaped = NULL; + + if (sym->type == S_UNKNOWN) + return; + + val = sym_get_string_value(sym); + + switch (sym->type) { + case S_BOOLEAN: + case S_TRISTATE: + /* + * We do not care about disabled ones, i.e. no need for + * what otherwise are "comments" in other printers. + */ + if (*val == 'n') + return; + + /* + * To have similar functionality to the C macro `IS_ENABLED()` + * we provide an empty `--cfg CONFIG_X` here in both `y` + * and `m` cases. + * + * Then, the common `fprintf()` below will also give us + * a `--cfg CONFIG_X="y"` or `--cfg CONFIG_X="m"`, which can + * be used as the equivalent of `IS_BUILTIN()`/`IS_MODULE()`. + */ + fprintf(fp, "--cfg=%s%s\n", CONFIG_, sym->name); + break; + case S_HEX: + if (val[0] != '0' || (val[1] != 'x' && val[1] != 'X')) + val_prefix = "0x"; + break; + default: + break; + } + + if (strlen(val_prefix) > 0) { + val_prefixed_len = strlen(val) + strlen(val_prefix) + 1; + val_prefixed = xmalloc(val_prefixed_len); + snprintf(val_prefixed, val_prefixed_len, "%s%s", val_prefix, val); + val = val_prefixed; + } + + /* All values get escaped: the `--cfg` option only takes strings */ + escaped = escape_string_value(val); + val = escaped; + + fprintf(fp, "--cfg=%s%s=%s\n", CONFIG_, sym->name, val); + + free(escaped); + free(val_prefixed); +} + /* * Write out a minimal config. * All values that has default values are skipped as this is redundant. @@ -1175,6 +1244,12 @@ int conf_write_autoconf(int overwrite) if (ret) return ret; + ret = __conf_write_autoconf(conf_get_rustccfg_name(), + print_symbol_for_rustccfg, + NULL); + if (ret) + return ret; + /* * Create include/config/auto.conf. This must be the last step because * Kbuild has a dependency on auto.conf and this marks the successful diff --git a/util/kconfig/lkc.h b/util/kconfig/lkc.h index 68dc8475b8f..559e04af857 100644 --- a/util/kconfig/lkc.h +++ b/util/kconfig/lkc.h @@ -127,11 +127,6 @@ static inline struct symbol *sym_get_choice_value(struct symbol *sym) return (struct symbol *)sym->curr.val; } -static inline bool sym_set_choice_value(struct symbol *ch, struct symbol *chval) -{ - return sym_set_tristate_value(chval, yes); -} - static inline bool sym_is_choice(struct symbol *sym) { return sym->flags & SYMBOL_CHOICE ? true : false; diff --git a/util/kconfig/menu.c b/util/kconfig/menu.c index 62b6313f51c..109325f31be 100644 --- a/util/kconfig/menu.c +++ b/util/kconfig/menu.c @@ -722,8 +722,8 @@ static void get_prompt_str(struct gstr *r, struct property *prop, if (!expr_eq(prop->menu->dep, prop->visible.expr)) get_dep_str(r, prop->visible.expr, " Visible if: "); - menu = prop->menu->parent; - for (i = 0; menu && i < 8; menu = menu->parent) { + menu = prop->menu; + for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) { bool accessible = menu_is_visible(menu); submenu[i++] = menu; @@ -733,16 +733,7 @@ static void get_prompt_str(struct gstr *r, struct property *prop, if (head && location) { jump = xmalloc(sizeof(struct jump_key)); - if (menu_is_visible(prop->menu)) { - /* - * There is not enough room to put the hint at the - * beginning of the "Prompt" line. Put the hint on the - * last "Location" line even when it would belong on - * the former. - */ - jump->target = prop->menu; - } else - jump->target = location; + jump->target = location; if (list_empty(head)) jump->index = 0; @@ -758,13 +749,7 @@ static void get_prompt_str(struct gstr *r, struct property *prop, menu = submenu[i]; if (jump && menu == location) jump->offset = strlen(r->s); - - if (menu == &rootmenu) - /* The real rootmenu prompt is ugly */ - str_printf(r, "%*cMain menu", j, ' '); - else - str_printf(r, "%*c-> %s", j, ' ', menu_get_prompt(menu)); - + str_printf(r, "%*c-> %s", j, ' ', menu_get_prompt(menu)); if (menu->sym) { str_printf(r, " (%s [=%s])", menu->sym->name ? menu->sym->name : "", diff --git a/util/kconfig/patches/0001-Kconfig-Add-KCONFIG_STRICT-mode.patch b/util/kconfig/patches/0001-Kconfig-Add-KCONFIG_STRICT-mode.patch index e87aaf5eaff..9e50eb39a12 100644 --- a/util/kconfig/patches/0001-Kconfig-Add-KCONFIG_STRICT-mode.patch +++ b/util/kconfig/patches/0001-Kconfig-Add-KCONFIG_STRICT-mode.patch @@ -19,7 +19,7 @@ Index: kconfig/confdata.c =================================================================== --- kconfig.orig/confdata.c +++ kconfig/confdata.c -@@ -430,6 +430,7 @@ load: +@@ -437,6 +437,7 @@ load: if (def == S_DEF_USER) { sym = sym_find(line + 2 + strlen(CONFIG_)); if (!sym) { @@ -27,7 +27,7 @@ Index: kconfig/confdata.c conf_set_changed(true); continue; } -@@ -512,6 +513,13 @@ load: +@@ -519,6 +520,13 @@ load: } free(line); fclose(in); diff --git a/util/kconfig/patches/0002-Kconfig-Change-symbol-override-from-warning-to-notic.patch b/util/kconfig/patches/0002-Kconfig-Change-symbol-override-from-warning-to-notic.patch index cc37c0712ce..c1ce24970c8 100644 --- a/util/kconfig/patches/0002-Kconfig-Change-symbol-override-from-warning-to-notic.patch +++ b/util/kconfig/patches/0002-Kconfig-Change-symbol-override-from-warning-to-notic.patch @@ -40,7 +40,7 @@ Index: kconfig/confdata.c static void conf_default_message_callback(const char *s) { printf("#\n# "); -@@ -440,7 +450,7 @@ load: +@@ -447,7 +457,7 @@ load: sym->type = S_BOOLEAN; } if (sym->flags & def_flags) { @@ -49,7 +49,7 @@ Index: kconfig/confdata.c } switch (sym->type) { case S_BOOLEAN: -@@ -479,7 +489,7 @@ load: +@@ -486,7 +496,7 @@ load: } if (sym->flags & def_flags) { @@ -58,7 +58,7 @@ Index: kconfig/confdata.c } if (conf_set_sym_val(sym, def, def_flags, p)) continue; -@@ -504,7 +514,7 @@ load: +@@ -511,7 +521,7 @@ load: break; case yes: if (cs->def[def].tri != no) diff --git a/util/kconfig/patches/0005-util-kconfig-Ignore-extra-symbols-in-configs-instead.patch b/util/kconfig/patches/0005-util-kconfig-Ignore-extra-symbols-in-configs-instead.patch index d8e2dfee38a..c05e4a64bfc 100644 --- a/util/kconfig/patches/0005-util-kconfig-Ignore-extra-symbols-in-configs-instead.patch +++ b/util/kconfig/patches/0005-util-kconfig-Ignore-extra-symbols-in-configs-instead.patch @@ -24,7 +24,7 @@ Index: kconfig/confdata.c =================================================================== --- kconfig.orig/confdata.c +++ kconfig/confdata.c -@@ -440,7 +440,9 @@ load: +@@ -447,7 +447,9 @@ load: if (def == S_DEF_USER) { sym = sym_find(line + 2 + strlen(CONFIG_)); if (!sym) { diff --git a/util/kconfig/patches/0007-kconfig-Allow-KCONFIG_STRICT-outside-of-confdata.c.patch b/util/kconfig/patches/0007-kconfig-Allow-KCONFIG_STRICT-outside-of-confdata.c.patch index 13e4d893d56..05a92d411d6 100644 --- a/util/kconfig/patches/0007-kconfig-Allow-KCONFIG_STRICT-outside-of-confdata.c.patch +++ b/util/kconfig/patches/0007-kconfig-Allow-KCONFIG_STRICT-outside-of-confdata.c.patch @@ -62,7 +62,7 @@ Index: kconfig/confdata.c =================================================================== --- kconfig.orig/confdata.c +++ kconfig/confdata.c -@@ -530,11 +530,7 @@ load: +@@ -537,11 +537,7 @@ load: free(line); fclose(in); diff --git a/util/kconfig/patches/0009-util-kconfig-Allow-emitting-false-booleans-into-kconfig-output.patch b/util/kconfig/patches/0009-util-kconfig-Allow-emitting-false-booleans-into-kconfig-output.patch index c74ef67745d..bfb89f94c28 100644 --- a/util/kconfig/patches/0009-util-kconfig-Allow-emitting-false-booleans-into-kconfig-output.patch +++ b/util/kconfig/patches/0009-util-kconfig-Allow-emitting-false-booleans-into-kconfig-output.patch @@ -14,7 +14,7 @@ Index: kconfig/confdata.c =================================================================== --- kconfig.orig/confdata.c +++ kconfig/confdata.c -@@ -715,7 +715,12 @@ static void print_symbol_for_dotconfig(F +@@ -725,7 +725,12 @@ static void print_symbol_for_dotconfig(F static void print_symbol_for_autoconf(FILE *fp, struct symbol *sym) { @@ -28,7 +28,7 @@ Index: kconfig/confdata.c } void print_symbol_for_listconfig(struct symbol *sym) -@@ -740,6 +745,10 @@ static void print_symbol_for_c(FILE *fp, +@@ -750,6 +755,10 @@ static void print_symbol_for_c(FILE *fp, case S_TRISTATE: switch (*val) { case 'n': @@ -39,7 +39,7 @@ Index: kconfig/confdata.c return; case 'm': sym_suffix = "_MODULE"; -@@ -751,6 +760,12 @@ static void print_symbol_for_c(FILE *fp, +@@ -761,6 +770,12 @@ static void print_symbol_for_c(FILE *fp, case S_HEX: if (val[0] != '0' || (val[1] != 'x' && val[1] != 'X')) val_prefix = "0x"; @@ -52,7 +52,7 @@ Index: kconfig/confdata.c break; case S_STRING: escaped = escape_string_value(val); -@@ -1108,8 +1123,9 @@ static int __conf_write_autoconf(const c +@@ -1177,8 +1192,9 @@ static int __conf_write_autoconf(const c conf_write_heading(file, comment_style); diff --git a/util/kconfig/patches/0014-util-kconfig-Move-Kconfig-deps-back-into-build-confi.patch b/util/kconfig/patches/0014-util-kconfig-Move-Kconfig-deps-back-into-build-confi.patch index 869adefc407..09079cde9fa 100644 --- a/util/kconfig/patches/0014-util-kconfig-Move-Kconfig-deps-back-into-build-confi.patch +++ b/util/kconfig/patches/0014-util-kconfig-Move-Kconfig-deps-back-into-build-confi.patch @@ -21,8 +21,8 @@ Index: kconfig/confdata.c =================================================================== --- kconfig.orig/confdata.c +++ kconfig/confdata.c -@@ -230,6 +230,13 @@ static const char *conf_get_autoheader_n - return name ? name : "include/generated/autoconf.h"; +@@ -237,6 +237,13 @@ static const char *conf_get_rustccfg_nam + return name ? name : "include/generated/rustc_cfg"; } +static const char *conf_get_autobase_name(void) @@ -35,7 +35,7 @@ Index: kconfig/confdata.c static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) { char *p2; -@@ -1024,19 +1031,19 @@ static int conf_write_autoconf_cmd(const +@@ -1093,19 +1100,19 @@ static int conf_write_autoconf_cmd(const static int conf_touch_deps(void) { diff --git a/util/kconfig/patches/0015-util-kconfig-chmod-w-before-savedefconfig.patch b/util/kconfig/patches/0015-util-kconfig-chmod-w-before-savedefconfig.patch deleted file mode 100644 index 2b96723693c..00000000000 --- a/util/kconfig/patches/0015-util-kconfig-chmod-w-before-savedefconfig.patch +++ /dev/null @@ -1,30 +0,0 @@ -From 48ad5c23680c81614663e09c6586ebeb26bf8c18 Mon Sep 17 00:00:00 2001 -From: Richard Marko -Date: Mon, 16 Oct 2023 15:26:33 +0200 -Subject: [PATCH] util/kconfig: chmod +w before savedefconfig - -This prevents a headscratcher when .config in root doesn't have a write -permission bit set which causes a build failure of savedefconfig -not able to write to copied file, for example - -*** Error while saving defconfig to: - build/mainboard/emulation/qemu-i440fx/cbfs-file.eU5E0t.out.tmp2 - -Change-Id: I2e7d35c9f6e8add3e7438d163850bc5fda5a99b2 -Signed-off-by: Richard Marko ---- - util/kconfig/Makefile.inc | 1 + - 1 file changed, 1 insertion(+) - -Index: kconfig/Makefile.inc -=================================================================== ---- kconfig.orig/Makefile.inc -+++ kconfig/Makefile.inc -@@ -34,6 +34,7 @@ oldconfig: KCONFIG_STRICT= - - savedefconfig: $(objk)/conf - cp $(DOTCONFIG) $(DEFCONFIG) -+ chmod +w $(DEFCONFIG) - $< --savedefconfig=$(DEFCONFIG) $(KBUILD_KCONFIG) - - FORCE: diff --git a/util/kconfig/patches/series b/util/kconfig/patches/series index 252eb64b9a5..655c4938680 100644 --- a/util/kconfig/patches/series +++ b/util/kconfig/patches/series @@ -10,4 +10,3 @@ 0010-reenable-source-in-choice.patch 0013-util-kconfig-detect-ncurses-on-FreeBSD.patch 0014-util-kconfig-Move-Kconfig-deps-back-into-build-confi.patch -0015-util-kconfig-chmod-w-before-savedefconfig.patch