diff --git a/archive.py b/archive.py index 4dfd64b..e17eba1 100644 --- a/archive.py +++ b/archive.py @@ -1,192 +1,192 @@ -# -*- coding:utf-8 -*- -# -# File : archive.py -# This file is part of RT-Thread RTOS -# COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Change Logs: -# Date Author Notes -# 2018-5-28 SummerGift Add copyright information -# 2020-4-10 SummerGift Code clear up -# - -import logging -import os -import shutil -import tarfile -import zipfile -import pkgsdb -from cmds.cmd_package.cmd_package_utils import is_windows, remove_folder - - -def unpack(archive_filename, bsp_package_path, package_info, package_name): - if ".tar.bz2" in archive_filename: - arch = tarfile.open(archive_filename, "r:bz2") - for tarinfo in arch: - arch.extract(tarinfo, bsp_package_path) - a = tarinfo.name - if not os.path.isdir(os.path.join(bsp_package_path, a)): - if is_windows(): - right_path = a.replace('/', '\\') - else: - right_path = a - a = os.path.join(os.path.split(right_path)[0], os.path.split(right_path)[1]) - - pkgsdb.save_to_database(a, archive_filename) - arch.close() - - if ".tar.gz" in archive_filename: - arch = tarfile.open(archive_filename, "r:gz") - for tarinfo in arch: - arch.extract(tarinfo, bsp_package_path) - a = tarinfo.name - if not os.path.isdir(os.path.join(bsp_package_path, a)): - if is_windows(): - right_path = a.replace('/', '\\') - else: - right_path = a - a = os.path.join(os.path.split(right_path)[0], os.path.split(right_path)[1]) - pkgsdb.save_to_database(a, archive_filename) - arch.close() - - if ".zip" in archive_filename: - if not handle_zip_package(archive_filename, bsp_package_path, package_name, package_info): - return False - - return True - - -def handle_zip_package(archive_filename, bsp_package_path, package_name, package_info): - package_version = package_info['ver'] - package_temp_path = os.path.join(bsp_package_path, "package_temp") - - try: - if remove_folder(package_temp_path): - os.makedirs(package_temp_path) - except Exception as e: - logging.warning('Error message : {0}'.format(e)) - - logging.info("BSP packages path {0}".format(bsp_package_path)) - logging.info("BSP package temp path: {0}".format(package_temp_path)) - logging.info("archive filename : {0}".format(archive_filename)) - - try: - flag = True - package_folder_name = "" - package_name_with_version = "" - arch = zipfile.ZipFile(archive_filename, "r") - for item in arch.namelist(): - arch.extract(item, package_temp_path) - if not os.path.isdir(os.path.join(package_temp_path, item)): - if is_windows(): - right_path = item.replace('/', '\\') - else: - right_path = item - - # Gets the folder name and changed folder name only once - if flag: - package_folder_name = os.path.split(right_path)[0] - package_name_with_version = package_name + '-' + package_version - flag = False - - right_name_to_db = right_path.replace(package_folder_name, package_name_with_version, 1) - right_path = os.path.join("package_temp", right_path) - pkgsdb.save_to_database(right_name_to_db, archive_filename, right_path) - arch.close() - - if not move_package_to_bsp_packages(package_folder_name, package_name, package_temp_path, package_version, - bsp_package_path): - return False - except Exception as e: - logging.warning('unpack error message : {0}'.format(e)) - logging.warning('unpack {0} failed'.format(os.path.basename(archive_filename))) - # remove temp folder and archive file - remove_folder(package_temp_path) - os.remove(archive_filename) - return False - - return True - - -def move_package_to_bsp_packages(package_folder_name, package_name, package_temp_path, package_version, - bsp_packages_path): - """move package in temp folder to bsp packages folder.""" - origin_package_folder_path = os.path.join(package_temp_path, package_folder_name) - package_name_with_version = package_name + '-' + package_version - package_folder_in_temp = os.path.join(package_temp_path, package_name_with_version) - bsp_package_path = os.path.join(bsp_packages_path, package_name_with_version) - logging.info("origin name: {0}".format(origin_package_folder_path)) - logging.info("rename name: {0}".format(package_folder_in_temp)) - - result = True - try: - # rename package folder name to package name with version - os.rename(origin_package_folder_path, package_folder_in_temp) - - # if there is no specified version package in the bsp package path, - # then move package from package_folder_in_temp to bsp_package_path - if not os.path.isdir(bsp_package_path): - shutil.move(package_folder_in_temp, bsp_package_path) - except Exception as e: - logging.warning('{0}'.format(e)) - result = False - finally: - # must remove temp folder - remove_folder(package_temp_path) - - return result - - -def package_integrity_test(path): - ret = True - - if path.find(".zip") != -1: - try: - if zipfile.is_zipfile(path): - # Test zip again to make sure it's a right zip file. - arch = zipfile.ZipFile(path, "r") - if arch.testzip(): - ret = False - arch.close() - else: - ret = False - print('package check error. \n') - except Exception as e: - print('Package test error message:%s\t' % e) - print("The archive package is broken. \n") - arch.close() - ret = False - - # if ".tar.bz2" in path:. - if path.find(".tar.bz2") != -1: - try: - if not tarfile.is_tarfile(path): - ret = False - except Exception as e: - print('Error message:%s' % e) - ret = False - - # if ".tar.gz" in path: - if path.find(".tar.gz") != -1: - try: - if not tarfile.is_tarfile(path): - ret = False - except Exception as e: - print('Error message:%s' % e) - ret = False - - return ret +# -*- coding:utf-8 -*- +# +# File : archive.py +# This file is part of RT-Thread RTOS +# COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Change Logs: +# Date Author Notes +# 2018-5-28 SummerGift Add copyright information +# 2020-4-10 SummerGift Code clear up +# + +import logging +import os +import shutil +import tarfile +import zipfile +import pkgsdb +from cmds.cmd_package.cmd_package_utils import is_windows, remove_folder + + +def unpack(archive_filename, bsp_package_path, package_info, package_name): + if ".tar.bz2" in archive_filename: + arch = tarfile.open(archive_filename, "r:bz2") + for tarinfo in arch: + arch.extract(tarinfo, bsp_package_path) + a = tarinfo.name + if not os.path.isdir(os.path.join(bsp_package_path, a)): + if is_windows(): + right_path = a.replace('/', '\\') + else: + right_path = a + a = os.path.join(os.path.split(right_path)[0], os.path.split(right_path)[1]) + + pkgsdb.save_to_database(a, archive_filename) + arch.close() + + if ".tar.gz" in archive_filename: + arch = tarfile.open(archive_filename, "r:gz") + for tarinfo in arch: + arch.extract(tarinfo, bsp_package_path) + a = tarinfo.name + if not os.path.isdir(os.path.join(bsp_package_path, a)): + if is_windows(): + right_path = a.replace('/', '\\') + else: + right_path = a + a = os.path.join(os.path.split(right_path)[0], os.path.split(right_path)[1]) + pkgsdb.save_to_database(a, archive_filename) + arch.close() + + if ".zip" in archive_filename: + if not handle_zip_package(archive_filename, bsp_package_path, package_name, package_info): + return False + + return True + + +def handle_zip_package(archive_filename, bsp_package_path, package_name, package_info): + package_version = package_info['ver'] + package_temp_path = os.path.join(bsp_package_path, "package_temp") + + try: + if remove_folder(package_temp_path): + os.makedirs(package_temp_path) + except Exception as e: + logging.warning('Error message : {0}'.format(e)) + + logging.info("BSP packages path {0}".format(bsp_package_path)) + logging.info("BSP package temp path: {0}".format(package_temp_path)) + logging.info("archive filename : {0}".format(archive_filename)) + + try: + flag = True + package_folder_name = "" + package_name_with_version = "" + arch = zipfile.ZipFile(archive_filename, "r") + for item in arch.namelist(): + arch.extract(item, package_temp_path) + if not os.path.isdir(os.path.join(package_temp_path, item)): + if is_windows(): + right_path = item.replace('/', '\\') + else: + right_path = item + + # Gets the folder name and changed folder name only once + if flag: + package_folder_name = os.path.split(right_path)[0] + package_name_with_version = package_name + '-' + package_version + flag = False + + right_name_to_db = right_path.replace(package_folder_name, package_name_with_version, 1) + right_path = os.path.join("package_temp", right_path) + pkgsdb.save_to_database(right_name_to_db, archive_filename, right_path) + arch.close() + + if not move_package_to_bsp_packages(package_folder_name, package_name, package_temp_path, package_version, + bsp_package_path): + return False + except Exception as e: + logging.warning('unpack error message : {0}'.format(e)) + logging.warning('unpack {0} failed'.format(os.path.basename(archive_filename))) + # remove temp folder and archive file + remove_folder(package_temp_path) + os.remove(archive_filename) + return False + + return True + + +def move_package_to_bsp_packages(package_folder_name, package_name, package_temp_path, package_version, + bsp_packages_path): + """move package in temp folder to bsp packages folder.""" + origin_package_folder_path = os.path.join(package_temp_path, package_folder_name) + package_name_with_version = package_name + '-' + package_version + package_folder_in_temp = os.path.join(package_temp_path, package_name_with_version) + bsp_package_path = os.path.join(bsp_packages_path, package_name_with_version) + logging.info("origin name: {0}".format(origin_package_folder_path)) + logging.info("rename name: {0}".format(package_folder_in_temp)) + + result = True + try: + # rename package folder name to package name with version + os.rename(origin_package_folder_path, package_folder_in_temp) + + # if there is no specified version package in the bsp package path, + # then move package from package_folder_in_temp to bsp_package_path + if not os.path.isdir(bsp_package_path): + shutil.move(package_folder_in_temp, bsp_package_path) + except Exception as e: + logging.warning('{0}'.format(e)) + result = False + finally: + # must remove temp folder + remove_folder(package_temp_path) + + return result + + +def package_integrity_test(path): + ret = True + + if path.find(".zip") != -1: + try: + if zipfile.is_zipfile(path): + # Test zip again to make sure it's a right zip file. + arch = zipfile.ZipFile(path, "r") + if arch.testzip(): + ret = False + arch.close() + else: + ret = False + print('package check error. \n') + except Exception as e: + print('Package test error message:%s\t' % e) + print("The archive package is broken. \n") + arch.close() + ret = False + + # if ".tar.bz2" in path:. + if path.find(".tar.bz2") != -1: + try: + if not tarfile.is_tarfile(path): + ret = False + except Exception as e: + print('Error message:%s' % e) + ret = False + + # if ".tar.gz" in path: + if path.find(".tar.gz") != -1: + try: + if not tarfile.is_tarfile(path): + ret = False + except Exception as e: + print('Error message:%s' % e) + ret = False + + return ret diff --git a/cmds/Kconfig b/cmds/Kconfig index f92fea2..eff439a 100644 --- a/cmds/Kconfig +++ b/cmds/Kconfig @@ -1,39 +1,39 @@ -menu "Env config" - -config SYS_AUTO_UPDATE_PKGS - bool "Auto update pkgs config" - default n - -config SYS_CREATE_MDK_IAR_PROJECT - bool "Auto create a mdk/iar project" - default n - -if SYS_CREATE_MDK_IAR_PROJECT - - choice - prompt "Project type" - help - Select the project type mdk or iar - - config SYS_CREATE_MDK4 - bool "MDK4" - - config SYS_CREATE_MDK5 - bool "MDK5" - - config SYS_CREATE_IAR - bool "IAR" - endchoice - -endif - -config SYS_PKGS_DOWNLOAD_ACCELERATE - bool "pkgs download using mirror server" - default y - help - When you open it, you will use the mirror address to download the software, - which can improve the download speed. - The synchronous cycle of the mirror address is usually half an hour. - -endmenu - +menu "Env config" + +config SYS_AUTO_UPDATE_PKGS + bool "Auto update pkgs config" + default n + +config SYS_CREATE_MDK_IAR_PROJECT + bool "Auto create a mdk/iar project" + default n + +if SYS_CREATE_MDK_IAR_PROJECT + + choice + prompt "Project type" + help + Select the project type mdk or iar + + config SYS_CREATE_MDK4 + bool "MDK4" + + config SYS_CREATE_MDK5 + bool "MDK5" + + config SYS_CREATE_IAR + bool "IAR" + endchoice + +endif + +config SYS_PKGS_DOWNLOAD_ACCELERATE + bool "pkgs download using mirror server" + default y + help + When you open it, you will use the mirror address to download the software, + which can improve the download speed. + The synchronous cycle of the mirror address is usually half an hour. + +endmenu + diff --git a/cmds/cmd_menuconfig.py b/cmds/cmd_menuconfig.py index d1eb2de..f6b76cc 100644 --- a/cmds/cmd_menuconfig.py +++ b/cmds/cmd_menuconfig.py @@ -1,240 +1,240 @@ -# -*- coding:utf-8 -*- -# -# File : cmd_menuconfig.py -# This file is part of RT-Thread RTOS -# COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Change Logs: -# Date Author Notes -# 2018-05-28 SummerGift Add copyright information -# 2019-01-07 SummerGift The prompt supports utf-8 encoding -# 2019-10-30 SummerGift fix bug when generate some config item -# - -import os -import platform -import re -from vars import Import -from .cmd_package.cmd_package_utils import find_macro_in_config - - -def is_pkg_special_config(config_str): - """judge if it's CONFIG_PKG_XX_PATH or CONFIG_PKG_XX_VER""" - - if isinstance(config_str, str): - if config_str.startswith("PKG_") and (config_str.endswith('_PATH') or config_str.endswith('_VER')): - return True - return False - - -def mk_rtconfig(filename): - try: - config = open(filename, 'r') - except Exception as e: - print('Error message:%s' % e) - print('open config:%s failed' % filename) - return - - rtconfig = open('rtconfig.h', 'w') - rtconfig.write('#ifndef RT_CONFIG_H__\n') - rtconfig.write('#define RT_CONFIG_H__\n\n') - - empty_line = 1 - - for line in config: - line = line.lstrip(' ').replace('\n', '').replace('\r', '') - - if len(line) == 0: - continue - - if line[0] == '#': - if len(line) == 1: - if empty_line: - continue - - rtconfig.write('\n') - empty_line = 1 - continue - - if line.startswith('# CONFIG_'): - line = ' ' + line[9:] - else: - line = line[1:] - rtconfig.write('/*%s */\n' % line) - - empty_line = 0 - else: - empty_line = 0 - setting = line.split('=') - if len(setting) >= 2: - if setting[0].startswith('CONFIG_'): - setting[0] = setting[0][7:] - - # remove CONFIG_PKG_XX_PATH or CONFIG_PKG_XX_VER - if is_pkg_special_config(setting[0]): - continue - - if setting[1] == 'y': - rtconfig.write('#define %s\n' % setting[0]) - else: - rtconfig.write('#define %s %s\n' % (setting[0], re.findall(r"^.*?=(.*)$", line)[0])) - - if os.path.isfile('rtconfig_project.h'): - rtconfig.write('#include "rtconfig_project.h"\n') - - rtconfig.write('\n') - rtconfig.write('#endif\n') - rtconfig.close() - - -def cmd(args): - env_root = Import('env_root') - os_version = platform.platform(True)[10:13] - kconfig_win7_path = os.path.join( - env_root, 'tools', 'bin', 'kconfig-mconf_win7.exe') - - if not os.path.exists('Kconfig'): - if platform.system() == "Windows": - os.system('chcp 65001 > nul') - - print("\n\033[1;31;40m 命令应当在某一特定 BSP 目录下执行,例如:\"rt-thread/bsp/stm32/stm32f091-st-nucleo\"\033[0m") - print("\033[1;31;40m请确保当前目录为 BSP 根目录,并且该目录中有 Kconfig 文件。\033[0m\n") - - print(" command should be used in a bsp root path with a Kconfig file.") - print("Example: \"rt-thread/bsp/stm32/stm32f091-st-nucleo\"") - print("You should check if there is a Kconfig file in your bsp root first.") - - if platform.system() == "Windows": - os.system('chcp 437 > nul') - - return False - - fn = '.config' - - if os.path.isfile(fn): - mtime = os.path.getmtime(fn) - else: - mtime = -1 - - if platform.system() == "Windows": - os.system('chcp 437 > nul') - - if args.menuconfig_fn: - print('use', args.menuconfig_fn) - import shutil - shutil.copy(args.menuconfig_fn, fn) - elif args.menuconfig_g: - mk_rtconfig(fn) - elif args.menuconfig_silent: - if float(os_version) >= 6.2: - os.system('kconfig-mconf Kconfig -n') - mk_rtconfig(fn) - else: - if os.path.isfile(kconfig_win7_path): - os.system('kconfig-mconf_win7 Kconfig -n') - else: - os.system('kconfig-mconf Kconfig -n') - - elif args.menuconfig_setting: - env_kconfig_path = os.path.join(env_root, r'tools\scripts\cmds') - beforepath = os.getcwd() - os.chdir(env_kconfig_path) - - if float(os_version) >= 6.2: - os.system('kconfig-mconf Kconfig') - else: - if os.path.isfile(kconfig_win7_path): - os.system('kconfig-mconf_win7 Kconfig') - else: - os.system('kconfig-mconf Kconfig') - - os.chdir(beforepath) - - return - - else: - if float(os_version) >= 6.2: - os.system('kconfig-mconf Kconfig') - else: - if os.path.isfile(kconfig_win7_path): - os.system('kconfig-mconf_win7 Kconfig') - else: - os.system('kconfig-mconf Kconfig') - - if os.path.isfile(fn): - mtime2 = os.path.getmtime(fn) - else: - mtime2 = -1 - - if mtime != mtime2: - mk_rtconfig(fn) - - if platform.system() == "Windows": - env_kconfig_path = os.path.join(env_root, r'tools\scripts\cmds') - fn = os.path.join(env_kconfig_path, '.config') - - if not os.path.isfile(fn): - return - - if find_macro_in_config(fn, 'SYS_AUTO_UPDATE_PKGS'): - os.system('pkgs --update') - print("==============================>The packages have been updated completely.") - - if find_macro_in_config(fn, 'SYS_CREATE_MDK_IAR_PROJECT'): - if find_macro_in_config(fn, 'SYS_CREATE_MDK4'): - os.system('scons --target=mdk4 -s') - print("Create mdk4 project done") - elif find_macro_in_config(fn, 'SYS_CREATE_MDK5'): - os.system('scons --target=mdk5 -s') - print("Create mdk5 project done") - elif find_macro_in_config(fn, 'SYS_CREATE_IAR'): - os.system('scons --target=iar -s') - print("Create iar project done") - - -def add_parser(sub): - parser = sub.add_parser('menuconfig', help=__doc__, description=__doc__) - - parser.add_argument('--config', - help='Using the user specified configuration file.', - dest='menuconfig_fn') - - parser.add_argument('--generate', - help='generate rtconfig.h by .config.', - action='store_true', - default=False, - dest='menuconfig_g') - - parser.add_argument('--silent', - help='Silent mode,don\'t display menuconfig window.', - action='store_true', - default=False, - dest='menuconfig_silent') - - parser.add_argument('-s', '--setting', - help='Env config,auto update packages and create mdk/iar project', - action='store_true', - default=False, - dest='menuconfig_setting') - - parser.add_argument('--easy', - help='easy mode, place kconfig everywhere, modify the option env="RTT_ROOT" default "../.."', - action='store_true', - default=False, - dest='menuconfig_easy') - - parser.set_defaults(func=cmd) +# -*- coding:utf-8 -*- +# +# File : cmd_menuconfig.py +# This file is part of RT-Thread RTOS +# COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Change Logs: +# Date Author Notes +# 2018-05-28 SummerGift Add copyright information +# 2019-01-07 SummerGift The prompt supports utf-8 encoding +# 2019-10-30 SummerGift fix bug when generate some config item +# + +import os +import platform +import re +from vars import Import +from .cmd_package.cmd_package_utils import find_macro_in_config + + +def is_pkg_special_config(config_str): + """judge if it's CONFIG_PKG_XX_PATH or CONFIG_PKG_XX_VER""" + + if isinstance(config_str, str): + if config_str.startswith("PKG_") and (config_str.endswith('_PATH') or config_str.endswith('_VER')): + return True + return False + + +def mk_rtconfig(filename): + try: + config = open(filename, 'r') + except Exception as e: + print('Error message:%s' % e) + print('open config:%s failed' % filename) + return + + rtconfig = open('rtconfig.h', 'w') + rtconfig.write('#ifndef RT_CONFIG_H__\n') + rtconfig.write('#define RT_CONFIG_H__\n\n') + + empty_line = 1 + + for line in config: + line = line.lstrip(' ').replace('\n', '').replace('\r', '') + + if len(line) == 0: + continue + + if line[0] == '#': + if len(line) == 1: + if empty_line: + continue + + rtconfig.write('\n') + empty_line = 1 + continue + + if line.startswith('# CONFIG_'): + line = ' ' + line[9:] + else: + line = line[1:] + rtconfig.write('/*%s */\n' % line) + + empty_line = 0 + else: + empty_line = 0 + setting = line.split('=') + if len(setting) >= 2: + if setting[0].startswith('CONFIG_'): + setting[0] = setting[0][7:] + + # remove CONFIG_PKG_XX_PATH or CONFIG_PKG_XX_VER + if is_pkg_special_config(setting[0]): + continue + + if setting[1] == 'y': + rtconfig.write('#define %s\n' % setting[0]) + else: + rtconfig.write('#define %s %s\n' % (setting[0], re.findall(r"^.*?=(.*)$", line)[0])) + + if os.path.isfile('rtconfig_project.h'): + rtconfig.write('#include "rtconfig_project.h"\n') + + rtconfig.write('\n') + rtconfig.write('#endif\n') + rtconfig.close() + + +def cmd(args): + env_root = Import('env_root') + os_version = platform.platform(True)[10:13] + kconfig_win7_path = os.path.join( + env_root, 'tools', 'bin', 'kconfig-mconf_win7.exe') + + if not os.path.exists('Kconfig'): + if platform.system() == "Windows": + os.system('chcp 65001 > nul') + + print("\n\033[1;31;40m 命令应当在某一特定 BSP 目录下执行,例如:\"rt-thread/bsp/stm32/stm32f091-st-nucleo\"\033[0m") + print("\033[1;31;40m请确保当前目录为 BSP 根目录,并且该目录中有 Kconfig 文件。\033[0m\n") + + print(" command should be used in a bsp root path with a Kconfig file.") + print("Example: \"rt-thread/bsp/stm32/stm32f091-st-nucleo\"") + print("You should check if there is a Kconfig file in your bsp root first.") + + if platform.system() == "Windows": + os.system('chcp 437 > nul') + + return False + + fn = '.config' + + if os.path.isfile(fn): + mtime = os.path.getmtime(fn) + else: + mtime = -1 + + if platform.system() == "Windows": + os.system('chcp 437 > nul') + + if args.menuconfig_fn: + print('use', args.menuconfig_fn) + import shutil + shutil.copy(args.menuconfig_fn, fn) + elif args.menuconfig_g: + mk_rtconfig(fn) + elif args.menuconfig_silent: + if float(os_version) >= 6.2: + os.system('kconfig-mconf Kconfig -n') + mk_rtconfig(fn) + else: + if os.path.isfile(kconfig_win7_path): + os.system('kconfig-mconf_win7 Kconfig -n') + else: + os.system('kconfig-mconf Kconfig -n') + + elif args.menuconfig_setting: + env_kconfig_path = os.path.join(env_root, r'tools\scripts\cmds') + beforepath = os.getcwd() + os.chdir(env_kconfig_path) + + if float(os_version) >= 6.2: + os.system('kconfig-mconf Kconfig') + else: + if os.path.isfile(kconfig_win7_path): + os.system('kconfig-mconf_win7 Kconfig') + else: + os.system('kconfig-mconf Kconfig') + + os.chdir(beforepath) + + return + + else: + if float(os_version) >= 6.2: + os.system('kconfig-mconf Kconfig') + else: + if os.path.isfile(kconfig_win7_path): + os.system('kconfig-mconf_win7 Kconfig') + else: + os.system('kconfig-mconf Kconfig') + + if os.path.isfile(fn): + mtime2 = os.path.getmtime(fn) + else: + mtime2 = -1 + + if mtime != mtime2: + mk_rtconfig(fn) + + if platform.system() == "Windows": + env_kconfig_path = os.path.join(env_root, r'tools\scripts\cmds') + fn = os.path.join(env_kconfig_path, '.config') + + if not os.path.isfile(fn): + return + + if find_macro_in_config(fn, 'SYS_AUTO_UPDATE_PKGS'): + os.system('pkgs --update') + print("==============================>The packages have been updated completely.") + + if find_macro_in_config(fn, 'SYS_CREATE_MDK_IAR_PROJECT'): + if find_macro_in_config(fn, 'SYS_CREATE_MDK4'): + os.system('scons --target=mdk4 -s') + print("Create mdk4 project done") + elif find_macro_in_config(fn, 'SYS_CREATE_MDK5'): + os.system('scons --target=mdk5 -s') + print("Create mdk5 project done") + elif find_macro_in_config(fn, 'SYS_CREATE_IAR'): + os.system('scons --target=iar -s') + print("Create iar project done") + + +def add_parser(sub): + parser = sub.add_parser('menuconfig', help=__doc__, description=__doc__) + + parser.add_argument('--config', + help='Using the user specified configuration file.', + dest='menuconfig_fn') + + parser.add_argument('--generate', + help='generate rtconfig.h by .config.', + action='store_true', + default=False, + dest='menuconfig_g') + + parser.add_argument('--silent', + help='Silent mode,don\'t display menuconfig window.', + action='store_true', + default=False, + dest='menuconfig_silent') + + parser.add_argument('-s', '--setting', + help='Env config,auto update packages and create mdk/iar project', + action='store_true', + default=False, + dest='menuconfig_setting') + + parser.add_argument('--easy', + help='easy mode, place kconfig everywhere, modify the option env="RTT_ROOT" default "../.."', + action='store_true', + default=False, + dest='menuconfig_easy') + + parser.set_defaults(func=cmd)