Received: by 10.223.185.116 with SMTP id b49csp1490298wrg; Fri, 16 Feb 2018 22:07:41 -0800 (PST) X-Google-Smtp-Source: AH8x226eEune+oCEJd33OKNXhe7saFcVEw/6C7Rr7IcX3SIO3cGxLWbOeDOLn0jPmWgVfXKb8UXa X-Received: by 10.99.127.29 with SMTP id a29mr6937538pgd.451.1518847661424; Fri, 16 Feb 2018 22:07:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518847661; cv=none; d=google.com; s=arc-20160816; b=xynLxPnE8RqH9TZ1KeKfaVes33h8CDQNLFFsPazPB1QflRSIwL3+NMHZKpl3Dp/Fgl BWAQFrOI7QIA6yuvLE3e+cdRi4Sdia16EKIQxgkzKwuvC5wbpBaesg6NBZ5t0WKBSEYE rBGh8O8PCoXwu9UMG6yPtXVZk/WYabn1WfQ2Y5r77maN52XGSs3TjPGfuvkcS4GKqEQw KaQ3bRmxXDvE/nVnYQUB/SJmDg/3vu2ofzlZaaMqHSOOyfme47YctT+BvsHwCS1c0x6L TN8Tl2XPLWkLLFdeWqHXB6o1hxcv+Rh2I0SyTj55WqB7h01j68odjWXf6132tkrwlqww TqZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=J4Qa4XFD2FFmHbaZiYkxNatPKzUSIjvobSP1JFRm838=; b=mZNBowpj+dwBOkv4r4ZA3fSuUsyNzLhZM03zE2u7D7aCZoIQLBJ8Fq+RQoY0HhOfgh iKL7wQQEqEnO/y4Yu002eFq/MyXHzpOImV1PntHk4TJy6XMMSNSaf2hnnHY9TY8PPHMZ IJSEVM9fHGxHHj0XAYs05I08djtD4YriQ5mwOyPTOir4s9ZQUMJ4QYSounWIdtrvJi8q mSHVfl4iTQ+pvD2LmPJ3CY9ydv7GjlGKp6N6Er+yFS9s9nMb47m0iRSwP37Yqx9ysNlA VjtO9pNSFPp/BxXuMdpmaUlpUfwuUyW81RJrtRFYvzUXN9bBKWSuucr/9OINqF+PIlNj dvKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uF47xfAV; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x9-v6si1421727pll.229.2018.02.16.22.07.25; Fri, 16 Feb 2018 22:07:41 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=uF47xfAV; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751035AbeBQGGq (ORCPT + 99 others); Sat, 17 Feb 2018 01:06:46 -0500 Received: from mail-lf0-f41.google.com ([209.85.215.41]:34968 "EHLO mail-lf0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750951AbeBQGGo (ORCPT ); Sat, 17 Feb 2018 01:06:44 -0500 Received: by mail-lf0-f41.google.com with SMTP id 70so751136lfw.2; Fri, 16 Feb 2018 22:06:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=J4Qa4XFD2FFmHbaZiYkxNatPKzUSIjvobSP1JFRm838=; b=uF47xfAVdGEvS/4WDYPybcgpnJx1liJe+SyHWsXQQPfMoeofS2KZBh5DhurnSUA2YO Nm9RSq+lWxovLEAztG1mG3MYvQ8MgPo0FHAP/cGM372zCtmBrqQ1M+vFQvZGF0UukU0f 6+B/ba8aglMnjSKWEEZ3X2INVCMNpsSGPcAMXKfB/oLuvROZRSEa3bg+pGp2a1bQEvlu znTqfeleUfj0k3ae0ZWEl6qCDagvQa2/q0DRNlQgqQpF9Ihlf+RgamgPGnaJ8fngrMV2 jiUj1N+c5LvsAwKBdz6oFlPw76dk7J7TtY/gcDKTzEpbAAeWQliyySXOZz6KEkV/D05A mZaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=J4Qa4XFD2FFmHbaZiYkxNatPKzUSIjvobSP1JFRm838=; b=jCHef9xnwWWsRcdOGj1ZJIS/RcOsyjEu0SWcDkYH31J11hl0DS7aARcL3tV2RUkxth V7uYTFLpyqzWBg4P6urIMolkBNJn+vs1ODwJuxGl3jZkjDdsncf3KsQ6C51fM+UilJaL 0f/WzE3+888AKdS/LNXRXS+X5Z8hIVxgaZbOCBCTnjAJgmrh/3RyHR1W6Rvo8HhxxW+Z 45sg803FvFcStqw7bT59jA22PudC40afe9mkMZJlladUtQx+z0JfVmzvdSW5jZ/XjgTL Au756MTbnj44Hghqh4Tizr1Ck/kz+bR2CeZ+tlvANgL51JfaRJshpN8ZXXYp6neqUEIv URvw== X-Gm-Message-State: APf1xPAlyNIrMaJCBP/zgyoQ0gi/YM+u/Kx5y7Ksq1H5JzJY7fGuZ6Wh 16Fd299Fsgb6MpTTRRUtsYU= X-Received: by 10.25.165.81 with SMTP id o78mr5824472lfe.77.1518847602527; Fri, 16 Feb 2018 22:06:42 -0800 (PST) Received: from huvuddator (ua-213-113-106-221.cust.bredbandsbolaget.se. [213.113.106.221]) by smtp.gmail.com with ESMTPSA id a3sm2255325ljd.80.2018.02.16.22.06.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 16 Feb 2018 22:06:41 -0800 (PST) Date: Sat, 17 Feb 2018 07:06:39 +0100 From: Ulf Magnusson To: Nicolas Pitre Cc: Masahiro Yamada , Linux Kbuild mailing list , Linus Torvalds , Greg Kroah-Hartman , Arnd Bergmann , Kees Cook , Randy Dunlap , Sam Ravnborg , Michal Marek , Linux Kernel Mailing List Subject: Re: [PATCH 08/23] kconfig: add 'macro' keyword to support user-defined function Message-ID: <20180217060639.jfcrgzvemluatnmo@huvuddator> References: <1518806331-7101-1-git-send-email-yamada.masahiro@socionext.com> <1518806331-7101-9-git-send-email-yamada.masahiro@socionext.com> <20180216235138.b4p6q62auvnzb2sy@huvuddator> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 16, 2018 at 11:44:25PM -0500, Nicolas Pitre wrote: > On Sat, 17 Feb 2018, Ulf Magnusson wrote: > > > On Sat, Feb 17, 2018 at 3:30 AM, Nicolas Pitre wrote: > > > On Sat, 17 Feb 2018, Ulf Magnusson wrote: > > > > > >> On Fri, Feb 16, 2018 at 02:49:31PM -0500, Nicolas Pitre wrote: > > >> > On Sat, 17 Feb 2018, Masahiro Yamada wrote: > > >> > > > >> > > Now, we got a basic ability to test compiler capability in Kconfig. > > >> > > > > >> > > config CC_HAS_STACKPROTECTOR > > >> > > bool > > >> > > default $(shell $CC -Werror -fstack-protector -c -x c /dev/null -o /dev/null) > > >> > > > > >> > > This works, but it is ugly to repeat this long boilerplate. > > >> > > > > >> > > We want to describe like this: > > >> > > > > >> > > config CC_HAS_STACKPROTECTOR > > >> > > bool > > >> > > default $(cc-option -fstack-protector) > > >> > > > > >> > > It is straight-forward to implement a new function, but I do not like > > >> > > to hard-code specialized functions like this. Hence, here is another > > >> > > feature to add functions from Kconfig files. > > >> > > > > >> > > A user-defined function can be defined as a string type symbol with > > >> > > a special keyword 'macro'. It can be referenced in the same way as > > >> > > built-in functions. This feature was also inspired by Makefile where > > >> > > user-defined functions are referenced by $(call func-name, args...), > > >> > > but I omitted the 'call' to makes it shorter. > > >> > > > > >> > > The macro definition can contain $(1), $(2), ... which will be replaced > > >> > > with arguments from the caller. > > >> > > > > >> > > Example code: > > >> > > > > >> > > config cc-option > > >> > > string > > >> > > macro $(shell $CC -Werror $(1) -c -x c /dev/null -o /dev/null) > > >> > > > >> > I think this syntax for defining a macro shouldn't start with the > > >> > "config" keyword, unless you want it to be part of the config symbol > > >> > space and land it in .config. And typing it as a "string" while it > > >> > actually returns y/n (hence a bool) is also strange. > > >> > > > >> > What about this instead: > > >> > > > >> > macro cc-option > > >> > bool $(shell $CC -Werror $(1) -c -x c /dev/null -o /dev/null) > > >> > > > >> > This makes it easier to extend as well if need be. > > >> > > > >> > > > >> > Nicolas > > >> > > >> I haven't gone over the patchset in detail yet and might be missing > > >> something here, but if this is just meant to be a textual shorthand, > > >> then why give it a type at all? > > > > > > It is meant to be like a user-defined function. > > > > > >> Do you think a simpler syntax like this would make sense? > > >> > > >> macro cc-option "$(shell $CC -Werror $(1) -c -x c /dev/null -o /dev/null)" > > >> > > >> That's the most general version, where you could use it for other stuff > > >> besides $(shell ...) as well, just to keep parity. > > > > > > This is not extendable. Let's imagine that you might want to implement > > > some kind of conditionals some day e.g.: > > > > > > macro complex_test > > > bool $(shell foo) if LOCKDEP_SUPPORT > > > bool y if DEBUG_DRIVER > > > bool n > > > > I still don't quite get the semantics here. How would the behavior > > change if the type was changed to say string or int in some or all of > > the lines? > > I admit this wouldn't make sense to have multiple different types. In > this example, the bool keyword acts as syntactic sugar more than > anything else. > > > Since the current model is to evaluate $() while the Kconfig files are > > being parsed, would this require evaluating Kconfig expressions during > > parsing? There is a relatively clean and (somewhat) easy to understand > > parsing/evaluation separation at the moment, which I like. > > Agreed. Let's forget about the conditionals then. > > > Nicolas This is also related to why it feels off to me to (at least for its own sake) make macro definitions mimic symbol definitions. To me, parsing being a different domain makes it "okay" to use a different syntax for macros compared to symbol definitions, especially if it happens to be handier. It even makes things less confusing, because there's less risk of mixing up the two domains (it's rare to mix up the preprocessor with C "proper", since the syntax is so different). More practically, I'm not sure that macro foo "definition" would be that hard to extend in practice, if you'd ever need to. You could always add a new keyword: fancy-macro/function/whatever foo ... I admit it'd be a bit ugly if you'd ever end up with something like macro foo "definition" bit_ugly It's still not the end of the world though, IMO, and I suspect there'd be better-looking options if you'd need to extend things on the macro side. That macro syntax seems like the simplest possible thing to me, with no obvious major drawbacks. Keeping parsing and evaluation cleanly separated is more important than the exact syntax though. It's a bonus if symbols and macros stand out as coming from different universes to people reading the Kconfig. Cheers, Ulf