Skip to contentSkip to conversation

kconfig: Add findconf script and helper program

PATCH In review Zev Weiss 3 participants 7 messages Jun 8, 2022 – Jun 10, 2022

Subsystems (2)
lore
Share & tools
lore

Zev Weiss

author
#0 lore raw

PATCH 1/1 kconfig: Add findconf script and helper program

scripts/findconf provides menuconfig's search functionality as a standalone, non-interactive command, somewhat in the spirit of scripts/config. It is meant to be useful for tasks like getting a quick overview of symbol dependencies or determining which Kconfig file to edit for a given symbol, without having to fire up one of the interactive config programs.

It accepts a single command-line flag, '-v', which causes it to also print the help text of each matching result.

---

This works a bit differently from [gmnq]conf in that it accepts (and requires) arguments, but I couldn't see an easy/obvious way of passing command-line args through the makefile infrastructure that invokes those, so the wrapper script passes things to it via environment variables instead. Suggestions welcome if there's a nicer way of achieving that.

 scripts/findconf           | 22 ++++++++++++
 scripts/kconfig/.gitignore |  1 +
 scripts/kconfig/Makefile   |  7 +++-
 scripts/kconfig/findconf.c | 74 ++++++++++++++++++++++++++++++++++++++
 scripts/kconfig/lkc.h      |  1 +
 scripts/kconfig/menu.c     |  2 +-
 6 files changed, 105 insertions(+), 2 deletions(-)
 create mode 100755 scripts/findconf
 create mode 100644 scripts/kconfig/findconf.c
