summaryrefslogtreecommitdiff
path: root/kconfiglib.py
AgeCommit message (Collapse)Author
2018-06-22Turn MenuNode/Symbol/Choice.referenced() into a @propertyUlf Magnusson
Having it as a function is inconsistent, since all other read-only fields use properties. Oversight. Major version will be bumped to 7, though the function version wasn't in for long.
2018-06-22Add Symbol/Choice.referenced() convenience methodsUlf Magnusson
Returns the union of the MenuNode.referenced() sets for all the menu nodes of the symbol/choice.
2018-06-20Simplify MenuNode.referenced() a bitUlf Magnusson
Can get the initial set from expr_items(self.dep), since it's always included and always returns a new set().
2018-06-20Rename KconfigSyntaxError to KconfigErrorUlf Magnusson
This exception is generated for semantic errors and e.g. when dependency loops are detected as well, so the name is bad. Keep the old name as an alias for now for backwards compatibility.
2018-06-19Add dependency loop detectionUlf Magnusson
Pretty long overdue. Until now, dependency loops have raised a hard-to-debug Python RecursionError during evaluation. A Kconfiglib exception is raised now instead, with a message that lists all the items in the loop. See the comment at the start of _check_dep_loop_sym() for an overview of the algorithm. At a high level, it's loop detection in a directed graph by keeping track of unvisited/visited nodes during depth-first search. (A third "visited, known to not be in a dependency loop" state is used as well.) Choices complicate things, as they're inherently loopy: The choice depends on the choice symbols and vice versa, and the choice symbols in a sense all depend on each other. Add the choice-to-choice-symbol dependencies separately after dependency loop detection, so that there's just the choice-symbol-to-choice dependencies to deal with. It simplifies things, as it makes it possible to tell dependencies from 'prompt' and 'default' conditions on the choice from choice symbol dependencies. Do some flag shenanigans to prevent the choice from being "re-entered" while looping through the choice symbols. Maybe this could be cleaned up a bit somehow... Example exception message: Dependency loop =============== A (defined at tests/Kdeploop10:1), with definition... config A bool depends on B ...depends on B (defined at tests/Kdeploop10:5), with definition... config B bool depends on C = 7 ...depends on C (defined at tests/Kdeploop10:9), with definition... config C int range D 8 ...depends on D (defined at tests/Kdeploop10:13), with definition... config D int default 3 if E default 8 ...depends on E (defined at tests/Kdeploop10:18), with definition... config E bool (select-related dependencies: F && G) ...depends on G (defined at tests/Kdeploop10:25), with definition... config G bool depends on H ...depends on the choice symbol H (defined at tests/Kdeploop10:32), with definition... config H bool prompt "H" if I && <choice> depends on I && <choice> ...depends on the choice symbol I (defined at tests/Kdeploop10:41), with definition... config I bool prompt "I" if <choice> depends on <choice> ...depends on <choice> (defined at tests/Kdeploop10:38), with definition... choice bool prompt "choice" if J ...depends on J (defined at tests/Kdeploop10:46), with definition... config J bool depends on A ...depends again on A (defined at tests/Kdeploop10:1)
2018-06-15Rename _copy_props_to_sc() to _add_props_to_sc()Ulf Magnusson
The properties themselves aren't really copied, just added to the Symbol/Choice property lists.
2018-06-15Comment wording nitUlf Magnusson
2018-06-15Rename _copy_deps_to_sc() to _copy_props_to_sc()Ulf Magnusson
More descriptive. Menu node properties are copied, not just their dependencies.
2018-06-14Correctly report choice locations in some warningsUlf Magnusson
Menu nodes were added to choices after parsing their properties, making some warnings generated during parsing (as opposed to in _check_choice_sanity()) incorrectly give the choice as '<choice> (undefined)'. Add the node before parsing choice properties to fix those warnings.
2018-06-14Remove redundant str()Ulf Magnusson
.format() will implicitly format the exception as a string.
2018-06-14Comment formatting nitUlf Magnusson
2018-06-14Fix MenuNode.referenced() on Kconfig.top_nodeUlf Magnusson
The property lists weren't created for Kconfig.top_node, making referenced() crash. Add a MenuNode constructor and create the property lists there instead of in _parse_properties().
2018-06-14Fix incorrectly ordered properties for some nested multi.def. symbolsUlf Magnusson
_propagate_deps() visits menu nodes roughly breadth-first, meaning properties on symbols and choices defined in multiple locations could end up in the wrong order when copied from the menu node for some unlucky if/menu nestings. Fix it by moving the menu-node-to-symbol/choice property copying in _finalize_tree() so that it's guaranteed to happen in definition order. This bug was introduced by commit 63a4418 ("Record which MenuNode has each property").
2018-06-13Add MenuNode function that returns referenced itemsUlf Magnusson
MenuNode.referenced() returns all symbols (and choices, for choice symbols) referenced in the properties (prompt, defaults, selects, ranges, etc.) and property conditions of the menu node. Handy e.g. when generating cross-references.
2018-06-12Grammar nitUlf Magnusson
2018-06-12Simplify expr_items()Ulf Magnusson
Same cleanup as for _make_depend_on(). Rename 'deps' to 'res' as well. The result can be used for other stuff besides figuring out dependencies.
2018-06-12Simplify _make_depend_on() some moreUlf Magnusson
Rearrange and break out common stuff. Already rename the 'sym' parameter to 'sc', as it could be a choice as well.
2018-06-12Simplify _make_depend_on()Ulf Magnusson
Relations have the same format as AND/OR expressions and can be handled with the same code. This gives an extra recursion for relational expressions (because they can only have symbols as operands), but they're much rarer than other expression types.
2018-06-12Replace a 'raise InternalError' with _internal_error()Ulf Magnusson
Oversight
2018-06-12Remove redundant 'pass' from exception classesUlf Magnusson
The docstrings make the body non-empty already.
2018-06-11Add a function for getting all items in an expressionUlf Magnusson
Handy e.g. when searching.
2018-06-06standard_config_filename() style nitUlf Magnusson
2018-05-30Add tool helper for loading/saving .config filesUlf Magnusson
Removes repeated KCONFIG_CONFIG boilerplate. Also make allyesconfig use KCONFIG_CONFIG when writing (oversight), and document the sys.exit() behavior for standard_kconfig().
2018-05-30Add tool helper for selecting the top-level KconfigUlf Magnusson
standard_kconfig() gets the top-level Kconfig file from the first command-line argument, defaulting to "Kconfig". This removes some boilerplate from tools.
2018-05-27Provide lists with all menus and commentsUlf Magnusson
Handy e.g. when implementing advanced search features.
2018-05-27Make Kconfig._choices publicUlf Magnusson
Useful in various places outside the library, e.g. in the upcoming packaged allyesconfig implementation, and when generating documentation.
2018-05-27Get rid of the predefined UNAME_RELEASE symbolUlf Magnusson
Commit cbf32e2 ("Expand environment variables in strings directly") added direct expansion of environment variables is strings, with commit b9384a1 ("Restore compatibility with $UNAME_RELEASE") adding a hack to restore compatibility with the predefined $UNAME_RELEASE symbol, used by DEFCONFIG_LIST in the Linux kernel. With the compatibility hack in place, there's no longer any need to define UNAME_RELEASE as a proper symbol. Remove it.
2018-05-27Simplify unquoted string default checkUlf Magnusson
D'oh
2018-05-26Micro-optimize _parse_help() loopUlf Magnusson
Shaves ~6% off the _parse_help() runtime for the x86 Kconfigs in cProfile.
2018-05-25Style nitUlf Magnusson
2018-05-25Warn if quotes are omitted around string defaultsUlf Magnusson
This takes some heuristics, as it's indistinguishable from a reference to an undefined symbol. Guess that the quotes are missing if the 'default' value isn't all-uppercase.
2018-05-19Warn for incompatible uses of 'option env=...'Ulf Magnusson
Since commit cbf32e2 ("Expand environment variables in strings directly"), Kconfiglib expands environment variables directly in strings instead of using the 'option env=...' mechanism (this is planned for the C tools too). This new behavior is backwards-compatible as long as all 'option env=...' symbols have the same name as the environment variables they reference. Warn if 'option env="FOO"' appears on a symbol that isn't named FOO, to point out compatibility issues and help with debugging.
2018-05-19Micro-optimize help text parsing some moreUlf Magnusson
This code is surprisingly hot.
2018-05-18Get rid of _dedent_rstrip()Ulf Magnusson
Only a single caller left now, in a hot loop.
2018-05-18Warn if prompt contains leading or trailing whitespaceUlf Magnusson
Also strip the prompt in that case. Leading/trailing whitespace in prompts leads to ugly workarounds in e.g. reStructuredText documentation, where '*prompt *' is invalid.
2018-05-18Restore compatibility with $UNAME_RELEASEUlf Magnusson
UNAME_RELEASE is expanded in one of the 'default's of the DEFCONFIG_LIST symbol in the Linux kernel. This broke after "$FOO" was changed to directly expand to the value of the environment variable FOO, rather than to the value of the symbol FOO. Restore compatibility with a small wrapper.
2018-05-18Refactor help text parsing loopUlf Magnusson
This is less twisty, and generates slightly smaller bytecode. Probably doesn't help to special-case the first line.
2018-05-17Move help text parsing into a separate functionUlf Magnusson
More readable.
2018-05-17Remove SRCARCH-related gotcha from module docstringUlf Magnusson
Now that environment variables are expanded directly with os.path.expandvars(), "$SRCARCH" will be kept as is if SRCARCH isn't set. arch/$SRCARCH/Kconfig won't exist, unlike arch//Kconfig.
2018-05-17Factor out adding of promptsUlf Magnusson
Get rid of some code duplication.
2018-05-17Factor out symbol type settingUlf Magnusson
Get rid of some code duplication.
2018-05-17Conditional reversal nitUlf Magnusson
2018-05-16Record which MenuNode has each propertyUlf Magnusson
This allows accurate documentation to be generated for symbols and choices defined in multiple locations. There are now MenuNode.defaults, MenuNode.selects, etc., lists that mirror the corresponding Symbol/Choice lists. Symbol/Choice.__str__() now correctly show property locations as well, by simply concatenating the strings returned by MenuNode.__str__() for each node. _parse_properties() was modified to add all properties directly to the menu node instead of adding them to the contained symbol or choice. The properties are then copied up to symbols and choices in _finalize_tree(). Dependency propagation is handled at the same time. As a side effect, this cleans up the code a bit and de-bloats _parse_properties(). Update the menuconfig implementation to use the new functionality. It now lists the menu nodes for symbols and choices with the correct properties for each node (previously, all defaults, selects, implies, and ranges appeared on the first definition).
2018-05-16Expand environment variables in strings directlyUlf Magnusson
Make "$FOO" directly reference the environment variable $FOO in e.g. 'source' statements, instead of the symbol FOO. Use os.path.expandvars() to expand strings (which preserves "$FOO" as-is if no environment variable FOO exists). This gets rid of the 'option env' "bounce" symbols, which are mostly just spam and are buggy in the C tools (dependencies aren't always respected, due to parsing and evaluation getting mixed up). The same change will probably appear soon in the C tools as well. Keep accepting 'option env' to preserve some backwards compatibility, but ignore it when expanding strings. For compatibility with the C tools, bounce symbols will need to be named the same as the environment variables they reference (which is the case for the Linux kernel). This is a compatibility break, so the major version will be bumped to 6 at the next release. The main motivation for adding this now is to allow recording properties on each MenuNode in a clean way. 'option env' symbols interact badly with delayed dependency propagation. Side note: I have a feeling that recording environment variable values might be redundant to trigger rebuilds if sync_deps() is run at each compile. It should detect all changes to symbol values due to environment variables changing value.
2018-05-01Force encoding to UTF-8 by default on Python 3Ulf Magnusson
Enough people have run into exceptions due to running in the C locale that it seems worthwhile. Add a new 'encoding' parameter to Kconfig.__init__() that specifies the encoding to use and make it default to "utf-8". Passing None gives the old behavior of using the encoding specified in the environment. Related PEP: https://www.python.org/dev/peps/pep-0538/
2018-05-01Make warnings available in a listUlf Magnusson
Also make printing of warnings to stderr optional. It's on by default, since it's almost always what you want. This makes printing and processing of warnings more flexible, compared to always printing warnings to stderr as soon as they're generated. It was inspired by wanting to promote certain warnings to errors in Zephyr, which previously required capturing stderr.
2018-05-01Make disable_warnings() disable all warningsUlf Magnusson
...including the optional ones. Previously, those were independent. This is more intuitive, and it seems unlikely that you'd want some of the optional warnings printed without having general warnings printed. This is a small API behavior change, so the major version will be bumped to 5 at the next release. Programs that enabled optional warnings without enabling general warnings will be affected. This means that all warnings now go through the same code path, which will come in handy for later changes (making the warnings available in a list, though with stderr printing still enabled by default). Add some more documentation for the Kconfig.__init__() 'warn' parameter and the enable_redun_warnings() function as well, and clean up the variable naming a bit.
2018-04-25Give filename and context for UnicodeDecodeErrorUlf Magnusson
These errors are a pain to debug otherwise, and might look like Kconfiglib brokenness. Another option would be ignore decoding errors, or do the 'surrogateescape' thing on reading and writing, but keep it simple for now. Pointing out the problem might be more helpful.
2018-04-25Print a warning for malformed .config linesUlf Magnusson
Flag lines matching neither 'CONFIG_FOO=...' nor '# CONFIG_FOO is not set' that aren't blank or comments.
2018-04-19Add Choice.direct_dep fieldUlf Magnusson
Same as Symbol.direct_dep (OR of node dependencies from all definition locations). It's handy to have available when generating information about choices.