-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSConstruct
172 lines (143 loc) · 6.72 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
#!/usr/bin/python3
from os import environ
from re import compile, findall, search
from SCons.Script import (
AddOption,
Default,
Dir,
Environment,
Exit,
GetOption,
SConscript,
)
from oyaml import safe_load
# create a global environment which all targets can start from
GlobalEnv = Environment(REPO_ROOT_DIR=Dir("#"), tools=[])
try:
GlobalEnv["ENV"]["TERM"] = environ["TERM"]
except Exception:
print("No terminal environment specified...")
# add option to choose target or platforam
AddOption("--targets", dest="targets", type="string", action="store")
AddOption("--platform", dest="platform", type="string", action="store")
# add option to make build verbose
AddOption("--verbose", dest="verbose", action="store_true")
# add option to build without debug info
AddOption("--release", dest="release", action="store_true")
components = None
platforms = None
with open("site_scons/components.yaml") as components_file:
components = safe_load(components_file)
with open("site_scons/platforms.yaml") as platforms_file:
platforms = safe_load(platforms_file)
COMPONENT_REGEX = compile(r"(?P<component>[A-Za-z]+)")
CONFIG_ID_REGEX = compile(r"(?:(\d+),?)")
network_dirs = {}
targets = GetOption("targets")
platform = GetOption("platform")
target_dict = {}
PlatformEnv = GlobalEnv.Clone()
NetworkEnv = PlatformEnv.Clone()
PlatformEnv["ARTIFACTS"] = {}
NetworkEnv["NETWORK_PATH"] = Dir("#/network")
NetworkEnv["NETWORK_DATA_DIR"] = NetworkEnv["NETWORK_PATH"].Dir("definition")
NetworkEnv["NETWORK_ARTIFACTS"] = GlobalEnv["REPO_ROOT_DIR"].Dir(f"platform-artifacts/network")
if platform:
if platform in platforms["configs"]:
PlatformEnv["PLATFORM_ID"] = platform
PlatformEnv["PLATFORM_ARTIFACTS"] = GlobalEnv["REPO_ROOT_DIR"].Dir(f"platform-artifacts/{platform.upper()}")
PlatformEnv["FEATURE_SELECTIONS"] = platforms["configs"][platform]["options"]["feature-selections"]
if targets:
for target in targets.split("+"):
component = search(COMPONENT_REGEX, target).group()
config_ids = [int(id) for id in findall(CONFIG_ID_REGEX, target)]
if component in platforms["configs"][platform]["ecu"]:
if len(config_ids) == 0:
target_dict[component] = platforms["configs"][platform]["ecu"][component]
else:
target_dict[component] = []
for config in platforms["configs"][platform]["ecu"][component].keys():
if config in config_ids:
target_dict[component].append(config)
else:
print(
f"Platform string '{platform}' does not contain any ecu named '{component}'"
)
Exit(1)
else:
for part in platforms["configs"][platform]["ecu"]:
target_dict[part] = platforms["configs"][platform]["ecu"][part]
else:
print(
f"Platform string '{platform}' does not match any platform in 'site_scons/platforms.yaml'"
)
Exit(1)
elif targets:
targets = targets.split('+')
for target in targets:
target_dict[target] = []
NetworkEnv.Tool("network")
dbc = NetworkEnv.BuildNetwork()
PlatformEnv["ARTIFACTS"]["DBC"] = dbc
Default(dbc)
multiple_targets = False
if len(target_dict) > 1:
multiple_targets = True
for target in target_dict:
component = search(COMPONENT_REGEX, target)
if not component:
print(
f"Target string '{target}' does not match the required format of '<component name1>:[<config id1>[,<config id2>[,...]]]'"
)
Exit(1)
if component["component"] not in components:
print(f"Unknown target '{target}'. See site_scons/components.yaml")
Exit(1)
config_ids = []
if platform:
config_ids = target_dict[target]
else:
config_ids = [int(id) for id in findall(CONFIG_ID_REGEX, target)]
target_sconscript = f"{components[component["component"]]['path']}SConscript"
PlatformEnv["ARTIFACTS"][f"{target.upper()}"] = SConscript(target_sconscript, exports={"CONFIG_IDS": config_ids, "PLATFORM_ENV": PlatformEnv, "NETWORK_ENV": NetworkEnv })
if PlatformEnv["ARTIFACTS"]:
AddOption("--upload", dest="upload", action="store_true")
AddOption("--debugger", dest="debugger", action="store_true")
for component in PlatformEnv["ARTIFACTS"]:
if component == "DBC":
continue
if any("FLASHABLE_ARTIFACT" in artifact for artifact in PlatformEnv["ARTIFACTS"][component]):
if GetOption("upload"):
if multiple_targets:
print(f"Cannot upload multiple targets...")
print(f"Exiting...")
Exit(1)
if type(PlatformEnv["ARTIFACTS"][component]["FLASHABLE_ARTIFACT"]["artifact"]) is list:
if len(PlatformEnv["ARTIFACTS"][component]["FLASHABLE_ARTIFACT"]["artifact"]) > 1:
print(f"Cannot flash multiple configs...")
print(f"Exiting...")
Exit(1)
artifact = PlatformEnv["ARTIFACTS"][component]["FLASHABLE_ARTIFACT"]["artifact"]
start_addr = PlatformEnv["ARTIFACTS"][component]["FLASHABLE_ARTIFACT"]["addr"]
tools = PlatformEnv["ARTIFACTS"][component]["FLASHABLE_ARTIFACT"]["tools"]
flashing_env = GlobalEnv.Clone(tools=tools)
upload = flashing_env.flash(source=artifact, start_addr=start_addr)
Default(upload)
if any("DEBUG_ARTIFACT" in artifact for artifact in PlatformEnv["ARTIFACTS"][component]):
if GetOption("debugger"):
if multiple_targets:
print(f"Cannot debug multiple targets...")
print(f"Exiting...")
Exit(1)
if type(PlatformEnv["ARTIFACTS"][component]["DEBUG_ARTIFACT"]["artifact"]) is list:
if len(PlatformEnv["ARTIFACTS"][component]["DEBUG_ARTIFACT"]["artifact"]) > 1:
print(f"Cannot debug multiple configs...")
print(f"Exiting...")
Exit(1)
artifact = PlatformEnv["ARTIFACTS"][component]["DEBUG_ARTIFACT"]["artifact"]
args = PlatformEnv["ARTIFACTS"][component]["DEBUG_ARTIFACT"]["args"]
tools = PlatformEnv["ARTIFACTS"][component]["DEBUG_ARTIFACT"]["tools"]
env = PlatformEnv["ARTIFACTS"][component]["DEBUG_ARTIFACT"].get("env", {})
debug_env = GlobalEnv.Clone(tools=tools, **env)
openocd_gdb = debug_env.openocd_gdb(artifact, *args)
Default(openocd_gdb)