-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathextra_script.py
More file actions
134 lines (112 loc) · 3.74 KB
/
extra_script.py
File metadata and controls
134 lines (112 loc) · 3.74 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
#
# Copyright (c) 2022 ZettaScale Technology
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# ZettaScale Zenoh Team, <zenoh@zettascale.tech>
#
import os
import subprocess
Import('env', 'projenv')
SRC_FILTER = []
CPPDEFINES = []
ZP_PLATFORM = None
BASE_SRC_FILTER = [
"+<*>",
"-<tests/>",
"-<example/>",
"-<system/>",
"+<system/common/>",
"+<system/socket/>",
]
def _platform_src_filter(system_dir):
return BASE_SRC_FILTER + [f"+<{system_dir}/>"]
FRAMEWORK = env.get("PIOFRAMEWORK")[0]
PLATFORM = env.get("PIOPLATFORM")
BOARD = env.get("PIOENV")
ZENOH_GENERIC = env.get("ZENOH_GENERIC", "0")
if ZENOH_GENERIC == "1":
FRAMEWORK = 'generic'
PLATFORM = 'generic'
BOARD = 'generic'
if FRAMEWORK == 'zephyr':
SRC_FILTER = _platform_src_filter("system/zephyr")
ZP_PLATFORM = "zephyr"
CPPDEFINES = [
"ZENOH_ZEPHYR",
]
elif FRAMEWORK == 'arduino':
PLATFORM = env.get("PIOPLATFORM")
if PLATFORM == 'espressif32':
SRC_FILTER = _platform_src_filter("system/arduino/esp32")
ZP_PLATFORM = "arduino_esp32"
CPPDEFINES = [
"ZENOH_ARDUINO_ESP32",
"ZENOH_COMPILER_GCC",
"ZENOH_C_STANDARD=99",
]
if PLATFORM == 'ststm32':
BOARD = env.get("PIOENV")
if BOARD == 'opencr':
SRC_FILTER = _platform_src_filter("system/arduino/opencr")
ZP_PLATFORM = "opencr"
CPPDEFINES = [
"ZENOH_ARDUINO_OPENCR",
"ZENOH_C_STANDARD=99",
"Z_FEATURE_MULTI_THREAD=0",
]
elif FRAMEWORK == 'espidf':
SRC_FILTER = _platform_src_filter("system/espidf")
ZP_PLATFORM = "espidf"
CPPDEFINES = [
"ZENOH_ESPIDF",
]
elif FRAMEWORK == 'mbed':
SRC_FILTER = _platform_src_filter("system/mbed")
ZP_PLATFORM = "mbed"
CPPDEFINES = [
"ZENOH_MBED",
"ZENOH_C_STANDARD=99",
]
elif FRAMEWORK == 'generic':
SRC_FILTER = BASE_SRC_FILTER
CPPDEFINES = ["ZENOH_GENERIC"]
env.Append(SRC_FILTER=SRC_FILTER)
env.Append(CPPDEFINES=CPPDEFINES)
# pass flags to the main project environment
projenv.Append(CPPDEFINES=CPPDEFINES)
# pass flags to a global build environment (for all libraries, etc)
global_env = DefaultEnvironment()
global_env.Append(CPPDEFINES=CPPDEFINES)
# Run CMake for zenoh-pico
# Default embedded buffer values
default_args = ["-DFRAG_MAX_SIZE=4096", "-DBATCH_UNICAST_SIZE=2048", "-DBATCH_MULTICAST_SIZE=2048"]
# Get the additional CMake arguments from the environment
cmake_extra_args = env.BoardConfig().get("build.cmake_extra_args", "")
cmake_extra_args_list = cmake_extra_args.split()
def _has_cmake_arg(name):
prefix = f"{name}="
return any(arg.startswith(prefix) for arg in cmake_extra_args_list)
if (
ZP_PLATFORM is not None
and not _has_cmake_arg("-DZP_PLATFORM")
):
cmake_extra_args_list.append(f"-DZP_PLATFORM={ZP_PLATFORM}")
# Add default value if needed
for default in default_args:
arg_name = default.split('=')[0]
if not any(arg.startswith(arg_name) for arg in cmake_extra_args_list):
cmake_extra_args_list.append(default)
# Define the source and binary directories
source_dir = os.getcwd()
build_dir = os.path.join(source_dir, "build")
os.makedirs(build_dir, exist_ok=True)
# Run the CMake command with the source and binary directories
print("Run command: cmake", source_dir, cmake_extra_args_list)
subprocess.run(["cmake", source_dir] + cmake_extra_args_list, cwd=build_dir, check=True)