summaryrefslogtreecommitdiff
path: root/kconfiglib.py
AgeCommit message (Collapse)Author
2019-03-16Warn for unquoted argument to 'source', etc.Ulf Magnusson
Print a warning suggesting to add quotes for things like source foo/bar/Kconfig menu title prompt unquoted Example warning: Kconfig:32: warning: style: quotes recommended around 'lib/Kconfig.debug' in 'source lib/Kconfig.debug' That quoteless syntax is supported for compatibility with old versions of the C tools. It only works for a single word.
2019-03-14Comment nitUlf Magnusson
2019-03-14Put two blank lines between top-level functions/classesUlf Magnusson
Make kconfiglib.py consistent with the utilities.
2019-03-14Refactor and optimize type parsing a bitUlf Magnusson
Have BOOL/TRISTATE/... match _T_BOOL/_T_TRISTATE/... so that _set_type() doesn't have to do any conversion in the common case. Conversion is still needed for _T_DEF_BOOL/_T_DEF_TRISTATE/..., but those are rare. Also make use of UNKNOWN being falsy. Piggyback some rearranging of global constants so that related stuff appears closer together, for readability.
2019-03-14Clarify shutil lazy importUlf Magnusson
2019-03-10Import 'platform' and 'subprocess' as neededUlf Magnusson
Saves around 10 ms of startup time when they aren't, as measured with '-X importtime'.
2019-03-08Fix typo in kconfig_filenames docUlf Magnusson
2019-03-06Code formatting nitUlf Magnusson
Make the exception argument to _KconfigIOError() harder to miss.
2019-03-06Give more helpful error messages when files are missingUlf Magnusson
The current error message talks a lot about $srctree, but $srctree is seldom the culprit in practice. More common is 'source "$(SOME_ENV_VAR)/foo"`, where SOME_ENV_VAR hasn't been set. Include the complete 'source ...' line for missing Kconfig files, and mention unset environment variables as a hint. Only mention $srctree briefly. Also shorten the message when a .config can't be a found a bit. This message would usually only be seen when working directly with the library.
2019-02-23Fix spelling in commentUlf Magnusson
2019-02-23Shorten Symbol/Choice.referenced()Ulf Magnusson
Use a set comprehension.
2019-02-23Shorten __repr__() and __str__() code a bitUlf Magnusson
2019-02-20Document that kconfig_filenames keeps absolute paths as-isUlf Magnusson
Came up in https://github.com/ulfalizer/Kconfiglib/issues/67.
2019-01-15Update copyright years for 2019Ulf Magnusson
2018-12-24Warn for '# CONFIG_FOO is not set' when FOO is referenced but undefinedUlf Magnusson
Due to an oversight, '# CONFIG_FOO is not set' with FOO undefined only triggered a warning about assigning an undefined symbol if FOO was never referenced inside the Kconfig files.
2018-12-24menuconfig: Prompt for save if a different .config would be savedUlf Magnusson
Previously, menuconfig.py only prompted for saving the configuration if .config didn't exist or the user changed symbol values within the interface. Also make it prompt for save if Kconfig symbols have been added, removed, or have had their defaults changed, provided it would make the saved .config differ from the loaded one. This usually won't matter for correctness, because loading an outdated configuration performs an implicit olddefconfig, but it's less confusing. Also add a Kconfig.missing_syms attribute that records all assignments to undefined symbols in the most recently loaded .config file. This is needed to implement the check for whether the saved .config would be different. As an unrelated change, always prompt for saving if a .config has been loaded from within the menuconfig interface. The intention is probably often to save the configuration somewhere else, even if it isn't modified.
2018-12-15Simplify _decoding_error() a bitUlf Magnusson
Also add quotes around the filename.
2018-12-15Fix user-defined preprocessor function example codeUlf Magnusson
The functions must be defined before they can be put into 'functions'.
2018-12-15Improve error for missing endchoice/endif/endmenuUlf Magnusson
Say what was expected in the error message.
2018-12-15Store file.readline in _readline instead of having _fileUlf Magnusson
Gets rid of some lookups. A bigger hotspot is all the _next_line() calls though. Wonder if there's some nice restructuring to avoid them. Getting rid of the _reuse_tokens flag would be nice too.
2018-12-15Tighten up _next_line()Ulf Magnusson
self._line is only used for error reporting, and the empty string returned at EOF would never be shown. Move the assignment to after readline() and use a local variable to hold the line instead, to get rid of some property lookups.
2018-12-15Check isspace() before EOF in _parse_help()Ulf Magnusson
More common. isspace() returns False for empty strings.
2018-12-09Clarify that load_config()'s filename argument defaults to NoneUlf Magnusson
Had missed the '(default: None)', and it doesn't hurt to point it out in the description either. Point out that filename=None is the default in the write_config() 'filename' description too, though it already had the '(default: None)'.
2018-12-08_save_old() code nitsUlf Magnusson
2018-12-08Simplify 'verbose' check in write_config()Ulf Magnusson
2018-12-08Preserve symlinks when writing .config.old filesUlf Magnusson
if .config is a symlink, then the intention is probably to overwrite the target, but rename()ing the symlink to .config.old interferes with that. Use the shutil.copyfile() fallback instead if .config is a symlink.
2018-12-08Make {load,write}_config(filename=None) implement the standard behaviorUlf Magnusson
Make the previously obligatory 'filename' argument to load_config() and write_config() default to None, and have that implement the behavior you'd usually want: read/write either KCONFIG_CONFIG or ".config" if unset, and read the 'option defconfig_list' configuration file if KCONFIG_CONFIG/".config" doesn't exist. For load_config(), filename=None also allows the configuration file to be missing without raising an error. load_config() returns True if a local configuration file was loaded, which is useful to check in the menuconfig (if no local configuration file exists, we always want to prompt for saving the configuration when exiting). Also add a 'verbose' argument (default True) to load_config() and read_config() that makes them print which files were read/written in filename=None mode. Also generalize olddefconfig.py and oldconfig.py to not require there to already be a local configuration file. This was a bit silly for olddefconfig.py in particular. Remove the examples/defconfig.py script. It's a duplicate of olddefconfig.py.
2018-12-08Save existing configuration to .<filename>.old in write_config()Ulf Magnusson
Add a default-True 'save_old' flag to write_config(). If 'save_old' is True and an existing configuration file is being overwritten, a copy of the old configuration file is saved to .<filename>.old (e.g. .config.old) in the same directory. Errors are ignored, as the old configuration would usually just be a nice-to-have, and not essential. The same functionality could be added for minimal configuration files and headers, but it's probably most useful for configuration files.
2018-12-07Rename 'val_sym' to 'sym' in str_value()Ulf Magnusson
Consistent with elsewhere.
2018-12-07Remove _internal_error()Ulf Magnusson
These type sanity checks have never hit once during development over the years, and were inconsistently applied too. Remove them to simplify the code. Keep the InternalError exception for backwards compatibility, in case something catches it.
2018-12-01Flag removed symbols as changed in sync_deps()Ulf Magnusson
If a symbol is removed from a Kconfig file, it makes sense to flag it as changed, so that things that still (probably accidentally) depend on it get rebuilt. Saw a patch for the C tools with the same effect floating around, so might as well add it already. The C tools had other brokeness as well though...
2018-12-01Tighten up help text parsingUlf Magnusson
Get rid of _indentation() and inline it into _parse_help(), adding some simplifications and optimizations along the way. Saves a few % of parsing of time. Help text parsing is surprisingly hot.
2018-11-26Reorder some tuples to put y firstUlf Magnusson
CONFIG_FOO=y and 'default y' and the like are more common than the n versions, so test for them first. Turning the tuples into sets would be even better on Python 3, as it optimizes sets with constant keys into a LOAD_CONST, but it has a performance penalty on Python 2.
2018-11-26Speed up more token membership testsUlf Magnusson
Similar change to commit 4b23936 ("Speed up some token tests"), just for more tests. This especially helps for the "not a property line" case in _parse_properties(), which checks against all the cases. Saves 2-3% of parsing time together with the earlier change.
2018-11-25Whitespace nitUlf Magnusson
2018-11-25Speed up some token testsUlf Magnusson
Turn some of the hotter membership test tuples into global sets, like was already done for _TYPE_TOKENS. That saves some global lookups for the tuple members and avoids repeatedly recreating tuples. It's 30%-50% faster in a microbenchmark, even for two-element tuples (with global lookups for the members).
2018-11-25Move _TOKEN_TO_TYPE conversion into _set_type()Ulf Magnusson
Factors out some code. Also use a quick 'is not UNKNOWN' test first inside it, which will usually fail, since single-def symbols are more common. That avoids building a tuple too.
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