util/kconfig: Uprev to Linux 5.13's kconfig

This was originally several commits that had to be squashed into one
because the intermediate states weren't able to build coreboot:

 - one to remove everything that wasn't our own code, leaving only
   regex.[ch], toada.c, description.md and Makefile.inc.
 - one to copy in Linux 5.13's scripts/kconfig and adapt Makefile.inc
   to make the original Makefile work again.
 - adapt abuild to use olddefconfig, simplifying matters.
 - apply patches in util/kconfig/patches.
 - Some more adaptations to the libpayload build system.

The patches are now in util/kconfig/patches/, reverse applying them
should lead to a util/kconfig/ tree that contains exactly the Linux
version + our own 5 files.

Change-Id: Ia0e8fe4e9022b278f34ab113a433ef4d45e5c355
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/37152
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Raul Rangel <rrangel@chromium.org>
This commit is contained in:
Patrick Georgi
2019-11-22 16:55:58 +01:00
parent 8585eabc5d
commit 53ea1d44f0
69 changed files with 6407 additions and 9476 deletions

View File

@@ -0,0 +1,43 @@
From c822f47921feb53b97f48f3aa8d1e843f5099c63 Mon Sep 17 00:00:00 2001
From: Stefan Reinauer <stefan.reinauer@coreboot.org>
Date: Fri, 17 Jul 2015 17:26:48 -0700
Subject: [PATCH] Kconfig: Add KCONFIG_STRICT mode
This is basically a -Werror mode for Kconfig. When exporting
KCONFIG_STRICT in the Makefile, warnings in Kconfig will produce
errors instead.
This will make it easier to spot unclean Kconfig files, settings
and dependencies.
Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
---
util/kconfig/confdata.c | 8 ++++++++
1 file changed, 8 insertions(+)
Index: kconfig/confdata.c
===================================================================
--- kconfig.orig/confdata.c
+++ kconfig/confdata.c
@@ -439,6 +439,7 @@ load:
if (def == S_DEF_USER) {
sym = sym_find(line + 2 + strlen(CONFIG_));
if (!sym) {
+ conf_warning("trying to assign non-existent symbol %s", line + strlen(CONFIG_));
conf_set_changed(true);
continue;
}
@@ -521,6 +522,13 @@ load:
}
free(line);
fclose(in);
+
+ name = getenv("KCONFIG_STRICT");
+ if (name && *name && conf_warnings) {
+ fprintf(stderr, "\nERROR: %d warnings encountered, and warnings are errors.\n\n", conf_warnings);
+ return 1;
+ }
+
return 0;
}

View File

@@ -0,0 +1,69 @@
From 20df4491aa88eb4a7f97090fbc4ff53f81926861 Mon Sep 17 00:00:00 2001
From: Martin Roth <martinroth@google.com>
Date: Wed, 21 Sep 2016 14:27:26 -0600
Subject: [PATCH] Kconfig: Change symbol override from warning to notice
Overriding symbols within a .config is pretty common when doing
automated builds with various different options. The warning
text makes it sound like this is an issue, so change it to say
'notice' instead. We could get rid of it completely, but it's
not a bad thing to know that we have two copies of the same symbol
in the .config.
BUG=chrome-os-partner:54059
TEST=copy a disabled kconfig option to the end and set it to y.
See notice text instead of warning.
Signed-off-by: Martin Roth <martinroth@google.com>
---
util/kconfig/confdata.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
Index: kconfig/confdata.c
===================================================================
--- kconfig.orig/confdata.c
+++ kconfig/confdata.c
@@ -184,6 +184,16 @@ static void conf_warning(const char *fmt
conf_warnings++;
}
+static void conf_notice(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ fprintf(stderr, "%s:%d:notice: ", conf_filename, conf_lineno);
+ vfprintf(stderr, fmt, ap);
+ fprintf(stderr, "\n");
+ va_end(ap);
+}
+
static void conf_default_message_callback(const char *s)
{
printf("#\n# ");
@@ -449,7 +459,7 @@ load:
sym->type = S_BOOLEAN;
}
if (sym->flags & def_flags) {
- conf_warning("override: reassigning to symbol %s", sym->name);
+ conf_notice("override: reassigning to symbol %s", sym->name);
}
switch (sym->type) {
case S_BOOLEAN:
@@ -488,7 +498,7 @@ load:
}
if (sym->flags & def_flags) {
- conf_warning("override: reassigning to symbol %s", sym->name);
+ conf_notice("override: reassigning to symbol %s", sym->name);
}
if (conf_set_sym_val(sym, def, def_flags, p))
continue;
@@ -513,7 +523,7 @@ load:
break;
case yes:
if (cs->def[def].tri != no)
- conf_warning("override: %s changes choice state", sym->name);
+ conf_notice("override: %s changes choice state", sym->name);
cs->def[def].val = sym;
break;
}

