cmake: Use environment variables file for all config binaries
This commit is contained in:
parent
26db058339
commit
f1e07663c4
6 changed files with 50 additions and 31 deletions
|
@ -107,6 +107,17 @@ function(__kconfig_generate_config sdkconfig sdkconfig_defaults)
|
||||||
idf_build_set_property(KCONFIG_PROJBUILDS "${kconfig_projbuilds}")
|
idf_build_set_property(KCONFIG_PROJBUILDS "${kconfig_projbuilds}")
|
||||||
|
|
||||||
idf_build_get_property(idf_target IDF_TARGET)
|
idf_build_get_property(idf_target IDF_TARGET)
|
||||||
|
idf_build_get_property(idf_path IDF_PATH)
|
||||||
|
|
||||||
|
string(REPLACE ";" " " kconfigs "${kconfigs}")
|
||||||
|
string(REPLACE ";" " " kconfig_projbuilds "${kconfig_projbuilds}")
|
||||||
|
|
||||||
|
# Place config-related environment arguments into config.env file
|
||||||
|
# to work around command line length limits for execute_process
|
||||||
|
# on Windows & CMake < 3.11
|
||||||
|
set(config_env_path "${CMAKE_CURRENT_BINARY_DIR}/config.env")
|
||||||
|
configure_file("${idf_path}/tools/kconfig_new/config.env.in" ${config_env_path})
|
||||||
|
idf_build_set_property(CONFIG_ENV_PATH ${config_env_path})
|
||||||
|
|
||||||
if(sdkconfig_defaults)
|
if(sdkconfig_defaults)
|
||||||
set(defaults_arg --defaults "${sdkconfig_defaults}")
|
set(defaults_arg --defaults "${sdkconfig_defaults}")
|
||||||
|
@ -116,26 +127,15 @@ function(__kconfig_generate_config sdkconfig sdkconfig_defaults)
|
||||||
list(APPEND defaults_arg --defaults "${sdkconfig_defaults}.${idf_target}")
|
list(APPEND defaults_arg --defaults "${sdkconfig_defaults}.${idf_target}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
idf_build_get_property(idf_path IDF_PATH)
|
|
||||||
idf_build_get_property(root_kconfig __ROOT_KCONFIG)
|
idf_build_get_property(root_kconfig __ROOT_KCONFIG)
|
||||||
idf_build_get_property(python PYTHON)
|
idf_build_get_property(python PYTHON)
|
||||||
|
|
||||||
string(REPLACE ";" " " kconfigs "${kconfigs}")
|
|
||||||
string(REPLACE ";" " " kconfig_projbuilds "${kconfig_projbuilds}")
|
|
||||||
|
|
||||||
# Place the long environment arguments into an input file
|
|
||||||
# to work around command line length limits for execute_process
|
|
||||||
# on Windows & CMake < 3.11
|
|
||||||
configure_file(
|
|
||||||
"${idf_path}/tools/kconfig_new/confgen.env.in"
|
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/confgen.env")
|
|
||||||
|
|
||||||
set(confgen_basecommand
|
set(confgen_basecommand
|
||||||
${python} ${idf_path}/tools/kconfig_new/confgen.py
|
${python} ${idf_path}/tools/kconfig_new/confgen.py
|
||||||
--kconfig ${root_kconfig}
|
--kconfig ${root_kconfig}
|
||||||
--config ${sdkconfig}
|
--config ${sdkconfig}
|
||||||
${defaults_arg}
|
${defaults_arg}
|
||||||
--env-file "${CMAKE_CURRENT_BINARY_DIR}/confgen.env")
|
--env-file ${config_env_path})
|
||||||
|
|
||||||
idf_build_get_property(build_dir BUILD_DIR)
|
idf_build_get_property(build_dir BUILD_DIR)
|
||||||
set(config_dir ${build_dir}/config)
|
set(config_dir ${build_dir}/config)
|
||||||
|
@ -221,10 +221,10 @@ function(__kconfig_generate_config sdkconfig sdkconfig_defaults)
|
||||||
|
|
||||||
# Custom target to run confserver.py from the build tool
|
# Custom target to run confserver.py from the build tool
|
||||||
add_custom_target(confserver
|
add_custom_target(confserver
|
||||||
COMMAND ${CMAKE_COMMAND} -E env
|
COMMAND ${PYTHON} ${IDF_PATH}/tools/kconfig_new/confserver.py
|
||||||
"COMPONENT_KCONFIGS=${kconfigs}"
|
--env-file ${config_env_path}
|
||||||
"COMPONENT_KCONFIGS_PROJBUILD=${kconfig_projbuilds}"
|
--kconfig ${IDF_PATH}/Kconfig
|
||||||
${PYTHON} ${IDF_PATH}/tools/kconfig_new/confserver.py --kconfig ${IDF_PATH}/Kconfig --config ${sdkconfig}
|
--config ${sdkconfig}
|
||||||
VERBATIM
|
VERBATIM
|
||||||
USES_TERMINAL)
|
USES_TERMINAL)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
|
@ -54,6 +54,8 @@ function(__ldgen_process_template template output)
|
||||||
string(REPLACE ";" " " kconfigs "${kconfigs}")
|
string(REPLACE ";" " " kconfigs "${kconfigs}")
|
||||||
string(REPLACE ";" " " kconfig_projbuilds "${kconfig_projbuilds}")
|
string(REPLACE ";" " " kconfig_projbuilds "${kconfig_projbuilds}")
|
||||||
|
|
||||||
|
idf_build_get_property(config_env_path CONFIG_ENV_PATH)
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${output}
|
OUTPUT ${output}
|
||||||
COMMAND ${python} ${idf_path}/tools/ldgen/ldgen.py
|
COMMAND ${python} ${idf_path}/tools/ldgen/ldgen.py
|
||||||
|
@ -62,11 +64,7 @@ function(__ldgen_process_template template output)
|
||||||
--input ${template}
|
--input ${template}
|
||||||
--output ${output}
|
--output ${output}
|
||||||
--kconfig ${root_kconfig}
|
--kconfig ${root_kconfig}
|
||||||
--env "COMPONENT_KCONFIGS=${kconfigs}"
|
--env-file "${config_env_path}"
|
||||||
--env "COMPONENT_KCONFIGS_PROJBUILD=${kconfig_projbuilds}"
|
|
||||||
--env "IDF_CMAKE=y"
|
|
||||||
--env "IDF_PATH=${idf_path}"
|
|
||||||
--env "IDF_TARGET=${idf_target}"
|
|
||||||
--libraries-file ${build_dir}/ldgen_libraries
|
--libraries-file ${build_dir}/ldgen_libraries
|
||||||
--objdump ${CMAKE_OBJDUMP}
|
--objdump ${CMAKE_OBJDUMP}
|
||||||
DEPENDS ${template} ${ldgen_fragment_files} ${ldgen_depends} ${SDKCONFIG}
|
DEPENDS ${template} ${ldgen_fragment_files} ${ldgen_depends} ${SDKCONFIG}
|
||||||
|
|
|
@ -2,5 +2,6 @@
|
||||||
"COMPONENT_KCONFIGS": "${kconfigs}",
|
"COMPONENT_KCONFIGS": "${kconfigs}",
|
||||||
"COMPONENT_KCONFIGS_PROJBUILD": "${kconfig_projbuilds}",
|
"COMPONENT_KCONFIGS_PROJBUILD": "${kconfig_projbuilds}",
|
||||||
"IDF_CMAKE": "y",
|
"IDF_CMAKE": "y",
|
||||||
"IDF_TARGET": "${idf_target}"
|
"IDF_TARGET": "${idf_target}",
|
||||||
|
"IDF_PATH": "${idf_path}"
|
||||||
}
|
}
|
|
@ -32,6 +32,10 @@ def main():
|
||||||
parser.add_argument('--env', action='append', default=[],
|
parser.add_argument('--env', action='append', default=[],
|
||||||
help='Environment to set when evaluating the config file', metavar='NAME=VAL')
|
help='Environment to set when evaluating the config file', metavar='NAME=VAL')
|
||||||
|
|
||||||
|
parser.add_argument('--env-file', type=argparse.FileType('r'),
|
||||||
|
help='Optional file to load environment variables from. Contents '
|
||||||
|
'should be a JSON object where each key/value pair is a variable.')
|
||||||
|
|
||||||
parser.add_argument('--version', help='Set protocol version to use on initial status',
|
parser.add_argument('--version', help='Set protocol version to use on initial status',
|
||||||
type=int, default=MAX_PROTOCOL_VERSION)
|
type=int, default=MAX_PROTOCOL_VERSION)
|
||||||
|
|
||||||
|
@ -54,6 +58,10 @@ def main():
|
||||||
for name, value in args.env:
|
for name, value in args.env:
|
||||||
os.environ[name] = value
|
os.environ[name] = value
|
||||||
|
|
||||||
|
if args.env_file is not None:
|
||||||
|
env = json.load(args.env_file)
|
||||||
|
os.environ.update(env)
|
||||||
|
|
||||||
run_server(args.kconfig, args.config)
|
run_server(args.kconfig, args.config)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import json
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -30,6 +31,17 @@ from pyparsing import ParseException, ParseFatalException
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
|
|
||||||
|
def _update_environment(args):
|
||||||
|
env = [(name, value) for (name,value) in (e.split("=",1) for e in args.env)]
|
||||||
|
for name, value in env:
|
||||||
|
value = " ".join(value.split())
|
||||||
|
os.environ[name] = value
|
||||||
|
|
||||||
|
if args.env_file is not None:
|
||||||
|
env = json.load(args.env_file)
|
||||||
|
os.environ.update(env)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
argparser = argparse.ArgumentParser(description="ESP-IDF linker script generator")
|
argparser = argparse.ArgumentParser(description="ESP-IDF linker script generator")
|
||||||
|
@ -68,6 +80,10 @@ def main():
|
||||||
action='append', default=[],
|
action='append', default=[],
|
||||||
help='Environment to set when evaluating the config file', metavar='NAME=VAL')
|
help='Environment to set when evaluating the config file', metavar='NAME=VAL')
|
||||||
|
|
||||||
|
argparser.add_argument('--env-file', type=argparse.FileType('r'),
|
||||||
|
help='Optional file to load environment variables from. Contents '
|
||||||
|
'should be a JSON object where each key/value pair is a variable.')
|
||||||
|
|
||||||
argparser.add_argument(
|
argparser.add_argument(
|
||||||
"--objdump",
|
"--objdump",
|
||||||
help="Path to toolchain objdump")
|
help="Path to toolchain objdump")
|
||||||
|
@ -93,7 +109,9 @@ def main():
|
||||||
|
|
||||||
generation_model = GenerationModel()
|
generation_model = GenerationModel()
|
||||||
|
|
||||||
sdkconfig = SDKConfig(kconfig_file, config_file, args.env)
|
_update_environment(args) # assign args.env and args.env_file to os.environ
|
||||||
|
|
||||||
|
sdkconfig = SDKConfig(kconfig_file, config_file)
|
||||||
|
|
||||||
for fragment_file in fragment_files:
|
for fragment_file in fragment_files:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -46,13 +46,7 @@ class SDKConfig:
|
||||||
# Operators supported by the expression evaluation
|
# Operators supported by the expression evaluation
|
||||||
OPERATOR = oneOf(["=", "!=", ">", "<", "<=", ">="])
|
OPERATOR = oneOf(["=", "!=", ">", "<", "<=", ">="])
|
||||||
|
|
||||||
def __init__(self, kconfig_file, sdkconfig_file, env=[]):
|
def __init__(self, kconfig_file, sdkconfig_file):
|
||||||
env = [(name, value) for (name,value) in (e.split("=",1) for e in env)]
|
|
||||||
|
|
||||||
for name, value in env:
|
|
||||||
value = " ".join(value.split())
|
|
||||||
os.environ[name] = value
|
|
||||||
|
|
||||||
self.config = kconfiglib.Kconfig(kconfig_file)
|
self.config = kconfiglib.Kconfig(kconfig_file)
|
||||||
self.config.load_config(sdkconfig_file)
|
self.config.load_config(sdkconfig_file)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue