-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSConstruct
More file actions
249 lines (227 loc) · 7.76 KB
/
Copy pathSConstruct
File metadata and controls
249 lines (227 loc) · 7.76 KB
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
240
241
242
243
244
245
246
247
248
249
import os
import subprocess
from datetime import datetime
Import('env')
with open(env['PROJECT_TOOL_S']) as f:
exec(f.read())
toolchain_sysroot = os.environ.get('CONFIG_TOOLCHAIN_SYSROOT', '')
toolchain_multiarch = env.get('GCC_DUMPMACHINE', 'aarch64-linux-gnu')
toolchain_lib_path = os.path.join(
toolchain_sysroot, 'usr', 'lib', toolchain_multiarch
) if toolchain_sysroot else ''
def config_enabled(name):
return os.environ.get(name, '').lower() in ('1', 'y', 'yes', 'true')
is_desktop = config_enabled('CONFIG_FACTORY_TEST_USE_DESKTOP')
is_product_mode = config_enabled('FACTORY_TEST_PRODUCT_MODE')
for config_header_name in ('global_config.h', 'lvgl_config.h'):
config_header = os.path.join(
env['PROJECT_PATH'], 'build', 'config', config_header_name
)
if os.path.exists(config_header):
with open(config_header, encoding='utf-8') as config_file:
config_content = config_file.read()
updated_config_content = config_content.replace('#define DEBUG 1\n', '')
if updated_config_content != config_content:
with open(config_header, 'w', encoding='utf-8') as config_file:
config_file.write(updated_config_content)
SRCS = append_srcs_dir(ADir('src'))
INCLUDE = [
ADir('src'),
ADir('src/app'),
ADir('src/logger'),
ADir('src/model'),
ADir('src/platform'),
ADir('src/reactive'),
ADir('src/serialization'),
ADir('src/view'),
ADir('src/view/screens'),
ADir('src/view/widgets'),
ADir('src/viewmodel'),
os.path.join(env['PROJECT_PATH'], 'build', 'scons-generated'),
os.path.join(
os.environ['SDK_PATH'],
'components',
'utilities',
'party',
'fmt',
'include',
),
os.path.join(os.environ['EXT_COMPONENTS_PATH'], 'Miniaudio', 'include'),
]
PRIVATE_INCLUDE = []
REQUIREMENTS = [
'lvgl_component',
'Miniaudio',
'pthread',
'dl',
'freetype',
'png16',
'jpeg',
'z',
'm',
] + ['libyaml', 'cjson']
if toolchain_sysroot:
REQUIREMENTS += [':libfmt.so.10']
if is_product_mode and not is_desktop:
REQUIREMENTS += ['drm']
if is_desktop:
REQUIREMENTS += pkg_config_ldflags('sdl2')
else:
REQUIREMENTS += [
'libcamera',
'libcamera-base',
'libnm',
'libgio-2.0',
'libgobject-2.0',
'libglib-2.0',
'gio-2.0',
'gobject-2.0',
'glib-2.0',
'libudev',
'libiperf',
'libsctp',
'liblirc',
'libgpiod',
]
REQUIREMENTS = list(dict.fromkeys(REQUIREMENTS))
STATIC_LIB = []
DYNAMIC_LIB = []
if not is_desktop:
if toolchain_sysroot:
serialport_static_lib = os.path.join(
toolchain_lib_path, 'libserialport.a'
)
if os.path.exists(serialport_static_lib):
STATIC_LIB.append(serialport_static_lib)
else:
REQUIREMENTS.append('libserialport')
else:
REQUIREMENTS.append('libserialport')
desktop_dependency_includes = []
if is_desktop:
try:
desktop_include_flags = subprocess.check_output(
['pkg-config', '--cflags-only-I', 'sdl2', 'freetype2', 'libpng'],
text=True,
).split()
desktop_dependency_includes = [
include_flag[2:]
for include_flag in desktop_include_flags
if include_flag.startswith('-I')
]
INCLUDE += desktop_dependency_includes
except (OSError, subprocess.CalledProcessError):
pass
DEFINITIONS = [
'-DFACTORY_TEST_SCONS_BUILD',
'-DFACTORY_TEST_PRODUCT_MODE={}'.format(1 if is_product_mode else 0),
'-std=c++17',
'-g',
]
if not toolchain_sysroot:
DEFINITIONS += ['-DFMT_HEADER_ONLY']
DEFINITIONS_PRIVATE = []
LDFLAGS = []
LINK_SEARCH_PATH = []
STATIC_FILES = [(ADir('assets'), 'assets')]
factory_test_config_header = os.path.join(
env['PROJECT_PATH'], 'build', 'config', 'factory_test_config.h'
)
factory_test_config_lines = [
'#pragma once\n\n',
'#define USE_DESKTOP {}\n'.format(1 if is_desktop else 0),
]
factory_test_config_content = ''.join(factory_test_config_lines)
if (not os.path.exists(factory_test_config_header)
or open(factory_test_config_header, encoding='utf-8').read()
!= factory_test_config_content):
with open(factory_test_config_header, 'w', encoding='utf-8') as config_file:
config_file.write(factory_test_config_content)
generated_include_dir = os.path.join(
env['PROJECT_PATH'], 'build', 'scons-generated'
)
os.makedirs(generated_include_dir, exist_ok=True)
version_header = os.path.join(generated_include_dir, 'version.h')
try:
git_commit = subprocess.check_output(
['git', 'rev-parse', '--short=8', 'HEAD'],
cwd=env['PROJECT_PATH'],
text=True,
stderr=subprocess.DEVNULL,
).strip()
except (OSError, subprocess.CalledProcessError):
git_commit = 'UNKNOWN'
version_content = '''#pragma once
#define FACTORY_TEST_MAJOR 0
#define FACTORY_TEST_MINOR 3
#define FACTORY_TEST_PATCH 1
#define FACTORY_TEST_BUILD_TIME "{}"
#define FACTORY_TEST_GIT_COMMIT "{}"
#define FACTORY_TEST_VERSION_STRINGIFY_IMPL(value) #value
#define FACTORY_TEST_VERSION_STRINGIFY(value) FACTORY_TEST_VERSION_STRINGIFY_IMPL(value)
namespace factory_test {{
inline constexpr char kVersion[] =
FACTORY_TEST_VERSION_STRINGIFY(FACTORY_TEST_MAJOR) "."
FACTORY_TEST_VERSION_STRINGIFY(FACTORY_TEST_MINOR) "."
FACTORY_TEST_VERSION_STRINGIFY(FACTORY_TEST_PATCH);
inline constexpr char kBuildTime[] = FACTORY_TEST_BUILD_TIME;
constexpr const char* get_version_str() noexcept {{ return kVersion; }}
constexpr const char* get_build_time_str() noexcept {{ return kBuildTime; }}
}} // namespace factory_test
#undef FACTORY_TEST_VERSION_STRINGIFY
#undef FACTORY_TEST_VERSION_STRINGIFY_IMPL
'''.format(datetime.now().strftime('%Y-%m-%d %H:%M:%S'), git_commit)
if not os.path.exists(version_header):
with open(version_header, 'w', encoding='utf-8') as version_file:
version_file.write(version_content)
if toolchain_sysroot:
INCLUDE += [
os.path.join(toolchain_sysroot, 'usr', 'include'),
os.path.join(toolchain_sysroot, 'usr', 'include', 'freetype2'),
os.path.join(toolchain_sysroot, 'usr', 'include', 'libpng16'),
os.path.join(toolchain_sysroot, 'usr', 'include', toolchain_multiarch),
]
LINK_SEARCH_PATH += [toolchain_lib_path]
LDFLAGS += [
'-Wl,-rpath-link,{}'.format(toolchain_lib_path),
'-B{}'.format(toolchain_lib_path),
]
if not is_desktop:
INCLUDE += [
os.path.join(toolchain_sysroot, 'usr', 'include', 'glib-2.0'),
os.path.join(toolchain_lib_path, 'glib-2.0', 'include'),
]
if not is_desktop:
INCLUDE += [os.path.join(toolchain_sysroot, 'usr', 'include', 'libnm')]
if is_product_mode and not is_desktop:
INCLUDE += [os.path.join(toolchain_sysroot, 'usr', 'include', 'libdrm')]
lvgl_component = list(filter(
lambda component: component['target'] == 'lvgl_component',
env['COMPONENTS'],
))[0]
if toolchain_sysroot:
lvgl_component['INCLUDE'] += [
os.path.join(toolchain_sysroot, 'usr', 'include', 'freetype2'),
os.path.join(toolchain_sysroot, 'usr', 'include', 'libpng16'),
]
elif is_desktop:
lvgl_component['INCLUDE'] += desktop_dependency_includes
if is_product_mode and not is_desktop:
lvgl_component['INCLUDE'] += [
os.path.join(toolchain_sysroot, 'usr', 'include', 'libdrm')
]
env['COMPONENTS'].append({
'target': env['PROJECT_NAME'],
'SRCS': SRCS,
'INCLUDE': INCLUDE,
'PRIVATE_INCLUDE': PRIVATE_INCLUDE,
'REQUIREMENTS': REQUIREMENTS,
'STATIC_LIB': STATIC_LIB,
'DYNAMIC_LIB': DYNAMIC_LIB,
'DEFINITIONS': DEFINITIONS,
'DEFINITIONS_PRIVATE': DEFINITIONS_PRIVATE,
'LDFLAGS': LDFLAGS,
'LINK_SEARCH_PATH': LINK_SEARCH_PATH,
'STATIC_FILES': STATIC_FILES,
'REGISTER': 'project',
})