From patchwork Mon May 28 09:21:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 137059 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp2595675lji; Mon, 28 May 2018 02:29:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLjvFTOPQTC2zz7EEORlZccPWNkrO58sy6UbbdqsqDe0WGcMu5haKjgJ/oDQWajhv0mSvXH X-Received: by 2002:a17:902:7105:: with SMTP id a5-v6mr4651366pll.171.1527499762712; Mon, 28 May 2018 02:29:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499762; cv=none; d=google.com; s=arc-20160816; b=AJVIrwme5UY/vxW5ueY4BpkNLW0+L1adysJHJclCJ7ExAplBg/gnA/rBEd6W+ROohM nk9T9BeBrP0/iuXi4vYI+E3iw5Jer3jwICxsNAA63bRrHCwoSViMkPZYfkK7ava9md/o 3/8yuqzUtX+ICjERHain83kyRG5Hg3QhXGidwzKQK6MONc1ftUEBy8hbK6NNbP1Fgh2i qietZL7WGA8hsvU6/0dEcDRPobjbHXtn5fb5vMJnPxtRR3oWTsf+WAegOatm8K/AEMKy jarH9yHXgifrxSW1g/NJwhcX9wG1Z5yp+UIY8gHrSOn5EYKS3D93HK9ZibRTw9yMzeXe 3jZA== 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=Ya/ZQhKy1YAggohbHXRbgTgfcGxUazykAPfdK9IVmIk=; b=j0ccEtsXvdWERBN3IrEqDvn6IupT43FdgzDGZXMGlJvMqrwuWur+JijkwtVwXVaxW2 IyMneZ3rDkLtHYOWtRtAP4kBSD+87d8PYPSrRLpmaSJiLQhsTamYr5CqCePtLHttW6fu 8dub5Fp5PNOrfl5XUuFdQ7GcGhwcqdU1DgA0AOhp0qrQSL4jVeZpvN0R7JVm3t+BRflJ +pf958Ro4EsUeHzGtYmEfRv50IPJX7gu/KTH3VE9BwrtEVPYS/8lLVxhBkli3eVdlujF xFbD7tT65WOX+n05jxPlRPg+yEJQbaceCfz1d4F5v8kx/Nn7nfwn1nGATEgSWGghzIsU TmrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=qzy0I94i; 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 v34-v6si1641930plg.524.2018.05.28.02.29.22; Mon, 28 May 2018 02:29:22 -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=qzy0I94i; 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 S1754271AbeE1J3U (ORCPT + 30 others); Mon, 28 May 2018 05:29:20 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:21621 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754326AbeE1JYQ (ORCPT ); Mon, 28 May 2018 05:24:16 -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 w4S9MInQ027506; Mon, 28 May 2018 18:22:26 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4S9MInQ027506 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527499347; bh=Ya/ZQhKy1YAggohbHXRbgTgfcGxUazykAPfdK9IVmIk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qzy0I94igBSBLc9C9py76RvAvxU+F1XH82NfMz1Sfz8c0nP7FtTdo8q5SDBBIvrN1 DqIUms4vLXQ0lRFBZ/20NTtxiLr642LCFY7Joi1piymxnsHaS8rjLjQ8pJX7+paFiq Ih+52aWMkmTkNtMhYn3dYUEKt5HFKJtSQK3wrSixaI3JicX7dAxKtcJyG4DHXGQCaV eMJ3iJa7hL7n3gGW3wCBZn3a4ce2mm9i69MjoLXL+KI9DEDj7fLW+8k4smTsr4Z3c2 5U5Y9MhT7W/bQ5LJM2dHODEVKArCvluC3iA3REPODh7aqi/H/rU2L/i16pYLiX0Py2 yqN1jmFv946BA== 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 09/31] kconfig: add 'shell' built-in function Date: Mon, 28 May 2018 18:21:46 +0900 Message-Id: <1527499328-13213-10-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 This accepts a single command to execute. It returns the standard output from it. [Example code] config HELLO string default "$(shell,echo hello world)" config Y def_bool $(shell,echo y) [Result] $ make -s alldefconfig && tail -n 2 .config CONFIG_HELLO="hello world" CONFIG_Y=y Caveat: Like environments, functions are expanded in the lexer. You cannot pass symbols to function arguments. This is a limitation to simplify the implementation. I want to avoid the dynamic function evaluation, which would introduce much more complexity. Signed-off-by: Masahiro Yamada --- Changes in v5: None Changes in v4: - Accept only one argument to simplify the implementation Changes in v3: None Changes in v2: None scripts/kconfig/preprocess.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) -- 2.7.4 diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index f32a496..528be59 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -106,8 +106,49 @@ struct function { char *(*func)(int argc, char *argv[]); }; +static char *do_shell(int argc, char *argv[]) +{ + FILE *p; + char buf[256]; + char *cmd; + size_t nread; + int i; + + cmd = argv[0]; + + p = popen(cmd, "r"); + if (!p) { + perror(cmd); + exit(1); + } + + nread = fread(buf, 1, sizeof(buf), p); + if (nread == sizeof(buf)) + nread--; + + /* remove trailing new lines */ + while (buf[nread - 1] == '\n') + nread--; + + buf[nread] = 0; + + /* replace a new line with a space */ + for (i = 0; i < nread; i++) { + if (buf[i] == '\n') + buf[i] = ' '; + } + + if (pclose(p) == -1) { + perror(cmd); + exit(1); + } + + return xstrdup(buf); +} + static const struct function function_table[] = { /* Name MIN MAX Function */ + { "shell", 1, 1, do_shell }, }; #define FUNCTION_MAX_ARGS 16