summaryrefslogtreecommitdiff
path: root/util/kconfig/patches/0009-util-kconfig-Allow-emitting-false-booleans-into-kconfig-output.patch
blob: 70e9d3f648bbde5a43db6241a95af7d50b032d31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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/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:
Index: kconfig/confdata.c
===================================================================
--- kconfig.orig/confdata.c
+++ kconfig/confdata.c
@@ -715,7 +715,12 @@ static void print_symbol_for_dotconfig(F
 
 static void print_symbol_for_autoconf(FILE *fp, struct symbol *sym)
 {
-	__print_symbol(fp, sym, OUTPUT_N_NONE, false);
+	int print_negatives = getenv("KCONFIG_NEGATIVES") != NULL;
+	enum output_n out = OUTPUT_N_NONE;
+	if (print_negatives) {
+		out = OUTPUT_N;
+	}
+	__print_symbol(fp, sym, out, false);
 }
 
 void print_symbol_for_listconfig(struct symbol *sym)
@@ -740,6 +745,10 @@ static void print_symbol_for_c(FILE *fp,
 	case S_TRISTATE:
 		switch (*val) {
 		case 'n':
+			if (getenv("KCONFIG_NEGATIVES") != NULL) {
+				val = "0";
+				break;
+			}
 			return;
 		case 'm':
 			sym_suffix = "_MODULE";
@@ -751,6 +760,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";
+		/* fall through */
+	case S_INT:
+		if (val[0] == '\0') {
+			val = "0";
+			val_prefix = "";
+		}
 		break;
 	case S_STRING:
 		escaped = escape_string_value(val);
@@ -1108,8 +1123,9 @@ static int __conf_write_autoconf(const c
 
 	conf_write_heading(file, comment_style);
 
+	int print_negatives = getenv("KCONFIG_NEGATIVES") != NULL;
 	for_all_symbols(i, sym)
-		if ((sym->flags & SYMBOL_WRITE) && sym->name)
+		if (((sym->flags & SYMBOL_WRITE) || (print_negatives && sym->type != S_STRING)) && sym->name)
 			print_symbol(file, sym);
 
 	fflush(file);