154568cb3Sopenharmony_ci#!/usr/bin/env python3
254568cb3Sopenharmony_ci# coding=utf-8
354568cb3Sopenharmony_ci# Transfer kconfig configuration file to buildef/config file.
454568cb3Sopenharmony_ci# Copyright © Huawei Technologies Co., Ltd. 2010-2020. All rights reserved.
554568cb3Sopenharmony_ci
654568cb3Sopenharmony_ciimport os
754568cb3Sopenharmony_ciimport sys
854568cb3Sopenharmony_ciimport logging
954568cb3Sopenharmony_cifrom Kconfig2macro import do_cmd
1054568cb3Sopenharmony_ci
1154568cb3Sopenharmony_ci
1254568cb3Sopenharmony_cilogging.basicConfig(level=logging.NOTSET)
1354568cb3Sopenharmony_ci
1454568cb3Sopenharmony_cidef make_buildef(home_path, kconf_dir, choice):
1554568cb3Sopenharmony_ci    kconfig_dir = "{}/build/uniproton_config/config_{}/defconfig".format(home_path,kconf_dir)
1654568cb3Sopenharmony_ci    buildef_file = "{}/build/uniproton_config/config_{}/prt_buildef.h".format(home_path,kconf_dir)
1754568cb3Sopenharmony_ci    if choice == "CREATE":
1854568cb3Sopenharmony_ci        paras = ["-f", kconfig_dir, "-o", buildef_file]
1954568cb3Sopenharmony_ci        if do_cmd(paras, False) != 0:
2054568cb3Sopenharmony_ci            logging.info("build prt_buildef.h failed.")
2154568cb3Sopenharmony_ci            return False
2254568cb3Sopenharmony_ci        logging.info("build prt_buildef.h succeed.")
2354568cb3Sopenharmony_ci    elif choice == "EXPORT":
2454568cb3Sopenharmony_ci        paras = ["-e", "-f", kconfig_dir, "-o", buildef_file]
2554568cb3Sopenharmony_ci        if do_cmd(paras, False) != 0:
2654568cb3Sopenharmony_ci            logging.info("export prt_buildef.h failed.")
2754568cb3Sopenharmony_ci            return False
2854568cb3Sopenharmony_ci        logging.info("export prt_buildef.h succeed.")
2954568cb3Sopenharmony_ci    else:
3054568cb3Sopenharmony_ci        os.remove(buildef_file)
3154568cb3Sopenharmony_ci    return True
32