summaryrefslogtreecommitdiff
path: root/kconfiglib.py
AgeCommit message (Collapse)Author
2018-02-16Include direct deps. in Symbol/Choice.__str__()Ulf Magnusson
Direct dependencies are significant for 'imply' even if the symbol has no properties, so they need to be included to get semantically equivalent output. Making the direct dependencies clear is helpful in general too, even if you can usually infer them from the properties they get propagated to.
2018-02-09Simplify visibility check in Choice._get_selection()Ulf Magnusson
The visibility of a symbol in an y-mode choice can only be n or y, so it's sufficient to check that it's not n (0).
2018-02-08Give hint about recognizing undefined symbolsUlf Magnusson
2018-02-08Fix typo in module docstringUlf Magnusson
It's the top-level Kconfig file that source's depending on $SRCARCH, not the top-level Makefile.
2018-02-08_parse_expr() docstring nitUlf Magnusson
2018-02-08Don't special-case user_value for choice symbols set to yUlf Magnusson
Previously, setting a choice symbol to y would only update user_selection on the parent choice and not the symbol's own user_value. Now both are updated. The point of the old behavior was to remember the m mode selections of a choice when it was switched back and forth between m and y mode, which was a feature I thought the C implementation had. On closer inspection, the C implementation never had that feature, though it might appear like it if you only make "lucky" changes (if you never select any symbols in y mode that were n in m mode). The new behavior is simpler and easier to understand: Symbol.user_value now always matches the value assigned in a .config file or via set_value(), provided the value was well-formed. This might avoid some special-casing in scripts too. The loss in usability is pretty minimal.
2018-02-07Allow "n"/"m"/"y" as aliases for 0/1/2 in set_value()Ulf Magnusson
More experience working with the API convinced me that it's worth it. Gets rid of ugly conversions in the menuconfig.py and oldconfig.py examples, and streamlines some things internally as well. Include two other small fixes as well: - Make warnings generated by Choice.set_value() match those generated by Symbol.set_value(). - Get rid of the input stripping in menuconfig.py. It's not like the interface is usable as-is anyway, and it just complicates the example.
2018-01-30Warn if choice symbol has prompt outside choiceUlf Magnusson
Defining a choice symbol in multiple places to add some properties to it outside the choice seems to actually be done deliberately by MIPS, but it's almost guaranteed to be an error if the definition(s) outside the choice have a prompt (and so can be changed by the user there), so warn for that.
2018-01-29Warn if a choice symbol has defaultsUlf Magnusson
Never has en affect.
2018-01-29Warn if menuconfig statement has no promptUlf Magnusson
Mirrors a warning in the C implementation.
2018-01-29Warn if help text is emptyUlf Magnusson
Personal pet peeve. Should add a warning to the C implementation too.
2018-01-29Refactor _check_sym_sanity()Ulf Magnusson
Arrange by type, which works pretty neatly except for the pesky ranges check. This also makes us do less work in the common BOOL/TRISTATE case. Get rid of _check_select_imply_sanity().
2018-01-29Move sym.ranges check to end of _check_sym_sanity()Ulf Magnusson
More important stuff up front.
2018-01-29Warn if a symbol/choice has multiple promptsUlf Magnusson
In a single location. Having multiple definitions with different prompts is okay.
2018-01-29Sanity-check range valuesUlf Magnusson
Must have a form compatible with the int/hex, like for defaults. Also refactor a bit and use a single _int_hex_value_is_sane() helper. Less duplication.
2018-01-29Improve int/hex sanity checkingUlf Magnusson
If a non-constant default is given, we can still check that it has the right type. Break out two int/hex value sanity checking functions.
2018-01-28Warn if a symbol is defined with multiple typesUlf Magnusson
2018-01-28Remove redundant is_constant checkUlf Magnusson
Constant as well as undefined symbols lack menu nodes, so it's sufficient to check 'nodes'.
2018-01-28Add some warnings related to selects and impliesUlf Magnusson
Only bool and tristate symbols can select and be selected. Also add docstrings to the sanity checking functions.
2018-01-28Warn if there's more than one help textUlf Magnusson
Mirrors a warning I added to the C implementation.
2018-01-28Add more choice type and prompt sanity checksUlf Magnusson
- Choices should have type bool or tristate - Choice values should have a prompt Also fix indentation mess-up.
2018-01-28Refactor post-parsing sanity checkingUlf Magnusson
Have separate functions for checking symbols and choices instead of mixing them up. Easier to read, and avoids some isinstance() checks. Add some comments too.
2018-01-28Error out for malformed hex/int/string defaultsUlf Magnusson
Instead of failing in more cryptic ways later. Also use 'orig_type' instead of 'type' for the UNKNOWN check. Oversight.
2018-01-28Add some post-parsing warningsUlf Magnusson
These are easiest to check after parsing, since a symbol/choice can be defined in multiple locations: - Warn if a symbol or choice defined without a type. Also warn for choice value symbols defined without a type, even if they automatically get their type from the choice. This feature isn't well-known and probably not used deliberately. - Warn if a choice is defined without a prompt - Warn of a choice default symbol is not contained in the choice Also move _name_and_loc_str() from the symbol class to the global scope and generalize it to be able to handle choices.
2018-01-28Give symbol definition location(s) in warningsUlf Magnusson
Helpful
2018-01-28Flag constant symbols where they're not allowedUlf Magnusson
Might break U-Boot if they ever upgrade Kconfiglib, because they have a 'select y' in there (which the C tools don't flag since they only look for quotes), but it's a one-line fix.
2018-01-28Only check for implicit submenus for symbolsUlf Magnusson
Implicit submenus are only ever created with a symbol as the base. _has_auto_menu_dep() would indirectly reject anything that wasn't a symbol anyway, but it led to redundant work. Also get rid of _check_auto_menu() and inline it into _finalize_tree(). It's easier to read without the recursive call being hidden inside _check_auto_menu(). Tweak the comments a bit too.
2018-01-27Generate a parse error for extra tokens at EOLUlf Magnusson
Extra unconsumed tokens at the end of lines were previously ignored. Better to flag it. Also inline _next_token() and _peek_token() into the syntax checking variants of _next_token(). This code is pretty hot, and it saves a few % of parsing time.
2018-01-27Parse error consistency nitUlf Magnusson
2018-01-27Simplify help text parsing and _next_line()Ulf Magnusson
- _saved_line already handles EOF automagically, so no need to special-case it at the end of help text parsing. - Check for EOF earlier in _next_line(). Bit silly to do it after line joining.
2018-01-27Tighten up syntax checkingUlf Magnusson
Now points out the error for stuff like 'config' with no symbol name following it instead of randomly failing later. 1-2% parsing performance hit tops it seems.
2018-01-26Remove long overview from kconfiglib.pyUlf Magnusson
No need to repeat what's already in the README. Just refer to the GitHub page. Include some other minor tweaks to the introductory sections.
2018-01-26Remove BOOL and TRISTATE from _TYPE_TO_BASEUlf Magnusson
No longer needed after 955ea4 ("Support <, > relational operators with tristates").
2018-01-25direct_dep documentation nitUlf Magnusson
It's also used for the warning added in 0087b40 ("Warn if a symbol with unsatisfied deps is selected") now.
2018-01-25Comment nitUlf Magnusson
2018-01-25Tighten up regexesUlf Magnusson
- Match the simpler strchr()y .config parsing done by the C implementation - Spell out \w as [a-zA-Z0-9_]. Easier to verify. - Use ASCII mode for Python 3 to be consistent with Python 2, where it's already the default. \s no longer matches obscure Unicode stuff. This also speeds up regex matching during parsing by about 15% on Python 3, increasing parsing performance by a few %. Looks like there's a tiny improvement for Python 2 as well.
2018-01-25Support <, > relational operators with tristatesUlf Magnusson
Mirrors 9059a3493ef ("kconfig: fix relational operators for bool and tristate symbols") in the C implementation.
2018-01-24Enable universal newlines mode for Python 2Ulf Magnusson
Use the "U" flag to open() rather than io.open() to avoid a ~14% parsing performance hit. See comment.
2018-01-24Warn if a symbol with unsatisfied deps is selectedUlf Magnusson
Mirrors a warning in the C implementation. Make it a bit more informative and simpler to decode for people who aren't super familiar with Kconfig. The warning is printed when/if the symbol is evaluated, e.g. when writing a .config or C header or accessing Symbol.str/tri_value. It is not printed if the symbol value has already been calculated and is cached and up-to-date, which avoids warning spam. Example: config Y_SYMBOL_1 def_bool y config Y_SYMBOL_2 def_bool y config SELECTED bool depends on !Y_SYMBOL_1 config SELECTING_1 def_bool y select SELECTED # Skipped in warning, because n config SELECTING_2 def_bool n select SELECTED config SELECTING_3 def_bool y select SELECTED if Y_SYMBOL_1 depends on Y_SYMBOL_2 # Defined in multiple locations config SELECTING_3 Generated warning: warning: SELECTED (defined at Kconfig:7) has unsatisfied direct dependencies (!Y_SYMBOL_1), but is currently being selected by the following symbols: SELECTING_3 (value: y, defined at Kconfig:20, Kconfig:26), with direct dependencies "y" (value: y) and select condition Y_SYMBOL_1 && Y_SYMBOL_2 (value: y) SELECTING_1 (value: y, defined at Kconfig:11), with direct dependencies "y" (value: y) Real-world example from test suite: warning: NOT_COHERENT_CACHE (defined at arch/powerpc/platforms/Kconfig.cputype:381) has unsatisfied direct dependencies (4xx || PPC_8xx || E200 || PPC_MPC512x || GAMECUBE_COMMON), but is currently being selected by the following symbols: AMIGAONE (value: y, defined at arch/powerpc/platforms/amigaone/Kconfig:2), with direct dependencies 6xx && BROKEN_ON_SMP (value: y) and select condition 6xx && BROKEN_ON_SMP (value: y)
2018-01-22Add some more detail to the module docstringUlf Magnusson
Clarify how to fetch help texts and prompts, mention the no-prompt warning.
2018-01-22Simplify escape()Ulf Magnusson
The fancy regex isn't really justified. Much faster with replace() too, though this is an unlikely hotspot. Could have used a \g<0> backreference to refer to the entire match instead of using a capturing group too. Hadn't discovered that. Add some selftests for escape() and unescape() too.
2018-01-22Mention user_value in the load_config() docstringUlf Magnusson
Can be handy to check which symbols got set, like merge_config.py does.
2018-01-22Fix outdated comments referencing user_str/tri_valueUlf Magnusson
Ended up with just user_value in the end before releasing Kconfiglib 2.
2018-01-22Add more detail to the write_autoconf() docstringUlf Magnusson
Same order as for .config files.
2018-01-22Add more detail to the write_config() docstringUlf Magnusson
Can be handy to know that the order of the assignments matches the Kconfig files.
2018-01-20Micro-optimize _T_HELP parsingUlf Magnusson
Shaves a few % more from _parse_properties().
2018-01-20Get rid of _next_help_line()Ulf Magnusson
Speeds things up a bit further. Rework the unget handling to save the ungotten line directly instead of using a flag. Add some help texts to tests/Klocation to make sure the line number is updated properly for those.
2018-01-19Simplify loop in _T_HELPUlf Magnusson
Bit easier to read.
2018-01-19Always rstrip() when dedentingUlf Magnusson
Factors out some code and makes the logic a bit more transparent. It's only used for help text lines.
2018-01-19Rearrange _T_HELP codeUlf Magnusson
Bit clearer.