From patchwork Thu May 17 06:16:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136103 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1881248lji; Wed, 16 May 2018 23:23:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqdvHXI6tS3JE9BcO8PNzZfcDEGipPBXXBlrOegJHMbNm/FlPk4FF6+D7DG6T8C0qjINo67 X-Received: by 2002:a17:902:f83:: with SMTP id 3-v6mr3970405plz.336.1526538228588; Wed, 16 May 2018 23:23:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526538228; cv=none; d=google.com; s=arc-20160816; b=Zbg6W3Jm6Nub0JED2nrqhJzM4rEhdJ9s+gY3jRRbLGRE0ZYrd0gAoTRZoZtyDXVEfi puQhg+XLe93E+PdeiPFh8b0IRUl9uLYgjn79HXBqqdaHUhadk+nmbsVrODs58yaMhvvU TRAWRP5AWcRsA2FO0+cgamei0l1iWD1+g/5O5FNM9D/jFWGpT8JUxbh+t8z5EsCdE4kh MtwtVbURm/oFWK8PtkkjFXa0lODmE632cZMwZWCKE3Y/qX6zE3lncDFbT+mRK6o/hQez UQIAvdTQ//Dt6LFsG8ywFHnzYr4BSgImgZD/OxIdpEDFedk70YKW3WbeeTQPxz1QnCRI KD9w== 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=AhHOPEC5Ia8wokTIBaVdLUk6EnhwEj+yWpUTa9SDN/A=; b=v8WmXEm2ZcAG37/aglBe70AAVo5MMujB6fwpdfjJfKzON/TAT+LiBTrKn+z4tT8Ump CO/2zRPCKVj3ldooojlTCE7V3z3WUW46o5Hdl25d/E1h0YK6gbrOoIvCHkMCQd4leWCD N3DTJewNHMevl6aO8zobREq/dxpW18nMg+U9c564WJXu8dUL4ddoccr3lq26S/AXyLlj yLuxGYrNhDm/4SdTqac27AT18qoQ4ATzSNkxhUe+q/ojmarydJ6QaPJncU9UpTXyfntF fNpcz5ClCa8Fp7UqJO/xeEL0YtjYyCKvp4r5MXnA8s2LzWXrSfqAtiu8KpOVeac2yiFu xZiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=qRkzpYU8; 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 y8-v6si4575709pli.242.2018.05.16.23.23.48; Wed, 16 May 2018 23:23:48 -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=qRkzpYU8; 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 S1752174AbeEQGTS (ORCPT + 29 others); Thu, 17 May 2018 02:19:18 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:24995 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750826AbeEQGTQ (ORCPT ); Thu, 17 May 2018 02:19:16 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4H6HbUB002841; Thu, 17 May 2018 15:17:51 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4H6HbUB002841 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1526537871; bh=AhHOPEC5Ia8wokTIBaVdLUk6EnhwEj+yWpUTa9SDN/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qRkzpYU8zJx+iOuI1p42YNqJNx2XkXzs4qvtGNVmPWh8mppWDvtoqRJ+YR/z9JuWB /yEYnDc0AGdapjo2vdsKp+YlWHjwERER7VDmI7kKCp1+Gca3u+wG6jrqbMuQ4X9Sl/ 9491W/HzXS1QlB01nKdUPIF5FdnUi8j7d7GyxcIyS4pvUwFjZ2rOD76g7Hfd31u34v 2nORY0ZJEp/Vb1k06TqCdwLxpUAh7BWEb47yv2wMX1EbuHuvxPWTWAY2XkcTL/bPVZ KQvNS5P5GDpM9PCCR1wc10JwEOMjMZJAUsjusccPCnPhFHA3KNB2uD7hfA9IEhAxF7 zcGLJa4xFtWIA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Linus Torvalds , Sam Ravnborg , Ulf Magnusson , "Luis R . Rodriguez" , linux-kernel@vger.kernel.org, Nicholas Piggin , Kees Cook , Emese Revfy , x86@kernel.org, Masahiro Yamada Subject: [PATCH v4 13/31] kconfig: support append assignment operator Date: Thu, 17 May 2018 15:16:52 +0900 Message-Id: <1526537830-22606-14-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526537830-22606-1-git-send-email-yamada.masahiro@socionext.com> References: <1526537830-22606-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 v4: None 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 5d7bd9d..47b32dc 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -208,6 +208,7 @@ static LIST_HEAD(variable_list); struct variable { char *name; char *value; + enum variable_flavor flavor; struct list_head node; }; @@ -250,18 +251,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 {