Tools: Add "idf.py save-defconfig" command to generate sdkconfig.defaults

This commit is contained in:
Roland Dobai 2021-12-14 15:31:08 +01:00
parent 5ddce053ea
commit 5118dd7cf3
6 changed files with 60 additions and 4 deletions

View File

@ -1,6 +1,6 @@
# #
# For a description of the syntax of this configuration file, # Please run the following command for opening a page with more information about this configuration file:
# see kconfig/kconfig-language.txt. # idf.py docs -sp api-reference/kconfig.html
# #
mainmenu "Espressif IoT Development Framework Configuration" mainmenu "Espressif IoT Development Framework Configuration"

View File

@ -23,7 +23,9 @@ After being updated, this configuration is saved inside ``sdkconfig`` file in th
Using sdkconfig.defaults Using sdkconfig.defaults
======================== ========================
In some cases, such as when ``sdkconfig`` file is under revision control, the fact that ``sdkconfig`` file gets changed by the build system may be inconvenient. The build system offers a way to avoid this, in the form of ``sdkconfig.defaults`` file. This file is never touched by the build system, and must be created manually. It can contain all the options which matter for the given application. The format is the same as that of the ``sdkconfig`` file. Once ``sdkconfig.defaults`` is created, ``sdkconfig`` can be deleted and added to the ignore list of the revision control system (e.g. ``.gitignore`` file for git). Project build targets will automatically create ``sdkconfig`` file, populated with the settings from ``sdkconfig.defaults`` file, and the rest of the settings will be set to their default values. Note that the build process will not override settings that are already in ``sdkconfig`` by ones from ``sdkconfig.defaults``. For more information, see :ref:`custom-sdkconfig-defaults`. In some cases, such as when ``sdkconfig`` file is under revision control, the fact that ``sdkconfig`` file gets changed by the build system may be inconvenient. The build system offers a way to avoid this, in the form of ``sdkconfig.defaults`` file. This file is never touched by the build system, and can be created manually or automatically. It can contain all the options which matter for the given application and are different from the default ones. The format is the same as that of the ``sdkconfig`` file. ``sdkconfig.defaults`` can be created manually when one remembers all the changed configurations. Otherwise, the file can be generated automatically by running the ``idf.py save-defconfig`` command.
Once ``sdkconfig.defaults`` is created, ``sdkconfig`` can be deleted and added to the ignore list of the revision control system (e.g. ``.gitignore`` file for ``git``). Project build targets will automatically create ``sdkconfig`` file, populated with the settings from ``sdkconfig.defaults`` file, and the rest of the settings will be set to their default values. Note that the build process will not override settings that are already in ``sdkconfig`` by ones from ``sdkconfig.defaults``. For more information, see :ref:`custom-sdkconfig-defaults`.
Kconfig Formatting Rules Kconfig Formatting Rules
======================== ========================

View File

