From patchwork Fri Apr 13 05:06:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133331 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp347090ljb; Thu, 12 Apr 2018 22:12:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/pbdeN8Q+A0h21o39LIpdLHSnOqv8n3VkBTz353emmeHorLqtgXZIm7EuGJh+hMiGpxihJ X-Received: by 10.98.75.12 with SMTP id y12mr10214992pfa.140.1523596371278; Thu, 12 Apr 2018 22:12:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523596371; cv=none; d=google.com; s=arc-20160816; b=OjHRYgDMA7toHUut67pDnLyiEl4ryKUox6APXZQ6VwwUEbXfA2sA/z+zBzFHk9FReH hL8GCXZOIVV4PRIt2LPjwyjSh9oyW7MoYzaz+nDuYCAVEoEcWfMkPuRKKMbG6hpEiYuC UkyIlYvMYms5LtO2qeDslA2kR+2CpV8gyE6/1AI4xUpmANoKJGELtGf6GZd3z1YU6zZ7 wJKVNqPKj62YGCbT1S9v66xLGX+amt0Xvd7B/It3BJPdek3hy+2zGZvyfshXKfZ6ySAc D/kLY/zJ+2WiLwbSv21vBMcnL9zwE8uz0fooUIJ1bCsiYAUqAbb+z6h4NldG95wASqKa l6uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=lX/bmRepQYJay/hK37IwnIxDgPI78f+j9u25nFP7mMs=; b=J6/aFvNmBo8slZOMpyXbxzDQNBgluoySidGlmnGmAyHqBkSDgK81JawiVZJRd9tc+L 94jbWXTGV8BXpyoUiP9qC8uYaI7rZr46Qox0cZMkS8HQDBcWCL2/a533Sl2JIMYQl2fO wDgy9wJEcE++Ewl2kDxBhEzu9P+VDAFI8IgGBPgo3t79L/lE87Jheq9woy3qiH/Co37y OCQSlFcAO3rns++xMqfZkYWH2D+kzzqTiU7kf0Aaw5UjiAyU34fS0rKIbqi0orNYR3CP XJdCjY0fDLDtYbdcLlr8GV2wqacsMDCUEpNwQfl3QeNE3rdZhOwht4ywUil0n/uEFFIs Wocw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=hkGyRQux; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t2si3411527pgb.209.2018.04.12.22.12.51; Thu, 12 Apr 2018 22:12:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=hkGyRQux; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753969AbeDMFMs (ORCPT + 29 others); Fri, 13 Apr 2018 01:12:48 -0400 Received: from conuserg-07.nifty.com ([210.131.2.74]:54504 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751042AbeDMFIQ (ORCPT ); Fri, 13 Apr 2018 01:08:16 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-07.nifty.com with ESMTP id w3D56lg8029209; Fri, 13 Apr 2018 14:07:00 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w3D56lg8029209 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1523596020; bh=lX/bmRepQYJay/hK37IwnIxDgPI78f+j9u25nFP7mMs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hkGyRQuxEfU+LF36K9zbTCWIlzlMMsWvNxRSBwS1Q+msTuEv6/qWrRXhd72biCt07 nR2Evg/IqgrFL/FucPR6zHC13OgiApCP7E+72hPxPr/umRWdL+9Frq40XGt8o2OOkt YWLzl1RMSMbEM9tRLud8ikFx58IJVwvg8/sVhGtZVRkyZPp7DIFj7icl5WySU8OECl GiukSqBq5s/4anFRIMmzHnJ3SZ4bFOA5+q9zRQqV+E7T6AGP9iuEb8XtgaSCMaXyoi mKNu58ZVU/V+6eevuwQNjM2PhkZvp58XlhBA0fsfcEhXd2cn3mow/EbwqUIPx9uArD DHunFqvWDP9fQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 14/30] kconfig: support append assignment operator Date: Fri, 13 Apr 2018 14:06:23 +0900 Message-Id: <1523595999-27433-15-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523595999-27433-1-git-send-email-yamada.masahiro@socionext.com> References: <1523595999-27433-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changes in v3: - newly added Changes in v2: None scripts/kconfig/lkc_proto.h | 1 + scripts/kconfig/preprocess.c | 29 +++++++++++++++++++++++++++-- scripts/kconfig/zconf.l | 1 + 3 files changed, 29 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 6303193..a8b7a33 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -52,6 +52,7 @@ const char * prop_get_type_name(enum prop_type type); enum variable_flavor { VAR_SIMPLE, VAR_RECURSIVE, + VAR_APPEND, }; void env_write_dep(FILE *f, const char *auto_conf_name); void variable_add(const char *name, const char *value, diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index a835c94..85972fb 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -86,6 +86,7 @@ static LIST_HEAD(variable_list); struct variable { char *name; char *value; + enum variable_flavor flavor; struct list_head node; }; @@ -116,18 +117,42 @@ void variable_add(const char *name, const char *value, enum variable_flavor flavor) { struct variable *v; + char *new_value; + bool append = false; v = variable_lookup(name); if (v) { - free(v->value); + /* For defined variables, += inherits the existing flavor */ + if (flavor == VAR_APPEND) { + flavor = v->flavor; + append = true; + } else { + free(v->value); + } } else { + /* For undefined variables, += assumes the recursive flavor */ + if (flavor == VAR_APPEND) + flavor = VAR_RECURSIVE; + v = xmalloc(sizeof(*v)); v->name = xstrdup(name); list_add_tail(&v->node, &variable_list); } - v->value = (flavor == VAR_SIMPLE) ? expand_string(value) : + v->flavor = flavor; + + new_value = (flavor == VAR_SIMPLE) ? expand_string(value) : xstrdup(value); + + if (append) { + v->value = xrealloc(v->value, + strlen(v->value) + strlen(new_value) + 2); + strcat(v->value, " "); + strcat(v->value, new_value); + free(new_value); + } else { + v->value = new_value; + } } static void variable_del(struct variable *v) diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index aa76942..c68ca56b 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l @@ -116,6 +116,7 @@ n [A-Za-z0-9_-] } "=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_RECURSIVE; return T_ASSIGN; } ":=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_SIMPLE; return T_ASSIGN; } + "+=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_APPEND; return T_ASSIGN; } [[:blank:]]+ . warn_ignored_character(*yytext); \n {