Linux-KBuild Archive mirror
 help / color / mirror / Atom feed
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	[thread overview]
Message-ID: <20230801174922.333700-3-bmasney@redhat.com> (raw)
In-Reply-To: <20230801174922.333700-1-bmasney@redhat.com>

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

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


  parent reply	other threads:[~2023-08-01 17:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-01 17:49 [PATCH 0/2] scripts: add two new scripts to look up Kconfigs Brian Masney
2023-08-01 17:49 ` [PATCH 1/2] scripts: add mod-to-kconfig.sh Brian Masney
2023-08-01 17:49 ` Brian Masney [this message]
2023-08-03  6:23   ` [PATCH 2/2] scripts: add kconfig lookup script Masahiro Yamada
2023-08-03 10:14     ` Brian Masney
2023-08-06 12:45       ` Masahiro Yamada
2025-07-27 18:38     ` Randy Dunlap
2025-07-29 14:03       ` Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230801174922.333700-3-bmasney@redhat.com \
    --to=bmasney@redhat.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).