Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2144028imm; Mon, 28 May 2018 02:30:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpURWFpROOvhuX6lDIwu53KKnuqrvXeZT5nrTkDFr92SGoc1OlKoV+ZEOmBMCBPRTl0X9SU X-Received: by 2002:a17:902:3081:: with SMTP id v1-v6mr13209154plb.266.1527499846379; Mon, 28 May 2018 02:30:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527499846; cv=none; d=google.com; s=arc-20160816; b=IDZKeAaF5cyUrno7DaGM5lpnvHJiqAlh5XEgGHLmrtgaIwRYBTB4Uy+/XD0vdimhQN Il38bkZD9pLUOWC7uDq7UytAoWZPSHIDoOo+rge5f/YdZSz0W88w8n/qxT9Rm8gdBELb S1A5br9ql/hDJZ3g4BmKgr8OXz7zcZmGJQmgp9fp9saJHUGCsSBOwneDLxcv2jbV+9i5 Ofp+7Mw4N45if4rhmrasESziltZNapc/tkT545V3PA057x4kZ7yscRhGxZ6PAR6sTM6e VKgCVM+Y8tGvUDh+FInT+4uRhIrOujYvCqTnGD4G0QVCwleJTuLgkhM24s5MNML+05U4 SAqQ== 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 n7-v6si7156877pgu.362.2018.05.28.02.30.31; Mon, 28 May 2018 02:30:46 -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 S1754237AbeE1J3U (ORCPT + 99 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(+) 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 -- 2.7.4