You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nuttx.apache.org by Tomek CEDRO <to...@cedro.info> on 2024/12/17 12:27:48 UTC

Kconfig: select vs depends on

Hello world :-)

Recent PR #2893 [1] proposed using "select" statement for "PIPES" as
dependency of "LIBUV" option. There is a preference to use "depends
on" in that case [2]. What are your preferences and experiences in
this area? Is there a policy / preference in this area for NuttX? :-)

What are dangers of using "select"? Why "depends on" is preferred?

Tomek

[1] https://github.com/apache/nuttx-apps/pull/2893
[2] https://docs.zephyrproject.org/latest/build/kconfig/tips.html#select-recommendations

-- 
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info

Re: Kconfig: select vs depends on

Posted by Alin Jerpelea <je...@gmail.com>.
Hi Tomek,
I preffer "select" instead of "depends on"
I dont remember having a policy yet but I think that we should be
consistent and replace all occurences then document the project agreed way.
Best regards
Alin

On Tue, 17 Dec 2024, 21:35 Tomek CEDRO, <to...@cedro.info> wrote:

> Hello world :-)
>
> Recent PR #2893 [1] proposed using "select" statement for "PIPES" as
> dependency of "LIBUV" option. There is a preference to use "depends
> on" in that case [2]. What are your preferences and experiences in
> this area? Is there a policy / preference in this area for NuttX? :-)
>
> What are dangers of using "select"? Why "depends on" is preferred?
>
> Tomek
>
> [1] https://github.com/apache/nuttx-apps/pull/2893
> [2]
> https://docs.zephyrproject.org/latest/build/kconfig/tips.html#select-recommendations
>
> --
> CeDeROM, SQ7MHZ, http://www.tomek.cedro.info
>

Re: Kconfig: select vs depends on

