Skip to content

[action] Automatically compiles to elf files based on selected attach #10096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ vdso.lds
# stm32cubemx
**/CubeMX_Config/Drivers/
**/CubeMX_Config/MDK-ARM/

# attachconfig output
attach-output
71 changes: 70 additions & 1 deletion tools/attachconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hex是不是更方便一些?
还有是否可以支持scons --target=mdk5的场景?
现在如果把UV4.exe加入路径,执行scons --target=mdk5 可以生产axf文件了。
建议这里可以检查常见的可执行文件,都拷贝过去。用之前清一下。
常见的,axf,elf,hex


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()
Expand All @@ -24,14 +92,14 @@ 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)
os.remove(config_bacakup)
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')
Expand All @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 7 additions & 1 deletion tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
' 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.')