Skip to content

Commit ed2a22f

Browse files
committed
kconfig: support append assignment operator
Support += operator. This appends a space and the text on the righthand side to a variable. The timing of the evaluation of the righthand side depends on the flavor of the variable. If the lefthand side was originally defined as a simple variable, the righthand side is expanded immediately. Otherwise, the expansion is deferred. Appending something to an undefined variable results in a recursive variable. To implement this, we need to remember the flavor of variables. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
1 parent 1175c02 commit ed2a22f

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎scripts/kconfig/lkc_proto.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const char * prop_get_type_name(enum prop_type type);
5252
enum variable_flavor {
5353
VAR_SIMPLE,
5454
VAR_RECURSIVE,
55+
VAR_APPEND,
5556
};
5657
void env_write_dep(FILE *f, const char *auto_conf_name);
5758
void variable_add(const char *name, const char *value,

‎scripts/kconfig/preprocess.c‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,23 @@ void variable_add(const char *name, const char *value,
222222
enum variable_flavor flavor)
223223
{
224224
struct variable *v;
225+
char *new_value;
226+
bool append = false;
225227

226228
v = variable_lookup(name);
227229
if (v) {
228-
free(v->value);
230+
/* For defined variables, += inherits the existing flavor */
231+
if (flavor == VAR_APPEND) {
232+
flavor = v->flavor;
233+
append = true;
234+
} else {
235+
free(v->value);
236+
}
229237
} else {
238+
/* For undefined variables, += assumes the recursive flavor */
239+
if (flavor == VAR_APPEND)
240+
flavor = VAR_RECURSIVE;
241+
230242
v = xmalloc(sizeof(*v));
231243
v->name = xstrdup(name);
232244
list_add_tail(&v->node, &variable_list);
@@ -235,9 +247,19 @@ void variable_add(const char *name, const char *value,
235247
v->flavor = flavor;
236248

237249
if (flavor == VAR_SIMPLE)
238-
v->value = expand_string(value);
250+
new_value = expand_string(value);
239251
else
240-
v->value = xstrdup(value);
252+
new_value = xstrdup(value);
253+
254+
if (append) {
255+
v->value = xrealloc(v->value,
256+
strlen(v->value) + strlen(new_value) + 2);
257+
strcat(v->value, " ");
258+
strcat(v->value, new_value);
259+
free(new_value);
260+
} else {
261+
v->value = new_value;
262+
}
241263
}
242264

243265
static void variable_del(struct variable *v)

‎scripts/kconfig/zconf.l‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ n [A-Za-z0-9_-]
116116
}
117117
"=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_RECURSIVE; return T_ASSIGN; }
118118
":=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_SIMPLE; return T_ASSIGN; }
119+
"+=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_APPEND; return T_ASSIGN; }
119120
[[:blank:]]+
120121
. warn_ignored_character(*yytext);
121122
\n {

0 commit comments

Comments
 (0)