Skip to content

Commit dc89343

Browse files
committed
脚本编译时支持选择开发板和机器人类型
1 parent dbec17c commit dc89343

File tree

5 files changed

+32
-242
lines changed

5 files changed

+32
-242
lines changed

.github/workflows/build_firmware.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
run: cd ${{github.workspace}} && git submodule init && git submodule update
3131

3232
- name: Build
33-
run: python ${{github.workspace}}/project.py build all
33+
run: python ${{github.workspace}}/project.py build all all
3434

3535
- uses: actions/upload-artifact@v3
3636
with:
@@ -40,7 +40,7 @@ jobs:
4040
run: cd ${{github.workspace}} && zip -r ${{github.workspace}}/firmware.zip ./firmware
4141

4242
- name: Create release
43-
run: echo "release_name=$(date +v%Y.%m.%d.vv%M.%S)" >> $GITHUB_ENV
43+
run: echo "release_name=$(date +v%Y.%m.%d.vv%H.%M)" >> $GITHUB_ENV
4444

4545
- uses: actions/create-release@v1
4646
id: create_release

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ hw/bsp/rm-c/drivers/hal/Core/Src/system_stm32f4xx.c
1111
.vscode/launch.json
1212
**.config.old
1313
firmware/**
14+
config/auto.Kconfig

config/Kconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
source "./auto.Kconfig"
2-
3-
# source "../src/Kconfig"

config/auto.Kconfig

Lines changed: 0 additions & 225 deletions
This file was deleted.

project.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
project_path = os.path.split(os.path.realpath(__file__))[0]
77

88

9-
def build_all():
9+
def build(board, robot):
10+
target = []
11+
1012
os.system("rm -rf " + project_path + '/firmware')
1113
for dirname in os.listdir(project_path + '/hw/bsp'):
1214
if os.path.isdir(project_path + '/hw/bsp/' + dirname):
1315
for filename in os.listdir(project_path + '/hw/bsp/' + dirname +
1416
'/config'):
1517
if os.path.isfile(project_path + '/hw/bsp/' + dirname +
16-
'/config/' + filename):
17-
if filename.endswith(".config"):
18+
'/config/' + filename) and (
19+
board == 'all' or dirname == board):
20+
if filename.endswith(".config") and (
21+
robot == 'all' or filename[:-7] == robot):
1822
shutil.copyfile(
1923
project_path + '/hw/bsp/' + dirname + '/config/' +
2024
filename, project_path + '/config/.config')
@@ -27,6 +31,16 @@ def build_all():
2731
project_path + '/firmware/' + dirname + '&' +
2832
filename[:-7] + '.elf')
2933

34+
print('\n')
35+
36+
target.append([dirname, filename[:-7]])
37+
if len(target) == 0:
38+
print('ERROR:No target select.')
39+
else:
40+
for item in target:
41+
print('Robot[' + item[1] + ']' + ' for board ' + item[0] +
42+
' build done.')
43+
3044

3145
def menuconfig(path):
3246
print('Start menu config.')
@@ -45,9 +59,14 @@ def config_cmake():
4559
)
4660

4761

62+
config_prefix = '_SUB_CFG_'
63+
64+
4865
def add_detail(file, name: str, value: str):
4966
name = name[7:]
5067
file.write('set(' + name + ' ' + value + ')\n')
68+
if name.startswith(config_prefix):
69+
return
5170
file.write('add_compile_definitions(' + name + '=${' + name + '})\n')
5271

5372

@@ -57,13 +76,13 @@ def foreach_config_single(head, file, path):
5776

5877
for dirname in os.listdir(path):
5978
if os.path.isdir(path + '/' + dirname):
60-
file.write('\n\tconfig _SUB_CFG_' + dirname + '\n\t\tbool \"' +
61-
dirname + '\"\n')
79+
file.write('\n\tconfig ' + config_prefix + dirname +
80+
'\n\t\tbool \"' + dirname + '\"\n')
6281
file.write('endchoice\n')
6382

6483
for dirname in os.listdir(path):
6584
if os.path.isdir(path + '/' + dirname):
66-
file.write('\nif ' + '_SUB_CFG_' + dirname + '\n\tsource \"' +
85+
file.write('\nif ' + config_prefix + dirname + '\n\tsource \"' +
6786
path + '/' + dirname + '/Kconfig"\nendif\n')
6887

6988

@@ -74,10 +93,10 @@ def foreach_config(head, file, path):
7493
for dirname in os.listdir(path):
7594
if os.path.isdir(path + '/' + dirname):
7695
file.write('\nmenu \"' + dirname + '"\n')
77-
file.write('\n\tconfig _SUB_CFG_' + dirname + '\n\t\ttristate \"' +
78-
dirname + '\"\n')
96+
file.write('\n\tconfig ' + config_prefix + dirname +
97+
'\n\t\ttristate \"' + dirname + '\"\n')
7998

80-
file.write('\nif ' + '_SUB_CFG_' + dirname + '\n\tsource \"' +
99+
file.write('\nif ' + config_prefix + dirname + '\n\tsource \"' +
81100
path + '/' + dirname + '/Kconfig"\nendif\n')
82101
file.write('endmenu\n')
83102
file.write('endmenu\n')
@@ -166,9 +185,6 @@ def generate_cmake(path):
166185
config_cmake()
167186

168187
elif cmd[1] == 'build':
169-
if cmd[2] == 'all':
170-
print("Build all target.")
171-
build_all()
172-
188+
build(cmd[2], cmd[3])
173189
else:
174190
print('错误的参数')

0 commit comments

Comments
 (0)