summaryrefslogtreecommitdiff
path: root/kconfiglib.py
AgeCommit message (Collapse)Author
2017-09-27Refactor _parse_expr(), fix get_kconfig_filename()Ulf Magnusson
Those are related: The hack in _parse_expr() accidentally overwrote the _filename variable, causing get_kconfig_filename() to return the wrong filename if the base Kconfig file ended with a 'source' statement. Remove the hack and explicitly pass all the variables. It might have made more sense in an older version of the code. Also add back the grammar in a different format, some more comments, and a mind dump from tinkering with the parsing code.
2017-09-27Undefault _parse_expr()'s 'filename' and 'linenr'Ulf Magnusson
Single user, not worth the obfuscation. Also fix an outdated reference re. 'transform_m' and remove the grammar as it makes things seem more complex than they really are.
2017-09-27Hide non-tristate symbols in non-y tristate choicesUlf Magnusson
There's old ad-hoc code that does this in the C implementation, added in f5eaa32 (kconfig: tristate choices with mixed tristate and boolean values). Unless a tristate choice is in "y" mode, non-tristate symbols get visibility "n". There are currently no tristate choices with non-tristate symbols in the kernel, so this never triggered. Modify some self tests that weren't aware of this behavior, and add some new ones. Also remove an old pointless test.
2017-09-26Micro-optimize _tokenize()Ulf Magnusson
- A small modification to _initial_token_re_match makes it reject comments too, saving some manual code (and probably lots of string copying). - Reorganize things to handle 'previous' in a nicer way. - Use tuples instead instead of lists in the no-tokens and _T_HELP cases. Could preallocate and return an empty _Feed too, but it seems like overkilling it. Profiling done with cProfile and line_profiler.
2017-09-26Simplify Symbol._make_conf() conditionalUlf Magnusson
2017-09-25Fix 'default' on non-visible choice symbolsUlf Magnusson
Previously, 'default CHOICE_SYM [if <cond>]' in a choice would skip any following 'default' properties if <cond> was non-'n'. However, those other defaults should still be considered if CHOICE_SYM has visibility 'n'. Previously, we'd immediately fall back to selecting the first visible symbol in the choice in that case. get_selection_from_defaults() now exactly mirrors sym_choice_default() from the C implementation, and got less convoluted too. Nothing in the kernel defconfigs triggered this. Add a new test case too.
2017-09-25Remove redundant str()Ulf Magnusson
2017-09-25Remove unhelpful invalidation commentsUlf Magnusson
Probably not worthwhile to do anything overly fancy in the mentioned cases. Add some more helpful comments instead. Piggyback another comment nit.
2017-09-25Don't set defaults that will always be overwrittenUlf Magnusson
The constructors previously defaulted all properties. This is dead code for properties that are always set on items from outside during parsing, and obfuscates the code flow and wastes time. Instead, just mention other properties that exist in comments in the constructors. Also add test cases for missing and empty 'choice' help texts. Removing the default 'self._help = None' assignment in Choice.__init__() wasn't caught by the selftests.
2017-09-25Rename _sym_lookup() to _lookup_sym()Ulf Magnusson
2017-09-25Simplify another conditional with 'in'Ulf Magnusson
2017-09-25Only compile .config matching regexes onceUlf Magnusson
We only look at the value $CONFIG_ had when the configuration was loaded, so it's safe. Forgotten cleanup.
2017-09-25Make 'menuconfig' generate a _T_CONFIG tokenUlf Magnusson
'menuconfig' only deals with presentation in the configuration interfaces, and we don't handle it in any special way yet. Also point this out with some comments.
2017-09-25Simplify some conditionals with 'in'Ulf Magnusson
Old overmicrooptimization. Many of these involve constants that don't need to be looked up now too, and so should get faster.
2017-09-25Add comment motivating _already_writtenUlf Magnusson
2017-09-25Get rid of _BOOL_STRUlf Magnusson
The default string conversions for bools is fine. Turns "true"/"false" into "True"/"False" in object string representations. Hopefully that's not too bad of a backwards-compatibiltiy break.
2017-09-25Prefix module- and class-internal names with _Ulf Magnusson
I didn't do this when I first wrote Kconfiglib, for whatever reason. Makes the public API clearer to people browsing the code (though it was already done for function names) and has some other nice side effects like uncluttering the module-level documentation and making autocompletion in ipython more useful. Might avoid pissing off some people too. Remove the trailing from _ from stuff that no longer clashes with keywords. Piggyback some formatting cleanups for stuff I happened to spot. It's a huge unwieldy diff anyway.
2017-09-24Use os.access() in get_defconfig_filename()Ulf Magnusson
...instead of os.path.exists(). This more closely mimics the test in the C implementation, which boils down to fopen(file, "r") == NULL. Could open(filename) and catch exceptions too, but it might be overkilling things.
2017-09-24Fix defconfig srctree absolute/relative mixup bugUlf Magnusson
This code in zconf.l says !=, not ==. Thought the behavior seemed weird. if (!f && name != NULL && name[0] != '/') { env = getenv(SRCTREE); if (env) { sprintf(fullname, "%s/%s", env, name); f = fopen(fullname, "r"); } } return f; Thankfully only broken for a short while. Also gives much simpler code.
2017-09-24Handle path cleanups in a cleaner wayUlf Magnusson
_clean_up_path() was only ever passed filenames, so stripping trailing slashes was redundant. Better to strike at the root of the problem too, which is the os.path.join() with 'base_dir' defaulting to ".". The old hack gave incorrect results in obscure cases: Turning .//oops into /oops is wrong. The new version should be Windows-friendly as well.
2017-09-24Remove defaulted open() "r" argumentUlf Magnusson
2017-09-24Fix get_defconfig_filename() $srctree search orderUlf Magnusson
Previously, $srctree/path/to/defconfig would be looked up before /path/to/defconfig, and the code wouldn't check if /path/to/defconfig was an absolute path ($srctree is ignored otherwise). Sloppy old oversights. The behavior now fully matches the C implementation. Also fix some related things: - An 'if m' suffices to select a defconfig. We previously required 'y'. - Make the code less hacky and possibly more Windows-friendly by using os.path.relpath() to de-absolutize paths, and stop using os.path.normpath() as it could change the meaning of paths that contain symbolic links. - Explain what happens if 'option defconfig_list' is set on multiple symbols and print a warning in that case. - Fix get_srctree(). It would previously return "." instead of None if $srctree was unset at parse time. Somehow forgot to to test this. The code is now much more straightforward.
2017-09-24Add _parse_cond() helper for some 'if <y>' casesUlf Magnusson
There's already parse_val_and_cond(), which handles '<x> if <y>' where both <x> and <y> need to be parsed. Add a corresponding _parse_cond() helper which can be used in cases where only <y> should be parsed (for 'select', 'imply', and 'range'). Also move both _parse_val_and_cond() and _parse_cond() outside _parse_properties(). More explicit, and shows a small performance improvement during parsing.
2017-09-22Explain why _make_and() can return NoneUlf Magnusson
Makes ANDs between nonexistent expressions yield a nonexistent expression.
2017-09-22Explain the expression structure clearerUlf Magnusson
2017-09-22Simplify _expr_to_str()Ulf Magnusson
- Get rid of _sym_str_string(), which was only used here. - Remove 'if expr is None' case that could never trigger - Add a test for printing string symbols, as they are a bit tricky: Default values should not be evaluated to tristate values.
2017-09-21Simplify expression representationUlf Magnusson
Store simple (<operator>, <operand 1>, <operand 2>) tuples instead of (<operator>, [list of operands]) tuples. The thought process behind the original representation was to avoid creating lots of nodes for long X && Y && Z && ... chains that sometimes appear, and possibly speed up evaluation. In retrospect, it's pretty bad, for the following reasons: 1) _make_and() and _make_or() created lots of new merged lists instead of simply reusing the tuples already allocated for the subexpressions. This is slow and memory hungry. 2) Any gain in evaluating long expressions would barely offset slower evaluation of short expressions. 3) The code became more complex. Most importantly, this change makes expressions more straightforward to work with for people peeking into internals.
2017-09-21Use non-numbered {} with format()Ulf Magnusson
Supported since Python 2.7, which is seven years old, plus it was already used in a few spots. Do some minor cleanup in the printing routines at the same time. Also remove dubious string append performance note, where it's more about wanting to pass something mutable anyway.
2017-09-20_parse_properties() nitUlf Magnusson
2017-09-20Simplify 'end_line' handlingUlf Magnusson
No need to set 'end_line_tokens' to None if we use 'end_line' as a flag. Also clarify the comments to make it clear that end_line* is only used for the first line after a block of properties. Also fix comment typo: s/nested functions/nested menus/
2017-09-20Merge T_DEF_BOOL and T_DEF_TRISTATE casesUlf Magnusson
Extend TOKEN_TO_TYPE to map T_DEF_BOOL and T_DEF_TRISTATE to BOOL and TRISTATE as a convenience.
2017-09-20Use tri_greater() where applicableUlf Magnusson
2017-09-20Add support for less/greater than comparisonsUlf Magnusson
Was added upstream in 31847b67 (kconfig: allow use of relations other than (in)equality). Completely unused (and undocumented) in the kernel except for in DEBUG_UART_8250_WORD in arch/arm/Kconfig.debug: depends on DEBUG_UART_8250_SHIFT >= 2 (That line was added before lt/gt support by the way, and assumed a feature that wasn't there.) This change (and the upstream one) also slightly changes how (in)equality comparisons work, making e.g. MY_HEX = 0x00037 evaluate to 'y' if MY_HEX is 0x37. Prior to this change, the strings needed to match exactly.
2017-09-19Add note on tokenization unhandled character hackUlf Magnusson
Isn't needed to be compatible with the latest upstream, but is kept around for compatibility.
2017-09-19File writing nitUlf Magnusson
2017-09-19Simplify dependency propagation for promptsUlf Magnusson
Old version was a bit roundabout.
2017-09-19Include 'if' deps. in _determine_actual_symbols()Ulf Magnusson
Previously, only WEIRD_1 and not WEIRD_2 would be considered not a choice symbol in the following fragment. This lead to a weird warning in U-Boot. choice config FOO config WEIRD_1 depends on FOO if FOO config WEIRD_2 endif endchoice Also add some testcases for weird choice symbols.
2017-09-19Clean up _parse_block() casesUlf Magnusson
Do the block.append() after parsing the complete item. More obvious.
2017-09-19Simplify block parsing logicUlf Magnusson
Require callers to always pass the list to append items to and remove the return values from _parse_file() and _parse_block(). Initialize menu.block and choice.block to [] rather than None.
2017-09-18Add 'imply' supportUlf Magnusson
This is like a 'select' that only changes the default value of a symbol, not limiting what values the user can set it to (with one exception: A symbol implied to 'y' can't be set to 'm'). Symbol.get_implied_symbols() was added, corresponding to Symbol.get_selected_symbols(), and Symbol.__str__() was extended to print implied symbols and weak reverse dependencies. Weak reverse dependencies are the 'imply' version of 'select's reverse dependencies.
2017-09-18Force M visibility to N in choices with mode YUlf Magnusson
This mirrors the following kconfig commit. Triggered a few test suite failures for ARM and SH. commit fa64e5f6a35efd5e77d639125d973077ca506074 Author: Dirk Gouders <dirk@gouders.net> Date: Fri Apr 29 10:24:52 2016 +0200 kconfig/symbol.c: handle choice_values that depend on 'm' symbols If choices consist of choice_values of type tristate that depend on symbols set to 'm', those choice_values are not set to 'n' if the choice is changed from 'm' to 'y' (in which case only one active choice_value is allowed). Those values are also written to the config file causing modules to be built when they should not. The following config can be used to reproduce and examine the problem; with the frontend of your choice set "Choice 0" and "Choice 1" to 'm', then set "Tristate Choice" to 'y' and save the configuration: config modules boolean modules default y option modules config dependency tristate "Dependency" default m choice prompt "Tristate Choice" default choice0 config choice0 tristate "Choice 0" config choice1 tristate "Choice 1" depends on dependency endchoice This patch sets tristate choice_values' visibility that depend on symbols set to 'm' to 'n' if the corresponding choice is set to 'y'. This makes them disappear from the choice list and will also cause the choice_values' value set to 'n' in sym_calc_value() and as a result they are written as "not set" to the resulting .config file. Reported-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Dirk Gouders <dirk@gouders.net> Tested-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Tested-by: Roger Quadros <rogerq@ti.com> Signed-off-by: Michal Marek <mmarek@suse.com>
2017-09-08Use platform.uname() instead of os.uname()Ulf Magnusson
Portable to non-Unix platforms.
2017-02-14Add support for the CONFIG_ environment variableChris Dornsife
Makes the prefix used in .config files configurable. Also add pip installation note to README.
2016-08-07Micro-optimize conditional in get_value()Ulf Magnusson
Saves a few source lines as well as bytes of bytecode.
2016-08-06Micro-optimize parse_val_and_cond()Ulf Magnusson
Saves a source line as well as some bytecode. Tuple evaluation is guaranteed to be from left to right: https://docs.python.org/2/reference/expressions.html#evaluation-order
2016-08-06Micro-optimize some conditionalsUlf Magnusson
Saves a few source lines as well as bytes of bytecode.
2015-08-06Fix _parse_block() 'parent' documentation re. ifs.Ulf Magnusson
Ifs do not have an object representation, so 'parent' can never be an if.
2015-07-25Symbol.get_value() style nit.Ulf Magnusson
2015-07-23Fix _FileFeed.peek_next() continuation line handling.André Erdmann
Typo - 'res' should be 'line'. Only affected .config header reading.
2015-06-23load_config() only expands existing env. variables.Ulf Magnusson