| Age | Commit message (Collapse) | Author |
|
Reported by pylint.
|
|
Macros should still be expanded within nested parentheses. Test it.
|
|
As an oversight, there was no check for nested parentheses in macro
arguments, making the preprocessor think the call ended after 'void)' in
def_bool $(success,echo 'void foo(void) { asm inline (""); }' | $(CC) -x c - -c -o /dev/null)
This broke the latest linux-next kernels, starting with commit
eb111869301e1 ("compiler-types.h: add asm_inline definition").
I remember seeing this when going through the C code, but somehow forgot
to put it in. Fix it, and clean up _expand_macro() a bit at the same
time.
Fixes: #76
|
|
Just requires making Kconfig.filename/linenr public.
'lineno' would be a more standard name, but be consistent with
MenuNode.linenr.
|
|
|
|
menuconfig.py tended to crash on I/O errors on Python 2, due to
forgetting to update some 'except OSError's. Catch EnvironmentError
instead.
EnvironmentError is a common base class of IOError and OSError on Python
2, and an alias for OSError on Python 3. Use it elsewhere too, as it
might help catch obscure I/O errors on Python 2.
|
|
Getting defaults, select, implies, and ranges without dependencies
propagated to conditions can be useful for symbols and choices as well,
e.g. when generating standalone documentation for properties.
|
|
Do 'add = fields.append'. Pointless as an optimization, but shaves some
lines, and obvious in context.
Also add test coverage for __repr__() for string symbols with user
values.
|
|
A wart of the warning control API (enable/disable_*_warnings()) is that
the current warning settings can't be queried. Querying warning settings
is useful in functions that want to temporarily enable/disable some
warning and then put things back to how they were.
kconfiglib.load_allconfig() ran into this, for example.
Make the internal warning control variables public (improve the naming
at the same time), and encourage just setting them directly. Keep the
old API for backwards compatibility.
Also remove _warn_redun_assign() and _warn_override(). They're trivial
and were called in a single place.
|
|
Sourcing a file with an absolute path and using rsource in it triggered
a relpath() between the absolute path and $srctree. Since e.g.
symlink/../bar/ = bar/ is not guaranteed for symlinks, this could lead
to the rsource'd file not being found if $srctree pointed to a symlink.
Switch to a simpler, more textual method for stripping $srctree from
glob results, which should be robust against symlink shenanigans. This
also makes the code a bit easier to follow.
Discovered by Marc Herbert.
Piggyback some minor cleanup.
|
|
Like was done a long time ago in kconfiglib.py. These functions are not
part of a standalone API.
Keep the docstrings for the compatibility tests, because those get
printed as the tests run.
|
|
Pro: Looks cleaner and matches how definitions are usually written.
Con: Makes it harder to discover that 'bool "foo"' is just shorthand for
'bool' + 'prompt "foo"' (though it's documented).
The pros probably win.
|
|
These are constant symbols, which is why the quotes showed up.
Special-case them to remove the quotes, to match what people expect.
Internally, n/m/y without quotes is taken as a shorthand for
"n"/"m"/"y".
|
|
Commit e81a77b ("Consistently put direct deps. last when propagating")
makes the position of the direct deps. in property conditions
predictable after dependency propagation, making it easy to strip them
as needed.
Use this to implement MenuNode.orig_{prompt,defaults,selects,implies,ranges},
which work like the non-orig_* versions but omit the direct deps. Use
those in turn to omit the direct deps in Symbol/Choice.__str__().
The direct deps. (with propagated parent deps.) can still be seen after
'depends on ...', so there is no loss of information.
This unclutters Kconfig definitions shown in menuconfig/guiconfig and in
any generated documentation. The old output also had duplicated
dependencies, though it doesn't matter for evaluation.
Before:
config A
bool
prompt "A" if DEP
default y if FOO && DEP
depends on DEP
After:
config A
bool
prompt "A"
default y if FOO
depends on DEP
|
|
Preparation for some later additions. Previously, the 'visible if' deps
appeared to the right of the 'depends on' deps. Now, the direct deps
always appear last.
With this change, the prompt tuple is only updated once for any given
menu node too, which should be a tiny bit faster.
|
|
Ye olde code.
|
|
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.
|
|
|
|
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.
|
|
The KCONFIG_WARN_UNDEF test often fails on Python 3.4 (3.5 not tested),
but the output is still correct. It just differs due to dict ordering
randomness.
Python 3.6 iterates over dicts in insertion order in practice, and
Python 3.7 made it part of the spec, so enable the test for 3.6 and
later.
Python 2.7 seems fine as well.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
The LD environment variable needs to be set now (in 4.19-rc2). It's
referenced by LD_DEAD_CODE_DATA_ELIMINATION.
The tests probably ought to run everything run via 'scriptconfig' in a
clean environment, because 'scriptconfig' automatically picks up
environment variables anyway. The current setup is nice in that it
indirectly catches stuff that might affect the defconfig tests though,
which don't use scriptconfig.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
This "architecture" has an unorthodox Kconfig setup that would require a
different testing setup.
|
|
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.
|
|
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.
|
|
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.
|
|
These are never used at the same time, and Symbol._visited is a good
name for both.
Gets rid of an internal attribute.
|
|
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).
|
|
Should test write_autoconf(), not write_config().
|
|
I accidentally broke this when I added the _defined_syms_set
optimization. No semantic difference, but having the order match is more
readable.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
Needs an initial rm_config() after earlier reorganization.
|
|
Missing 'not'. Add some literals to the Kstrict testcase.
|
|
Settings KCONFIG_STRICT to y in the environment turns on warnings for
all references to undefined symbols within Kconfig files (with the only
gotcha that hex literals must be prefixed by 0x or 0X, to make it
possible to distinguish them from undefined references).
Always flagging undefined references gets awkward, as some projects
(e.g. the Linux kernel) use multiple Kconfig trees with shared files,
leading to some safe undefined references. It's helpful for other
projects though.
Having KCONFIG_STRICT as an environment variable is handy when multiple
tools are involved.
Piggyback a small README change re. warnings. Kconfiglib now has many
more warnings than the C tools.
|
|
Analogous to def_bool and def_tristate, setting the type and adding a
default at the same time.
This is a Kconfiglib extension. These keywords can be useful in projects
that make use of symbols defined in multiple locations, and remove some
Kconfig inconsistency.
|
|
Instead of having 'source' and 'gsource', have 'source' always glob, but
require the pattern to match at least one file, throwing KconfigError
otherwise.
Have separate 'osource' and 'orsource' statements (the o is for
"optional") for cases where it's okay for the pattern to not match any
files.
This is analogous to 'include' and '-include' in Make.
The biggest flaw with 'gsource' was that there was no way to do a
globbing match while requiring something to match, possibly leading to
subtle failures.
Preserve backwards compatibility by having "gsource" and "grsource" be
aliases for "osource" and "orsource", respectively.
Also include some related changes:
- Kconfig.srctree is now set to the empty string if $srctree is unset,
rather than to None. This gives nice behavior with os.path.join() and
os.path.relpath(), which treat the empty string as the current
directory (without adding './', for os.path.join()).
- When $srctree is set, Kconfig files in the current directory will no
longer override Kconfig files in $srctree when the relative paths
match. This was likely a bug all along in the C tools, and probably
only makes sense for .config files.
I've seen it cause breakage in Zephyr.
- Clarify the behavior of $srctree in the Kconfig.__init__() docstring.
- Make MenuNode.filename be relative to $srctree for the Kconfig file
passed to Kconfig.__init__(). This makes it consistent.
The major version will be bumped later due to the small Kconfig.srctree
API change.
|