Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2144728imm; Mon, 28 May 2018 02:31:45 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo3BQ1O6CWY9Y0uFAMXhk6RxHAWmjX5h73B4H9MK8dyi8e9rude8Il6mYqGaiyLxqQcionX X-Received: by 2002:a62:f80c:: with SMTP id d12-v6mr12785653pfh.159.1527499905710; Mon, 28 May 2018 02:31:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499905; cv=none; d=google.com; s=arc-20160816; b=x/INT32hjGf3kGdwoShFAFei8x38dMULjWW7fdG2VhCZOlQ/c/7dlirYOuCPkmPi/R PEdn2e46zlC+2SX2u6M/L9c5yhzVC7ga0csyqjn8jgKb+QBJe5tqE0MWfdcIfg102nMk roNkRKcql2e2jr1D7dQkxJkfvmJ38N5zVL92LGXAMVxTt9v0wm+eXfhYdCIzX51W0hN5 1ZyPRLPzu+qGkC42Y9p7Pk9uev23ePs0+P0GuPp/NPtpWskq9x/V25auBFdivykWKNH1 Vv/UVANpyIbktiircE6RYJ2q/Im7My4t0aJWFbdu4J9WOrOeFr69G2/tTiT1mxZuSmlC RmCg== 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=eZ7Dn7/LEJcOdurXvi4kEK8PWh0jBitZmbMz5stFI3s=; b=iS+xFhfXtzsMmYvFBwLktafONN/FeLKtd7Lc02GVqO07c1ao9xNG9nm5mIeO2NYK+h SduKP14SHWidK227BXsd/yiohZ3OEjRpyTp74FGV7+l9QpnKHb9usKeAxaTEbBotIgZe YcCMG/LE/RuIKdEmWI6xXYP6LoS/coDgz7fVmkdu7F9FR5e9HgrUiNoaURoZXohMOTt0 HHPV69IGlOID8Zxdt/LEbtAFooyG6cQt+EVnLxGs3nvGGmN5OO8k4si1bEykWDcEH02a jdcltMVY0m9sfnv5JYgG3igUH537A/H5a+KMdMs52Y90zsdJws682O0OWgmzVR83wFB2 QXWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=o9WL31Gd; 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 f4-v6si23261643pgs.16.2018.05.28.02.31.31; Mon, 28 May 2018 02:31:45 -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=o9WL31Gd; 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 S1754303AbeE1JYO (ORCPT + 99 others); Mon, 28 May 2018 05:24:14 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21449 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754133AbeE1JYM (ORCPT ); Mon, 28 May 2018 05:24:12 -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 w4S9MInU027506; Mon, 28 May 2018 18:22:29 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInU027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499350; bh=eZ7Dn7/LEJcOdurXvi4kEK8PWh0jBitZmbMz5stFI3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o9WL31GdIVXbbhLQbc2bn+fT3GL477ZNVXsohtcil5Yu3yzOhkMaBD9iyTuwAIhUy iU5W4OLWqkHsTLvzL/i+OWucqFx7l1ndTThuZ9YdTZtT+vphVhUIUjt3oilD73WWlp nCmzSDH1sO7kKY/f1kEh1ql28sncWhpfKYa3ywsiFAps66KsjxEtsT8ZuhVFLjQceM 4bU3q2cMwM2PgOda7WT7ATtvqcDnCqTMuyq5D2VPIHtiqraoVtOBpw5HH4vJmFIvPj PZlYC3fJHwW/QGJr6wcCneTY2Urb2hPwgg5RVXrFlf2xb3sZooNKbLwOV1TCxY8sDQ 5RBjsvo6ZzQ1A== 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 13/31] kconfig: support simply expanded variable Date: Mon, 28 May 2018 18:21:50 +0900 Message-Id: <1527499328-13213-14-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 The previous commit added variable and user-defined function. They work similarly in the sense that the evaluation is deferred until they are used. This commit adds another type of variable, simply expanded variable, as we see in Make. The := operator defines a simply expanded variable, expanding the righthand side immediately. This works like traditional programming language variables. Signed-off-by: Masahiro Yamada --- Changes in v5: - Fix multiple expansion bug of simple variables Changes in v4: None Changes in v3: - newly added Changes in v2: None scripts/kconfig/lkc_proto.h | 7 ++++++- scripts/kconfig/preprocess.c | 19 ++++++++++++++++--- scripts/kconfig/zconf.l | 3 ++- scripts/kconfig/zconf.y | 5 +++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 2b16d6e..6303193 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -49,8 +49,13 @@ const char * sym_get_string_value(struct symbol *sym); const char * prop_get_type_name(enum prop_type type); /* preprocess.c */ +enum variable_flavor { + VAR_SIMPLE, + VAR_RECURSIVE, +}; void env_write_dep(FILE *f, const char *auto_conf_name); -void variable_add(const char *name, const char *value); +void variable_add(const char *name, const char *value, + enum variable_flavor flavor); void variable_all_del(void); char *expand_string(const char *in); char *expand_dollar(const char **str); diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 46487fe..d103683 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -185,6 +185,7 @@ static LIST_HEAD(variable_list); struct variable { char *name; char *value; + enum variable_flavor flavor; struct list_head node; }; @@ -203,15 +204,22 @@ static struct variable *variable_lookup(const char *name) static char *variable_expand(const char *name, int argc, char *argv[]) { struct variable *v; + char *res; v = variable_lookup(name); if (!v) return NULL; - return expand_string_with_args(v->value, argc, argv); + if (v->flavor == VAR_RECURSIVE) + res = expand_string_with_args(v->value, argc, argv); + else + res = xstrdup(v->value); + + return res; } -void variable_add(const char *name, const char *value) +void variable_add(const char *name, const char *value, + enum variable_flavor flavor) { struct variable *v; @@ -224,7 +232,12 @@ void variable_add(const char *name, const char *value) list_add_tail(&v->node, &variable_list); } - v->value = xstrdup(value); + v->flavor = flavor; + + if (flavor == VAR_SIMPLE) + v->value = expand_string(value); + else + v->value = xstrdup(value); } static void variable_del(struct variable *v) diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index dd08f7a..376af6c 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l @@ -114,7 +114,8 @@ n [A-Za-z0-9_-] yylval.string = text; return T_VARIABLE; } - "=" { BEGIN(ASSIGN_VAL); return T_ASSIGN; } + "=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_RECURSIVE; return T_ASSIGN; } + ":=" { BEGIN(ASSIGN_VAL); yylval.flavor = VAR_SIMPLE; return T_ASSIGN; } [[:blank:]]+ . warn_ignored_character(*yytext); \n { diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index e15e8c7..6f9b0aa 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -41,6 +41,7 @@ static struct menu *current_menu, *current_entry; struct expr *expr; struct menu *menu; const struct kconf_id *id; + enum variable_flavor flavor; } %token T_MAINMENU @@ -78,7 +79,7 @@ static struct menu *current_menu, *current_entry; %token T_OPEN_PAREN %token T_EOL %token T_VARIABLE -%token T_ASSIGN +%token T_ASSIGN %token T_ASSIGN_VAL %left T_OR @@ -517,7 +518,7 @@ word_opt: /* empty */ { $$ = NULL; } /* assignment statement */ -assignment_stmt: T_VARIABLE T_ASSIGN assign_val T_EOL { variable_add($1, $3); free($1); free($3); } +assignment_stmt: T_VARIABLE T_ASSIGN assign_val T_EOL { variable_add($1, $3, $2); free($1); free($3); } assign_val: /* empty */ { $$ = xstrdup(""); }; -- 2.7.4