2018-01-03 16:38:50 +01:00
|
|
|
#!/usr/bin/env python3
|
2019-10-29 19:32:17 +01:00
|
|
|
|
2020-01-28 07:19:55 +01:00
|
|
|
# Writes/updates the zephyr/.config configuration file by merging configuration
|
|
|
|
# files passed as arguments, e.g. board *_defconfig and application prj.conf
|
|
|
|
# files.
|
|
|
|
#
|
|
|
|
# When fragments haven't changed, zephyr/.config is both the input and the
|
|
|
|
# output, which just updates it. This is handled in the CMake files.
|
|
|
|
#
|
|
|
|
# Also does various checks (most via Kconfiglib warnings).
|
|
|
|
|
2018-05-04 16:47:59 +02:00
|
|
|
import argparse
|
2018-08-02 11:58:07 +02:00
|
|
|
import os
|
2018-06-06 16:06:22 +02:00
|
|
|
import sys
|
2018-06-15 15:31:47 +02:00
|
|
|
import textwrap
|
2018-06-06 16:06:22 +02:00
|
|
|
|
2020-01-20 15:27:09 +01:00
|
|
|
# Zephyr doesn't use tristate symbols. They're supported here just to make the
|
|
|
|
# script a bit more generic.
|
|
|
|
from kconfiglib import Kconfig, split_expr, expr_value, expr_str, BOOL, \
|
|
|
|
TRISTATE, TRI_TO_STR, AND
|
2018-11-17 20:28:09 +01:00
|
|
|
|
2018-05-04 16:47:59 +02:00
|
|
|
|
|
|
|
def main():
|
2018-11-17 20:28:09 +01:00
|
|
|
args = parse_args()
|
2018-05-04 16:47:59 +02:00
|
|
|
|
2020-02-12 15:42:09 +01:00
|
|
|
if args.zephyr_base:
|
|
|
|
os.environ['ZEPHYR_BASE'] = args.zephyr_base
|
|
|
|
|
kconfig/cmake: Improve reconfiguration behavior
There are some issues with the behavior when rerunning CMake in an
already initialized build directory:
1. The check for assignments to promptless symbols in configuration
fragments isn't run when reconfiguring, because it only runs if
zephyr/.config doesn't exist
2. As outlined in
https://github.com/zephyrproject-rtos/zephyr/issues/9573, you can
get into situations where zephyr/.config is invalid (e.g. due to
being outdated), but menuconfig/guiconfig can't be run to fix it
3. If kconfig.py fails while merging fragments during reconfiguration,
it will ignore the fragments during the next reconfiguration and use
the existing zephyr/.config instead, because the fragment checksum
is calculated and saved before running kconfig.py
(Footnote: The input configuration file(s) to kconfig.py can be either a
list of configuration fragments, when merging fragments, or just
zephyr/.config, if the merged configuration is up-to-date. The output
configuration file is always zephyr/.config.)
To fix the first two issues, explicitly tell kconfig.py when it's
dealing with handwritten configuration input (fragments), via a new
--handwritten-input-configs flag. This is more robust than checking
whether zephyr/.config exists, which was the old logic.
When dealing with handwritten input, there should be no assignments to
promptless symbols. Assignments to promptless symbols is expected in
zephyr/.config however, because it doubles as configuration output.
When running menuconfig/guiconfig, the input configuration is
zephyr/.config rather than configuration fragments, so this change also
makes sure that menuconfig can always be run as long as zephyr/.config
exists and is up-to-date.
To fix the last issue, only write the checksum for the configuration
fragments if kconfig.py succeeds (which means it wrote a
zephyr/.config).
Also improve naming a bit, add help texts for the command-line
parameters to kconfig.py, and simplify write_kconfig_filenames() by
moving logic into it.
Partial fix for
https://github.com/zephyrproject-rtos/zephyr/issues/9573, without the
part in #issuecomment-469701831. Can still run into issues when e.g.
when CMake files can't make sense of settings.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-20 11:25:13 +01:00
|
|
|
print("Parsing " + args.kconfig_file)
|
|
|
|
kconf = Kconfig(args.kconfig_file, warn_to_stderr=False,
|
2019-12-17 08:39:07 +01:00
|
|
|
suppress_traceback=True)
|
2018-05-04 16:47:59 +02:00
|
|
|
|
kconfig/cmake: Improve reconfiguration behavior
There are some issues with the behavior when rerunning CMake in an
already initialized build directory:
1. The check for assignments to promptless symbols in configuration
fragments isn't run when reconfiguring, because it only runs if
zephyr/.config doesn't exist
2. As outlined in
https://github.com/zephyrproject-rtos/zephyr/issues/9573, you can
get into situations where zephyr/.config is invalid (e.g. due to
being outdated), but menuconfig/guiconfig can't be run to fix it
3. If kconfig.py fails while merging fragments during reconfiguration,
it will ignore the fragments during the next reconfiguration and use
the existing zephyr/.config instead, because the fragment checksum
is calculated and saved before running kconfig.py
(Footnote: The input configuration file(s) to kconfig.py can be either a
list of configuration fragments, when merging fragments, or just
zephyr/.config, if the merged configuration is up-to-date. The output
configuration file is always zephyr/.config.)
To fix the first two issues, explicitly tell kconfig.py when it's
dealing with handwritten configuration input (fragments), via a new
--handwritten-input-configs flag. This is more robust than checking
whether zephyr/.config exists, which was the old logic.
When dealing with handwritten input, there should be no assignments to
promptless symbols. Assignments to promptless symbols is expected in
zephyr/.config however, because it doubles as configuration output.
When running menuconfig/guiconfig, the input configuration is
zephyr/.config rather than configuration fragments, so this change also
makes sure that menuconfig can always be run as long as zephyr/.config
exists and is up-to-date.
To fix the last issue, only write the checksum for the configuration
fragments if kconfig.py succeeds (which means it wrote a
zephyr/.config).
Also improve naming a bit, add help texts for the command-line
parameters to kconfig.py, and simplify write_kconfig_filenames() by
moving logic into it.
Partial fix for
https://github.com/zephyrproject-rtos/zephyr/issues/9573, without the
part in #issuecomment-469701831. Can still run into issues when e.g.
when CMake files can't make sense of settings.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-20 11:25:13 +01:00
|
|
|
if args.handwritten_input_configs:
|
|
|
|
# Warn for assignments to undefined symbols, but only for handwritten
|
|
|
|
# fragments, to avoid warnings-turned-errors when using an old
|
|
|
|
# configuration file together with updated Kconfig files
|
|
|
|
kconf.warn_assign_undef = True
|
2019-06-03 19:56:44 +02:00
|
|
|
|
kconfig/cmake: Improve reconfiguration behavior
There are some issues with the behavior when rerunning CMake in an
already initialized build directory:
1. The check for assignments to promptless symbols in configuration
fragments isn't run when reconfiguring, because it only runs if
zephyr/.config doesn't exist
2. As outlined in
https://github.com/zephyrproject-rtos/zephyr/issues/9573, you can
get into situations where zephyr/.config is invalid (e.g. due to
being outdated), but menuconfig/guiconfig can't be run to fix it
3. If kconfig.py fails while merging fragments during reconfiguration,
it will ignore the fragments during the next reconfiguration and use
the existing zephyr/.config instead, because the fragment checksum
is calculated and saved before running kconfig.py
(Footnote: The input configuration file(s) to kconfig.py can be either a
list of configuration fragments, when merging fragments, or just
zephyr/.config, if the merged configuration is up-to-date. The output
configuration file is always zephyr/.config.)
To fix the first two issues, explicitly tell kconfig.py when it's
dealing with handwritten configuration input (fragments), via a new
--handwritten-input-configs flag. This is more robust than checking
whether zephyr/.config exists, which was the old logic.
When dealing with handwritten input, there should be no assignments to
promptless symbols. Assignments to promptless symbols is expected in
zephyr/.config however, because it doubles as configuration output.
When running menuconfig/guiconfig, the input configuration is
zephyr/.config rather than configuration fragments, so this change also
makes sure that menuconfig can always be run as long as zephyr/.config
exists and is up-to-date.
To fix the last issue, only write the checksum for the configuration
fragments if kconfig.py succeeds (which means it wrote a
zephyr/.config).
Also improve naming a bit, add help texts for the command-line
parameters to kconfig.py, and simplify write_kconfig_filenames() by
moving logic into it.
Partial fix for
https://github.com/zephyrproject-rtos/zephyr/issues/9573, without the
part in #issuecomment-469701831. Can still run into issues when e.g.
when CMake files can't make sense of settings.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-20 11:25:13 +01:00
|
|
|
# prj.conf may override settings from the board configuration, so
|
|
|
|
# disable warnings about symbols being assigned more than once
|
|
|
|
kconf.warn_assign_override = False
|
|
|
|
kconf.warn_assign_redun = False
|
2018-05-04 16:47:59 +02:00
|
|
|
|
kconfig/cmake: Improve reconfiguration behavior
There are some issues with the behavior when rerunning CMake in an
already initialized build directory:
1. The check for assignments to promptless symbols in configuration
fragments isn't run when reconfiguring, because it only runs if
zephyr/.config doesn't exist
2. As outlined in
https://github.com/zephyrproject-rtos/zephyr/issues/9573, you can
get into situations where zephyr/.config is invalid (e.g. due to
being outdated), but menuconfig/guiconfig can't be run to fix it
3. If kconfig.py fails while merging fragments during reconfiguration,
it will ignore the fragments during the next reconfiguration and use
the existing zephyr/.config instead, because the fragment checksum
is calculated and saved before running kconfig.py
(Footnote: The input configuration file(s) to kconfig.py can be either a
list of configuration fragments, when merging fragments, or just
zephyr/.config, if the merged configuration is up-to-date. The output
configuration file is always zephyr/.config.)
To fix the first two issues, explicitly tell kconfig.py when it's
dealing with handwritten configuration input (fragments), via a new
--handwritten-input-configs flag. This is more robust than checking
whether zephyr/.config exists, which was the old logic.
When dealing with handwritten input, there should be no assignments to
promptless symbols. Assignments to promptless symbols is expected in
zephyr/.config however, because it doubles as configuration output.
When running menuconfig/guiconfig, the input configuration is
zephyr/.config rather than configuration fragments, so this change also
makes sure that menuconfig can always be run as long as zephyr/.config
exists and is up-to-date.
To fix the last issue, only write the checksum for the configuration
fragments if kconfig.py succeeds (which means it wrote a
zephyr/.config).
Also improve naming a bit, add help texts for the command-line
parameters to kconfig.py, and simplify write_kconfig_filenames() by
moving logic into it.
Partial fix for
https://github.com/zephyrproject-rtos/zephyr/issues/9573, without the
part in #issuecomment-469701831. Can still run into issues when e.g.
when CMake files can't make sense of settings.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-20 11:25:13 +01:00
|
|
|
# Load configuration files
|
|
|
|
print(kconf.load_config(args.configs_in[0]))
|
|
|
|
for config in args.configs_in[1:]:
|
2018-09-04 15:12:25 +02:00
|
|
|
# replace=False creates a merged configuration
|
2019-06-03 19:56:44 +02:00
|
|
|
print(kconf.load_config(config, replace=False))
|
2018-05-04 16:47:59 +02:00
|
|
|
|
kconfig/cmake: Improve reconfiguration behavior
There are some issues with the behavior when rerunning CMake in an
already initialized build directory:
1. The check for assignments to promptless symbols in configuration
fragments isn't run when reconfiguring, because it only runs if
zephyr/.config doesn't exist
2. As outlined in
https://github.com/zephyrproject-rtos/zephyr/issues/9573, you can
get into situations where zephyr/.config is invalid (e.g. due to
being outdated), but menuconfig/guiconfig can't be run to fix it
3. If kconfig.py fails while merging fragments during reconfiguration,
it will ignore the fragments during the next reconfiguration and use
the existing zephyr/.config instead, because the fragment checksum
is calculated and saved before running kconfig.py
(Footnote: The input configuration file(s) to kconfig.py can be either a
list of configuration fragments, when merging fragments, or just
zephyr/.config, if the merged configuration is up-to-date. The output
configuration file is always zephyr/.config.)
To fix the first two issues, explicitly tell kconfig.py when it's
dealing with handwritten configuration input (fragments), via a new
--handwritten-input-configs flag. This is more robust than checking
whether zephyr/.config exists, which was the old logic.
When dealing with handwritten input, there should be no assignments to
promptless symbols. Assignments to promptless symbols is expected in
zephyr/.config however, because it doubles as configuration output.
When running menuconfig/guiconfig, the input configuration is
zephyr/.config rather than configuration fragments, so this change also
makes sure that menuconfig can always be run as long as zephyr/.config
exists and is up-to-date.
To fix the last issue, only write the checksum for the configuration
fragments if kconfig.py succeeds (which means it wrote a
zephyr/.config).
Also improve naming a bit, add help texts for the command-line
parameters to kconfig.py, and simplify write_kconfig_filenames() by
moving logic into it.
Partial fix for
https://github.com/zephyrproject-rtos/zephyr/issues/9573, without the
part in #issuecomment-469701831. Can still run into issues when e.g.
when CMake files can't make sense of settings.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-20 11:25:13 +01:00
|
|
|
if args.handwritten_input_configs:
|
|
|
|
# Check that there are no assignments to promptless symbols, which
|
|
|
|
# have no effect.
|
2019-11-16 03:36:01 +01:00
|
|
|
#
|
kconfig/cmake: Improve reconfiguration behavior
There are some issues with the behavior when rerunning CMake in an
already initialized build directory:
1. The check for assignments to promptless symbols in configuration
fragments isn't run when reconfiguring, because it only runs if
zephyr/.config doesn't exist
2. As outlined in
https://github.com/zephyrproject-rtos/zephyr/issues/9573, you can
get into situations where zephyr/.config is invalid (e.g. due to
being outdated), but menuconfig/guiconfig can't be run to fix it
3. If kconfig.py fails while merging fragments during reconfiguration,
it will ignore the fragments during the next reconfiguration and use
the existing zephyr/.config instead, because the fragment checksum
is calculated and saved before running kconfig.py
(Footnote: The input configuration file(s) to kconfig.py can be either a
list of configuration fragments, when merging fragments, or just
zephyr/.config, if the merged configuration is up-to-date. The output
configuration file is always zephyr/.config.)
To fix the first two issues, explicitly tell kconfig.py when it's
dealing with handwritten configuration input (fragments), via a new
--handwritten-input-configs flag. This is more robust than checking
whether zephyr/.config exists, which was the old logic.
When dealing with handwritten input, there should be no assignments to
promptless symbols. Assignments to promptless symbols is expected in
zephyr/.config however, because it doubles as configuration output.
When running menuconfig/guiconfig, the input configuration is
zephyr/.config rather than configuration fragments, so this change also
makes sure that menuconfig can always be run as long as zephyr/.config
exists and is up-to-date.
To fix the last issue, only write the checksum for the configuration
fragments if kconfig.py succeeds (which means it wrote a
zephyr/.config).
Also improve naming a bit, add help texts for the command-line
parameters to kconfig.py, and simplify write_kconfig_filenames() by
moving logic into it.
Partial fix for
https://github.com/zephyrproject-rtos/zephyr/issues/9573, without the
part in #issuecomment-469701831. Can still run into issues when e.g.
when CMake files can't make sense of settings.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-20 11:25:13 +01:00
|
|
|
# This only makes sense when loading handwritten fragments and not when
|
|
|
|
# loading zephyr/.config, because zephyr/.config is configuration
|
|
|
|
# output and also assigns promptless symbols.
|
2019-11-16 05:05:41 +01:00
|
|
|
check_no_promptless_assign(kconf)
|
2019-11-16 03:36:01 +01:00
|
|
|
|
2020-01-20 15:27:09 +01:00
|
|
|
# Print warnings for symbols that didn't get the assigned value. Only
|
|
|
|
# do this for handwritten input too, to avoid likely unhelpful warnings
|
|
|
|
# when using an old configuration and updating Kconfig files.
|
|
|
|
check_assigned_sym_values(kconf)
|
|
|
|
check_assigned_choice_values(kconf)
|
2018-05-04 16:47:59 +02:00
|
|
|
|
2018-08-02 11:58:07 +02:00
|
|
|
# Hack: Force all symbols to be evaluated, to catch warnings generated
|
|
|
|
# during evaluation. Wait till the end to write the actual output files, so
|
|
|
|
# that we don't generate any output if there are warnings-turned-errors.
|
|
|
|
#
|
|
|
|
# Kconfiglib caches calculated symbol values internally, so this is still
|
|
|
|
# fast.
|
|
|
|
kconf.write_config(os.devnull)
|
|
|
|
|
2020-01-28 06:11:44 +01:00
|
|
|
if kconf.warnings:
|
|
|
|
# Put a blank line between warnings to make them easier to read
|
|
|
|
for warning in kconf.warnings:
|
|
|
|
print("\n" + warning, file=sys.stderr)
|
2018-06-13 05:58:35 +02:00
|
|
|
|
2020-01-28 06:11:44 +01:00
|
|
|
# Turn all warnings into errors, so that e.g. assignments to undefined
|
|
|
|
# Kconfig symbols become errors.
|
|
|
|
#
|
|
|
|
# A warning is generated by this script whenever a symbol gets a
|
|
|
|
# different value than the one it was assigned. Keep that one as just a
|
|
|
|
# warning for now.
|
|
|
|
err("Aborting due to Kconfig warnings")
|
2018-05-04 16:47:59 +02:00
|
|
|
|
2018-08-02 11:58:07 +02:00
|
|
|
# Write the merged configuration and the C header
|
kconfig/cmake: Improve reconfiguration behavior
There are some issues with the behavior when rerunning CMake in an
already initialized build directory:
1. The check for assignments to promptless symbols in configuration
fragments isn't run when reconfiguring, because it only runs if
zephyr/.config doesn't exist
2. As outlined in
https://github.com/zephyrproject-rtos/zephyr/issues/9573, you can
get into situations where zephyr/.config is invalid (e.g. due to
being outdated), but menuconfig/guiconfig can't be run to fix it
3. If kconfig.py fails while merging fragments during reconfiguration,
it will ignore the fragments during the next reconfiguration and use
the existing zephyr/.config instead, because the fragment checksum
is calculated and saved before running kconfig.py
(Footnote: The input configuration file(s) to kconfig.py can be either a
list of configuration fragments, when merging fragments, or just
zephyr/.config, if the merged configuration is up-to-date. The output
configuration file is always zephyr/.config.)
To fix the first two issues, explicitly tell kconfig.py when it's
dealing with handwritten configuration input (fragments), via a new
--handwritten-input-configs flag. This is more robust than checking
whether zephyr/.config exists, which was the old logic.
When dealing with handwritten input, there should be no assignments to
promptless symbols. Assignments to promptless symbols is expected in
zephyr/.config however, because it doubles as configuration output.
When running menuconfig/guiconfig, the input configuration is
zephyr/.config rather than configuration fragments, so this change also
makes sure that menuconfig can always be run as long as zephyr/.config
exists and is up-to-date.
To fix the last issue, only write the checksum for the configuration
fragments if kconfig.py succeeds (which means it wrote a
zephyr/.config).
Also improve naming a bit, add help texts for the command-line
parameters to kconfig.py, and simplify write_kconfig_filenames() by
moving logic into it.
Partial fix for
https://github.com/zephyrproject-rtos/zephyr/issues/9573, without the
part in #issuecomment-469701831. Can still run into issues when e.g.
when CMake files can't make sense of settings.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-20 11:25:13 +01:00
|
|
|
print(kconf.write_config(args.config_out))
|
kconfig/devicetree: Print path to headers when configuring
Change the output during CMake configure from
Devicetree configuration written to .../devicetree.conf
Parsing /home/ulf/z/z/Kconfig
Loaded configuration '.../frdm_kw41z_defconfig'
Merged configuration '.../prj.conf'
Configuration saved to '.../.config'
to
Devicetree header saved to '.../devicetree_unfixed.h'
Parsing /home/ulf/z/z/Kconfig
Loaded configuration '.../frdm_kw41z_defconfig'
Merged configuration '.../prj.conf'
Configuration saved to '.../.config'
Kconfig header saved to '.../autoconf.h'
devicetree_unfixed.h is more useful to be aware of than devicetree.conf
(still hoping we can get rid of it at some point), and seeing the
Kconfig header clarifies things to.
"Saved" instead of "written" for consistency. Maybe it could say
"Kconfig configuration" instead of "configuration" too, though it gets a
bit spammy in other contexts where the message shows up.
Updates Kconfiglib (and menuconfig/guiconfig, just to sync) to upstream
revision 061e71f7d7, to get this commit in, which is used to print the
header path:
Return a message from Kconfig.write_autoconf()
Like for Kconfig.write_config() and Kconfig.write_min_config(),
return a string from Kconfig.write_autoconf() with a message saying
that the header got saved, or that there were no changes to it. Can
be handy in tools.
Also make the "no change" message for the various files more
specific, by mentioning what type of file it is (configuration,
header, etc.)
Return True/False from Kconfig._write_if_changed() to indicate if
the file was updated. This also allows it to be reused in
Kconfig.write_min_config().
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-31 06:38:10 +01:00
|
|
|
print(kconf.write_autoconf(args.header_out))
|
2018-08-02 11:58:07 +02:00
|
|
|
|
kconfig/cmake: Improve reconfiguration behavior
There are some issues with the behavior when rerunning CMake in an
already initialized build directory:
1. The check for assignments to promptless symbols in configuration
fragments isn't run when reconfiguring, because it only runs if
zephyr/.config doesn't exist
2. As outlined in
https://github.com/zephyrproject-rtos/zephyr/issues/9573, you can
get into situations where zephyr/.config is invalid (e.g. due to
being outdated), but menuconfig/guiconfig can't be run to fix it
3. If kconfig.py fails while merging fragments during reconfiguration,
it will ignore the fragments during the next reconfiguration and use
the existing zephyr/.config instead, because the fragment checksum
is calculated and saved before running kconfig.py
(Footnote: The input configuration file(s) to kconfig.py can be either a
list of configuration fragments, when merging fragments, or just
zephyr/.config, if the merged configuration is up-to-date. The output
configuration file is always zephyr/.config.)
To fix the first two issues, explicitly tell kconfig.py when it's
dealing with handwritten configuration input (fragments), via a new
--handwritten-input-configs flag. This is more robust than checking
whether zephyr/.config exists, which was the old logic.
When dealing with handwritten input, there should be no assignments to
promptless symbols. Assignments to promptless symbols is expected in
zephyr/.config however, because it doubles as configuration output.
When running menuconfig/guiconfig, the input configuration is
zephyr/.config rather than configuration fragments, so this change also
makes sure that menuconfig can always be run as long as zephyr/.config
exists and is up-to-date.
To fix the last issue, only write the checksum for the configuration
fragments if kconfig.py succeeds (which means it wrote a
zephyr/.config).
Also improve naming a bit, add help texts for the command-line
parameters to kconfig.py, and simplify write_kconfig_filenames() by
moving logic into it.
Partial fix for
https://github.com/zephyrproject-rtos/zephyr/issues/9573, without the
part in #issuecomment-469701831. Can still run into issues when e.g.
when CMake files can't make sense of settings.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-20 11:25:13 +01:00
|
|
|
# Write the list of parsed Kconfig files to a file
|
|
|
|
write_kconfig_filenames(kconf, args.kconfig_list_out)
|
2019-02-20 17:49:46 +01:00
|
|
|
|
2018-08-02 11:58:07 +02:00
|
|
|
|
2019-11-16 05:05:41 +01:00
|
|
|
def check_no_promptless_assign(kconf):
|
2019-11-16 03:36:01 +01:00
|
|
|
# Checks that no promptless symbols are assigned
|
2018-06-15 15:31:47 +02:00
|
|
|
|
2019-11-16 03:36:01 +01:00
|
|
|
for sym in kconf.unique_defined_syms:
|
|
|
|
if sym.user_value is not None and promptless(sym):
|
2020-01-22 22:50:05 +01:00
|
|
|
err(f"""\
|
|
|
|
{sym.name_and_loc} is assigned in a configuration file, but is not directly
|
|
|
|
user-configurable (has no prompt). It gets its value indirectly from other
|
|
|
|
symbols. """ + SYM_INFO_HINT.format(sym))
|
2018-06-15 15:31:47 +02:00
|
|
|
|
|
|
|
|
2020-01-20 15:27:09 +01:00
|
|
|
def check_assigned_sym_values(kconf):
|
|
|
|
# Verifies that the values assigned to symbols "took" (matches the value
|
|
|
|
# the symbols actually got), printing warnings otherwise. Choice symbols
|
|
|
|
# are checked separately, in check_assigned_choice_values().
|
|
|
|
|
|
|
|
for sym in kconf.unique_defined_syms:
|
|
|
|
if sym.choice:
|
|
|
|
continue
|
2018-06-06 16:06:22 +02:00
|
|
|
|
|
|
|
user_value = sym.user_value
|
2020-01-20 15:27:09 +01:00
|
|
|
if user_value is None:
|
|
|
|
continue
|
|
|
|
|
|
|
|
# Tristate values are represented as 0, 1, 2. Having them as "n", "m",
|
|
|
|
# "y" is more convenient here, so convert.
|
|
|
|
if sym.type in (BOOL, TRISTATE):
|
|
|
|
user_value = TRI_TO_STR[user_value]
|
|
|
|
|
|
|
|
if user_value != sym.str_value:
|
2020-02-12 15:42:09 +01:00
|
|
|
msg = f"{sym.name_and_loc} was assigned the value '{user_value}'" \
|
|
|
|
f" but got the value '{sym.str_value}'. "
|
2020-01-20 15:27:09 +01:00
|
|
|
|
|
|
|
# List any unsatisfied 'depends on' dependencies in the warning
|
|
|
|
mdeps = missing_deps(sym)
|
|
|
|
if mdeps:
|
|
|
|
expr_strs = []
|
|
|
|
for expr in mdeps:
|
|
|
|
estr = expr_str(expr)
|
|
|
|
if isinstance(expr, tuple):
|
|
|
|
# Add () around dependencies that aren't plain symbols.
|
|
|
|
# Gives '(FOO || BAR) (=n)' instead of
|
|
|
|
# 'FOO || BAR (=n)', which might be clearer.
|
|
|
|
estr = f"({estr})"
|
2020-02-12 15:42:09 +01:00
|
|
|
expr_strs.append(f"{estr} "
|
|
|
|
f"(={TRI_TO_STR[expr_value(expr)]})")
|
2020-01-20 15:27:09 +01:00
|
|
|
|
|
|
|
msg += "Check these unsatisfied dependencies: " + \
|
|
|
|
", ".join(expr_strs) + ". "
|
|
|
|
|
|
|
|
warn(msg + SYM_INFO_HINT.format(sym))
|
|
|
|
|
|
|
|
|
|
|
|
def missing_deps(sym):
|
|
|
|
# check_assigned_sym_values() helper for finding unsatisfied dependencies.
|
|
|
|
#
|
|
|
|
# Given direct dependencies
|
|
|
|
#
|
|
|
|
# depends on <expr> && <expr> && ... && <expr>
|
|
|
|
#
|
|
|
|
# on 'sym' (which can also come from e.g. a surrounding 'if'), returns a
|
|
|
|
# list of all <expr>s with a value less than the value 'sym' was assigned
|
|
|
|
# ("less" instead of "not equal" just to be general and handle tristates,
|
|
|
|
# even though Zephyr doesn't use them).
|
|
|
|
#
|
|
|
|
# For string/int/hex symbols, just looks for <expr> = n.
|
|
|
|
#
|
|
|
|
# Note that <expr>s can be something more complicated than just a symbol,
|
|
|
|
# like 'FOO || BAR' or 'FOO = "string"'.
|
2018-06-06 16:06:22 +02:00
|
|
|
|
2020-01-20 15:27:09 +01:00
|
|
|
deps = split_expr(sym.direct_dep, AND)
|
2018-06-28 12:06:12 +02:00
|
|
|
|
2020-01-20 15:27:09 +01:00
|
|
|
if sym.type in (BOOL, TRISTATE):
|
|
|
|
return [dep for dep in deps if expr_value(dep) < sym.user_value]
|
|
|
|
# string/int/hex
|
|
|
|
return [dep for dep in deps if expr_value(dep) == 0]
|
2018-06-28 12:06:12 +02:00
|
|
|
|
2020-01-20 15:27:09 +01:00
|
|
|
|
|
|
|
def check_assigned_choice_values(kconf):
|
|
|
|
# Verifies that any choice symbols that were selected (by setting them to
|
|
|
|
# y) ended up as the selection, printing warnings otherwise.
|
2018-06-28 12:06:12 +02:00
|
|
|
#
|
|
|
|
# We check choice symbols separately to avoid warnings when two different
|
|
|
|
# choice symbols within the same choice are set to y. This might happen if
|
2020-02-12 15:42:09 +01:00
|
|
|
# a choice selection from a board defconfig is overridden in a prj.conf,
|
|
|
|
# for example. The last choice symbol set to y becomes the selection (and
|
|
|
|
# all other choice symbols get the value n).
|
2018-06-28 12:06:12 +02:00
|
|
|
#
|
|
|
|
# Without special-casing choices, we'd detect that the first symbol set to
|
|
|
|
# y ended up as n, and print a spurious warning.
|
|
|
|
|
2020-01-20 15:27:09 +01:00
|
|
|
for choice in kconf.unique_choices:
|
|
|
|
if choice.user_selection and \
|
|
|
|
choice.user_selection is not choice.selection:
|
|
|
|
|
2020-01-22 22:50:05 +01:00
|
|
|
warn(f"""\
|
2020-01-28 07:23:10 +01:00
|
|
|
The choice symbol {choice.user_selection.name_and_loc} was selected (set =y),
|
2020-01-22 22:50:05 +01:00
|
|
|
but {choice.selection.name_and_loc if choice.selection else "no symbol"} ended
|
|
|
|
up as the choice selection. """ + SYM_INFO_HINT.format(choice.user_selection))
|
2019-11-16 03:36:01 +01:00
|
|
|
|
2018-06-28 12:06:12 +02:00
|
|
|
|
2020-01-20 15:27:09 +01:00
|
|
|
# Hint on where to find symbol information. Used like
|
|
|
|
# SYM_INFO_HINT.format(sym).
|
2019-11-16 03:36:01 +01:00
|
|
|
SYM_INFO_HINT = """\
|
|
|
|
See http://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_{0.name}.html
|
|
|
|
and/or look up {0.name} in the menuconfig/guiconfig interface. The Application
|
|
|
|
Development Primer, Setting Configuration Values, and Kconfig - Tips and Best
|
|
|
|
Practices sections of the manual might be helpful too.\
|
|
|
|
"""
|
2018-06-06 16:06:22 +02:00
|
|
|
|
|
|
|
|
2018-06-15 15:31:47 +02:00
|
|
|
def promptless(sym):
|
|
|
|
# Returns True if 'sym' has no prompt. Since the symbol might be defined in
|
|
|
|
# multiple locations, we need to check all locations.
|
|
|
|
|
2018-09-04 15:12:25 +02:00
|
|
|
return not any(node.prompt for node in sym.nodes)
|
2018-06-15 15:31:47 +02:00
|
|
|
|
2019-08-08 14:46:08 +02:00
|
|
|
|
kconfig/cmake: Improve reconfiguration behavior
There are some issues with the behavior when rerunning CMake in an
already initialized build directory:
1. The check for assignments to promptless symbols in configuration
fragments isn't run when reconfiguring, because it only runs if
zephyr/.config doesn't exist
2. As outlined in
https://github.com/zephyrproject-rtos/zephyr/issues/9573, you can
get into situations where zephyr/.config is invalid (e.g. due to
being outdated), but menuconfig/guiconfig can't be run to fix it
3. If kconfig.py fails while merging fragments during reconfiguration,
it will ignore the fragments during the next reconfiguration and use
the existing zephyr/.config instead, because the fragment checksum
is calculated and saved before running kconfig.py
(Footnote: The input configuration file(s) to kconfig.py can be either a
list of configuration fragments, when merging fragments, or just
zephyr/.config, if the merged configuration is up-to-date. The output
configuration file is always zephyr/.config.)
To fix the first two issues, explicitly tell kconfig.py when it's
dealing with handwritten configuration input (fragments), via a new
--handwritten-input-configs flag. This is more robust than checking
whether zephyr/.config exists, which was the old logic.
When dealing with handwritten input, there should be no assignments to
promptless symbols. Assignments to promptless symbols is expected in
zephyr/.config however, because it doubles as configuration output.
When running menuconfig/guiconfig, the input configuration is
zephyr/.config rather than configuration fragments, so this change also
makes sure that menuconfig can always be run as long as zephyr/.config
exists and is up-to-date.
To fix the last issue, only write the checksum for the configuration
fragments if kconfig.py succeeds (which means it wrote a
zephyr/.config).
Also improve naming a bit, add help texts for the command-line
parameters to kconfig.py, and simplify write_kconfig_filenames() by
moving logic into it.
Partial fix for
https://github.com/zephyrproject-rtos/zephyr/issues/9573, without the
part in #issuecomment-469701831. Can still run into issues when e.g.
when CMake files can't make sense of settings.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-20 11:25:13 +01:00
|
|
|
def write_kconfig_filenames(kconf, kconfig_list_path):
|
|
|
|
# Writes a sorted list with the absolute paths of all parsed Kconfig files
|
|
|
|
# to 'kconfig_list_path'. The paths are realpath()'d, and duplicates are
|
|
|
|
# removed. This file is used by CMake to look for changed Kconfig files. It
|
|
|
|
# needs to be deterministic.
|
2019-02-20 17:49:46 +01:00
|
|
|
|
kconfig/cmake: Improve reconfiguration behavior
There are some issues with the behavior when rerunning CMake in an
already initialized build directory:
1. The check for assignments to promptless symbols in configuration
fragments isn't run when reconfiguring, because it only runs if
zephyr/.config doesn't exist
2. As outlined in
https://github.com/zephyrproject-rtos/zephyr/issues/9573, you can
get into situations where zephyr/.config is invalid (e.g. due to
being outdated), but menuconfig/guiconfig can't be run to fix it
3. If kconfig.py fails while merging fragments during reconfiguration,
it will ignore the fragments during the next reconfiguration and use
the existing zephyr/.config instead, because the fragment checksum
is calculated and saved before running kconfig.py
(Footnote: The input configuration file(s) to kconfig.py can be either a
list of configuration fragments, when merging fragments, or just
zephyr/.config, if the merged configuration is up-to-date. The output
configuration file is always zephyr/.config.)
To fix the first two issues, explicitly tell kconfig.py when it's
dealing with handwritten configuration input (fragments), via a new
--handwritten-input-configs flag. This is more robust than checking
whether zephyr/.config exists, which was the old logic.
When dealing with handwritten input, there should be no assignments to
promptless symbols. Assignments to promptless symbols is expected in
zephyr/.config however, because it doubles as configuration output.
When running menuconfig/guiconfig, the input configuration is
zephyr/.config rather than configuration fragments, so this change also
makes sure that menuconfig can always be run as long as zephyr/.config
exists and is up-to-date.
To fix the last issue, only write the checksum for the configuration
fragments if kconfig.py succeeds (which means it wrote a
zephyr/.config).
Also improve naming a bit, add help texts for the command-line
parameters to kconfig.py, and simplify write_kconfig_filenames() by
moving logic into it.
Partial fix for
https://github.com/zephyrproject-rtos/zephyr/issues/9573, without the
part in #issuecomment-469701831. Can still run into issues when e.g.
when CMake files can't make sense of settings.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-20 11:25:13 +01:00
|
|
|
with open(kconfig_list_path, 'w') as out:
|
|
|
|
for path in sorted({os.path.realpath(os.path.join(kconf.srctree, path))
|
|
|
|
for path in kconf.kconfig_filenames}):
|
2019-11-16 05:12:00 +01:00
|
|
|
print(path, file=out)
|
2019-02-20 17:49:46 +01:00
|
|
|
|
2018-06-15 15:31:47 +02:00
|
|
|
|
2018-05-04 16:47:59 +02:00
|
|
|
def parse_args():
|
2019-10-29 19:32:17 +01:00
|
|
|
parser = argparse.ArgumentParser()
|
2018-04-26 18:55:37 +02:00
|
|
|
|
kconfig/cmake: Improve reconfiguration behavior
There are some issues with the behavior when rerunning CMake in an
already initialized build directory:
1. The check for assignments to promptless symbols in configuration
fragments isn't run when reconfiguring, because it only runs if
zephyr/.config doesn't exist
2. As outlined in
https://github.com/zephyrproject-rtos/zephyr/issues/9573, you can
get into situations where zephyr/.config is invalid (e.g. due to
being outdated), but menuconfig/guiconfig can't be run to fix it
3. If kconfig.py fails while merging fragments during reconfiguration,
it will ignore the fragments during the next reconfiguration and use
the existing zephyr/.config instead, because the fragment checksum
is calculated and saved before running kconfig.py
(Footnote: The input configuration file(s) to kconfig.py can be either a
list of configuration fragments, when merging fragments, or just
zephyr/.config, if the merged configuration is up-to-date. The output
configuration file is always zephyr/.config.)
To fix the first two issues, explicitly tell kconfig.py when it's
dealing with handwritten configuration input (fragments), via a new
--handwritten-input-configs flag. This is more robust than checking
whether zephyr/.config exists, which was the old logic.
When dealing with handwritten input, there should be no assignments to
promptless symbols. Assignments to promptless symbols is expected in
zephyr/.config however, because it doubles as configuration output.
When running menuconfig/guiconfig, the input configuration is
zephyr/.config rather than configuration fragments, so this change also
makes sure that menuconfig can always be run as long as zephyr/.config
exists and is up-to-date.
To fix the last issue, only write the checksum for the configuration
fragments if kconfig.py succeeds (which means it wrote a
zephyr/.config).
Also improve naming a bit, add help texts for the command-line
parameters to kconfig.py, and simplify write_kconfig_filenames() by
moving logic into it.
Partial fix for
https://github.com/zephyrproject-rtos/zephyr/issues/9573, without the
part in #issuecomment-469701831. Can still run into issues when e.g.
when CMake files can't make sense of settings.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-20 11:25:13 +01:00
|
|
|
parser.add_argument("--handwritten-input-configs",
|
|
|
|
action="store_true",
|
|
|
|
help="Assume the input configuration fragments are "
|
|
|
|
"handwritten fragments and do additional checks "
|
|
|
|
"on them, like no promptless symbols being "
|
|
|
|
"assigned")
|
2020-02-12 15:42:09 +01:00
|
|
|
parser.add_argument("--zephyr-base",
|
|
|
|
help="Path to current Zephyr installation")
|
kconfig/cmake: Improve reconfiguration behavior
There are some issues with the behavior when rerunning CMake in an
already initialized build directory:
1. The check for assignments to promptless symbols in configuration
fragments isn't run when reconfiguring, because it only runs if
zephyr/.config doesn't exist
2. As outlined in
https://github.com/zephyrproject-rtos/zephyr/issues/9573, you can
get into situations where zephyr/.config is invalid (e.g. due to
being outdated), but menuconfig/guiconfig can't be run to fix it
3. If kconfig.py fails while merging fragments during reconfiguration,
it will ignore the fragments during the next reconfiguration and use
the existing zephyr/.config instead, because the fragment checksum
is calculated and saved before running kconfig.py
(Footnote: The input configuration file(s) to kconfig.py can be either a
list of configuration fragments, when merging fragments, or just
zephyr/.config, if the merged configuration is up-to-date. The output
configuration file is always zephyr/.config.)
To fix the first two issues, explicitly tell kconfig.py when it's
dealing with handwritten configuration input (fragments), via a new
--handwritten-input-configs flag. This is more robust than checking
whether zephyr/.config exists, which was the old logic.
When dealing with handwritten input, there should be no assignments to
promptless symbols. Assignments to promptless symbols is expected in
zephyr/.config however, because it doubles as configuration output.
When running menuconfig/guiconfig, the input configuration is
zephyr/.config rather than configuration fragments, so this change also
makes sure that menuconfig can always be run as long as zephyr/.config
exists and is up-to-date.
To fix the last issue, only write the checksum for the configuration
fragments if kconfig.py succeeds (which means it wrote a
zephyr/.config).
Also improve naming a bit, add help texts for the command-line
parameters to kconfig.py, and simplify write_kconfig_filenames() by
moving logic into it.
Partial fix for
https://github.com/zephyrproject-rtos/zephyr/issues/9573, without the
part in #issuecomment-469701831. Can still run into issues when e.g.
when CMake files can't make sense of settings.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-20 11:25:13 +01:00
|
|
|
parser.add_argument("kconfig_file",
|
|
|
|
help="Top-level Kconfig file")
|
|
|
|
parser.add_argument("config_out",
|
|
|
|
help="Output configuration file")
|
|
|
|
parser.add_argument("header_out",
|
|
|
|
help="Output header file")
|
|
|
|
parser.add_argument("kconfig_list_out",
|
|
|
|
help="Output file for list of parsed Kconfig files")
|
|
|
|
parser.add_argument("configs_in",
|
|
|
|
nargs="+",
|
|
|
|
help="Input configuration fragments. Will be merged "
|
|
|
|
"together.")
|
2018-01-03 16:38:50 +01:00
|
|
|
|
2018-11-17 20:28:09 +01:00
|
|
|
return parser.parse_args()
|
2018-04-26 18:55:37 +02:00
|
|
|
|
|
|
|
|
2019-11-16 03:36:01 +01:00
|
|
|
def warn(msg):
|
|
|
|
# Use a large fill() width to try to avoid linebreaks in the symbol
|
2020-01-28 07:23:10 +01:00
|
|
|
# reference link, and add some extra newlines to set the message off from
|
2019-11-16 03:36:01 +01:00
|
|
|
# surrounding text (this usually gets printed as part of spammy CMake
|
2020-01-28 07:23:10 +01:00
|
|
|
# output)
|
|
|
|
print("\n" + textwrap.fill("warning: " + msg, 100) + "\n", file=sys.stderr)
|
2019-11-16 03:36:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
def err(msg):
|
2020-01-28 07:23:10 +01:00
|
|
|
sys.exit("\n" + textwrap.fill("error: " + msg, 100) + "\n")
|
2019-11-16 03:36:01 +01:00
|
|
|
|
|
|
|
|
2018-05-04 16:47:59 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|