ulfalizer / Kconfiglib

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

Invalid warning - kconfiglib complains about undefined variable under if guard #92

Open ceolin opened 4 years ago

ceolin commented 4 years ago
if LOG_BACKEND_RTT_BUFFER                                                                               
config LOG_BACKEND_RTT_BUFFER                                                      
        int "Buffer number used for logger output."                                
        range 0 SEGGER_RTT_MAX_NUM_UP_BUFFERS                                      
        default 0                                                                  
        help                                                                       
          Select index of up-buffer used for logger output, by default it uses  
          terminal up-buffer and its settings.                                             
endif

In this example from Zephyr, if SEGGER_RTT_MAX_NUM_UP_BUFFERS is not defined, kconfiglib is raising a warning even if it is under a if guard.

leandrolanzieri commented 4 years ago

AFAIK the only thing the if is doing there is to express a dependency. So that's the same as writing:

config LOG_BACKEND_RTT_BUFFER
        int "Buffer number used for logger output."
        range 0 SEGGER_RTT_MAX_NUM_UP_BUFFERS
        depends on LOG_BACKEND_RTT_BUFFER                               
        default 0     

The Kconfig symbol exists regardless of the value of LOG_BACKEND_RTT_BUFFER. When the KCONFIG_WARN_UNDEF option is set I don't see any reason why there should not be a warning because of SEGGER_RTT_MAX_NUM_UP_BUFFERS not being defined.