summaryrefslogtreecommitdiff
path: root/kconfiglib.py
AgeCommit message (Collapse)Author
2018-11-24Use constants when _tokens_i is knownUlf Magnusson
Same deal as for the initial token, except we sometimes know that we're dealing with the second token as well. Inline _expect_nonconst_sym_and_eol() and _expect_str(), which are single-use. That allows more specific error messages to be used as well. Also tweak an outdated comment in _tokenize() re. None-termination. Token fetching is more manual now.
2018-11-24Simplify eval_string() a bitUlf Magnusson
2018-11-24Optimize fetching of initial token on lineUlf Magnusson
Another possible optimization was missed in commit ab89ef6 ("Get rid of _next_token() and _peek_token()"): The index of the initial token on a line is known to be 0, so there's no need to check _tokens_i. Also reads a bit clearer.
2018-11-23Clarify that select/imply is a no-op for choice symbolsUlf Magnusson
The warning for selecting/implying a choice symbol could be misunderstood as saying that select/imply has no effect on choice symbols in a particular case. Select/imply never has an effect on choice symbols though. Rephrase the warning to make it clearer.
2018-11-23Flag extra trailing tokens in all contextsUlf Magnusson
The following cases were let through without a parse error (with the extra tokens just being ignored): - endif/endmenu/enchoice <extra tokens> - default FOO <extra tokens> (though 'default FOO if' flagged an error) Make them generate an error.
2018-11-23Get rid of _next_token() and _peek_token()Ulf Magnusson
These are pretty hot. Inline them to save a few % of parsing time. They're pretty simple anyway. _tokens_i was initialized to -1 to simplify the _next_token() implementation. With _next_token() gone, initialize it to 0 instead, which simplifies some other code.
2018-11-21Make quotes consistent in parse error messagesUlf Magnusson
2018-11-21Remove message re. Kconfiglib 10 backwards compat. breakUlf Magnusson
The message has been in for three months now. Hopefully that was enough for it to get noticed.
2018-11-21Use 'foo.__class__ is Bar' instead of 'isinstance(foo, Bar)'Ulf Magnusson
This is 30%-60% faster for both the matching and non-matching case, as measured with timeit on Python 2.7 and 3.6, and saves at least a few percent of total parsing time (and probably some evaluation time too). isinstance(foo, tuple) is particularly slow. Symbol and Choice instances are always created by us, so potential subclassing shouldn't be a problem.
2018-11-18sync_deps() docstring format nitUlf Magnusson
2018-11-17Add support for KCONFIG_ALLCONFIGUlf Magnusson
This allows some symbol values to be forced while running all{def,no,yes,mod}config.py. See Documentation/kbuild/kconfig.txt in the Linux kernel. Add a helper function load_allconfig() to Kconfiglib to avoid code duplication in the tools. Also add functions for enabling/disabling the warning that's generated when a symbol is assigned multiple times in a (set of) .config files and the values differ. It should be disabled when merging the KCONFIG_ALLCONFIG configuration file. Previously, only the warning generated when the assigned values are identical could be disabled. Disable all warnings related to assigning a symbol multiple times in examples/merge_config.py as well.
2018-11-17Kconfig formatting nit in docstringUlf Magnusson
2018-11-17Remove outdated comment in eval_string()Ulf Magnusson
2018-11-07Add a fast path for string parsingUlf Magnusson
For strings with no $ or \ in them (99.86% of all strings in the Linux x86 Kconfigs), we can just find() the matching quote directly. Saves a few % of tokenization time.
2018-11-06Comment nitUlf Magnusson
2018-11-06Always strip trailing whitespace in 'MenuNode.help' and __str__()Ulf Magnusson
Previously, you could get either one or two newlines at the end of MenuNode.help and the various __str__() methods, though this wasn't documented. Always stripping trailing whitespace is cleaner e.g. when using print(), which automatically appends a trailing newline, and makes things consistent. Hopefully nothing relied on the old undocumented behavior. It's fine for genrest.py at least.
2018-11-06Whitespace nitUlf Magnusson
2018-11-03Make UNKNOWN falsyUlf Magnusson
Set UNKNOWN (representing 'no type') to 0, which is falsy, to simplify some checks. Also reorder some dictionary keys for consistency.
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