Posted by Tomek CEDRO <to...@cedro.info>.
On Tue, Dec 17, 2024 at 2:12 PM <mi...@bofc.pl> wrote:
> On 2024-12-17 13:27:48, Tomek CEDRO wrote:
> > Hello world :-)
> >
> > Recent PR #2893 [1] proposed using "select" statement for "PIPES" as
> > dependency of "LIBUV" option. There is a preference to use "depends
> > on" in that case [2]. What are your preferences and experiences in
> > this area? Is there a policy / preference in this area for NuttX? :-)
> >
> > What are dangers of using "select"? Why "depends on" is preferred?
> Select gonna fail for "nested dependencies".
>
> CONFIG_A depends on CONFIG_B which depends on CONFIG_C
>
> If you select A, A will select B, but it will not select C automatically,
> A will have to have both "select B" and "select C". This can lead to bugs
>
> I - personally - prefer depends for visible (user selectable) entries. While
> select can be used to select invisible entries like
>
> | config CHIP_X
> |     bool "select chip X"
> |     select HAVE_UART
> |     select HAVE_SPI
>
> If you don't want for user to miss on some features I also include reversed
> config like:
>
> | comment "psmq requires SYSTEM_EMBEDLOG and !DISABLE_MQUEUE"
> |         depends on DISABLE_MQUEUE || !SYSTEM_EMBEDLOG
> |
> | menuconfig SYSTEM_PSMQ
> |         bool "psmq"
> |         default n
> |         depends on !DISABLE_MQUEUE && SYSTEM_EMBEDLOG
>
> In this case if you have enabled mqueue and embedlog you will see selectable
>
> | [ ] psmq
>
> otherwise you will see comment
>
> | --- psmq requires SYSTEM_EMBEDLOG and !DISABLE_MQUEUE ---
>
> This has number of perks:
> - user see all potential features he can choose from, regardless of what is
>   currently selected
> - end user will immediatelly and explicitly see what gets pulled for a config
> - no chance to break with nested dependencies - if embedlog suddenly starts to
>   require new option, only embedlog kconfig will have to be modified (with new
>   depends on option)
> - no illegal configurations are possible with depends (while it is possible with
>   select)
>
> So, rule of thumb - use select only for non-visible (non-selectable anywhere)
> symbols - use depends everywhere else.
>
> --
> .-----------------.-------------------.----------------------.-----------------.
> | Michal Lyszczek | Embedded C, Linux |   Company Address    |  .-. opensource |
> | +48 727 564 419 | Software Engineer | Akacjowa 10a; 55-330 |  oo|  supporter |
> | https://bofc.pl `----.--------------: Brzezinka Sredzka PL | /`'\      &     |
> | GPG FF1EBFE7E3A974B1 | Bits of Code | NIP:   813 349 58 78 |(\_;/) programer |
> `----------------------^--------------^----------------------^-----------------'

Thank you Michal for perfect explanation with real world examples!! :-)

Looks like this policy is good for us (NuttX) and in align with other projects?
1. Kconfig "select" only for non-visible (non-selectable anywhere) symbols.
2  Kconfig "depends on" everywhere else.

-- 
CeDeROM, SQ7MHZ, http://www.tomek.cedro.info

Re: Kconfig: select vs depends on

Posted by Nathan Hartman <ha...@gmail.com>.
On Tue, Dec 17, 2024 at 8:12 AM <mi...@bofc.pl> wrote:

> On 2024-12-17 13:27:48, Tomek CEDRO wrote:
> > Hello world :-)
> >
> > Recent PR #2893 [1] proposed using "select" statement for "PIPES" as
> > dependency of "LIBUV" option. There is a preference to use "depends
> > on" in that case [2]. What are your preferences and experiences in
> > this area? Is there a policy / preference in this area for NuttX? :-)
> >
> > What are dangers of using "select"? Why "depends on" is preferred?
> Select gonna fail for "nested dependencies".
>
> CONFIG_A depends on CONFIG_B which depends on CONFIG_C
>
> If you select A, A will select B, but it will not select C automatically,
> A will have to have both "select B" and "select C". This can lead to bugs


Also, if A uses "select B" and you select A, it will select B. But if you
change your mind and deselect A, it does not deselect B automatically. So
if you go through the menus and experiment with selecting and deselecting
different things, you'll end up with extra stuff selected that you may not
be aware of.

More below...

I - personally - prefer depends for visible (user selectable) entries. While
> select can be used to select invisible entries like
>
> | config CHIP_X
> |     bool "select chip X"
> |     select HAVE_UART
> |     select HAVE_SPI
>
> If you don't want for user to miss on some features I also include reversed
> config like:
>
> | comment "psmq requires SYSTEM_EMBEDLOG and !DISABLE_MQUEUE"
> |         depends on DISABLE_MQUEUE || !SYSTEM_EMBEDLOG
> |
> | menuconfig SYSTEM_PSMQ
> |         bool "psmq"
> |         default n
> |         depends on !DISABLE_MQUEUE && SYSTEM_EMBEDLOG
>
> In this case if you have enabled mqueue and embedlog you will see
> selectable
>
> | [ ] psmq
>
> otherwise you will see comment
>
> | --- psmq requires SYSTEM_EMBEDLOG and !DISABLE_MQUEUE ---
>
> This has number of perks:
> - user see all potential features he can choose from, regardless of what is
>   currently selected
> - end user will immediatelly and explicitly see what gets pulled for a
> config
> - no chance to break with nested dependencies - if embedlog suddenly
> starts to
>   require new option, only embedlog kconfig will have to be modified (with
> new
>   depends on option)
> - no illegal configurations are possible with depends (while it is
> possible with
>   select)
>
> So, rule of thumb - use select only for non-visible (non-selectable
> anywhere)
> symbols - use depends everywhere else.


This is a sensible rule of thumb. I remember reading it somewhere before.

For non-visible items, select makes more sense.

For visible (user-selectable) options, the user should explicitly control
what is selected and what isn't.

Nathan

Re: Kconfig: select vs depends on

Posted by mi...@bofc.pl.
On 2024-12-17 13:27:48, Tomek CEDRO wrote:
> Hello world :-)
> 
> Recent PR #2893 [1] proposed using "select" statement for "PIPES" as
> dependency of "LIBUV" option. There is a preference to use "depends
> on" in that case [2]. What are your preferences and experiences in
> this area? Is there a policy / preference in this area for NuttX? :-)
> 
> What are dangers of using "select"? Why "depends on" is preferred?
Select gonna fail for "nested dependencies".

CONFIG_A depends on CONFIG_B which depends on CONFIG_C

If you select A, A will select B, but it will not select C automatically,
A will have to have both "select B" and "select C". This can lead to bugs

I - personally - prefer depends for visible (user selectable) entries. While
select can be used to select invisible entries like

| config CHIP_X
|     bool "select chip X"
|     select HAVE_UART
|     select HAVE_SPI

If you don't want for user to miss on some features I also include reversed
config like:

| comment "psmq requires SYSTEM_EMBEDLOG and !DISABLE_MQUEUE"
|         depends on DISABLE_MQUEUE || !SYSTEM_EMBEDLOG
| 
| menuconfig SYSTEM_PSMQ
|         bool "psmq"
|         default n
|         depends on !DISABLE_MQUEUE && SYSTEM_EMBEDLOG

In this case if you have enabled mqueue and embedlog you will see selectable

| [ ] psmq

otherwise you will see comment

| --- psmq requires SYSTEM_EMBEDLOG and !DISABLE_MQUEUE ---

This has number of perks:
- user see all potential features he can choose from, regardless of what is
  currently selected
- end user will immediatelly and explicitly see what gets pulled for a config
- no chance to break with nested dependencies - if embedlog suddenly starts to
  require new option, only embedlog kconfig will have to be modified (with new
  depends on option)
- no illegal configurations are possible with depends (while it is possible with
  select)

So, rule of thumb - use select only for non-visible (non-selectable anywhere)
symbols - use depends everywhere else.

-- 
.-----------------.-------------------.----------------------.-----------------.
| Michal Lyszczek | Embedded C, Linux |   Company Address    |  .-. opensource |
| +48 727 564 419 | Software Engineer | Akacjowa 10a; 55-330 |  oo|  supporter |
| https://bofc.pl `----.--------------: Brzezinka Sredzka PL | /`'\      &     |
| GPG FF1EBFE7E3A974B1 | Bits of Code | NIP:   813 349 58 78 |(\_;/) programer |
`----------------------^--------------^----------------------^-----------------'