From: Angus Gratton Date: Sun, 14 Jan 2018 22:55:00 +0000 (+1100) Subject: confgen: Create config file if missing X-Git-Tag: v3.1-rc2~9^2~75 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=99a2359c5c725796a660d3891383a146fe391bc7;p=esp-idf confgen: Create config file if missing --- diff --git a/tools/cmake/kconfig.cmake b/tools/cmake/kconfig.cmake index 2c7e68ede2..6fd68de145 100644 --- a/tools/cmake/kconfig.cmake +++ b/tools/cmake/kconfig.cmake @@ -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} diff --git a/tools/kconfig_new/confgen.py b/tools/kconfig_new/confgen.py index afca4176d4..ca5ee63903 100755 --- a/tools/kconfig_new/confgen.py +++ b/tools/kconfig_new/confgen.py @@ -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)