Skip to content

Commit 4709e46

Browse files
committed
[tools] Automatically compiles to elf files based on selected attachconfig
1 parent b506228 commit 4709e46

File tree

4 files changed

+85
-2
lines changed

4 files changed

+85
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,6 @@ vdso.lds
6363
# stm32cubemx
6464
**/CubeMX_Config/Drivers/
6565
**/CubeMX_Config/MDK-ARM/
66+
67+
# attachconfig output
68+
attach-output

tools/attachconfig.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,74 @@
55

66
from 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
977
def 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

54123
def GetAttachConfig(action,attachconfig,attachconfig_result):

tools/building.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
340340
GenAttachConfigProject()
341341
exit(0)
342342

343+
if GetOption('attachtest'):
344+
from attachconfig import AttachTestConfig
345+
AttachTestConfig()
346+
exit(0)
347+
343348
if GetOption('genconfig'):
344349
from env_utility import genconfig
345350
genconfig()

tools/options.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,10 @@ def AddOptions():
147147
help = 'View attachconfig or add attach to.config.'+\
148148
'e.g. scons --attach=? View all attachconfig for the current bsp.'+\
149149
' or scons --attach=component.cherryusb_cdc Set option component.cherryusb_cdc inside attachconfig to.config.'+\
150-
' or scons --attach=default Restore.config and rtconfig to before attch was set.')
150+
' or scons --attach=default Restore.config and rtconfig to before attch was set.')
151+
AddOption('--attachtest',
152+
dest = 'attachtest',
153+
type = 'string',
154+
help = 'Automatically compiles to elf files based on selected attachconfig'+\
155+
'e.g. scons --attachtest=all Automatically compiles all options of attachconfig to elf.'+\
156+
' or scons --attachtest=component.cherryusb_cdc Generate elf files according to the config compilation of this option.')

0 commit comments

Comments
 (0)