55
66from SCons .Script import *
77
8+ #根据每个config编译出elf并保存在attach_output
9+ def AttachTestConfig (program = None ):
10+ Rtt_Root = os .getcwd ()
11+ config_file = os .path .join (os .getcwd (), 'rtt_root' , Rtt_Root , '.config' )
12+ config_bacakup = config_file + '.origin'
13+ rtconfig_file = os .path .join (os .getcwd (), 'rtt_root' , Rtt_Root , 'rtconfig.h' )
14+ rtconfig__bacakup = rtconfig_file + '.origin'
15+
16+ if GetOption ('attachtest' ) == 'all' :
17+
18+ #处理工作,将备份的文件删除,便于后面的操作
19+ if os .path .exists (config_bacakup ):
20+ shutil .copyfile (config_bacakup , config_file )
21+ os .remove (config_bacakup )
22+ if os .path .exists (rtconfig__bacakup ):
23+ shutil .copyfile (rtconfig__bacakup , rtconfig_file )
24+ os .remove (rtconfig__bacakup )
25+
26+ attachconfig = []
27+ attachconfig_err = []
28+ GetAttachConfig ("get" ,attachconfig ,0 )
29+ print ("\033 [32m✅ Start to Test has: \033 [0m" )
30+ prefix = attachconfig [0 ]
31+ for line in attachconfig :
32+ os .system ("scons --attach=" + line )
33+ os .system ("scons -j4" )
34+ try :
35+ if not os .path .exists ("rt-thread.elf" ):
36+ raise FileNotFoundError (f"compile error,elf generation failed" )
37+
38+ os .makedirs ("attach-output" , exist_ok = True )
39+ dst_path = os .path .join ("attach-output" , os .path .basename (line + ".elf" ))
40+
41+ shutil .move ("rt-thread.elf" , dst_path )
42+ print (f"\033 [32m✅ Generation Success! " + line + ".elf -> {dst_path}\033 [0m" )
43+
44+ except Exception as e :
45+ print (f"\033 [31m❌ Generation failure : { str (e )} \033 [0m" )
46+
47+ os .system ("scons --attach=default" )
48+
49+
50+ print ("\033 [32m✅ success!\033 [0m" )
51+ else :
52+
53+ if os .path .exists (config_bacakup ):
54+ shutil .copyfile (config_bacakup , config_file )
55+ os .remove (config_bacakup )
56+ if os .path .exists (rtconfig__bacakup ):
57+ shutil .copyfile (rtconfig__bacakup , rtconfig_file )
58+ os .remove (rtconfig__bacakup )
59+
60+ attachconfig = GetOption ('attachtest' )
61+ print ("\033 [32m✅ Start to Test : " + str (attachconfig )+ "\033 [0m" )
62+ os .system ("scons --attach=" + attachconfig )
63+ os .system ("scons -j4" )
64+ try :
65+ if not os .path .exists ("rt-thread.elf" ):
66+ raise FileNotFoundError (f"compile error,elf generation failed" )
67+ os .makedirs ("attach-output" , exist_ok = True )
68+ dst_path = os .path .join ("attach-output" , os .path .basename (line + ".elf" ))
69+ shutil .move ("rt-thread.elf" , dst_path )
70+ print (f"\033 [32m✅ Generation Success! " + attachconfig + ".elf -> {dst_path}\033 [0m" )
71+ except Exception as e :
72+ print (f"\033 [31m❌ Generation failure : { str (e )} \033 [0m" )
73+ os .system ("scons --attach=default" )
74+ print ("\033 [32m✅ Success to generation!\033 [0m" )
75+
876# SCons AttachConfig Command Function
977def GenAttachConfigProject (program = None ):
1078 Rtt_Root = os .getcwd ()
@@ -24,14 +92,14 @@ def GenAttachConfigProject(program = None):
2492 prefix = temp_prefix [0 ]
2593 print (line )
2694
27-
2895 elif GetOption ('attach' ) == 'default' :
2996 if os .path .exists (config_bacakup ):
3097 shutil .copyfile (config_bacakup , config_file )
3198 os .remove (config_bacakup )
3299 if os .path .exists (rtconfig__bacakup ):
33100 shutil .copyfile (rtconfig__bacakup , rtconfig_file )
34101 os .remove (rtconfig__bacakup )
102+ os .system ("pkgs --update-force" )
35103 print ("\033 [32m✅ Default .config and rtconfig.h recovery success!\033 [0m" )
36104 else :
37105 attachconfig = GetOption ('attach' )
@@ -49,6 +117,7 @@ def GenAttachConfigProject(program = None):
49117 destination .write (line + '\n ' )
50118 from env_utility import defconfig
51119 defconfig (Rtt_Root )
120+ os .system ("pkgs --update" )
52121 print ("\033 [32m✅ AttachConfig add success!\033 [0m" )
53122
54123def GetAttachConfig (action ,attachconfig ,attachconfig_result ):
0 commit comments