Skip to content

Commit 427e177

Browse files
authored
[action/ci] add qemu-pre-build-and-post-build for RT_SMART build (#10203)
[action/ci] add qemu-pre-build-and-post-build for RT_SMART build
1 parent b4e051a commit 427e177

File tree

4 files changed

+175
-14
lines changed

4 files changed

+175
-14
lines changed

.github/ALL_BSP_COMPILE.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
"RTT_TOOL_CHAIN": "sourcery-arm",
7070
"SUB_RTT_BSP": [
7171
"phytium/aarch32",
72-
"qemu-vexpress-a9",
7372
"airm2m/air32f103",
7473
"acm32/acm32f0x0-nucleo",
7574
"acm32/acm32f0x0-nucleo",
@@ -457,6 +456,14 @@
457456
"nrf5x/nrf52840",
458457
"nrf5x/nrf5340"
459458
]
459+
},
460+
{
461+
"RTT_BSP": "arm-none-bsp-smart",
462+
"RTT_TOOL_CHAIN": "sourcery-arm",
463+
"RTT_SMART_TOOL_CHAIN": "arm-linux-musleabi",
464+
"SUB_RTT_BSP": [
465+
"qemu-vexpress-a9"
466+
]
460467
}
461468
]
462469
}

.github/workflows/bsp_buildings.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ jobs:
216216
pip3 install esptool
217217
echo "RTT_EXEC_PATH=/opt/riscv32-esp-elf/bin" >> $GITHUB_ENV
218218
219+
- name: Install Arm Musl ToolChains
220+
if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-arm' && matrix.legs.RTT_SMART_TOOL_CHAIN == 'arm-linux-musleabi' && success() }}
221+
shell: bash
222+
run: |
223+
wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/v1.7/arm-linux-musleabi_for_x86_64-pc-linux-gnu_stable.tar.bz2
224+
sudo tar xjf arm-linux-musleabi_for_x86_64-pc-linux-gnu_stable.tar.bz2 -C /opt
225+
/opt/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin/arm-linux-musleabi-gcc --version
226+
219227
- name: Install Simulator Tools
220228
if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'gcc' && success() }}
221229
run: |

bsp/qemu-vexpress-a9/.ci/attachconfig/ci.attachconfig.yml

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
bsp_board_info:
2+
arch: arm
3+
toolchain: arm-none-eabi-gcc
4+
pre_build: |
5+
scons --version
6+
build_cmd: |
7+
scons -j8
8+
post_build: |
9+
scons --version
10+
run_cmd: ./qemu-nographic.sh
11+
qemu_flag: true
112
# ------ PERIPHERAL CI ------
213
peripheral.UARTv2:
314
kconfig:
@@ -15,15 +26,39 @@ peripheral.LVGL:
1526
- CONFIG_BSP_USING_LVGL=y
1627

1728
# ------ online-packages CI ------
29+
online-packages.tools.coremark:
30+
kconfig:
31+
- CONFIG_PKG_USING_COREMARK=y
32+
- CONFIG_COREMARK_ITERATIONS=36000
33+
pre_build: |
34+
scons --version
35+
build_cmd: |
36+
scons -j8
37+
post_build: |
38+
scons --version
39+
ci_build_run_flag : true
40+
buildcheckresult: "core_main" #检查编译的log中是否有匹配字
41+
msh_cmd: |
42+
ps
43+
version
44+
core_mark
45+
msh_cmd_timeout: 60
46+
checkresult: 'CoreMark 1.0' #检查执行过程中的log是否有匹配字
47+
1848
online-packages.misc.entertainment.tetris:
1949
kconfig:
2050
- CONFIG_PKG_USING_TETRIS=y
2151
online-packages.misc.entertainment.2048:
2252
kconfig:
2353
- CONFIG_PKG_USING_2048=y
24-
online-packages.ai.llmchat:
54+
# ------ RT_SMART PART ------
55+
rt_smart.base:
56+
env:
57+
RTT_CC_PREFIX: arm-linux-musleabi-
58+
RTT_EXEC_PATH: /opt/arm-linux-musleabi_for_x86_64-pc-linux-gnu/bin
59+
pre_build: |
60+
echo $RTT_CC_PREFIX
2561
kconfig:
26-
- CONFIG_WEBCLIENT_USING_MBED_TLS=y
27-
- CONFIG_BSP_DRV_EMAC=y
28-
- CONFIG_PKG_USING_LLMCHAT=y
29-
- CONFIG_PKG_LLM_API_KEY="sk-xxxxxx"
62+
- CONFIG_RT_USING_SMART=y
63+
- CONFIG_RT_USING_MEMHEAP=y
64+
- CONFIG_RT_USING_DFS_V2=y

