summaryrefslogtreecommitdiff
path: root/kconfiglib.py
AgeCommit message (Collapse)Author
2018-11-02Fix removal of multiple consecutive 'if' nodesUlf Magnusson
Despite 'if' nodes being flattened before 'if' removal, consecutive 'if' nodes can still show up for code like the following: ... if X endif if X endif ... _remove_ifs() failed to remove the second 'if' node, leading to a crash e.g. when turning on show-all mode in the menuconfig in a menu with such code (due to the unexpected 'if' node). Stuff like the above could potentially result from 'osource's with no matches, though I just spotted the error while looking over the code. Fix the 'if' removal logic to properly handle consecutive 'if' nodes.
2018-11-01Don't show backtraces for expected exceptions in toolsUlf Magnusson
KconfigError and IOError are part of normal operation and don't indicate a problem with the library itself. Catch and print them in standard_kconfig() and sys.exit(), to avoid spammy backtraces from e.g. menuconfig.py when Kconfig files don't exist or have errors.
2018-11-01Refactor _remove_ifs()Ulf Magnusson
Can get away with a single variable by assigning node.list earlier, and save a tiny bit of work with a chained assignment. Also clarify what the tricky Python chained assignments correspond to, where it matters.
2018-10-31Make errno/strerror/filename available on IOErrorUlf Magnusson
An error reporting flaw was that most raised IOErrors got their errno/strerror/filename fields stripped, due to wanting to show a custom messages. The problem was that adding back 'errno' and 'strerror' made IOError.__str__() always return a fixed string ("[Errno <errno>] <strerror>"), ignoring any custom message. This is friendly to users, but unfriendly to scripts (the menuconfig had a workaround). Make things friendly to both by raising an internal subclass of IOError instead, that preserves errno/strerror/filename but prints a custom message. The exception can then still be caught as IOError/OSError by scripts.
2018-10-30Simplify _INIT_SRCTREE_NOTE definitionUlf Magnusson
2018-10-30Remove no longer needed 'node.item is None' testsUlf Magnusson
After commit e0256b6 ("Have MENU and COMMENT match _T_MENU and _T_COMMENT"), the only falsy value for node.item is None, since all token constants are truthy (since they're never 0).
2018-10-28Replace 'indent == 0' with 'not indent'Ulf Magnusson
Tiny bit faster and smaller. Clear in context.
2018-10-28Have MENU and COMMENT match _T_MENU and _T_COMMENTUlf Magnusson
Same approach as for the expression type symbolic constants. Removes a tiny bit of conversion and makes things a bit more consistent.
2018-10-28Shorten exception class definitions a bitUlf Magnusson
2018-10-28Remove leftover comment in _add_choice_deps()Ulf Magnusson
Made more sense when the code was part of _build_dep(). The same thing is explained in the function docstring now.
2018-10-28Micro-optimize dependency loop checkingUlf Magnusson
Turn the _check_dep_loop_sym lookup into a LOAD_FAST inside the loop.
2018-10-26Support enabling the assignment-to-undef. symbol warning via the environmentUlf Magnusson
This makes it possible to enable it for the bundled tools, by setting KCONFIG_WARN_UNDEF_ASSIGN=y. Previously, the code had to be modified to call Kconfig.enable_undef_warnings(). Also rename KCONFIG_STRICT to KCONFIG_WARN_UNDEF, for consistency. Keep supporting KCONFIG_STRICT as an alias for backwards compatibility.
2018-10-25Move _is_num() into _check_undef_syms()Ulf Magnusson
_check_undef_syms() is the only caller.
2018-10-22Use standard_sc_expr_str() in _name_and_loc()Ulf Magnusson
Makes choices show up as <choice (name, if any)>, which is nice. Previously, just the name was shown for named choices.
2018-10-22Move _check_sym/choice_sanity() into the Kconfig classUlf Magnusson
This makes the calls to Kconfig._warn() a bit less awkward (self._warn() instead of sym/choice.kconfig._warn()). Also move the loops over the symbols/choices into the functions, as a small optimization.
2018-10-22Micro-optimize _make_depend_on() callsUlf Magnusson
Store the function in a local variable outside the loop in _build_dep().
2018-10-21Allow programmatically expanding preprocessor functions with argsUlf Magnusson
Add a Variable.expanded_value_w_args() function for expanding a preprocessor function with particular arguments. This is what expanded_value should have been, because expanded_value_w_args() is more general (expanded_value corresponds to zero arguments). Keep expanded_value for backwards compatibility though. Also add a simple __repr__() to Variable. It could show the expanded value, but that might mean calling shell functions or user-defined functions as a side effect (possibly with missing arguments). Not sure that's a good idea, so just show the unexpanded value.
2018-10-21Test _parse_block() blank line case earlierUlf Magnusson
Can be treated as just another case, and moved later so that the cases become sorted by frequency.
2018-10-21Sort _parse_properties() cases by frequencyUlf Magnusson
Use the Linux x86 Kconfig frequencies. Most cases were already sorted, but the blank line case was treated specially. 'imply' was checked too early too (though it's used more in some other projects).
2018-10-21Simplify node->item property copyingUlf Magnusson
Turn _add_props_to_sc() into _add_props_to_sym(), and handle choices separately, as they're trivial. This gets rid of some if's too.
2018-10-16Make Kconfig.choices match its descriptionUlf Magnusson
Kconfig.choices has accidentally been identical to Kconfig.unique_choices all along, because named choices defined in multiple locations (which are pretty obscure) were only added once. Fix Kconfig.choices to match its description. This simplifies the code a bit too. Kconfig.unique_choices is usually what you want.
2018-10-15Fix typo in _add_props_to_sc() commentUlf Magnusson
2018-10-13Add some hints re. generating custom configuration outputUlf Magnusson
It's not obvious that Symbol.config_string can be useful even when generating other output formats, as it provides a hook for _write_to_conf. Mention it in the 'config_string' documentation and in relevant parts of the README.
2018-10-08_shell_fn() comment nitUlf Magnusson
2018-10-08Remove redundant elifs in expr_value()Ulf Magnusson
Leftover from assigning a 'res' variable.
2018-10-07Remove useless local variable in _parse_factor()Ulf Magnusson
Not sure how I missed that one so long...
2018-10-06Clean up naming in expr_value()Ulf Magnusson
Reuse the v1/v2 naming for the operands for the relation case, and call the relation variable 'rel' instead of 'op'. Piggy-back removal of the 'res' variable. Just as readable without it. Indirectly strips some locals.
2018-10-06Use a common variable name for deps in tri_valueUlf Magnusson
Might clarify the scopes a bit.
2018-10-06Hint that load_config() with replace=False is for mergingUlf Magnusson
2018-10-03Fix parse error message on the line after help textsUlf Magnusson
The correct error and line number was reported, but not the correct line contents. self._line needs to be set before calling _tokenize(), so that _parse_error() knows the context. There's no need to set self._line for empty lines, because we immediately end up back in _next_line() after parsing the help text, which refetches the empty line and updates self._line.
2018-10-02Clean up documentation a bit re. named choiceUlf Magnusson
Zephyr uses several named choices, and I've seen them in other projects now too, so don't imply that they aren't used. The menuconfig interface now has better support for them than the C tools too, where adding symbols by defining a choice in multiple locations is broken. Also remove a reference to Kconfiglib 1.
2018-10-02__slots__ formatting consistency nitUlf Magnusson
2018-10-01Don't set filename and linenr on 'if' menu nodesUlf Magnusson
There's no way to query them later, as 'if's get flattened and removed, and they're not needed during parsing either.
2018-09-29Clarify node_iter() documentation re. iteration orderUlf Magnusson
The old version might not have made it obvious that a node is visited before its children.
2018-09-29Refactor parsing to get rid of _saved_lineUlf Magnusson
Handle the line-after-help-text case specially, which allows _has_tokens (renamed to _reuse_tokens) to be used as the unget mechanism for help texts as well, leaving _saved_line unused. Move the _reuse_tokens check into _next_line(). This makes _parse_block() as straightforward as _parse_properties(), and simplifies _parse_properties() a tiny bit too by getting rid of the '_tokens_i = -1' assignment.
2018-09-27Remove stray tab characterUlf Magnusson
2018-09-27Unmatched endchoice/endif/endmenu formatting nitUlf Magnusson
Easier to read.
2018-09-27Give clearer errors for bad endchoice/endif/endmenu nestingUlf Magnusson
An endchoice/endif/endmenu with no corresponding choice/if/menu generated a cryptic 'unrecognized construct' parse error. Improve the error message so that the problem is pointed out explicitly: kconfiglib.KconfigError: Kconfig:37: couldn't parse 'endmenu': no corresponding 'menu' Reported in https://github.com/ulfalizer/Kconfiglib/issues/56.
2018-09-23Add support for user-defined Python preprocessor functionsUlf Magnusson
Allow preprocessor functions to be defined in Python by putting a module called 'kconfigfunctions' into sys.path. Internally, this simply adds the functions to the predefined functions in Kconfig._functions. User-defined Python functions make it simple to integrate information from existing Python tools into Kconfig, e.g. to have Kconfig symbols depend on hardware information stored in some other format. This might be used to get device tree information into Kconfig in Zephyr. Piggyback module docstring documentation for some extensions that were previously only mentioned in the README.
2018-09-19Remove unused variable reported by flake8Ulf Magnusson
Also remove some redundant backslashes within brackets.
2018-09-08Clean up kernel Makefile patch and add new targetsUlf Magnusson
Add two new targets: - 'make kmenuconfig' runs the menuconfig interface - 'make dumpvarsconfig' lists all referenced environment variables together with their values (assuming they used the preprocessor syntax) Remove the 'kconfiglibtestconfig' target, which is no longer used. Also clean up the target definitions. The joys of ancient code.
2018-09-05Clean up _expand_name() commentsUlf Magnusson
Some grammar, some copy-paste errors ('string' should be 'name').
2018-09-04Fix outdated comment re. $() yielding non-const symbolsUlf Magnusson
This is handled earlier in _tokenize() now.
2018-09-04Allow macro expansion within symbol namesUlf Magnusson
The C implementation supports this (though it's undocumented, and unused to far). This can be used e.g. to dynamically instatiate symbols from template files: Kconfig.template: config $(subsys)_LOG bool "Enable logging for $(subsys)" depends on $(subsys)_HAS_LOG ... other stuff dependent on $(subsys) Elsewhere: subsys = FOO source "Kconfig.template" subsys = BAR source "Kconfig.template" Pretty sure this can easily be abused, but it should be supported at least.
2018-09-03Test symbolic constants with 'is (not)'Ulf Magnusson
Saves a few % of total parsing time, and probably some evaluation time too. Microbenchmarking on Python 3 shows that 'is' is about 30% faster than '==' for comparing integers on my machine. This is safe even without assuming Python's small-integer optimization (which caches objects for small integers, guaranteeing that small integer literals always refer to the same object): We always refer to symbolic constants using their symbolic names (_T_*, etc.), so they're guaranteed to always refer to the same integer objects anyway. This optimization is safe for client code too, unless you get some unlikely situation where (1) there is no small-integer optimization, (2) expressions get pickled and unpickled or the like, which would be unsafe across Kconfiglib versions anyway, and (3) the client code tests symbolic constants with 'is' instead of '==' (which isn't advertised as safe, and a bad idea in general when pickling is involved). That's probably too obscure to worry about.
2018-08-30Allow user values on 'option env' symbolsUlf Magnusson
Gets rid of a check, doesn't hurt. The check was added before 'option env' was changed to just add a 'default' under the hood. Note: New Kconfig code doesn't need 'option env'. Environment variables are now expanded directly, including in the C tools. 'option env' is only maintained for backwards compatibility.
2018-08-29Improve the running-without-Makefile-patch documentationUlf Magnusson
- Include an updated list of environment variables, with sample values - Give a method for listing all referenced environment variables, via Kconfig.env_vars - Remove the note that says that Kconfiglib will warn if an unset environment variable is referenced. It's not true anymore with the preprocessor, which silently expands unset variables to the empty string. Not setting essential environment variables causes obvious errors at least.
2018-08-29_check_undef_syms() nitUlf Magnusson
Factor out the call to the iterator.
2018-08-26Improve menu structure for promptless choicesUlf Magnusson
Promptless choices can appear "legitimately" if you define a named choice in multiple locations to add on some symbols (which is broken in the C tools though). Prior to this fix, the promptless choice would get flattened, with the choice symbols appearing in the same menu as the (invisible) choice. This looks confusing. Skip flattening promptless choices to fix it.
2018-08-25Add a Kconfig.env_vars attribute that lists env. variablesUlf Magnusson
Kconfig.env_vars is a set() with the names of all environment variables referenced in the configuration. Can be used e.g. for custom incremental build implementations, though sync_deps() already indirectly catches any relevant changes to environment variables.