cmake kconfig: Pass environment variables to confgen.py via a file

Works around "command line too long" errors when using Windows
and CMake < 3.11

Closes IDF-711
This commit is contained in:
Angus Gratton 2019-06-26 15:56:47 +10:00 committed by Angus Gratton
parent 0c8192f3be
commit 26db058339
3 changed files with 22 additions and 4 deletions

View file

@ -123,15 +123,19 @@ function(__kconfig_generate_config sdkconfig sdkconfig_defaults)
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
${python} ${idf_path}/tools/kconfig_new/confgen.py
--kconfig ${root_kconfig}
--config ${sdkconfig}
${defaults_arg}
--env "COMPONENT_KCONFIGS=${kconfigs}"
--env "COMPONENT_KCONFIGS_PROJBUILD=${kconfig_projbuilds}"
--env "IDF_CMAKE=y"
--env "IDF_TARGET=${idf_target}")
--env-file "${CMAKE_CURRENT_BINARY_DIR}/confgen.env")
idf_build_get_property(build_dir BUILD_DIR)
set(config_dir ${build_dir}/config)

View file

@ -0,0 +1,6 @@
{
"COMPONENT_KCONFIGS": "${kconfigs}",
"COMPONENT_KCONFIGS_PROJBUILD": "${kconfig_projbuilds}",
"IDF_CMAKE": "y",
"IDF_TARGET": "${idf_target}"
}

View file

@ -198,6 +198,10 @@ def main():
parser.add_argument('--env', action='append', default=[],
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.')
args = parser.parse_args()
for fmt, filename in args.output:
@ -214,6 +218,10 @@ def main():
for name, value in args.env:
os.environ[name] = value
if args.env_file is not None:
env = json.load(args.env_file)
os.environ.update(env)
config = kconfiglib.Kconfig(args.kconfig)
config.disable_redun_warnings()
config.disable_override_warnings()