tools/ci/bsp_buildings.py

Lines changed: 119 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
#
2+
# Copyright (c) 2025, RT-Thread Development Team
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Change Logs:
7+
# Date Author Notes
8+
# 2025-04-21 supperthomas add the smart yml support and add env
9+
#
10+
import subprocess
11+
import threading
12+
import time
13+
import logging
14+
import sys
115
import os
216
import shutil
317
import re
@@ -36,7 +50,7 @@ def run_cmd(cmd, output_info=True):
3650
return output_str_list, res
3751

3852

39-
def build_bsp(bsp, scons_args='',name='default'):
53+
def build_bsp(bsp, scons_args='',name='default', pre_build_commands=None, post_build_command=None,build_check_result = None,bsp_build_env=None):
4054
"""
4155
build bsp.
4256
@@ -56,21 +70,41 @@ def build_bsp(bsp, scons_args='',name='default'):
5670
5771
"""
5872
success = True
73+
# 设置环境变量
74+
if bsp_build_env is not None:
75+
print("Setting environment variables:")
76+
for key, value in bsp_build_env.items():
77+
print(f"{key}={value}")
78+
os.environ[key] = value # 设置环境变量
5979
os.chdir(rtt_root)
6080
os.makedirs(f'{rtt_root}/output/bsp/{bsp}', exist_ok=True)
6181
if os.path.exists(f"{rtt_root}/bsp/{bsp}/Kconfig"):
6282
os.chdir(rtt_root)
63-
run_cmd(f'scons -C bsp/{bsp} --pyconfig-silent', output_info=False)
83+
run_cmd(f'scons -C bsp/{bsp} --pyconfig-silent', output_info=True)
6484

6585
os.chdir(f'{rtt_root}/bsp/{bsp}')
66-
run_cmd('pkgs --update-force', output_info=False)
86+
run_cmd('pkgs --update-force', output_info=True)
6787
run_cmd('pkgs --list')
6888

6989
nproc = multiprocessing.cpu_count()
90+
if pre_build_commands is not None:
91+
print("Pre-build commands:")
92+
print(pre_build_commands)
93+
for command in pre_build_commands:
94+
print(command)
95+
output, returncode = run_cmd(command, output_info=True)
96+
print(output)
97+
if returncode != 0:
98+
print(f"Pre-build command failed: {command}")
99+
print(output)
70100
os.chdir(rtt_root)
101+
# scons 编译命令
71102
cmd = f'scons -C bsp/{bsp} -j{nproc} {scons_args}' # --debug=time for debug time
72-
__, res = run_cmd(cmd, output_info=True)
73-
103+
output, res = run_cmd(cmd, output_info=True)
104+
if build_check_result is not None:
105+
if res != 0 or not check_output(output, build_check_result):
106+
print("Build failed or build check result not found")
107+
print(output)
74108
if res != 0:
75109
success = False
76110
else:
@@ -83,6 +117,13 @@ def build_bsp(bsp, scons_args='',name='default'):
83117
shutil.copy(file, f'{rtt_root}/output/bsp/{bsp}/{name.replace("/", "_")}.{file_type[2:]}')
84118

85119
os.chdir(f'{rtt_root}/bsp/{bsp}')
120+
if post_build_command is not None:
121+
for command in post_build_command:
122+
output, returncode = run_cmd(command, output_info=True)
123+
print(output)
124+
if returncode != 0:
125+
print(f"Post-build command failed: {command}")
126+
print(output)
86127
run_cmd('scons -c', output_info=False)
87128

88129
return success
@@ -158,7 +199,17 @@ def build_bsp_attachconfig(bsp, attach_file):
158199

159200
return res
160201

202+
def check_output(output, check_string):
203+
"""检查输出中是否包含指定字符串"""
204+
output_str = ''.join(output) if isinstance(output, list) else str(output)
205+
flag = check_string in output_str
206+
if flag == True:
207+
print('Success: find string ' + check_string)
208+
else:
209+
print(output)
210+
print(f"::error:: can not find string {check_string} output: {output_str}")
161211

212+
return flag
162213
if __name__ == "__main__":
163214
"""
164215
build all bsp and attach config.
@@ -169,10 +220,12 @@ def build_bsp_attachconfig(bsp, attach_file):
169220
"""
170221
failed = 0
171222
count = 0
223+
ci_build_run_flag = False
224+
qemu_timeout_second = 50
172225

