Message ID | 20230801174922.333700-3-bmasney@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2881261vqg; Tue, 1 Aug 2023 12:18:22 -0700 (PDT) X-Google-Smtp-Source: APBJJlGez885GxQcr/iLYSvlKOr9YBppm34DaDAYWgG7F609iIfPvXYuXb4MkHPP3iHQ8W87ojwC X-Received: by 2002:a17:902:b086:b0:1b1:9272:55f3 with SMTP id p6-20020a170902b08600b001b1927255f3mr10484342plr.66.1690917502422; Tue, 01 Aug 2023 12:18:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690917502; cv=none; d=google.com; s=arc-20160816; b=yMtN3e3Y5x/wVkYR6i8ZE5DMcjUvy1HQlqSR650DV8YE4Jcq/LNXwJ9ECiQ79cx+EW lM2qHrrPcp6BDlAqiclCFxyfX4G8ccDmGCx31sfSTlxth7NTJTqB6bYbWiE1t8VuLlGP ERrX00XJv3rsPT1dr+Ao9ddyimcgN+sgNBt48GbRoJ4Jy3DtNHbg95QvLHx6lSaLoxOq 4NKTdJ9SK6+lKhrvA4NWoxv1M2CAxajJ88LLQ7hiwv/ApbqanVHk8fzT526D0RU7sud9 EkeljZQj132xGy+KENQVWI6vDNcHo4cp0uMi02KeWRBtJe0vPtZFMACIrWuPRmFyDqEp mt3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=c9F/mZ8r3UfV+OIZ7ILNLdJAv9iDV2O+GTrVi9NsxDI=; fh=eDiNsT7Uv6uWvqt/f9p+kVzl1n6u5sWaKwIQIWQdpoo=; b=aud+mxZiNDltzyjUTcdybRRJkTiOMM4ggUedbK3cvtiB5V/CD1U46CQxgqFh6dKS/M 6IUqiD3seqT+ET0EjSfYpsoRHXC4Q05NXx8a2mS70zUQwOKVy+LuqTfwE3v1Ka+T/q+b ggbdmlmzpN/WWniWIrmuRfx5DK45EDF+LLhoQMx6SUSbQBq8pNJu7a4Dv2PANbjCyiHD LaaWKspDVTKLQRqRss64zHDMAb14TRIt3t3Q3q6HKJdpycCaYZusq5mBQrCVQoGkmYgW Y8RPi5RYcXd67bpBL5Q1S/6rC4yHa07hnZJerB2GiP1b8Wj6Wz2bX7wkMUflP6nw+vMt LsxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=a854x+ip; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t18-20020a170902e85200b001b9ea592e75si74554plg.265.2023.08.01.12.18.09; Tue, 01 Aug 2023 12:18:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=a854x+ip; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231668AbjHARul (ORCPT <rfc822;dengxinlin2429@gmail.com> + 99 others); Tue, 1 Aug 2023 13:50:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231945AbjHARue (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 1 Aug 2023 13:50:34 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 891931BF3 for <linux-kernel@vger.kernel.org>; Tue, 1 Aug 2023 10:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690912181; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c9F/mZ8r3UfV+OIZ7ILNLdJAv9iDV2O+GTrVi9NsxDI=; b=a854x+ipoUcRUHj/6jUUoa4Nno1vbX8u6v0DUANEYTTFxAEPciHfgxglpI+Kvtve8E9Nys 3ambPVg/pCwFMEl0QuE1fMnQxRBOWe2ZniJUE2ZmZTwe7hx1TuJXkZBW7Ipa6tHIqs6qS3 +YmkcMGP5Tj+oo7IWzLu4G/8GjE92CU= Received: from mail-yw1-f199.google.com (mail-yw1-f199.google.com [209.85.128.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-548-j6clVZ5uP4uzTBjZvZHBjA-1; Tue, 01 Aug 2023 13:49:39 -0400 X-MC-Unique: j6clVZ5uP4uzTBjZvZHBjA-1 Received: by mail-yw1-f199.google.com with SMTP id 00721157ae682-584375eacacso54367007b3.0 for <linux-kernel@vger.kernel.org>; Tue, 01 Aug 2023 10:49:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690912179; x=1691516979; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c9F/mZ8r3UfV+OIZ7ILNLdJAv9iDV2O+GTrVi9NsxDI=; b=Lt+aiPfUjPMKWsKgMbMu6LN/2fhnZLKFI3Awkctz2Ho1/Knh1B3if9FDAdNb8VIPXz nlj5ZdzJBYncCOTo0o7E5xcXaR7diVZgLo7RGSL2eO8R9djvcIOn+QC7qfYia9jsuslg Cejuucd8yUbAYv+z4k0Qo0bmoxcO3blHeWNBs4gTV4wO4OtGx313ol0Q0OQdbjadHTDp 2bGBLg/dL3bdZkSCum9Jk4Lfoi+qSrZ0MNKVMQI3nmcSuuALoInk/WC1F/I+6mtTJm6h gP75PdNC/X3FjsgqUH0r9jODgeKeuVh73Vf8eD/q3xvwqRu3mzWFvCsXcSlxETvYI1f+ m7yg== X-Gm-Message-State: ABy/qLYn2sPR/4X4n8GvEWweY1ObtACCeeK2i7HWX0CyrBGW718tnS6Q kjxWM8Zb5BPtvSRLl+8JazfWt/bjQCf3qzdDXFpi8Nb4NsfaVQZrKp7u+JzDKEVAnT3/+zIQCtt MkbYhMJLl61SeSr/Z7i7MVPVL X-Received: by 2002:a81:6c92:0:b0:583:d722:9ae9 with SMTP id h140-20020a816c92000000b00583d7229ae9mr11884616ywc.41.1690912179345; Tue, 01 Aug 2023 10:49:39 -0700 (PDT) X-Received: by 2002:a81:6c92:0:b0:583:d722:9ae9 with SMTP id h140-20020a816c92000000b00583d7229ae9mr11884609ywc.41.1690912179086; Tue, 01 Aug 2023 10:49:39 -0700 (PDT) Received: from brian-x1.. ([2600:381:222b:e67:295d:9324:c84:3382]) by smtp.gmail.com with ESMTPSA id k187-20020a0dc8c4000000b005773afca47bsm3881728ywd.27.2023.08.01.10.49.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Aug 2023 10:49:38 -0700 (PDT) From: Brian Masney <bmasney@redhat.com> To: masahiroy@kernel.org Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org Subject: [PATCH 2/2] scripts: add kconfig lookup script Date: Tue, 1 Aug 2023 13:49:22 -0400 Message-ID: <20230801174922.333700-3-bmasney@redhat.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230801174922.333700-1-bmasney@redhat.com> References: <20230801174922.333700-1-bmasney@redhat.com> MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773055510969527738 X-GMAIL-MSGID: 1773055510969527738 |
Series |
scripts: add two new scripts to look up Kconfigs
|
|
Commit Message
Brian Masney
Aug. 1, 2023, 5:49 p.m. UTC
Add a script that allows looking up the full Kconfig entry based on
the symbol name. Documentation and example usage is found at the top
of the script itself.
Signed-off-by: Brian Masney <bmasney@redhat.com>
---
scripts/kconfig/lookup.sh | 77 +++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
create mode 100755 scripts/kconfig/lookup.sh
Comments
On Wed, Aug 2, 2023 at 2:49 AM Brian Masney <bmasney@redhat.com> wrote: > > Add a script that allows looking up the full Kconfig entry based on > the symbol name. Documentation and example usage is found at the top > of the script itself. > > Signed-off-by: Brian Masney <bmasney@redhat.com> > --- > scripts/kconfig/lookup.sh | 77 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 77 insertions(+) > create mode 100755 scripts/kconfig/lookup.sh Everyone tends to have their own utility scripts on their machines. I think this patch set falls into that category as "create a wrapper script of grep" is what everyone does to reduce typing. FWIW, I have the following scripts in my ~/bin directory. $ cat ~/bin/kgrep #!/bin/sh exec find . -name .repo -prune -o -name .git -prune -o -type f \ \( -name 'Kconfig*' -o -name 'Config.in' \) \ -print0 | xargs -0 grep --color -n "$@" $ cat ~/bin/mgrep #!/bin/sh exec find . -name .repo -prune -o -name .git -prune -o -type f \ \( -name 'Makefile*' -o -name 'Kbuild*' -o -name "*.mk" \) \ -print0 | xargs -0 grep --color -n "$@" masahiro@zoe:~/ref/linux(master)$ kgrep -A5 TSL2772 ./drivers/iio/light/Kconfig:564:config TSL2772 ./drivers/iio/light/Kconfig-565- tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light and proximity sensors" ./drivers/iio/light/Kconfig-566- depends on I2C ./drivers/iio/light/Kconfig-567- help ./drivers/iio/light/Kconfig-568- Support for: tsl2571, tsl2671, tmd2671, tsl2771, tmd2771, tsl2572, tsl2672, ./drivers/iio/light/Kconfig-569- tmd2672, tsl2772, tmd2772 devices. masahiro@zoe:~/ref/linux(master)$ mgrep efivarfs.o ./fs/efivarfs/Makefile:6:obj-$(CONFIG_EFIVAR_FS) += efivarfs.o ./fs/efivarfs/Makefile:8:efivarfs-objs := inode.o file.o super.o vars.o That's my local way to satisfy my demand. I do not intend to force my way or merge it in the upstream. > > diff --git a/scripts/kconfig/lookup.sh b/scripts/kconfig/lookup.sh > new file mode 100755 > index 000000000000..d1ff52b23835 > --- /dev/null > +++ b/scripts/kconfig/lookup.sh > @@ -0,0 +1,77 @@ > +#!/usr/bin/env bash > +# SPDX-License-Identifier: GPL-2.0-only > +# > +# Copyright (C) 2023 Red Hat, Inc. All Rights Reserved. > +# Written by Brian Masney <bmasney@redhat.com> > +# > +# This script takes as input one or more Kconfig symbols and outputs the full > +# entry from the Kconfig file. It can be invoked by reading a list of symbol > +# names from either stdin or as command line arguments. Example output: > +# > +# x1:~/src/linux$ ./scripts/kconfig/lookup.sh TSL2772 SOUND > +# # drivers/iio/light/Kconfig > +# config TSL2772 > +# tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light and proximity sensors" > +# depends on I2C > +# help > +# Support for: tsl2571, tsl2671, tmd2671, tsl2771, tmd2771, tsl2572, tsl2672, > +# tmd2672, tsl2772, tmd2772 devices. > +# Provides iio_events and direct access via sysfs. > +# > +# # arch/um/drivers/Kconfig > +# config SOUND > +# tristate > +# default UML_SOUND > +# > +# # sound/Kconfig > +# menuconfig SOUND > +# tristate "Sound card support" > +# depends on HAS_IOMEM > +# help > +# If you have a sound card in your computer, i.e. if it can say more > +# than an occasional beep, say Y. > + > + > +process_kconfig() > +{ > + KCONFIG="${1/CONFIG_/}" > + > + FOUND=0 > + for KCONFIG_FILE in $(git grep -E "^(config|menuconfig) ${KCONFIG}$" | \ > + awk -F: '{print $1}') ; do > + echo "# ${KCONFIG_FILE}" > + awk "/^(config|menuconfig) ${KCONFIG}$/{ m=1; print; next; } \ > + /^(choice|comment|config|end|if|menuconfig|source)/ { m=0; } m" \ > + "${KCONFIG_FILE}" > + FOUND=1 > + done > + > + if [[ "${FOUND}" = "0" ]] ; then > + echo "Skipping ${KCONFIG} since Kconfig symbol is not found" >&2 > + return 1 > + fi > + > +} > + > +# Run this script from the toplevel kernel source directory. > +SCRIPT_PATH=$(readlink -f "$0") > +cd "$(dirname "${SCRIPT_PATH}")/../.." || exit 1 > + > +RET=0 > +if [[ $# == 0 ]] ; then > + # Read Kconfig names from stdin > + while read -r KCONFIG ; do > + if ! process_kconfig "${KCONFIG}" ; then > + RET=1 > + fi > + done > +else > + # Read Kconfig names from the command line arguments > + for NUM in $(seq 1 "$#") ; do > + if ! process_kconfig "${!NUM}" ; then > + RET=1 > + fi > + done > +fi > + > +exit "${RET}" > -- > 2.41.0 > -- Best Regards Masahiro Yamada
On Thu, Aug 03, 2023 at 03:23:16PM +0900, Masahiro Yamada wrote: > Everyone tends to have their own utility scripts > on their machines. > > I think this patch set falls into that category > as "create a wrapper script of grep" is what everyone > does to reduce typing. > > > > > FWIW, I have the following scripts in my ~/bin directory. > > > > $ cat ~/bin/kgrep > #!/bin/sh > > exec find . -name .repo -prune -o -name .git -prune -o -type f \ > \( -name 'Kconfig*' -o -name 'Config.in' \) \ > -print0 | xargs -0 grep --color -n "$@" > > > $ cat ~/bin/mgrep > #!/bin/sh > > exec find . -name .repo -prune -o -name .git -prune -o -type f \ > \( -name 'Makefile*' -o -name 'Kbuild*' -o -name "*.mk" \) \ > -print0 | xargs -0 grep --color -n "$@" > > > > > masahiro@zoe:~/ref/linux(master)$ kgrep -A5 TSL2772 > ./drivers/iio/light/Kconfig:564:config TSL2772 > ./drivers/iio/light/Kconfig-565- tristate "TAOS TSL/TMD2x71 and > TSL/TMD2x72 Family of light and proximity sensors" > ./drivers/iio/light/Kconfig-566- depends on I2C > ./drivers/iio/light/Kconfig-567- help > ./drivers/iio/light/Kconfig-568- Support for: tsl2571, tsl2671, > tmd2671, tsl2771, tmd2771, tsl2572, tsl2672, > ./drivers/iio/light/Kconfig-569- tmd2672, tsl2772, tmd2772 devices. > > masahiro@zoe:~/ref/linux(master)$ mgrep efivarfs.o > ./fs/efivarfs/Makefile:6:obj-$(CONFIG_EFIVAR_FS) += efivarfs.o > ./fs/efivarfs/Makefile:8:efivarfs-objs := inode.o file.o super.o vars.o > > > > That's my local way to satisfy my demand. > I do not intend to force my way or merge it in the upstream. OK, fair enough. Those are useful little utilities and simpler than what I posted. If something like these had been in the scripts/ directory, then I wouldn't have spent the time to write yet another script that does basically the same thing. I get what you are saying, however having a script to lookup a Kconfig by name or module will be useful to other people. Brian
On Thu, Aug 3, 2023 at 7:14 PM Brian Masney <bmasney@redhat.com> wrote: > > On Thu, Aug 03, 2023 at 03:23:16PM +0900, Masahiro Yamada wrote: > > Everyone tends to have their own utility scripts > > on their machines. > > > > I think this patch set falls into that category > > as "create a wrapper script of grep" is what everyone > > does to reduce typing. > > > > > > > > > > FWIW, I have the following scripts in my ~/bin directory. > > > > > > > > $ cat ~/bin/kgrep > > #!/bin/sh > > > > exec find . -name .repo -prune -o -name .git -prune -o -type f \ > > \( -name 'Kconfig*' -o -name 'Config.in' \) \ > > -print0 | xargs -0 grep --color -n "$@" > > > > > > $ cat ~/bin/mgrep > > #!/bin/sh > > > > exec find . -name .repo -prune -o -name .git -prune -o -type f \ > > \( -name 'Makefile*' -o -name 'Kbuild*' -o -name "*.mk" \) \ > > -print0 | xargs -0 grep --color -n "$@" > > > > > > > > > > masahiro@zoe:~/ref/linux(master)$ kgrep -A5 TSL2772 > > ./drivers/iio/light/Kconfig:564:config TSL2772 > > ./drivers/iio/light/Kconfig-565- tristate "TAOS TSL/TMD2x71 and > > TSL/TMD2x72 Family of light and proximity sensors" > > ./drivers/iio/light/Kconfig-566- depends on I2C > > ./drivers/iio/light/Kconfig-567- help > > ./drivers/iio/light/Kconfig-568- Support for: tsl2571, tsl2671, > > tmd2671, tsl2771, tmd2771, tsl2572, tsl2672, > > ./drivers/iio/light/Kconfig-569- tmd2672, tsl2772, tmd2772 devices. > > > > masahiro@zoe:~/ref/linux(master)$ mgrep efivarfs.o > > ./fs/efivarfs/Makefile:6:obj-$(CONFIG_EFIVAR_FS) += efivarfs.o > > ./fs/efivarfs/Makefile:8:efivarfs-objs := inode.o file.o super.o vars.o > > > > > > > > That's my local way to satisfy my demand. > > I do not intend to force my way or merge it in the upstream. > > OK, fair enough. > > Those are useful little utilities and simpler than what I posted. If > something like these had been in the scripts/ directory, then I > wouldn't have spent the time to write yet another script that does > basically the same thing. I get what you are saying, however having > a script to lookup a Kconfig by name or module will be useful to other > people. > > Brian > I do not want to fill the scripts/ directory with random trivial scripts. I need to draw a line between "the time cost for writing the code by myself" vs "the time cost for searching for a similar script". I'd rather write the code by myself if it is a script of a few lines.
diff --git a/scripts/kconfig/lookup.sh b/scripts/kconfig/lookup.sh new file mode 100755 index 000000000000..d1ff52b23835 --- /dev/null +++ b/scripts/kconfig/lookup.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0-only +# +# Copyright (C) 2023 Red Hat, Inc. All Rights Reserved. +# Written by Brian Masney <bmasney@redhat.com> +# +# This script takes as input one or more Kconfig symbols and outputs the full +# entry from the Kconfig file. It can be invoked by reading a list of symbol +# names from either stdin or as command line arguments. Example output: +# +# x1:~/src/linux$ ./scripts/kconfig/lookup.sh TSL2772 SOUND +# # drivers/iio/light/Kconfig +# config TSL2772 +# tristate "TAOS TSL/TMD2x71 and TSL/TMD2x72 Family of light and proximity sensors" +# depends on I2C +# help +# Support for: tsl2571, tsl2671, tmd2671, tsl2771, tmd2771, tsl2572, tsl2672, +# tmd2672, tsl2772, tmd2772 devices. +# Provides iio_events and direct access via sysfs. +# +# # arch/um/drivers/Kconfig +# config SOUND +# tristate +# default UML_SOUND +# +# # sound/Kconfig +# menuconfig SOUND +# tristate "Sound card support" +# depends on HAS_IOMEM +# help +# If you have a sound card in your computer, i.e. if it can say more +# than an occasional beep, say Y. + + +process_kconfig() +{ + KCONFIG="${1/CONFIG_/}" + + FOUND=0 + for KCONFIG_FILE in $(git grep -E "^(config|menuconfig) ${KCONFIG}$" | \ + awk -F: '{print $1}') ; do + echo "# ${KCONFIG_FILE}" + awk "/^(config|menuconfig) ${KCONFIG}$/{ m=1; print; next; } \ + /^(choice|comment|config|end|if|menuconfig|source)/ { m=0; } m" \ + "${KCONFIG_FILE}" + FOUND=1 + done + + if [[ "${FOUND}" = "0" ]] ; then + echo "Skipping ${KCONFIG} since Kconfig symbol is not found" >&2 + return 1 + fi + +} + +# Run this script from the toplevel kernel source directory. +SCRIPT_PATH=$(readlink -f "$0") +cd "$(dirname "${SCRIPT_PATH}")/../.." || exit 1 + +RET=0 +if [[ $# == 0 ]] ; then + # Read Kconfig names from stdin + while read -r KCONFIG ; do + if ! process_kconfig "${KCONFIG}" ; then + RET=1 + fi + done +else + # Read Kconfig names from the command line arguments + for NUM in $(seq 1 "$#") ; do + if ! process_kconfig "${!NUM}" ; then + RET=1 + fi + done +fi + +exit "${RET}"