From patchwork Mon May 28 09:21:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 137066 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2597225lji; Mon, 28 May 2018 02:30:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqc4oCpezBYMXcO7j+ndAr0U+4Dg96jNO4H1IPhUVDNUUgQupuy1AkfMyRdzdf1ydWL9V4H X-Received: by 2002:a63:5f12:: with SMTP id t18-v6mr9733220pgb.81.1527499858441; Mon, 28 May 2018 02:30:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499858; cv=none; d=google.com; s=arc-20160816; b=CMtDIHhdbK/nzpSwGQdxi/VruEPw1sXoJyw5sPJLKCsqWDtjXqr1B1dGXcVAZJ7I5O ps3tqYdAc1nQKbQw0MdJCPoL6Cw4fA51xEcLMt3gOkE7FRjW77jLPIb/sMBFNI2dc+uG 3HVmzvMOh0o20EONhsX+DRGMPZijze4NazC9sw3Qs2M3n7I/R+eKtqFNlfm9vFu6KNYc EFbHVfWjnJrxhe3w5XRAtzYl/fPKbdbwjs0UgfCVrKTWvvwP01Ln+LQVIrRFYJuMpdsC UuHawOCDZHgy7KFOMbruYERaKDZ74QHOem9l6wTZ32JGmXy0DCsDsKP+KOvXiNhN+dsd HPkg== 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 o89-v6si4601785pfi.165.2018.05.28.02.30.58; Mon, 28 May 2018 02:30: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 S1754546AbeE1Jaz (ORCPT + 30 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(-) -- 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 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 {