- 
                Notifications
    You must be signed in to change notification settings 
- Fork 8.2k
scripts: kconfig: Replace conf with Python #5569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
812c8a7
              e7426e3
              e1b4229
              0a96841
              c067079
              13547f8
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -37,17 +37,34 @@ set(COMMAND_FOR_menuconfig ${KCONFIG_MCONF} ${KCONFIG_ROOT}) | |
| set(COMMAND_FOR_oldconfig ${KCONFIG_CONF} --oldconfig ${KCONFIG_ROOT}) | ||
| set(COMMAND_FOR_xconfig qconf ${KCONFIG_ROOT}) | ||
|  | ||
| # Set environment variables so that Kconfig can prune Kconfig source | ||
| # files for other architectures | ||
| set(ENV{ENV_VAR_ARCH} ${ARCH}) | ||
| set(ENV{ENV_VAR_BOARD_DIR} ${BOARD_DIR}) | ||
|  | ||
| foreach(kconfig_target ${kconfig_target_list}) | ||
| add_custom_target( | ||
| ${kconfig_target} | ||
| ${CMAKE_COMMAND} -E env | ||
| srctree=${PROJECT_SOURCE_DIR} | ||
| KERNELVERSION=${PROJECT_VERSION} | ||
| KCONFIG_CONFIG=${DOTCONFIG} | ||
| ${COMMAND_FOR_${kconfig_target}} | ||
| WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig | ||
| USES_TERMINAL | ||
| ) | ||
| if (NOT WIN32) | ||
|          | ||
| add_custom_target( | ||
| ${kconfig_target} | ||
| ${CMAKE_COMMAND} -E env | ||
| srctree=${PROJECT_SOURCE_DIR} | ||
| KERNELVERSION=${PROJECT_VERSION} | ||
| KCONFIG_CONFIG=${DOTCONFIG} | ||
| ENV_VAR_ARCH=$ENV{ENV_VAR_ARCH} | ||
| ENV_VAR_BOARD_DIR=$ENV{ENV_VAR_BOARD_DIR} | ||
| ${COMMAND_FOR_${kconfig_target}} | ||
| WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig | ||
| USES_TERMINAL | ||
| ) | ||
| else() | ||
| add_custom_target( | ||
| ${kconfig_target} | ||
| ${CMAKE_COMMAND} -E echo | ||
| "=========================================" | ||
| "Reconfiguration not supported on Windows." | ||
| "=========================================" | ||
| ) | ||
| endif() | ||
| endforeach() | ||
|  | ||
| # Bring in extra configuration files dropped in by the user or anyone else; | ||
|  | @@ -81,80 +98,27 @@ foreach(f ${merge_config_files_with_absolute_paths}) | |
| endif() | ||
| endforeach() | ||
|  | ||
| # Calculate a checksum of merge_config_files to determine if we need | ||
| # to re-generate .config | ||
| set(merge_config_files_checksum "") | ||
| foreach(f ${merge_config_files_with_absolute_paths}) | ||
| file(MD5 ${f} checksum) | ||
| set(merge_config_files_checksum "${merge_config_files_checksum}${checksum}") | ||
| endforeach() | ||
|  | ||
| # Create a new .config if it does not exists, or if the checksum of | ||
| # the dependencies has changed | ||
| set(merge_config_files_checksum_file ${PROJECT_BINARY_DIR}/.cmake.dotconfig.checksum) | ||
| set(CREATE_NEW_DOTCONFIG "") | ||
| if(NOT EXISTS ${DOTCONFIG}) | ||
| set(CREATE_NEW_DOTCONFIG 1) | ||
| else() | ||
| # Read out what the checksum was previously | ||
| file(READ | ||
| ${merge_config_files_checksum_file} | ||
| merge_config_files_checksum_prev | ||
| ) | ||
| set(CREATE_NEW_DOTCONFIG 1) | ||
| if( | ||
| ${merge_config_files_checksum} STREQUAL | ||
| ${merge_config_files_checksum_prev} | ||
| ) | ||
| set(CREATE_NEW_DOTCONFIG 0) | ||
| endif() | ||
| endif() | ||
| if(CREATE_NEW_DOTCONFIG) | ||
| execute_process( | ||
| COMMAND | ||
| ${PROJECT_SOURCE_DIR}/scripts/kconfig/merge_config.sh | ||
| -m | ||
| -q | ||
| -O ${PROJECT_BINARY_DIR} | ||
| ${merge_config_files} | ||
| WORKING_DIRECTORY ${APPLICATION_SOURCE_DIR} | ||
| # The working directory is set to the app dir such that the user | ||
| # can use relative paths in CONF_FILE, e.g. CONF_FILE=nrf5.conf | ||
| RESULT_VARIABLE ret | ||
| ) | ||
| if(NOT "${ret}" STREQUAL "0") | ||
| message(FATAL_ERROR "command failed with return code: ${ret}") | ||
| endif() | ||
|  | ||
| execute_process( | ||
| COMMAND ${KCONFIG_CONF} | ||
| --olddefconfig | ||
| ${KCONFIG_ROOT} | ||
| WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig | ||
| RESULT_VARIABLE ret | ||
| ) | ||
| if(NOT "${ret}" STREQUAL "0") | ||
| message(FATAL_ERROR "command failed with return code: ${ret}") | ||
| endif() | ||
|  | ||
| file(WRITE | ||
| ${merge_config_files_checksum_file} | ||
| ${merge_config_files_checksum} | ||
| ) | ||
| endif() | ||
|  | ||
| # Force CMAKE configure when the configuration files changes. | ||
| foreach(merge_config_input ${merge_config_files} ${DOTCONFIG}) | ||
| set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${merge_config_input}) | ||
| endforeach() | ||
|  | ||
| message(STATUS "Generating zephyr/include/generated/autoconf.h") | ||
| execute_process( | ||
| COMMAND ${KCONFIG_CONF} | ||
| --silentoldconfig | ||
| ${KCONFIG_ROOT} | ||
| WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/kconfig | ||
| ) | ||
| COMMAND | ||
| ${PYTHON_EXECUTABLE} | ||
| ${PROJECT_SOURCE_DIR}/scripts/kconfig/kconfig.py | ||
| ${KCONFIG_ROOT} | ||
| ${PROJECT_BINARY_DIR}/.config | ||
| ${PROJECT_BINARY_DIR}/include/generated/autoconf.h | ||
| ${merge_config_files} | ||
| WORKING_DIRECTORY ${APPLICATION_SOURCE_DIR} | ||
| # The working directory is set to the app dir such that the user | ||
| # can use relative paths in CONF_FILE, e.g. CONF_FILE=nrf5.conf | ||
| RESULT_VARIABLE ret | ||
| ) | ||
| if(NOT "${ret}" STREQUAL "0") | ||
| message(FATAL_ERROR "command failed with return code: ${ret}") | ||
| endif() | ||
|  | ||
| add_custom_target(config-sanitycheck DEPENDS ${DOTCONFIG}) | ||
|  | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #!/usr/bin/env python3 | ||
| # Modified from: https://github.com/ulfalizer/Kconfiglib/blob/master/examples/merge_config.py | ||
|          | ||
| from kconfiglib import Kconfig, Symbol, BOOL, STRING, TRISTATE, TRI_TO_STR | ||
|          | ||
| import sys | ||
|  | ||
| if len(sys.argv) < 5: | ||
| print('usage: {} Kconfig dotconfig autoconf conf1 [conf2 ...]' | ||
| .format(sys.argv[0])) | ||
| sys.exit(1) | ||
|  | ||
| print("Parsing Kconfig tree in {}".format(sys.argv[1])) | ||
| kconf = Kconfig(sys.argv[1]) | ||
|  | ||
| # Enable warnings for assignments to undefined symbols | ||
| kconf.enable_undef_warnings() | ||
|  | ||
| # (This script uses alldefconfig as the base. Other starting states could be | ||
| # set up here as well. The approach in examples/allnoconfig_simpler.py could | ||
| # provide an allnoconfig starting state for example.) | ||
|  | ||
| print("Using {} as base".format(sys.argv[4])) | ||
| for config in sys.argv[5:]: | ||
| print("Merging {}".format(config)) | ||
| # Create a merged configuration by loading the fragments with replace=False | ||
| for config in sys.argv[4:]: | ||
| kconf.load_config(config, replace=False) | ||
|  | ||
| # Write the merged configuration | ||
| kconf.write_config(sys.argv[2]) | ||
|          | ||
|  | ||
| # Output autoconf | ||
| kconf.write_autoconf(sys.argv[3]) | ||
|          | ||
|  | ||
| # Print warnings for symbols whose actual value doesn't match the assigned | ||
| # value | ||
| for sym in kconf.defined_syms: | ||
| # Was the symbol assigned to? | ||
| #print('name: {} value: {}'.format(sym.name, sym.str_value)) | ||
| if sym.user_value is not None: | ||
| # 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[sym.user_value] | ||
| else: | ||
| user_value = sym.user_value | ||
| if user_value != sym.str_value: | ||
| print('warning: {} was assigned the value "{}" but got the ' | ||
| 'value "{}" -- check dependencies' | ||
| .format(sym.name, user_value, sym.str_value)) | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep looking for
confin non-Windows builds, including MSYS2.