Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 1 | From af6c23be63d14860c8c1f0d9fcbc020f7c11d84d Mon Sep 17 00:00:00 2001 |
| 2 | From: Stefan Reinauer <reinauer@chromium.org> |
| 3 | Date: Thu, 20 Aug 2015 11:19:34 -0700 |
| 4 | Subject: [PATCH] kconfig: Allow KCONFIG_STRICT outside of confdata.c |
| 5 | |
| 6 | To catch dependency errors in symbol.c (such as the ones |
| 7 | fixed by I51b4ee326f082c6a656a813ee5772e9c34f5c343) we need |
| 8 | to check for global kconfig warnings before saving config |
| 9 | files. |
| 10 | |
| 11 | This patch will produce errors for wrong dependencies and |
| 12 | add catching of errors to conf, nconf and mconf. Sorry, |
| 13 | gconf users, you will have to wait. |
| 14 | |
| 15 | Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org> |
| 16 | --- |
| 17 | util/kconfig/conf.c | 10 ++++++++++ |
| 18 | util/kconfig/confdata.c | 6 +----- |
| 19 | util/kconfig/lkc.h | 3 +++ |
| 20 | util/kconfig/mconf.c | 10 ++++++++++ |
| 21 | util/kconfig/nconf.c | 13 +++++++++++++ |
| 22 | util/kconfig/qconf.cc | 2 ++ |
| 23 | util/kconfig/symbol.c | 1 + |
| 24 | 7 files changed, 40 insertions(+), 5 deletions(-) |
| 25 | |
| 26 | Index: kconfig/conf.c |
| 27 | =================================================================== |
| 28 | --- kconfig.orig/conf.c |
| 29 | +++ kconfig/conf.c |
| 30 | @@ -16,6 +16,8 @@ |
| 31 | |
| 32 | #include "lkc.h" |
| 33 | |
| 34 | +int kconfig_warnings = 0; |
| 35 | + |
| 36 | static void conf(struct menu *menu); |
| 37 | static void check_conf(struct menu *menu); |
| 38 | |
Patrick Georgi | 7eb03cb | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 39 | @@ -720,6 +722,7 @@ int main(int ac, char **av) |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 40 | const char *progname = av[0]; |
| 41 | int opt; |
| 42 | const char *name, *defconfig_file = NULL /* gcc uninit */; |
| 43 | + char *env; |
| 44 | int no_conf_write = 0; |
| 45 | |
| 46 | tty_stdio = isatty(0) && isatty(1); |
Patrick Georgi | 4c9b9e9 | 2022-10-28 01:00:26 +0200 | [diff] [blame] | 47 | @@ -827,6 +830,13 @@ int main(int ac, char **av) |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 48 | break; |
| 49 | } |
| 50 | |
| 51 | + env = getenv("KCONFIG_STRICT"); |
| 52 | + if (env && *env && kconfig_warnings) { |
| 53 | + fprintf(stderr, "\n*** ERROR: %d warnings encountered, and " |
| 54 | + "warnings are errors.\n\n", kconfig_warnings); |
| 55 | + exit(1); |
| 56 | + } |
| 57 | + |
| 58 | if (sync_kconfig) { |
| 59 | name = getenv("KCONFIG_NOSILENTUPDATE"); |
| 60 | if (name && *name) { |
| 61 | Index: kconfig/confdata.c |
| 62 | =================================================================== |
| 63 | --- kconfig.orig/confdata.c |
| 64 | +++ kconfig/confdata.c |
Patrick Georgi | 7f93aa4 | 2023-11-20 17:58:40 +0100 | [diff] [blame] | 65 | @@ -537,11 +537,7 @@ load: |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 66 | free(line); |
| 67 | fclose(in); |
| 68 | |
| 69 | - name = getenv("KCONFIG_STRICT"); |
| 70 | - if (name && *name && conf_warnings) { |
| 71 | - fprintf(stderr, "\nERROR: %d warnings encountered, and warnings are errors.\n\n", conf_warnings); |
| 72 | - return 1; |
| 73 | - } |
| 74 | + kconfig_warnings += conf_warnings; |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | Index: kconfig/lkc.h |
| 79 | =================================================================== |
| 80 | --- kconfig.orig/lkc.h |
| 81 | +++ kconfig/lkc.h |
| 82 | @@ -39,6 +39,9 @@ void zconf_nextfile(const char *name); |
| 83 | int zconf_lineno(void); |
| 84 | const char *zconf_curname(void); |
| 85 | |
| 86 | +/* conf.c */ |
| 87 | +extern int kconfig_warnings; |
| 88 | + |
| 89 | /* confdata.c */ |
| 90 | const char *conf_get_configname(void); |
| 91 | void set_all_choice_values(struct symbol *csym); |
| 92 | Index: kconfig/mconf.c |
| 93 | =================================================================== |
| 94 | --- kconfig.orig/mconf.c |
| 95 | +++ kconfig/mconf.c |
| 96 | @@ -24,6 +24,8 @@ |
| 97 | |
| 98 | #define JUMP_NB 9 |
| 99 | |
| 100 | +int kconfig_warnings = 0; |
| 101 | + |
| 102 | static const char mconf_readme[] = |
| 103 | "Overview\n" |
| 104 | "--------\n" |
Patrick Georgi | 7eab8ef | 2023-11-20 18:03:34 +0100 | [diff] [blame^] | 105 | @@ -953,6 +955,7 @@ static void conf_save(void) |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 106 | static int handle_exit(void) |
| 107 | { |
| 108 | int res; |
| 109 | + char *env; |
| 110 | |
| 111 | save_and_exit = 1; |
| 112 | reset_subtitle(); |
Patrick Georgi | 7eab8ef | 2023-11-20 18:03:34 +0100 | [diff] [blame^] | 113 | @@ -967,6 +970,13 @@ static int handle_exit(void) |
Patrick Georgi | 53ea1d4 | 2019-11-22 16:55:58 +0100 | [diff] [blame] | 114 | |
| 115 | end_dialog(saved_x, saved_y); |
| 116 | |
| 117 | + env = getenv("KCONFIG_STRICT"); |
| 118 | + if (env && *env && kconfig_warnings) { |
| 119 | + fprintf(stderr, "\n*** ERROR: %d warnings encountered, and " |
| 120 | + "warnings are errors.\n\n", kconfig_warnings); |
| 121 | + res = 2; |
| 122 | + } |
| 123 | + |
| 124 | switch (res) { |
| 125 | case 0: |
| 126 | if (conf_write(filename)) { |
| 127 | Index: kconfig/nconf.c |
| 128 | =================================================================== |
| 129 | --- kconfig.orig/nconf.c |
| 130 | +++ kconfig/nconf.c |
| 131 | @@ -15,6 +15,8 @@ |
| 132 | #include "nconf.h" |
| 133 | #include <ctype.h> |
| 134 | |
| 135 | +int kconfig_warnings = 0; |
| 136 | + |
| 137 | static const char nconf_global_help[] = |
| 138 | "Help windows\n" |
| 139 | "------------\n" |
| 140 | @@ -645,6 +647,8 @@ static void set_config_filename(const ch |
| 141 | static int do_exit(void) |
| 142 | { |
| 143 | int res; |
| 144 | + char *env; |
| 145 | + |
| 146 | if (!conf_get_changed()) { |
| 147 | global_exit = 1; |
| 148 | return 0; |
| 149 | @@ -660,6 +664,15 @@ static int do_exit(void) |
| 150 | return -1; |
| 151 | } |
| 152 | |
| 153 | + env = getenv("KCONFIG_STRICT"); |
| 154 | + if (env && *env && kconfig_warnings) { |
| 155 | + btn_dialog(main_window, |
| 156 | + "\nWarnings encountered, and warnings are errors.\n\n", |
| 157 | + 1, |
| 158 | + "<OK>"); |
| 159 | + res = 2; |
| 160 | + } |
| 161 | + |
| 162 | /* if we got here, the user really wants to exit */ |
| 163 | switch (res) { |
| 164 | case 0: |
| 165 | Index: kconfig/qconf.cc |
| 166 | =================================================================== |
| 167 | --- kconfig.orig/qconf.cc |
| 168 | +++ kconfig/qconf.cc |
| 169 | @@ -26,6 +26,8 @@ |
| 170 | #include "images.h" |
| 171 | |
| 172 | |
| 173 | +int kconfig_warnings = 0; |
| 174 | + |
| 175 | static QApplication *configApp; |
| 176 | static ConfigSettings *configSettings; |
| 177 | |
| 178 | Index: kconfig/symbol.c |
| 179 | =================================================================== |
| 180 | --- kconfig.orig/symbol.c |
| 181 | +++ kconfig/symbol.c |
| 182 | @@ -319,6 +319,7 @@ static void sym_warn_unmet_dep(struct sy |
| 183 | " Selected by [m]:\n"); |
| 184 | |
| 185 | fputs(str_get(&gs), stderr); |
| 186 | + kconfig_warnings++; |
| 187 | } |
| 188 | |
| 189 | void sym_calc_value(struct symbol *sym) |