scripts/findconf new file +22 -0
new file mode 100755
index 000000000000..c59132548082
@@ -0,0 +1,22 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Find Kconfig symbols matching one or more regexen.  Pass '-v' to
+# also show help text.
+
+if [ "$1" = "-v" ]; then
+	export FINDCONF_SHOW_HELP=1
+	shift
+fi
+
+if [ $# = 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
+	echo >&$(($# ? 1 : 2)) "Usage: $(basename $0) [-v] REGEX [REGEX ...]"
+	exit $((!$#))
+fi
+
+n=0
+for q in "$@"; do
+	export FINDCONF_QUERY_$((n++))="$q"
+done
+
+exec make findconfig
scripts/kconfig/.gitignore +1 -0
index 500e7424b3ef..a3ea0600c731 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 /conf
+/findconf
 /[gmnq]conf
 /[gmnq]conf-cfg
 /qconf-moc.cc
scripts/kconfig/Makefile +6 -1
index b8ef0fb4bbef..99e48b2d8563 100644
@@ -35,6 +35,7 @@ menuconfig-prog	:= mconf
 nconfig-prog	:= nconf
 gconfig-prog	:= gconf
 xconfig-prog	:= qconf
+findconfig-prog	:= findconf
 
 define config_rule
 PHONY += $(1)
@@ -45,7 +46,7 @@ PHONY += build_$(1)
 build_$(1): $(obj)/$($(1)-prog)
 endef
 
-$(foreach c, config menuconfig nconfig gconfig xconfig, $(eval $(call config_rule,$(c))))
+$(foreach c, config menuconfig nconfig gconfig xconfig findconfig, $(eval $(call config_rule,$(c))))
 
 PHONY += localmodconfig localyesconfig
 localyesconfig localmodconfig: $(obj)/conf
@@ -155,6 +156,10 @@ HOSTCFLAGS_parser.tab.o	:= -I $(srctree)/$(src)
 hostprogs	+= conf
 conf-objs	:= conf.o $(common-objs)
 
+# findconf: standalone non-interactive config-symbol search
+hostprogs	+= findconf
+findconf-objs	:= findconf.o $(common-objs)
+
 # nconf: Used for the nconfig target based on ncurses
 hostprogs	+= nconf
 nconf-objs	:= nconf.o nconf.gui.o $(common-objs)
scripts/kconfig/findconf.c new file +74 -0

74 lines not on this page · raw message

scripts/kconfig/lkc.h +1 -0
index fa8c010aa683..b4730f580dee 100644
@@ -102,6 +102,7 @@ struct menu *menu_get_root_menu(struct menu *menu);
 struct menu *menu_get_parent_menu(struct menu *menu);
 bool menu_has_help(struct menu *menu);
 const char *menu_get_help(struct menu *menu);
+void get_symbol_str(struct gstr *r, struct symbol *sym, struct list_head *head);
 struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head);
 void menu_get_ext_help(struct menu *menu, struct gstr *help);
 
scripts/kconfig/menu.c +1 -1
index 3d6f7cba8846..4b990c73e431 100644
@@ -800,7 +800,7 @@ static void get_symbol_props_str(struct gstr *r, struct symbol *sym,
 /*
  * head is optional and may be NULL
  */
-static void get_symbol_str(struct gstr *r, struct symbol *sym,
+void get_symbol_str(struct gstr *r, struct symbol *sym,
 		    struct list_head *head)
 {
 	struct property *prop;
Signature · 1 line
2.36.1
#1 lore raw

Hi--

Quoted 7 lines · Zev Weiss

scripts/findconf provides menuconfig's search functionality as a standalone, non-interactive command, somewhat in the spirit of scripts/config. It is meant to be useful for tasks like getting a quick overview of symbol dependencies or determining which Kconfig file to edit for a given symbol, without having to fire up one of the interactive config programs.

Quoted 5 lines

It accepts a single command-line flag, '-v', which causes it to also print the help text of each matching result.

---

I can see how this could be useful.
It's a little easier to use than what I currently do:

$ findconfig  DRM_HISI_HIBMC
./drivers/gpu/drm/hisilicon/hibmc/Kconfig:2:config DRM_HISI_HIBMC

then $EDITOR that_Kconfig_file

In testing, I am seeing this:

#

# using defaults found in /boot/config-5.3.18-150300.59.63-default
#
.config:421:warning: symbol value 'm' invalid for I8K
.config:2335:warning: symbol value 'm' invalid for MTD_NAND_ECC_SW_HAMMING
.config:2484:warning: symbol value 'm' invalid for PVPANIC
.config:8671:warning: symbol value 'm' invalid for INTERCONNECT
.config:9369:warning: symbol value 'm' invalid for CRYPTO_ARCH_HAVE_LIB_BLAKE2S
.config:9370:warning: symbol value 'm' invalid for CRYPTO_LIB_BLAKE2S_GENERIC
.config:9653:warning: symbol value '1' invalid for KASAN_STACK

How do I specify/choose a .config file to be used?

Oh, use KCONFIG_CONFIG=filename

Please update (add) usage/help text in scripts/kconfig/Makefile.

Quoted 8 lines

This works a bit differently from [gmnq]conf in that it accepts (and requires) arguments, but I couldn't see an easy/obvious way of passing command-line args through the makefile infrastructure that invokes those, so the wrapper script passes things to it via environment variables instead. Suggestions welcome if there's a nicer way of achieving that.

Quoted 10 lines
 scripts/findconf           | 22 ++++++++++++
 scripts/kconfig/.gitignore |  1 +
 scripts/kconfig/Makefile   |  7 +++-
 scripts/kconfig/findconf.c | 74 ++++++++++++++++++++++++++++++++++++++
 scripts/kconfig/lkc.h      |  1 +
 scripts/kconfig/menu.c     |  2 +-
 6 files changed, 105 insertions(+), 2 deletions(-)
 create mode 100755 scripts/findconf
 create mode 100644 scripts/kconfig/findconf.c

thanks.

Signature · 1 line
~Randy
author
#2 lore raw
Quoted 13 lines · Randy Dunlap

Hi--

Quoted 10 lines · Zev Weiss

scripts/findconf provides menuconfig's search functionality as a standalone, non-interactive command, somewhat in the spirit of scripts/config. It is meant to be useful for tasks like getting a quick overview of symbol dependencies or determining which Kconfig file to edit for a given symbol, without having to fire up one of the interactive config programs.

It accepts a single command-line flag, '-v', which causes it to also print the help text of each matching result.

Quoted 8 lines
Quoted 2 lines

---

I can see how this could be useful.
It's a little easier to use than what I currently do:

$ findconfig  DRM_HISI_HIBMC
./drivers/gpu/drm/hisilicon/hibmc/Kconfig:2:config DRM_HISI_HIBMC

I'm guessing 'findconfig' here is some personal shell alias/function/script? (I can't see any references to it in the kernel source tree.)

Quoted 7 lines

then $EDITOR that_Kconfig_file

In testing, I am seeing this:

#

Quoted 10 lines
# using defaults found in /boot/config-5.3.18-150300.59.63-default
#
.config:421:warning: symbol value 'm' invalid for I8K
.config:2335:warning: symbol value 'm' invalid for MTD_NAND_ECC_SW_HAMMING
.config:2484:warning: symbol value 'm' invalid for PVPANIC
.config:8671:warning: symbol value 'm' invalid for INTERCONNECT
.config:9369:warning: symbol value 'm' invalid for CRYPTO_ARCH_HAVE_LIB_BLAKE2S
.config:9370:warning: symbol value 'm' invalid for CRYPTO_LIB_BLAKE2S_GENERIC
.config:9653:warning: symbol value '1' invalid for KASAN_STACK

This I assume is just due to the contents of your .config file relative to the current Kconfig definitions and not a problem with anything in this patch?

Quoted 4 lines

How do I specify/choose a .config file to be used?

Oh, use KCONFIG_CONFIG=filename

Ah, I guess that'd be a nice thing to add a flag for to the wrapper script -- I'll include that in v2.

Quoted 3 lines

Please update (add) usage/help text in scripts/kconfig/Makefile.

Ack, will do.

Thanks for the review!

Zev

#3 lore raw
Quoted 17 lines · Zev Weiss
Quoted 16 lines · Randy Dunlap

Hi--

Quoted 12 lines · Zev Weiss

scripts/findconf provides menuconfig's search functionality as a standalone, non-interactive command, somewhat in the spirit of scripts/config.  It is meant to be useful for tasks like getting a quick overview of symbol dependencies or determining which Kconfig file to edit for a given symbol, without having to fire up one of the interactive config programs.

It accepts a single command-line flag, '-v', which causes it to also print the help text of each matching result.

---

Quoted 8 lines
Quoted 5 lines

I can see how this could be useful.
It's a little easier to use than what I currently do:

$ findconfig  DRM_HISI_HIBMC
./drivers/gpu/drm/hisilicon/hibmc/Kconfig:2:config DRM_HISI_HIBMC

I'm guessing 'findconfig' here is some personal shell alias/function/script?  (I can't see any references to it in the kernel source tree.)

Yes, it's just local.

Quoted 18 lines
Quoted 7 lines

then $EDITOR that_Kconfig_file

In testing, I am seeing this:

#

Quoted 10 lines
# using defaults found in /boot/config-5.3.18-150300.59.63-default
#
.config:421:warning: symbol value 'm' invalid for I8K
.config:2335:warning: symbol value 'm' invalid for MTD_NAND_ECC_SW_HAMMING
.config:2484:warning: symbol value 'm' invalid for PVPANIC
.config:8671:warning: symbol value 'm' invalid for INTERCONNECT
.config:9369:warning: symbol value 'm' invalid for CRYPTO_ARCH_HAVE_LIB_BLAKE2S
.config:9370:warning: symbol value 'm' invalid for CRYPTO_LIB_BLAKE2S_GENERIC
.config:9653:warning: symbol value '1' invalid for KASAN_STACK
Quoted 1 line

This I assume is just due to the contents of your .config file relative to the current Kconfig definitions and not a problem with anything in this patch?

There is no .config file in the linux/ source tree at the top level. I use O=build_dir for all builds.

Quoted 20 lines
Quoted 5 lines

How do I specify/choose a .config file to be used?

Oh, use KCONFIG_CONFIG=filename

Ah, I guess that'd be a nice thing to add a flag for to the wrapper script -- I'll include that in v2.

Quoted 3 lines

Please update (add) usage/help text in scripts/kconfig/Makefile.

Ack, will do.

Thanks for the review!

Zev

#4 lore raw
Quoted 55 lines · Randy Dunlap
Quoted 20 lines · Zev Weiss
Quoted 19 lines · Randy Dunlap

Hi--

Quoted 7 lines · Zev Weiss

scripts/findconf provides menuconfig's search functionality as a standalone, non-interactive command, somewhat in the spirit of scripts/config. It is meant to be useful for tasks like getting a quick overview of symbol dependencies or determining which Kconfig file to edit for a given symbol, without having to fire up one of the interactive config programs.

Quoted 5 lines

It accepts a single command-line flag, '-v', which causes it to also print the help text of each matching result.

---

I can see how this could be useful.
It's a little easier to use than what I currently do:

Quoted 7 lines
Quoted 2 lines
$ findconfig  DRM_HISI_HIBMC
./drivers/gpu/drm/hisilicon/hibmc/Kconfig:2:config DRM_HISI_HIBMC

I'm guessing 'findconfig' here is some personal shell alias/function/script? (I can't see any references to it in the kernel source tree.)

Yes, it's just local.

Quoted 21 lines
Quoted 20 lines

then $EDITOR that_Kconfig_file

In testing, I am seeing this:

#

# using defaults found in /boot/config-5.3.18-150300.59.63-default
#
.config:421:warning: symbol value 'm' invalid for I8K
.config:2335:warning: symbol value 'm' invalid for
MTD_NAND_ECC_SW_HAMMING
.config:2484:warning: symbol value 'm' invalid for PVPANIC
.config:8671:warning: symbol value 'm' invalid for INTERCONNECT
.config:9369:warning: symbol value 'm' invalid for
CRYPTO_ARCH_HAVE_LIB_BLAKE2S
.config:9370:warning: symbol value 'm' invalid for
CRYPTO_LIB_BLAKE2S_GENERIC
.config:9653:warning: symbol value '1' invalid for KASAN_STACK
Quoted 28 lines
Quoted 3 lines

This I assume is just due to the contents of your .config file relative to the current Kconfig definitions and not a problem with anything in this patch?

There is no .config file in the linux/ source tree at the top level. I use O=build_dir for all builds.

Quoted 21 lines
Quoted 5 lines

How do I specify/choose a .config file to be used?

Oh, use KCONFIG_CONFIG=filename

Ah, I guess that'd be a nice thing to add a flag for to the wrapper script -- I'll include that in v2.

Quoted 3 lines

Please update (add) usage/help text in scripts/kconfig/Makefile.

Ack, will do.

Thanks for the review!

Zev

Another idea might be to add the following to
scripts/kconfig/Makefile:

@@ -77,7 +76,13 @@ PHONY += $(simple-targets)
$(simple-targets): $(obj)/conf

        $(Q)$< $(silent) --$@ $(Kconfig)

-PHONY += savedefconfig defconfig
+PHONY += findconfig savedefconfig defconfig
+
+findconfig: $(obj)/conf
+ $(Q)$< $(silent) --$@=$(KCONFIG_FIND) $(Kconfig)
+
+%_findconfig: $(obj)/conf
+ $(Q)$< $(silent) --findconfig=$* $(Kconfig)

savedefconfig: $(obj)/conf

        $(Q)$< $(silent) --$@=defconfig $(Kconfig)

Instead of adding a separate program for this,
you can modify scripts/kconfig/conf.c

- add 'findconfig' to enum input_mode
- add 'findconfig' to long_opts[]
- add 'case findconfig' to main() function

Then, you can do

$ make findconfig KCONFIG_FIND=DRM_HISI_HIBMC

or

$ make DRM_HISI_HIBMC_findconfig

as a shorthand.

scripts/findconf is unneeded
but you can put your own script in ~/bin
if you want to save your typing even more.

Signature · 2 lines
Best Regards
Masahiro Yamada
author
#5 lore raw
Quoted 132 lines · Masahiro Yamada
Quoted 55 lines · Randy Dunlap
Quoted 20 lines · Zev Weiss
Quoted 19 lines · Randy Dunlap

Hi--

Quoted 7 lines · Zev Weiss

scripts/findconf provides menuconfig's search functionality as a standalone, non-interactive command, somewhat in the spirit of scripts/config. It is meant to be useful for tasks like getting a quick overview of symbol dependencies or determining which Kconfig file to edit for a given symbol, without having to fire up one of the interactive config programs.

Quoted 5 lines

It accepts a single command-line flag, '-v', which causes it to also print the help text of each matching result.

---

I can see how this could be useful.
It's a little easier to use than what I currently do:

Quoted 7 lines
Quoted 2 lines
$ findconfig  DRM_HISI_HIBMC
./drivers/gpu/drm/hisilicon/hibmc/Kconfig:2:config DRM_HISI_HIBMC

I'm guessing 'findconfig' here is some personal shell alias/function/script? (I can't see any references to it in the kernel source tree.)

Yes, it's just local.

Quoted 21 lines
Quoted 20 lines

then $EDITOR that_Kconfig_file

In testing, I am seeing this:

#

# using defaults found in /boot/config-5.3.18-150300.59.63-default
#
.config:421:warning: symbol value 'm' invalid for I8K
.config:2335:warning: symbol value 'm' invalid for
MTD_NAND_ECC_SW_HAMMING
.config:2484:warning: symbol value 'm' invalid for PVPANIC
.config:8671:warning: symbol value 'm' invalid for INTERCONNECT
.config:9369:warning: symbol value 'm' invalid for
CRYPTO_ARCH_HAVE_LIB_BLAKE2S
.config:9370:warning: symbol value 'm' invalid for
CRYPTO_LIB_BLAKE2S_GENERIC
.config:9653:warning: symbol value '1' invalid for KASAN_STACK
Quoted 28 lines
Quoted 3 lines

This I assume is just due to the contents of your .config file relative to the current Kconfig definitions and not a problem with anything in this patch?

There is no .config file in the linux/ source tree at the top level. I use O=build_dir for all builds.

Quoted 21 lines
Quoted 5 lines

How do I specify/choose a .config file to be used?

Oh, use KCONFIG_CONFIG=filename

Ah, I guess that'd be a nice thing to add a flag for to the wrapper script -- I'll include that in v2.

Quoted 3 lines

Please update (add) usage/help text in scripts/kconfig/Makefile.

Ack, will do.

Thanks for the review!

Zev

Another idea might be to add the following to
scripts/kconfig/Makefile:

(quoted diff) +0 -0
@@ -77,7 +76,13 @@ PHONY += $(simple-targets)

$(simple-targets): $(obj)/conf

       $(Q)$< $(silent) --$@ $(Kconfig)
(quoted diff) +7 -1
-PHONY += savedefconfig defconfig
+PHONY += findconfig savedefconfig defconfig
+
+findconfig: $(obj)/conf
+       $(Q)$< $(silent) --$@=$(KCONFIG_FIND) $(Kconfig)
+
+%_findconfig: $(obj)/conf
+       $(Q)$< $(silent) --findconfig=$* $(Kconfig)

savedefconfig: $(obj)/conf

       $(Q)$< $(silent) --$@=defconfig $(Kconfig)

Instead of adding a separate program for this,
you can modify scripts/kconfig/conf.c

- add 'findconfig' to enum input_mode
- add 'findconfig' to long_opts[]
- add 'case findconfig' to main() function

Then, you can do

$ make findconfig KCONFIG_FIND=DRM_HISI_HIBMC

or

Quoted 9 lines
$ make DRM_HISI_HIBMC_findconfig

as a shorthand.

scripts/findconf is unneeded
but you can put your own script in ~/bin
if you want to save your typing even more.

Hmm, interesting idea -- it seems a bit more awkward to use though, and if everyone who makes much use of it is likely to be writing their own little ad-hoc wrapper script anyway, it seems like we might as well do that once and check it in?

The current approach also provides support for multi-query searches, which while it isn't critical is slightly more convenient than running it multiple times or cramming everything into a single combined regex (analogous to grep's '-e' flag).

That said, if you and/or others have a strong preference for doing it via a make target I could rearrange it to work that way instead.

Thanks,
Zev

#6 lore raw
Quoted 149 lines · Zev Weiss
Quoted 132 lines · Masahiro Yamada
Quoted 55 lines · Randy Dunlap
Quoted 20 lines · Zev Weiss
Quoted 19 lines · Randy Dunlap

Hi--

Quoted 7 lines · Zev Weiss

scripts/findconf provides menuconfig's search functionality as a standalone, non-interactive command, somewhat in the spirit of scripts/config. It is meant to be useful for tasks like getting a quick overview of symbol dependencies or determining which Kconfig file to edit for a given symbol, without having to fire up one of the interactive config programs.

Quoted 5 lines

It accepts a single command-line flag, '-v', which causes it to also print the help text of each matching result.

---

I can see how this could be useful.
It's a little easier to use than what I currently do:

Quoted 7 lines
Quoted 2 lines
$ findconfig  DRM_HISI_HIBMC
./drivers/gpu/drm/hisilicon/hibmc/Kconfig:2:config DRM_HISI_HIBMC

I'm guessing 'findconfig' here is some personal shell alias/function/script? (I can't see any references to it in the kernel source tree.)

Yes, it's just local.

Quoted 21 lines
Quoted 20 lines

then $EDITOR that_Kconfig_file

In testing, I am seeing this:

#

# using defaults found in /boot/config-5.3.18-150300.59.63-default
#
.config:421:warning: symbol value 'm' invalid for I8K
.config:2335:warning: symbol value 'm' invalid for
MTD_NAND_ECC_SW_HAMMING
.config:2484:warning: symbol value 'm' invalid for PVPANIC
.config:8671:warning: symbol value 'm' invalid for INTERCONNECT
.config:9369:warning: symbol value 'm' invalid for
CRYPTO_ARCH_HAVE_LIB_BLAKE2S
.config:9370:warning: symbol value 'm' invalid for
CRYPTO_LIB_BLAKE2S_GENERIC
.config:9653:warning: symbol value '1' invalid for KASAN_STACK
Quoted 28 lines
Quoted 3 lines

This I assume is just due to the contents of your .config file relative to the current Kconfig definitions and not a problem with anything in this patch?

There is no .config file in the linux/ source tree at the top level. I use O=build_dir for all builds.

Quoted 21 lines
Quoted 5 lines

How do I specify/choose a .config file to be used?

Oh, use KCONFIG_CONFIG=filename

Ah, I guess that'd be a nice thing to add a flag for to the wrapper script -- I'll include that in v2.

Quoted 3 lines

Please update (add) usage/help text in scripts/kconfig/Makefile.

Ack, will do.

Thanks for the review!

Zev

Another idea might be to add the following to
scripts/kconfig/Makefile:

(quoted diff) +0 -0
@@ -77,7 +76,13 @@ PHONY += $(simple-targets)

$(simple-targets): $(obj)/conf

       $(Q)$< $(silent) --$@ $(Kconfig)
(quoted diff) +7 -1
-PHONY += savedefconfig defconfig
+PHONY += findconfig savedefconfig defconfig
+
+findconfig: $(obj)/conf
+       $(Q)$< $(silent) --$@=$(KCONFIG_FIND) $(Kconfig)
+
+%_findconfig: $(obj)/conf
+       $(Q)$< $(silent) --findconfig=$* $(Kconfig)

savedefconfig: $(obj)/conf

       $(Q)$< $(silent) --$@=defconfig $(Kconfig)

Instead of adding a separate program for this,
you can modify scripts/kconfig/conf.c

- add 'findconfig' to enum input_mode
- add 'findconfig' to long_opts[]
- add 'case findconfig' to main() function

Then, you can do

$ make findconfig KCONFIG_FIND=DRM_HISI_HIBMC

or

Quoted 9 lines
$ make DRM_HISI_HIBMC_findconfig

as a shorthand.

scripts/findconf is unneeded
but you can put your own script in ~/bin
if you want to save your typing even more.

Hmm, interesting idea -- it seems a bit more awkward to use though, and if everyone who makes much use of it is likely to be writing their own little ad-hoc wrapper script anyway, it seems like we might as well do that once and check it in?

Quoted 8 lines

The current approach also provides support for multi-query searches, which while it isn't critical is slightly more convenient than running it multiple times or cramming everything into a single combined regex (analogous to grep's '-e' flag).

That said, if you and/or others have a strong preference for doing it via a make target I could rearrange it to work that way instead.

Hmm, OK. Then, let's keep scripts/findconfig.

But, I'd like to pass the regex pattern via the --findconfig= option.

In the shell script, can you do some conversion?

Quoted 3 lines

Thanks,
Zev

Signature · 2 lines
Best Regards
Masahiro Yamada