@ -877,6 +877,31 @@ endmenu\n" >> ${IDF_PATH}/Kconfig
grep "Warning: Command efuse_common_table is deprecated and will be removed in the next major release." tmp.log || failure "Missing deprecation warning with command \"efuse_common_table\"" grep "Warning: Command efuse_common_table is deprecated and will be removed in the next major release." tmp.log || failure "Missing deprecation warning with command \"efuse_common_table\""
rm tmp.log rm tmp.log
print_status "Save-defconfig checks"
cd ${TESTDIR}/template
rm -f sdkconfig.defaults
rm -f sdkconfig
idf.py fullclean > /dev/null
echo "CONFIG_COMPILER_OPTIMIZATION_SIZE=y" >> sdkconfig
echo "CONFIG_ESPTOOLPY_FLASHFREQ_80M=y" >> sdkconfig
idf.py save-defconfig
wc -l sdkconfig.defaults
grep "CONFIG_IDF_TARGET" sdkconfig.defaults && failure "CONFIG_IDF_TARGET should not be in sdkconfig.defaults"
grep "CONFIG_COMPILER_OPTIMIZATION_SIZE=y" sdkconfig.defaults || failure "Missing CONFIG_COMPILER_OPTIMIZATION_SIZE=y in sdkconfig.defaults"
grep "CONFIG_ESPTOOLPY_FLASHFREQ_80M=y" sdkconfig.defaults || failure "Missing CONFIG_ESPTOOLPY_FLASHFREQ_80M=y in sdkconfig.defaults"
idf.py fullclean > /dev/null
rm -f sdkconfig.defaults
rm -f sdkconfig
idf.py set-target esp32c3
echo "CONFIG_PARTITION_TABLE_OFFSET=0x8001" >> sdkconfig
idf.py save-defconfig
wc -l sdkconfig.defaults
grep "CONFIG_IDF_TARGET=\"esp32c3\"" sdkconfig.defaults || failure "Missing CONFIG_IDF_TARGET=\"esp32c3\" in sdkconfig.defaults"
grep "CONFIG_PARTITION_TABLE_OFFSET=0x8001" sdkconfig.defaults || failure "Missing CONFIG_PARTITION_TABLE_OFFSET=0x8001 in sdkconfig.defaults"
idf.py fullclean > /dev/null
rm -f sdkconfig.defaults
rm -f sdkconfig
print_status "All tests completed" print_status "All tests completed"
if [ -n "${FAILURES}" ]; then if [ -n "${FAILURES}" ]; then
echo "Some failures were detected:" echo "Some failures were detected:"

View File

@ -243,4 +243,12 @@ function(__kconfig_generate_config sdkconfig sdkconfig_defaults)
--config ${sdkconfig} --config ${sdkconfig}
VERBATIM VERBATIM
USES_TERMINAL) USES_TERMINAL)
add_custom_target(save-defconfig
COMMAND ${prepare_kconfig_files_command}
COMMAND ${confgen_basecommand}
--dont-write-deprecated
--output savedefconfig ${CMAKE_SOURCE_DIR}/sdkconfig.defaults
USES_TERMINAL
)
endfunction() endfunction()

View File

@ -515,6 +515,11 @@ def action_extensions(base_actions, project_path):
'help': 'Chip target.' 'help': 'Chip target.'
} }
] ]
},
'save-defconfig': {
'callback': build_target,
'help': 'Generate a sdkconfig.defaults with options different from the default ones',
'options': global_options
} }
} }
} }

View File

@ -9,7 +9,6 @@
# #
# SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD # SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
from __future__ import print_function
import argparse import argparse
import json import json
@ -18,6 +17,7 @@ import os.path
import re import re
import sys import sys
import tempfile import tempfile
import textwrap
import gen_kconfig_doc import gen_kconfig_doc
import kconfiglib import kconfiglib
@ -328,6 +328,21 @@ def write_config(deprecated_options, config, filename):
deprecated_options.append_config(config, filename) deprecated_options.append_config(config, filename)
def write_min_config(deprecated_options, config, filename):
target_symbol = config.syms['IDF_TARGET']
# 'esp32` is harcoded here because the default value of IDF_TARGET is set on the first run from the environment
# variable. I.E. `esp32 is not defined as default value.
write_target = target_symbol.str_value != 'esp32'
CONFIG_HEADING = textwrap.dedent('''\
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
#
{}\
'''.format(target_symbol.config_string if write_target else ''))
config.write_min_config(filename, header=CONFIG_HEADING)
def write_header(deprecated_options, config, filename): def write_header(deprecated_options, config, filename):
CONFIG_HEADING = """/* CONFIG_HEADING = """/*
* Automatically generated file. DO NOT EDIT. * Automatically generated file. DO NOT EDIT.
@ -560,6 +575,7 @@ OUTPUT_FORMATS = {'config': write_config,
'docs': write_docs, 'docs': write_docs,
'json': write_json, 'json': write_json,
'json_menus': write_json_menus, 'json_menus': write_json_menus,
'savedefconfig': write_min_config,
} }