173226
rtt_root = os.getcwd()
174227
srtt_bsp = os.getenv('SRTT_BSP').split(',')
175-
228+
print(srtt_bsp)
176229
for bsp in srtt_bsp:
177230
count += 1
178231
print(f"::group::Compiling BSP: =={count}=== {bsp} ====")
@@ -207,26 +260,80 @@ def build_bsp_attachconfig(bsp, attach_file):
207260
continue
208261

209262
config_file = os.path.join(rtt_root, 'bsp', bsp, '.config')
210-
263+
# 在使用 pre_build_commands 之前,确保它被定义
264+
pre_build_commands = None
265+
build_command = None
266+
post_build_command = None
267+
qemu_command = None
268+
build_check_result = None
269+
commands = None
270+
check_result = None
271+
bsp_build_env = None
211272
for projects in yml_files_content:
212273
for name, details in projects.items():
274+
# 如果是bsp_board_info,读取基本的信息
275+
if(name == 'bsp_board_info'):
276+
print(details)
277+
pre_build_commands = details.get("pre_build").splitlines()
278+
build_command = details.get("build_cmd").splitlines()
279+
post_build_command = details.get("post_build").splitlines()
280+
qemu_command = details.get("run_cmd")
281+
282+
if details.get("kconfig") is not None:
283+
if details.get("buildcheckresult") is not None:
284+
build_check_result = details.get("buildcheckresult")
285+
else:
286+
build_check_result = None
287+
if details.get("msh_cmd") is not None:
288+
commands = details.get("msh_cmd").splitlines()
289+
else:
290+
msh_cmd = None
291+
if details.get("checkresult") is not None:
292+
check_result = details.get("checkresult")
293+
else:
294+
check_result = None
295+
if details.get("ci_build_run_flag") is not None:
296+
ci_build_run_flag = details.get("ci_build_run_flag")
297+
else:
298+
ci_build_run_flag = None
299+
if details.get("pre_build") is not None:
300+
pre_build_commands = details.get("pre_build").splitlines()
301+
if details.get("env") is not None:
302+
bsp_build_env = details.get("env")
303+
else:
304+
bsp_build_env = None
305+
if details.get("build_cmd") is not None:
306+
build_command = details.get("build_cmd").splitlines()
307+
else:
308+
build_command = None
309+
if details.get("post_build") is not None:
310+
post_build_command = details.get("post_build").splitlines()
311+
if details.get("run_cmd") is not None:
312+
qemu_command = details.get("run_cmd")
313+
else:
314+
qemu_command = None
213315
count += 1
214316
config_bacakup = config_file+'.origin'
215317
shutil.copyfile(config_file, config_bacakup)
318+
#加载yml中的配置放到.config文件
216319
with open(config_file, 'a') as destination:
217320
if details.get("kconfig") is None:
321+
#如果没有Kconfig,读取下一个配置
218322
continue
219323
if(projects.get(name) is not None):
324+
# 获取Kconfig中所有的信息
220325
detail_list=get_details_and_dependencies([name],projects)
221326
for line in detail_list:
222327
destination.write(line + '\n')
223328
scons_arg=[]
329+
#如果配置中有scons_arg
224330
if details.get('scons_arg') is not None:
225331
for line in details.get('scons_arg'):
226332
scons_arg.append(line)
227333
scons_arg_str=' '.join(scons_arg) if scons_arg else ' '
228334
print(f"::group::\tCompiling yml project: =={count}==={name}=scons_arg={scons_arg_str}==")
229-
res = build_bsp(bsp, scons_arg_str,name=name)
335+
# #开始编译bsp
336+
res = build_bsp(bsp, scons_arg_str,name=name,pre_build_commands=pre_build_commands,post_build_command=post_build_command,build_check_result=build_check_result,bsp_build_env =bsp_build_env)
230337
if not res:
231338
print(f"::error::build {bsp} {name} failed.")
232339
add_summary(f'\t- ❌ build {bsp} {name} failed.')
@@ -235,11 +342,15 @@ def build_bsp_attachconfig(bsp, attach_file):
235342
add_summary(f'\t- ✅ build {bsp} {name} success.')
236343
print("::endgroup::")
237344

345+
238346
shutil.copyfile(config_bacakup, config_file)
239347
os.remove(config_bacakup)
240348

349+
350+
241351
attach_dir = os.path.join(rtt_root, 'bsp', bsp, '.ci/attachconfig')
242352
attach_list = []
353+
#这里是旧的文件方式
243354
for root, dirs, files in os.walk(attach_dir):
244355
for file in files:
245356
if file.endswith('attach'):

0 commit comments

Comments
 (0)