View File

@@ -0,0 +1,25 @@
From 887ae0ac3dc53fc73488a4dbc1fbf36fa620ce8b Mon Sep 17 00:00:00 2001
From: Martin Roth <martinroth@google.com>
Date: Tue, 6 Dec 2016 14:28:44 -0700
Subject: [PATCH] util/kconfig/conf.c: Fix newline in error printf
For some reason the \n in the defconfig save error was not escaped.
Signed-off-by: Martin Roth <martinroth@google.com>
---
util/kconfig/conf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Index: kconfig/conf.c
===================================================================
--- kconfig.orig/conf.c
+++ kconfig/conf.c
@@ -900,7 +900,7 @@ int main(int ac, char **av)
if (input_mode == savedefconfig) {
if (conf_write_defconfig(defconfig_file)) {
- fprintf(stderr, "n*** Error while saving defconfig to: %s\n\n",
+ fprintf(stderr, "\n*** Error while saving defconfig to: %s\n\n",
defconfig_file);
return 1;
}

View File

@@ -0,0 +1,46 @@
From e8287a030fc8fcec7404aa6731aef21a48035786 Mon Sep 17 00:00:00 2001
From: Elyes HAOUAS <ehaouas@noos.fr>
Date: Tue, 5 Jun 2018 08:41:29 +0200
Subject: [PATCH] {src,util}: Use NULL instead of 0 for pointer
Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
---
util/kconfig/lxdialog/util.c | 2 +-
util/kconfig/qconf.h | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
Index: kconfig/lxdialog/util.c
===================================================================
--- kconfig.orig/lxdialog/util.c
+++ kconfig/lxdialog/util.c
@@ -370,7 +370,7 @@ void print_autowrap(WINDOW * win, const
{
int newl, cur_x, cur_y;
int prompt_len, room, wlen;
- char tempstr[MAX_LEN + 1], *word, *sp, *sp2, *newline_separator = 0;
+ char tempstr[MAX_LEN + 1], *word, *sp, *sp2, *newline_separator = NULL;
strcpy(tempstr, prompt);
Index: kconfig/qconf.h
===================================================================
--- kconfig.orig/qconf.h
+++ kconfig/qconf.h
@@ -42,7 +42,7 @@ class ConfigList : public QTreeWidget {
Q_OBJECT
typedef class QTreeWidget Parent;
public:
- ConfigList(QWidget *parent, const char *name = 0);
+ ConfigList(QWidget *parent, const char *name = NULL);
~ConfigList();
void reinit(void);
ConfigItem* findConfigItem(struct menu *);
@@ -188,7 +188,7 @@ class ConfigInfoView : public QTextBrows
typedef class QTextBrowser Parent;
QMenu *contextMenu;
public:
- ConfigInfoView(QWidget* parent, const char *name = 0);
+ ConfigInfoView(QWidget* parent, const char *name = NULL);
bool showDebug(void) const { return _showDebug; }
public slots:

View File

@@ -0,0 +1,37 @@
From 2796443d5a2194400e56e6762e0f748ed0f0470c Mon Sep 17 00:00:00 2001
From: Martin Roth <martinroth@google.com>
Date: Wed, 10 Feb 2016 16:06:00 -0700
Subject: [PATCH] util/kconfig: Ignore extra symbols in configs instead of
failing
When updating an old .config file that has a symbol that has been
removed from the current Kconfig tree, kconfig will generate a warning
and fail to save the updated file. This is incredibly annoying, and
not the goal when trying to eliminate Kconfig warnings.
Instead of generating a warning, just print a message that it's being
ignored. This will remove the offending symbol, while allowing the
updated config file to be saved.
Split the change from 1 line to 3 lines to keep it at 80 characters.
Signed-off-by: Martin Roth <martinroth@google.com>
---
util/kconfig/confdata.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
Index: kconfig/confdata.c
===================================================================
--- kconfig.orig/confdata.c
+++ kconfig/confdata.c
@@ -449,7 +449,9 @@ load:
if (def == S_DEF_USER) {
sym = sym_find(line + 2 + strlen(CONFIG_));
if (!sym) {
- conf_warning("trying to assign non-existent symbol %s", line + strlen(CONFIG_));
+ conf_message(
+ "ignoring nonexistent symbol %s",
+ line + 2 + strlen(CONFIG_));
conf_set_changed(true);
continue;
}

View File

@@ -0,0 +1,28 @@
From d470f1069744c3e6ef2e928217c1a4a23a87efa2 Mon Sep 17 00:00:00 2001
From: zbao <fishbaozi@gmail.com>
Date: Sat, 26 Sep 2015 06:20:53 -0400
Subject: [PATCH] util/kconfig: Set parameter of mkdir to only one for mingw.
The second parameter is to set file permissions for the directory, which
is not needed in mingw.
Signed-off-by: Zheng Bao <fishbaozi@gmail.com>
---
util/kconfig/confdata.c | 4 ++++
1 file changed, 4 insertions(+)
Index: kconfig/confdata.c
===================================================================
--- kconfig.orig/confdata.c
+++ kconfig/confdata.c
@@ -164,6 +164,10 @@ struct conf_printer {
void (*print_comment)(FILE *, const char *, void *);
};
+#ifdef __MINGW32__
+#define mkdir(_n,_p) mkdir((_n))
+#endif
+
static void conf_warning(const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));

View File

@@ -0,0 +1,189 @@
From af6c23be63d14860c8c1f0d9fcbc020f7c11d84d Mon Sep 17 00:00:00 2001
From: Stefan Reinauer <reinauer@chromium.org>
Date: Thu, 20 Aug 2015 11:19:34 -0700
Subject: [PATCH] kconfig: Allow KCONFIG_STRICT outside of confdata.c
To catch dependency errors in symbol.c (such as the ones
fixed by I51b4ee326f082c6a656a813ee5772e9c34f5c343) we need
to check for global kconfig warnings before saving config
files.
This patch will produce errors for wrong dependencies and
add catching of errors to conf, nconf and mconf. Sorry,
gconf users, you will have to wait.
Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
---
util/kconfig/conf.c | 10 ++++++++++
util/kconfig/confdata.c | 6 +-----
util/kconfig/lkc.h | 3 +++
util/kconfig/mconf.c | 10 ++++++++++
util/kconfig/nconf.c | 13 +++++++++++++
util/kconfig/qconf.cc | 2 ++
util/kconfig/symbol.c | 1 +
7 files changed, 40 insertions(+), 5 deletions(-)
Index: kconfig/conf.c
===================================================================
--- kconfig.orig/conf.c
+++ kconfig/conf.c
@@ -16,6 +16,8 @@
#include "lkc.h"
+int kconfig_warnings = 0;
+
static void conf(struct menu *menu);
static void check_conf(struct menu *menu);
@@ -732,6 +734,7 @@ int main(int ac, char **av)
const char *progname = av[0];
int opt;
const char *name, *defconfig_file = NULL /* gcc uninit */;
+ char *env;
int no_conf_write = 0;
tty_stdio = isatty(0) && isatty(1);
@@ -838,6 +841,13 @@ int main(int ac, char **av)
break;
}
+ env = getenv("KCONFIG_STRICT");
+ if (env && *env && kconfig_warnings) {
+ fprintf(stderr, "\n*** ERROR: %d warnings encountered, and "
+ "warnings are errors.\n\n", kconfig_warnings);
+ exit(1);
+ }
+
if (sync_kconfig) {
name = getenv("KCONFIG_NOSILENTUPDATE");
if (name && *name) {
Index: kconfig/confdata.c
===================================================================
--- kconfig.orig/confdata.c
+++ kconfig/confdata.c
@@ -539,11 +539,7 @@ load:
free(line);
fclose(in);
- name = getenv("KCONFIG_STRICT");
- if (name && *name && conf_warnings) {
- fprintf(stderr, "\nERROR: %d warnings encountered, and warnings are errors.\n\n", conf_warnings);
- return 1;
- }
+ kconfig_warnings += conf_warnings;
return 0;
}
Index: kconfig/lkc.h
===================================================================
--- kconfig.orig/lkc.h
+++ kconfig/lkc.h
@@ -39,6 +39,9 @@ void zconf_nextfile(const char *name);
int zconf_lineno(void);
const char *zconf_curname(void);
+/* conf.c */
+extern int kconfig_warnings;
+
/* confdata.c */
const char *conf_get_configname(void);
void set_all_choice_values(struct symbol *csym);
Index: kconfig/mconf.c
===================================================================
--- kconfig.orig/mconf.c
+++ kconfig/mconf.c
@@ -24,6 +24,8 @@
#define JUMP_NB 9
+int kconfig_warnings = 0;
+
static const char mconf_readme[] =
"Overview\n"
"--------\n"
@@ -948,6 +950,7 @@ static void conf_save(void)
static int handle_exit(void)
{
int res;
+ char *env;
save_and_exit = 1;
reset_subtitle();
@@ -962,6 +965,13 @@ static int handle_exit(void)
end_dialog(saved_x, saved_y);
+ env = getenv("KCONFIG_STRICT");
+ if (env && *env && kconfig_warnings) {
+ fprintf(stderr, "\n*** ERROR: %d warnings encountered, and "
+ "warnings are errors.\n\n", kconfig_warnings);
+ res = 2;
+ }
+
switch (res) {
case 0:
if (conf_write(filename)) {
Index: kconfig/nconf.c
===================================================================
--- kconfig.orig/nconf.c
+++ kconfig/nconf.c
@@ -15,6 +15,8 @@
#include "nconf.h"
#include <ctype.h>
+int kconfig_warnings = 0;
+
static const char nconf_global_help[] =
"Help windows\n"
"------------\n"
@@ -645,6 +647,8 @@ static void set_config_filename(const ch
static int do_exit(void)
{
int res;
+ char *env;
+
if (!conf_get_changed()) {
global_exit = 1;
return 0;
@@ -660,6 +664,15 @@ static int do_exit(void)
return -1;
}
+ env = getenv("KCONFIG_STRICT");
+ if (env && *env && kconfig_warnings) {
+ btn_dialog(main_window,
+ "\nWarnings encountered, and warnings are errors.\n\n",
+ 1,
+ "<OK>");
+ res = 2;
+ }
+
/* if we got here, the user really wants to exit */
switch (res) {
case 0:
Index: kconfig/qconf.cc
===================================================================
--- kconfig.orig/qconf.cc
+++ kconfig/qconf.cc
@@ -26,6 +26,8 @@
#include "images.h"
+int kconfig_warnings = 0;
+
static QApplication *configApp;
static ConfigSettings *configSettings;
Index: kconfig/symbol.c
===================================================================
--- kconfig.orig/symbol.c
+++ kconfig/symbol.c
@@ -319,6 +319,7 @@ static void sym_warn_unmet_dep(struct sy
" Selected by [m]:\n");
fputs(str_get(&gs), stderr);
+ kconfig_warnings++;
}
void sym_calc_value(struct symbol *sym)

View File

@@ -0,0 +1,94 @@
From 5e2355bf017b3347b29126a0eeb866558334f704 Mon Sep 17 00:00:00 2001
From: Stefan Reinauer <stefan.reinauer@coreboot.org>
Date: Fri, 3 Apr 2015 20:01:38 +0200
Subject: [PATCH] kconfig: Add wildcard support for "source"
Kconfig's include directive "source" does not support
wildcards (e.g. source src/mainboard/*/Kconfig) which
makes automatic inclusion of all boards a tedious task
and prevents us from implementing "drop in" boards.
In our Makefile.inc files we already include mainboard
directories per wildcard, so let's add the infrastructure
to do the same with Kconfig.
v2: change from wordexp to glob for better portability.
Signed-off-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
---
util/kconfig/lexer.l | 27 +++++++++++++++++++++++++++
util/kconfig/lkc.h | 1 +
util/kconfig/parser.y | 2 +-
3 files changed, 29 insertions(+), 1 deletion(-)
Index: kconfig/lexer.l
===================================================================
--- kconfig.orig/lexer.l
+++ kconfig/lexer.l
@@ -8,6 +8,7 @@
%{
#include <assert.h>
+#include <glob.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
@@ -438,6 +439,32 @@ void zconf_nextfile(const char *name)
current_file = file;
}
+void zconf_nextfiles(const char *wildcard)
+{
+ glob_t g;
+ char **w;
+ int i;
+
+ if (glob(wildcard, 0, NULL, &g) != 0) {
+ return;
+ }
+ if (g.gl_pathv == NULL) {
+ globfree(&g);
+ return;
+ }
+
+ /* working through files backwards, since
+ * we're first pushing them on a stack
+ * before actually handling them.
+ */
+ for (i = g.gl_pathc; i > 0; i--) {
+ w = &g.gl_pathv[i - 1];
+ zconf_nextfile(*w);
+ }
+
+ globfree(&g);
+}
+
static void zconf_endfile(void)
{
struct buffer *parent;
Index: kconfig/lkc.h
===================================================================
--- kconfig.orig/lkc.h
+++ kconfig/lkc.h
@@ -36,6 +36,7 @@ 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);
int zconf_lineno(void);
const char *zconf_curname(void);
Index: kconfig/parser.y
===================================================================
--- kconfig.orig/parser.y
+++ kconfig/parser.y
@@ -358,7 +358,7 @@ menu_option_list:
source_stmt: T_SOURCE T_WORD_QUOTE T_EOL
{
printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
- zconf_nextfile($2);
+ zconf_nextfiles($2);
free($2);
};

View File

@@ -0,0 +1,93 @@
commit ab0cc6067d5a00182e89fbec82b942eb3d803204
Author: Patrick Georgi <pgeorgi@google.com>
Date: Fri Nov 22 22:08:15 2019 +0100
util/kconfig: Allow emitting false booleans into kconfig output
This is controlled by an environment variable so the same tool is
useful in different contexts.
Change-Id: I9e62b05e45709f1539e455e2eed37308609be15e
Signed-off-by: Patrick Georgi <pgeorgi@google.com>
Index: kconfig/confdata.c
===================================================================
--- kconfig.orig/confdata.c
+++ kconfig/confdata.c
@@ -687,6 +687,9 @@ header_print_symbol(FILE *fp, struct sym
switch (*value) {
case 'n':
+ if (getenv("KCONFIG_NEGATIVES") != NULL)
+ fprintf(fp, "#define %s%s%s 0\n",
+ CONFIG_, sym->name, suffix);
break;
case 'm':
suffix = "_MODULE";
@@ -702,14 +705,28 @@ header_print_symbol(FILE *fp, struct sym
if (value[0] != '0' || (value[1] != 'x' && value[1] != 'X'))
prefix = "0x";
+ if (value[0] == '\0') {
+ /*
+ * prefix is reset to remain closer to the older
+ * coreboot patch. No need to keep this once kconfig
+ * is fully upreved
+ */
+ prefix = "";
+ value = "0";
+ }
fprintf(fp, "#define %s%s %s%s\n",
CONFIG_, sym->name, prefix, value);
break;
}
case S_STRING:
+ if (value[0] == '\0')
+ break;
+ if (!(sym->flags & SYMBOL_WRITE))
+ break;
+ /* fall through */
case S_INT:
fprintf(fp, "#define %s%s %s\n",
- CONFIG_, sym->name, value);
+ CONFIG_, sym->name, value[0]?value:"0");
break;
default:
break;
@@ -1080,6 +1097,7 @@ int conf_write_autoconf(int overwrite)
const char *autoconf_name = conf_get_autoconfig_name();
FILE *out, *out_h;
int i;
+ int print_negatives = getenv("KCONFIG_NEGATIVES") != NULL;
if (!overwrite && is_present(autoconf_name))
return 0;
@@ -1104,11 +1122,13 @@ int conf_write_autoconf(int overwrite)
for_all_symbols(i, sym) {
sym_calc_value(sym);
- if (!(sym->flags & SYMBOL_WRITE) || !sym->name)
+ if (!(sym->flags & SYMBOL_WRITE) && !print_negatives)
+ continue;
+ if (!sym->name)
continue;
/* write symbols to auto.conf and autoconf.h */
- conf_write_symbol(out, sym, &kconfig_printer_cb, (void *)1);
+ conf_write_symbol(out, sym, &kconfig_printer_cb, print_negatives?NULL:(void *)1);
conf_write_symbol(out_h, sym, &header_printer_cb, NULL);
}
fclose(out);
Index: kconfig/symbol.c
===================================================================
--- kconfig.orig/symbol.c
+++ kconfig/symbol.c
@@ -757,7 +757,7 @@ const char *sym_get_string_default(struc
}
case S_INT:
case S_HEX:
- return str;
+ return "0";
case S_STRING:
return str;
case S_UNKNOWN:

View File

@@ -0,0 +1,16 @@
Kconfig 5.8 (since commit 09d5873e4d1f70202314b5fe40160f9b14b9d2d0)
blocks using the source statement within choice but that's a pattern we
use intensively. Re-enable it.
Index: kconfig/parser.y
===================================================================
--- kconfig.orig/parser.y
+++ kconfig/parser.y
@@ -134,6 +134,7 @@ stmt_list_in_choice:
| stmt_list_in_choice comment_stmt
| stmt_list_in_choice config_stmt
| stmt_list_in_choice if_stmt_in_choice
+ | stmt_list_in_choice source_stmt
| stmt_list_in_choice error T_EOL { zconf_error("invalid statement"); }
;

View File

@@ -0,0 +1,39 @@
Index: kconfig/confdata.c
===================================================================
--- kconfig.orig/confdata.c
+++ kconfig/confdata.c
@@ -241,6 +241,13 @@ static const char *conf_get_autoconfig_n
return name ? name : "include/config/auto.conf";
}
+static const char *conf_get_autobase_name(void)
+{
+ char *name = getenv("KCONFIG_SPLITCONFIG");
+
+ return name ? name : "include/config/";
+}
+
static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
{
char *p2;
@@ -1024,7 +1031,7 @@ static int conf_touch_deps(void)
struct symbol *sym;
int res, i;
- strcpy(depfile_path, "include/config/");
+ strcpy(depfile_path, conf_get_autobase_name());
depfile_prefix_len = strlen(depfile_path);
name = conf_get_autoconfig_name();
@@ -1102,7 +1109,10 @@ int conf_write_autoconf(int overwrite)
if (!overwrite && is_present(autoconf_name))
return 0;
- conf_write_dep("include/config/auto.conf.cmd");
+ char autoconfcmd_path[PATH_MAX];
+ snprintf(autoconfcmd_path, sizeof(autoconfcmd_path), "%s%s",
+ conf_get_autobase_name(), "auto.conf.cmd");
+ conf_write_dep(autoconfcmd_path);
if (conf_touch_deps())
return 1;

View File

@@ -0,0 +1,124 @@
commit 7b2deddbb0ef350e189fe42c025b07c943aedc4c
Author: Raul E Rangel <rrangel@chromium.org>
Date: Thu Jul 25 15:49:52 2019 -0600
Kconfig: Write tmp files into same directory as target files
This removes the need for COREBOOT_BUILD_DIR in Kconfig. Since the
original files will be replaced with the tmp file, the parent directory
already needs to be writable.
Before this change, the tmp files would be created in the CWD (src) if
COREBOOT_BUILD_DIR was not specified.
BUG=b:112267918
TEST=emerge-grunt coreboot and verified no tmp files were created in the
src directory.
Change-Id: Icdaf2ff3dd1ec98813b75ef55b96e38e1ca19ec7
Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/34244
Reviewed-by: Martin Roth <martinroth@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Index: kconfig/confdata.c
===================================================================
--- kconfig.orig/confdata.c
+++ kconfig/confdata.c
@@ -880,6 +880,16 @@ next_menu:
return 0;
}
+
+static int conf_mktemp(const char *path, char *tmpfile)
+{
+ if (snprintf(tmpfile, PATH_MAX, "%s.tmp.XXXXXX", path) >= PATH_MAX) {
+ errno = EOVERFLOW;
+ return -1;
+ }
+ return mkstemp(tmpfile);
+}
+
int conf_write(const char *name)
{
FILE *out;
@@ -1001,7 +1011,14 @@ static int conf_write_dep(const char *na
struct file *file;
FILE *out;
- out = fopen("..config.tmp", "w");
+ if (make_parent_dir(name))
+ return 1;
+ char filename[PATH_MAX];
+ int fd = conf_mktemp(name, filename);
+ if (fd == -1)
+ return 1;
+
+ out = fdopen(fd, "w");
if (!out)
return 1;
fprintf(out, "deps_config := \\\n");
@@ -1019,9 +1036,7 @@ static int conf_write_dep(const char *na
fprintf(out, "\n$(deps_config): ;\n");
fclose(out);
- if (make_parent_dir(name))
- return 1;
- rename("..config.tmp", name);
+ rename(filename, name);
return 0;
}
@@ -1117,11 +1132,26 @@ int conf_write_autoconf(int overwrite)
if (conf_touch_deps())
return 1;
- out = fopen(".tmpconfig", "w");
+ if (make_parent_dir(autoconf_name))
+ return 1;
+ char filename[PATH_MAX];
+ int fd = conf_mktemp(autoconf_name, filename);
+ if (fd == -1)
+ return 1;
+ out = fdopen(fd, "w");
if (!out)
return 1;
- out_h = fopen(".tmpconfig.h", "w");
+ name = getenv("KCONFIG_AUTOHEADER");
+ if (!name)
+ name = "include/generated/autoconf.h";
+ if (make_parent_dir(name))
+ return 1;
+ char filename_h[PATH_MAX];
+ int fd_h = conf_mktemp(name, filename_h);
+ if (fd_h == -1)
+ return 1;
+ out_h = fdopen(fd_h, "w");
if (!out_h) {
fclose(out);
return 1;
@@ -1144,21 +1174,14 @@ int conf_write_autoconf(int overwrite)
fclose(out);
fclose(out_h);
- name = getenv("KCONFIG_AUTOHEADER");
- if (!name)
- name = "include/generated/autoconf.h";
- if (make_parent_dir(name))
- return 1;
- if (rename(".tmpconfig.h", name))
+ if (rename(filename_h, name))
return 1;
- if (make_parent_dir(autoconf_name))
- return 1;
/*
* This must be the last step, kbuild has a dependency on auto.conf
* and this marks the successful completion of the previous steps.
*/
- if (rename(".tmpconfig", autoconf_name))
+ if (rename(filename, autoconf_name))
return 1;
return 0;

View File

@@ -0,0 +1,12 @@
0001-Kconfig-Add-KCONFIG_STRICT-mode.patch
0002-Kconfig-Change-symbol-override-from-warning-to-notic.patch
0003-util-kconfig-conf.c-Fix-newline-in-error-printf.patch
0004-src-util-Use-NULL-instead-of-0-for-pointer.patch
0005-util-kconfig-Ignore-extra-symbols-in-configs-instead.patch
0006-util-kconfig-Set-parameter-of-mkdir-to-only-one-for-.patch
0007-kconfig-Allow-KCONFIG_STRICT-outside-of-confdata.c.patch
0008-kconfig-Add-wildcard-support-for-source.patch
0009-util-kconfig-Allow-emitting-false-booleans-into-kconfig-output.patch
0010-reenable-source-in-choice.patch
0011-remove-include-config-hardcodes.patch
0012-safer-tmpfiles.patch