diff --git a/.gitignore b/.gitignore index 7f7bab74a77..b8954d60aed 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,6 @@ vdso.lds # stm32cubemx **/CubeMX_Config/Drivers/ **/CubeMX_Config/MDK-ARM/ + +# attachconfig output +attach-output \ No newline at end of file diff --git a/tools/attachconfig.py b/tools/attachconfig.py index df89fd23c3d..37ac295be04 100644 --- a/tools/attachconfig.py +++ b/tools/attachconfig.py @@ -5,6 +5,74 @@ from SCons.Script import * +#根据每个config编译出elf并保存在attach_output +def AttachTestConfig(program = None): + Rtt_Root = os.getcwd() + config_file = os.path.join(os.getcwd(), 'rtt_root', Rtt_Root, '.config') + config_bacakup = config_file+'.origin' + rtconfig_file = os.path.join(os.getcwd(), 'rtt_root', Rtt_Root, 'rtconfig.h') + rtconfig__bacakup = rtconfig_file+'.origin' + + if GetOption('attachtest') == 'all': + + #处理工作,将备份的文件删除,便于后面的操作 + if os.path.exists(config_bacakup): + shutil.copyfile(config_bacakup, config_file) + os.remove(config_bacakup) + if os.path.exists(rtconfig__bacakup): + shutil.copyfile(rtconfig__bacakup, rtconfig_file) + os.remove(rtconfig__bacakup) + + attachconfig=[] + attachconfig_err=[] + GetAttachConfig("get",attachconfig,0) + print("\033[32m✅ Start to Test has: \033[0m") + prefix=attachconfig[0] + for line in attachconfig: + os.system("scons --attach=" +line) + os.system("scons -j4" ) + try: + if not os.path.exists("rt-thread.elf"): + raise FileNotFoundError(f"compile error,elf generation failed") + + os.makedirs("attach-output", exist_ok=True) + dst_path = os.path.join("attach-output", os.path.basename(line+".elf")) + + shutil.move("rt-thread.elf", dst_path) + print(f"\033[32m✅ Generation Success! "+line+".elf -> {dst_path}\033[0m") + + except Exception as e: + print(f"\033[31m❌ Generation failure : {str(e)} \033[0m") + + os.system("scons --attach=default") + + + print("\033[32m✅ success!\033[0m") + else: + + if os.path.exists(config_bacakup): + shutil.copyfile(config_bacakup, config_file) + os.remove(config_bacakup) + if os.path.exists(rtconfig__bacakup): + shutil.copyfile(rtconfig__bacakup, rtconfig_file) + os.remove(rtconfig__bacakup) + + attachconfig=GetOption('attachtest') + print("\033[32m✅ Start to Test : "+str(attachconfig)+"\033[0m") + os.system("scons --attach=" +attachconfig) + os.system("scons -j4" ) + try: + if not os.path.exists("rt-thread.elf"): + raise FileNotFoundError(f"compile error,elf generation failed") + os.makedirs("attach-output", exist_ok=True) + dst_path = os.path.join("attach-output", os.path.basename(line+".elf")) + shutil.move("rt-thread.elf", dst_path) + print(f"\033[32m✅ Generation Success! "+attachconfig+".elf -> {dst_path}\033[0m") + except Exception as e: + print(f"\033[31m❌ Generation failure : {str(e)} \033[0m") + os.system("scons --attach=default") + print("\033[32m✅ Success to generation!\033[0m") + # SCons AttachConfig Command Function def GenAttachConfigProject(program = None): Rtt_Root = os.getcwd() @@ -24,7 +92,6 @@ def GenAttachConfigProject(program = None): prefix=temp_prefix[0] print(line) - elif GetOption('attach') == 'default': if os.path.exists(config_bacakup): shutil.copyfile(config_bacakup, config_file) @@ -32,6 +99,7 @@ def GenAttachConfigProject(program = None): if os.path.exists(rtconfig__bacakup): shutil.copyfile(rtconfig__bacakup, rtconfig_file) os.remove(rtconfig__bacakup) + os.system("pkgs --update-force" ) print("\033[32m✅ Default .config and rtconfig.h recovery success!\033[0m") else: attachconfig=GetOption('attach') @@ -49,6 +117,7 @@ def GenAttachConfigProject(program = None): destination.write(line + '\n') from env_utility import defconfig defconfig(Rtt_Root) + os.system("pkgs --update" ) print("\033[32m✅ AttachConfig add success!\033[0m") def GetAttachConfig(action,attachconfig,attachconfig_result): diff --git a/tools/building.py b/tools/building.py index 6054490cf65..2ae1b166a1e 100644 --- a/tools/building.py +++ b/tools/building.py @@ -340,6 +340,11 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ GenAttachConfigProject() exit(0) + if GetOption('attachtest'): + from attachconfig import AttachTestConfig + AttachTestConfig() + exit(0) + if GetOption('genconfig'): from env_utility import genconfig genconfig() diff --git a/tools/options.py b/tools/options.py index 2e92de8bd3e..21125176803 100644 --- a/tools/options.py +++ b/tools/options.py @@ -147,4 +147,10 @@ def AddOptions(): help = 'View attachconfig or add attach to.config.'+\ 'e.g. scons --attach=? View all attachconfig for the current bsp.'+\ ' or scons --attach=component.cherryusb_cdc Set option component.cherryusb_cdc inside attachconfig to.config.'+\ - ' or scons --attach=default Restore.config and rtconfig to before attch was set.') \ No newline at end of file + ' or scons --attach=default Restore.config and rtconfig to before attch was set.') + AddOption('--attachtest', + dest = 'attachtest', + type = 'string', + help = 'Automatically compiles to elf files based on selected attachconfig'+\ + 'e.g. scons --attachtest=all Automatically compiles all options of attachconfig to elf.'+\ + ' or scons --attachtest=component.cherryusb_cdc Generate elf files according to the config compilation of this option.') \ No newline at end of file