]> granicus.if.org Git - esp-idf/commitdiff
confgen: Create config file if missing
authorAngus Gratton <angus@espressif.com>
Sun, 14 Jan 2018 22:55:00 +0000 (09:55 +1100)
committerAngus Gratton <gus@projectgus.com>
Sun, 29 Apr 2018 23:59:20 +0000 (09:59 +1000)
tools/cmake/kconfig.cmake
tools/kconfig_new/confgen.py

index 2c7e68ede27def40911362f02f0a4ae8dcde9637..6fd68de14527a0b053c39e823ab3783bb03de596 100644 (file)
@@ -62,6 +62,7 @@ function(build_component_config)
   execute_process(COMMAND python ${IDF_PATH}/tools/kconfig_new/confgen.py
     --kconfig ${ROOT_KCONFIG}
     --config ${SDKCONFIG}
+    --create-config-if-missing
     --env "COMPONENT_KCONFIGS=${kconfigs}"
     --env "COMPONENT_KCONFIGS_PROJBUILD=${kconfigs_projbuild}"
     --output header ${SDKCONFIG_HEADER}
index afca4176d4a52cf4935f10c6430b6502cbe48c44..ca5ee63903efa442f6652e5a264e4c1581106dcf 100755 (executable)
@@ -39,13 +39,18 @@ def main():
                         nargs='?',
                         default=None)
 
+    parser.add_argument('--create-config-if-missing',
+                        help='If set, a new config file will be saved if the old one is not found',
+                        action='store_true')
+
     parser.add_argument('--kconfig',
                         help='KConfig file with config item definitions',
                         required=True)
 
     parser.add_argument('--output', nargs=2, action='append',
                         help='Write output file (format and output filename)',
-                        metavar=('FORMAT', 'FILENAME'))
+                        metavar=('FORMAT', 'FILENAME'),
+                        default=[])
 
     parser.add_argument('--env', action='append', default=[],
                         help='Environment to set when evaluating the config file', metavar='NAME=VAL')
@@ -69,7 +74,13 @@ def main():
     config = kconfiglib.Kconfig(args.kconfig)
 
     if args.config is not None:
-        config.load_config(args.config)
+        if os.path.exists(args.config):
+            config.load_config(args.config)
+        elif args.create_config_if_missing:
+            print("Creating config file %s..." % args.config)
+            config.write_config(args.config)
+        else:
+            raise RuntimeError("Config file not found: %s" % args.config)
 
         for output_type, filename in args.output:
             temp_file = tempfile.mktemp(prefix="confgen_tmp")
@@ -146,5 +157,15 @@ OUTPUT_FORMATS = {
     "cmake" : write_cmake,
     "docs" : gen_kconfig_doc.write_docs }
 
+class FatalError(RuntimeError):
+    """
+    Class for runtime errors (not caused by bugs but by user input).
+    """
+    pass
+
 if __name__ == '__main__':
-    main()
+    try:
+        main()
+    except FatalError as e:
+        print("A fatal error occurred: %s" % e)
+        sys.exit(2)