-
Notifications
You must be signed in to change notification settings - Fork 11
/
SConstruct
239 lines (186 loc) · 6.1 KB
/
SConstruct
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# scons 命令行参数说明
#
# scons a b c -Q --prefix=/home/ INSTANCE=10
#
# 其中:
# a b c 是Targets,编译目标
# -q --prefix 是Options,编译选项
# INSTANCE 是Variables,编译变量
import os
import sys
import pdb
import multiprocessing
# pdb.set_trace()
# Help(
# """
# Usage:
# - scons -C bsps/vandor/borad target
# - scons -C bsps/vandor/borad --target=mdk5/vs2012/vsc
# - scons -C bsps/vandor/board --menuconfig
# """,
# append=True,
# )
# 调试使用
print("ARGUMENTS:", ARGUMENTS)
print("COMMAND_LINE_TARGETS:", COMMAND_LINE_TARGETS)
print("BUILD_TARGET:", BUILD_TARGET)
print("DEFAULT_TARGETS:", DEFAULT_TARGETS)
####################################################
# Command-Line Options
#
# scons --prefix=/home/xxx
# scons -j 4
# scons -Q
#
# scons提供了一些常用的命令行选项,请参考
# https://www.scons.org/doc/HTML/scons-man.html#f-SetOption
####################################################
# AddOption函数添加自定义命令行选项
# AddOption(
# "--prefix",
# dest="prefix",
# type="string",
# nargs=1,
# action="store",
# metavar="DIR",
# help="installation prefix",
# )
AddOption(
"--list-board",
dest="list-board",
action="store_true",
default=False,
help="list all avaliabe board",
)
AddOption(
"--start-sitl",
"--sitl",
"--simulation",
dest="start-sitl",
action="store_true",
default=False,
help="start a software in loop simulation",
)
# SetOption函数设置命令行选项值,但优先级低于从命令行输入的
# SetOption("prefix", "/home/")
# GetOption函数获取命令行选项值
# print("--prefix=%s" % GetOption("prefix"))
####################################################
# Command-Line Construction Variables
#
# scons NAME=foo
# scons RELEASE=1 CC="cl.exe"
####################################################
# 通过命令行输入的变量都存在了ARGUMENTS字典里面
# https://www.scons.org/doc/HTML/scons-man.html#v-ARGUMENTS
# print("ARGUMENTS = ")
# print(ARGUMENTS)
# 获取命令行变量值
# debug = ARGUMENTS.get('debug', 0)
# debug = ARGUMENTS["debug"]
# 判断命令行是否设置某个值
# if "debug" in ARGUMENTS:
# print(ARGUMENTS debug = %s" % ARGUMENTS["debug"])
# 循环穷举所有的输入白能量
# for arg in ARGUMENTS:
# print("ARGUMENTS %s = %s" % (arg, ARGUMENTS[arg]))
# 通过命令行输入的变量同时也存在了ARGLIST数组里面
# https://www.scons.org/doc/HTML/scons-man.html#v-ARGLIST
# print("ARGLIST = ")
# print(ARGLIST)
# 循环穷举列出ARGLIST中变量
# for key, value in ARGLIST:
# print("ARGLIST %s = %s" % (key, value))
# 根据ARGUMENTS创建变量列表
# vars = Variables(None, ARGUMENTS)
# 增加一个变量
# vars.Add('RELEASE', help='Set to 1 to build for release', default=0)
# Help(vars.GenerateHelpText(env))
####################################################
# Command-Line Targets
#
# scons install all
####################################################
# 通过命令行输入的target都保存在COMMAND_LINE_TARGETS数组里面
# print("COMMAND_LINE_TARGETS =")
# print(COMMAND_LINE_TARGETS)
# 将help目标转为显示帮助
# if "help" in COMMAND_LINE_TARGETS:
# SetOption("help", True)
SetOption("help", True)
# 将clean目标转为清空编译
# if "clean" in COMMAND_LINE_TARGETS:
# SetOption("clean", True)
####################################################
# Command(target, source, action, [key=val, ...])
# 对source执行action生成target
####################################################
# 可以使用Command函数来实现一些类似make中phony伪目标
# 由于是伪目标target是不存在的,因此伪目标每次必定执行
# 生成uorb消息
# Command("update_uorb", None, "")
# 生成param定义
# Command("update_param", None, "")
# 生成mavlink消息
# Command("update_mavlink", None, "")
# 软件在环仿真
# Command("sitl", None, "")
# 显示所有可用目标
# def list_target(target=None, source=None, env=None):
# for root, dirs, files in os.walk("bsps"):
# if "SConstruct" in files:
# print(root)
# return 0
# Command("list_target", None, list_target)
# 格式化代码
# def clang_format_code(target, source, env):
# cmd = "clang-format -style=google -i foo.c"
# os.system(cmd)
# scons format
# Command("format", None, clang_format_code)
# scons clang-tidy
# Command("clang-tidy", None, clang_format_code)
####################################################
# Alias(alias, [targets, [action]])
# 生成目标targets时执行action动作
####################################################
##################################################################
##################################################################
# Default("sitl")
# for vendor in os.listdir("target"):
# for product in os.listdir("target/" + vendor):
# print("target/"+ vendor +"/"+ product)
# Command("target#"+ vendor +"#"+ product, [], scons_target)
# Default("sitl/qemu-vexpress-a9")
# 设置编译默认线程数,如果命令行会覆盖当前值
num_jobs = multiprocessing.cpu_count()
SetOption("num_jobs", num_jobs)
# 必须通过-C指定BSP目录,无法在根目录下直接编译
# bsp_root = GetOption("directory")
# if BUILD_TARGETS:
# print(BUILD_TARGETS)
# if not bsp_root:
# # SetOption("no_exec", 1)
# print(
# """
# can NOT run scons in project root path! please change to bsp-dir then run 'scons'.
# or use 'scons -C bsp-dir' to specific start path.
# """
# )
# elif os.path.exist(bsp_root):
# # SetOption("no_exec", 1)
# print("bsp-dir {} not exist".format(bsp_root))
# 列出所有支持的板子
if GetOption("list-board"):
print("-------------------------------------")
print("all avaliabe board:")
print("-------------------------------------")
for root, dirs, files in os.walk("bsps"):
if "SConstruct" in files:
print(root)
print("")
exit(0)
# 启动sitl虚拟飞行仿真
if GetOption("start-sitl"):
os.system("pushd bsps\sitl\qemu && scons && qemu.bat && popd")
exit(0)