Merge branch 'feature/idf_py_savedefconfig' into 'master'

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

Closes IDF-2970

See merge request espressif/esp-idf!16409
pull/8134/head
Roland Dobai 2021-12-20 08:23:43 +00:00
commit b886dc6998
6 zmienionych plików z 60 dodań i 4 usunięć

Wyświetl plik

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

Wyświetl plik

@ -23,7 +23,9 @@ After being updated, this configuration is saved inside ``sdkconfig`` file in th
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
========================

Wyświetl plik

@ -889,6 +889,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\""
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"
if [ -n "${FAILURES}" ]; then
echo "Some failures were detected:"

Wyświetl plik

@ -241,4 +241,12 @@ function(__kconfig_generate_config sdkconfig sdkconfig_defaults)
--config ${sdkconfig}
VERBATIM
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()

Wyświetl plik

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

Wyświetl plik

@ -9,7 +9,6 @@
#
# SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
from __future__ import print_function
import argparse
import json
@ -18,6 +17,7 @@ import os.path
import re
import sys
import tempfile
import textwrap
import gen_kconfig_doc
import kconfiglib
@ -336,6 +336,21 @@ def write_config(deprecated_options, 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):
CONFIG_HEADING = """/*
* Automatically generated file. DO NOT EDIT.
@ -568,6 +583,7 @@ OUTPUT_FORMATS = {'config': write_config,
'docs': write_docs,
'json': write_json,
'json_menus': write_json_menus,
'savedefconfig': write_min_config,
}