ulfalizer / Kconfiglib

A flexible Python 2/3 Kconfig implementation and library
ISC License
450 stars 161 forks source link

Differing view of prompt attribute between C Kconfig and Kconfiglib #79

Closed rupran closed 4 years ago

rupran commented 4 years ago

I'm playing around with Kconfiglib as I'm trying to replace a standalone copy of Kconfig in one of our tools, and noticed a difference between the C version and Kconfiglib.

Consider the following Kconfig file (this is a minimal example, I originally found this difference for the FRAME_POINTER option in current x86 Linux kernels):

config FOO
        bool

config BAR
        bool "With prompt"
        default y

config BAR
        bool
        default n if FOO

In the C implementation, two menu nodes will show up for the symbol BAR, and both will show the two different default values/conditions. Additionally, both will have one prompt property set (as the Kconfig parser will store this property in the same struct symbol for both definitions) which contains the "With prompt" string.

In Kconfiglib, however, the menu node for the latter definition will have its prompt attribute set to None, while the default values/conditions (taken from menunode.item.defaults) are the same for both definitions.

Is this intended?

ulfalizer commented 4 years ago

Are you using the vanilla C Kconfig tools from the Linux kernel? I just get a single "With prompt" entry for BAR in the C menuconfig.

Note that you'll get two menu nodes with Kconfiglib too, but only one of them will be visible in the menuconfig interface. You can see the other one if you go into show-all mode though (press A).

ulfalizer commented 4 years ago

It's also legal to give a symbol multiple prompts btw. Try playing around with this:

config FOO
    bool "First prompt"

config FOO
    bool "Second prompt"
rupran commented 4 years ago

Are you using the vanilla C Kconfig tools from the Linux kernel? I just get a single "With prompt" entry for BAR in the C menuconfig.

Note that you'll get two menu nodes with Kconfiglib too, but only one of them will be visible in the menuconfig interface. You can see the other one if you go into show-all mode though (press A).

Yes, you are right, I got confused between menu->prompt and the P_PROMPT properties contained in menu->sym->prompt. If I understand Kconfiglib correctly, it does not implement the latter (which in Kconfig contains both prompts), right?

ulfalizer commented 4 years ago

Yeah, Kconfiglib arranges things slightly differently there. Prompts only exist on MenuNode objects (which correspond to struct menu in the C code). Each symbol/choice has a nodes attribute with a list of its MenuNodes.

To print all the prompts for a symbol defined in multiple locations, you'd do this for example:

for node in sym.nodes:
    if node.prompt:
        print(node.prompt[0])

(prompt[1] is the prompt condition, which determines the visibility.)

Another option would've been to have had some Property class, but it seemed messy from an API perspective.

rupran commented 4 years ago

Sounds great, I'll give it a try!

Thank you for your great work on Kconfiglib!