Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2144889imm; Mon, 28 May 2018 02:31:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqYCkvBzD4RQqwnmjNajySaoR++GbUA9hcEvLS/22tUv2lFaSc18+B7e2NrRsAXkcE5aYm4 X-Received: by 2002:a17:902:205:: with SMTP id 5-v6mr12597295plc.301.1527499918478; Mon, 28 May 2018 02:31:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499918; cv=none; d=google.com; s=arc-20160816; b=j7UjNF6G6myKQRNYLhusxEWW2gwa+KAaS9/X7xKqNmq1rZ4UJSv/mZ6f2nFPfofPaX yN3ixNDNqx+yLK06n/T6WvF2iLzrlcjOwWivSHEmHkTBpNm71zE45R+CIMhA07H+WpqP OjQvkUQ3PcJFxzbZT2D+ULP5UkivwKE8lXLSlUPl4VzTOZsUOB6gtH3AODjb/VriOweK +Hlw8wuFpyYkZCek/bK9kZ/JNFV57DrBZxUqpCissxDahlSFBIyYEjmeYVBFoNHpsYsc 0KuMxwa5U83n/468es1Jqpd2uys1B3ZsT4oD4/bBg8nr6S7Ze0ejnBtBBeoeiP0jiLHj +6+g== 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=3oQUZQmz3ZbFWUKPhXIaBpGvdPd2p7aJebc3HxGnsy4=; b=gedxDEr9OskFOIg6CZKiNLstpU6+Ojr89QVTqhR+XoVn1P16mHWR/kL8FIWgXF7zli u2xoQQi/D00NdX60P3kDEkdIQiDGjzAFjRSzqtTMWUrnjBk9ocqvy7hHXZi+vJJVaakT Z8qF+HmmcpzLoxewBG97o1/cU5izBJh6mqobcQMjzPFGRqjgZbORsb1HM1NlWbar+O+w NzJUX4ksuIwtYlRniVb1fU5ug+jXSvIraWFCCDnvoBvYuXHyln9VI3Uwvq67wXeSgWqF jvoDQU8DRtbGKxZWN4RvKqVtUR+lxTEs/DdYCibWcWh3WYX9lIkjv48CXpiMsD0fb5pD oDew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=Pkj70tln; 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 91-v6si29442284ply.55.2018.05.28.02.31.43; Mon, 28 May 2018 02:31:58 -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=Pkj70tln; 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 S1754537AbeE1Jaz (ORCPT + 99 others); Mon, 28 May 2018 05:30:55 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21512 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754219AbeE1JYO (ORCPT ); Mon, 28 May 2018 05:24:14 -0400 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4S9MInV027506; Mon, 28 May 2018 18:22:30 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInV027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499351; bh=3oQUZQmz3ZbFWUKPhXIaBpGvdPd2p7aJebc3HxGnsy4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pkj70tlnqR8w6Ez0EADseBu0P8neHXTjSeyOaiViIAr6tTsJF8ZrZS2ATU7H74+2l pWsxwW9gcGb2N4FaFU2F/uINE4ZaJ2aVU6pno6sIq+NXTWvYScxIXY8VB3jVMaEai6 sXfEomZuN1L5hJQ0vcFCrYgAfn7D2//BxC6Vm1mY7rdzIaniZrdQZIAi8xTrCD4IDT NNSMaabHMQNTK0zL7NM3p+JGrJHQsAp1A0rjTNqFWGt/54QoV/A77vgA5vpj5LnGML /NUeDkMrlTI7N+aeRB4UGkI9o55u8pKZ9RubFQ+Ebm3XIzAlG5r0td252d2XZJCwuO vDABnsFymCGZg== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Kees Cook , Nicholas Piggin , "Luis R . Rodriguez" , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Linus Torvalds , Masahiro Yamada Subject: [PATCH v5 14/31] kconfig: support append assignment operator Date: Mon, 28 May 2018 18:21:51 +0900 Message-Id: <1527499328-13213-15-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1527499328-13213-1-git-send-email-yamada.masahiro@socionext.com> References: <1527499328-13213-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 v5: None Changes in v4: None Changes in v3: - newly added Changes in v2: None scripts/kconfig/lkc_proto.h | 1 + scripts/kconfig/preprocess.c | 28 +++++++++++++++++++++++++--- scripts/kconfig/zconf.l | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) 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 d103683..56aa1f0 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -222,11 +222,23 @@ 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); @@ -235,9 +247,19 @@ void variable_add(const char *name, const char *value, v->flavor = flavor; if (flavor == VAR_SIMPLE) - v->value = expand_string(value); + new_value = expand_string(value); else - v->value = xstrdup(value); + new_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 376af6c..a6cbe2d 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 { -- 2.7.4