]> granicus.if.org Git - esp-idf/commitdiff
cmake kconfig: Pass environment variables to confgen.py via a file
authorAngus Gratton <angus@espressif.com>
Wed, 26 Jun 2019 05:56:47 +0000 (15:56 +1000)
committerAngus Gratton <gus@projectgus.com>
Mon, 1 Jul 2019 05:54:10 +0000 (15:54 +1000)
Works around "command line too long" errors when using Windows
and CMake < 3.11

Closes IDF-711

tools/cmake/kconfig.cmake
tools/kconfig_new/confgen.env.in [new file with mode: 0644]
tools/kconfig_new/confgen.py

index 97702935eeb1b9210fbe6bbed6617aba9ae93871..bd1a30668781ea43fa59dce87e54b5c74298a701 100644 (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)
diff --git a/tools/kconfig_new/confgen.env.in b/tools/kconfig_new/confgen.env.in
new file mode 100644 (file)
index 0000000..e639c4d
--- /dev/null
@@ -0,0 +1,6 @@
+{
+    "COMPONENT_KCONFIGS": "${kconfigs}",
+    "COMPONENT_KCONFIGS_PROJBUILD": "${kconfig_projbuilds}",
+    "IDF_CMAKE": "y",
+    "IDF_TARGET": "${idf_target}"
+}
index bbd4e28042f6ed2bec668c752afa7c77f7603e72..d4e875290221870552a4aa5f227cf9465e34b05b 100755 (executable)
@@ -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()