summaryrefslogtreecommitdiff
path: root/kconfiglib.py
AgeCommit message (Collapse)Author
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.
2018-08-25Add a Kconfig.kconfig_filenames attributeUlf Magnusson
Kconfig.kconfig_filenames is an ordered list of all Kconfig files included in the configuration, relative to $srctree. Can be used e.g. for custom incremental build implementations, though sync_deps() already indirectly catches any relevant changes to files. Piggyback some ' -> " quote style consistency cleanups.
2018-08-25Simplify _check_undefined_syms() with node_iter()Ulf Magnusson
Wasn't available when the original version was written. Also rename _check_undefined_syms() to _check_undef_syms(). That shortening is used elsewhere.
2018-08-25Clean up expr_str() a bitUlf Magnusson
- Test in the order AND, OR, NOT, like in other places. This matches the frequency too. - Use 'not isinstance(expr, tuple)', which is a bit faster than isinstance(expr, (Symbol, Choice)).
2018-08-24Show include paths in menuconfig symbol informationUlf Magnusson
Add a MenuNode.include_path attribute that holds a tuple of (filename, linenr) tuples, giving the locations of the 'source' statements via which the node's Kconfig file was included, starting from the top-level Kconfig file. Use MenuNode.include_path to give the include path for symbols and other items in the help display in the menuconfig interface. This is useful for figuring out how Kconfig files are organized, and when reorganizing things.
2018-08-23Fix recursive 'source' error reportingUlf Magnusson
The recursive 'source' detection was still fine, but the error reporting had broken due a missed variable renaming. The test suite didn't catch it, because a different type of KconfigError was raised instead, due to a separate error in the test suite (need to include tests/Krecursive{1,2}, since paths are relative to $srctree). Fix the variable name and tighten up the tests to check that the KconfigError message is the one we except. Tighten up the dependency loop detection tests in the same way too.
2018-08-23Fix file descriptor leak for the top-level Kconfig fileUlf Magnusson
Needs to be close()d. The other Kconfig files are close()d in _leave_file(). Could drop the reference somehow too, but an explicit close() is best for PyPy, which doesn't do reference counting.
2018-08-23Flag extra tokens after 'if'/'depends on'/'visible if' expressionsUlf Magnusson
Extra trailing tokens after 'if <expr>', 'depends on <expr>', and 'visible if <expr>' now trigger syntax errors instead of being ignored. Oversight. This indirectly makes Kconfig.eval_expr() detect extra trailing tokens as well.
2018-08-22Add a generic node iteratorUlf Magnusson
Suggested by Mitja Horvat (pinkfluid) in https://github.com/ulfalizer/Kconfiglib/pull/50. Kconfig.node_iter() iterates through all menu nodes in the menu tree in Kconfig order. This saves scripts the trouble of implementing their own tree walking code. Have node_iter() take a 'unique_syms' flag that can be enabled to only include symbols defined in multiple locations once. This is often what you want when generating output (and is used by write_config()). Order is still preserved. Piggyback a fix to a syntax error test comment. Parsing has been tightened up now.
2018-08-22Introduce Kconfig.unique_defined_syms and Kconfig.unique_choicesUlf Magnusson
These are the same as Kconfig.defined_syms and Kconfig.choices, except duplicates are removed. Kconfig order is still preserved. This is almost always what you want when iterating through symbols and choices, as it potentially saves work, avoids generating duplicates when writing output, and still preserves Kconfig order for readability. The old attributes will be kept for backwards compatibility (maybe there's some rare cases where they could be useful too). They're created internally anyway.
2018-08-21Merge Symbol._checked and Symbol._writtenUlf Magnusson
These are never used at the same time, and Symbol._visited is a good name for both. Gets rid of an internal attribute.
2018-08-21Handle multiple definition locations in a nicer wayUlf Magnusson
Instead of precalculating a set() to get unique symbols, precalculate a list with any duplicates from multiple definition locations removed, and preserve the order of the symbols within it. This makes it possible to get rid of the Symbol._written shenanigans in functions that only need to iterate through unique symbols in sorted order, which is all of them except write_config() (because it needs to walk the entire menu tree).
2018-08-21Make auto.conf symbol order match .config symbol orderUlf Magnusson
Not likely that you'd need to inspect it, since it's more of an implementation detail of incremental builds, but it doesn't hurt.
2018-08-21Make header symbol order match .config symbol order againUlf Magnusson
I accidentally broke this when I added the _defined_syms_set optimization. No semantic difference, but having the order match is more readable.
2018-08-21Refactor write_config() a bitUlf Magnusson
Since the 'top_node' menu node itself is skipped, we can start from there and move the tree walk to the beginning of the loop. For an empty configuration (top_node.list set to None) the tree walk immediately discovers that there are no more nodes and returns.
2018-08-18Grammar nitUlf Magnusson
2018-08-18Document that MenuNode.filename is relative to $srctreeUlf Magnusson
..or to the current directory of $srctree isn't set.
2018-08-18Look up the top-level Kconfig file relative to $srctreeUlf Magnusson
Due to an old design braino, the top-level Kconfig filename passed to Kconfig.__init__() wasn't looked up relative to $srctree, breaking out-of-tree usage for e.g. menuconfig. Fixing it required ugliness like srctree = os.environ.get("srctree", "") kconfiglib.Kconfig(os.path.join(srctree, "Kconfig")) Change the behavior of Kconfig.__init__() to look up the top-level Kconfig file relative to $srctree. This means that all Kconfig files (both the top-level file and any source'd files) now use $srctree, which makes the vast majority of scripts just work when running out-of-tree. Also remove the note re. loading a subset of Kconfig files. Saying that the top-level file and all source'd Kconfig files are looked up relative to $srctree should make the behavior clear enough. Print a note about the new behavior whenever the top-level Kconfig file can't be opened, as this change could be breaking for some scripts. This is a slight backwards-compatiblity break, so the major version will be bumped.
2018-08-18Revert "Fix $srctree logic for the top-level Kconfig file"Ulf Magnusson
This reverts commit 8a3999bc708e8468ff79665e3cbdfccd603160e1. I realized that this should go in a major release at least, because it has the potential to break scripts that rely on the old behavior of ignoring $srctree for the filename passed to Kconfig.__init__(). A dummy release will bump the version to 9.4.2. Any future release with the change will be 10.0.0.
2018-08-17rsource documentation nitsUlf Magnusson
Fix some grammar nits, and add a motivation at the end (wanting to create self-contained Kconfig trees that can appear anywhere relative to the top-level Kconfig file).
2018-08-17Fix $srctree logic for the top-level Kconfig fileUlf Magnusson
Due to a major design braino, the top-level Kconfig file passed to Kconfig.__init__() wasn't looked up relative to $srctree, breaking out-of-tree usage for e.g. menuconfig. With this change, Kconfig files are consistently looked up relative to $srctree, which makes a lot more sense. Also remove note re. loading a subset of Kconfig files. Saying that the top-level file and all source'd Kconfig files are looked up relative to $srctree should make the behavior clear enough.
2018-08-14Use += instead of extend()Ulf Magnusson
+= also does an in-place modification for lists, and it's a bit faster. Also get rid of an 'if node.defaults' tests. Both symbols and choices can have defaults, and it's not worthwhile as an optimization either.
2018-08-12Simplify menuconfig-without-prompt warningUlf Magnusson
node.item is already available as 'sym'.
2018-08-12Simplify _warn_select_unsatisfied_deps() a bitUlf Magnusson
select_val was only used in a single place, and there's no real harm in calculating expr_value(self.direct_dep) twice for a warning.
2018-08-11Don't pass encoding= to Popen()Ulf Magnusson
Popen()'s 'encoding' parameter is Python 3.6+ only. Unfortunately, Popen()'s universal_newlines=True without 'encoding' will use the encoding from the environment. Do a manual version instead, so that we can still use the user-specified encoding (usually UTF-8). That might prevent problems on systems that are (poorly) configured to use the C locale.
2018-08-10Improve naming in the custom expr. printing functionsUlf Magnusson
- *_fn() prefixes on functions are a bit silly. It makes more sense for the expr_str() parameter, so keep it there. - Use *_expr_str() instead of just *_str(), to make it clearer that these deal with expressions.
2018-08-10Support custom printing of symbols/choices in expressionsUlf Magnusson
Allow custom output formats for symbols/choices when turning expressions into strings, via a user-supplied callback function (sc_str_fn). This makes things like turning symbols into links in generated documentation and displaying symbol values in the menuconfig interface less hacky to implement. Two new Symbol/Choice.custom_str() functions were added, as passing extra arguments to __str__() is awkward.
2018-07-31Look for '$(' instead of '$' for inline macro expansionsUlf Magnusson
This gives a less confusing KconfigError message for syntax errors like 'config $FOO'.
2018-07-24Restore compatibility with old kernelsUlf Magnusson
Add a small hack to restore compatibility with older (2015-) versions of the Linux kernel. Weird help tokens like -help- and --help--- are now accepted again. Compatibility was originally dropped by commit c19fc11 ("Drop some compatibility and tighten up lexing"), but it turns that people are still using Kconfiglib with older kernels. The new compatibility hack has pretty minimal impact at least.
2018-07-24Use universal newlines mode in $(shell) implementationUlf Magnusson
This prevents e.g. stray \r's in command output on Windows after stripping trailing newlines.
2018-07-20Fix detection of hex literalsUlf Magnusson
Missing 'not'. Add some literals to the Kstrict testcase.