From 5118dd7cf39041eb0aabd1cdfceb5726cedac137 Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Tue, 14 Dec 2021 15:31:08 +0100 Subject: [PATCH] Tools: Add "idf.py save-defconfig" command to generate sdkconfig.defaults --- Kconfig | 4 ++-- docs/en/api-reference/kconfig.rst | 4 +++- tools/ci/test_build_system_cmake.sh | 25 +++++++++++++++++++++++++ tools/cmake/kconfig.cmake | 8 ++++++++ tools/idf_py_actions/core_ext.py | 5 +++++ tools/kconfig_new/confgen.py | 18 +++++++++++++++++- 6 files changed, 60 insertions(+), 4 deletions(-) diff --git a/Kconfig b/Kconfig index e00c0d7f6b..0ab2e745ee 100644 --- a/Kconfig +++ b/Kconfig @@ -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" diff --git a/docs/en/api-reference/kconfig.rst b/docs/en/api-reference/kconfig.rst index ee9711488d..9d697fa62a 100644 --- a/docs/en/api-reference/kconfig.rst +++ b/docs/en/api-reference/kconfig.rst @@ -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 ======================== diff --git a/tools/ci/test_build_system_cmake.sh b/tools/ci/test_build_system_cmake.sh index 849404a293..6d52297afe 100755 --- a/tools/ci/test_build_system_cmake.sh +++ b/tools/ci/test_build_system_cmake.sh @@ -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\"" 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:" diff --git a/tools/cmake/kconfig.cmake b/tools/cmake/kconfig.cmake index 40e425e258..3400ba61a2 100644 --- a/tools/cmake/kconfig.cmake +++ b/tools/cmake/kconfig.cmake @@ -243,4 +243,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() diff --git a/tools/idf_py_actions/core_ext.py b/tools/idf_py_actions/core_ext.py index b67c2e82c4..930d1614fe 100644 --- a/tools/idf_py_actions/core_ext.py +++ b/tools/idf_py_actions/core_ext.py @@ -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 } } } diff --git a/tools/kconfig_new/confgen.py b/tools/kconfig_new/confgen.py index 4e9d1e9618..fa176e5718 100755 --- a/tools/kconfig_new/confgen.py +++ b/tools/kconfig_new/confgen.py @@ -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 @@ -328,6 +328,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. @@ -560,6 +575,7 @@ OUTPUT_FORMATS = {'config': write_config, 'docs': write_docs, 'json': write_json, 'json_menus': write_json_menus, + 'savedefconfig': write_min_config, }