blob: b5d7594c79ae4dbf8e06c52102a3f265a64a2bae [file] [log] [blame]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +01001#!/usr/bin/env python3
2
3""" tfm_build_manager.py:
4
5 Controlling class managing multiple build configruations for tfm """
6
7from __future__ import print_function
Xinyu Zhang433771e2022-04-01 16:49:17 +08008from json import tool
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +01009
10__copyright__ = """
11/*
Feder Liang357b1602022-01-11 16:47:49 +080012 * Copyright (c) 2018-2022, Arm Limited. All rights reserved.
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010013 *
14 * SPDX-License-Identifier: BSD-3-Clause
15 *
16 */
17 """
Karl Zhang08681e62020-10-30 13:56:03 +080018
19__author__ = "tf-m@lists.trustedfirmware.org"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010020__project__ = "Trusted Firmware-M Open CI"
Xinyu Zhang06286a92021-07-22 14:00:51 +080021__version__ = "1.4.0"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010022
23import os
24import sys
Karl Zhangaff558a2020-05-15 14:28:23 +010025from .utils import *
Minos Galanakisea421232019-06-20 17:11:28 +010026from time import time
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010027from copy import deepcopy
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010028from .structured_task import structuredTask
29from .tfm_builder import TFM_Builder
Xinyu Zhang1fa7f982022-04-20 17:46:17 +080030from build_helper.build_helper_config_maps import *
Xinyu Zhangfd2e1152021-12-17 18:09:01 +080031
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010032class TFM_Build_Manager(structuredTask):
33 """ Class that will load a configuration out of a json file, schedule
34 the builds, and produce a report """
35
36 def __init__(self,
37 tfm_dir, # TFM root directory
38 work_dir, # Current working directory(ie logs)
39 cfg_dict, # Input config dictionary of the following form
40 # input_dict = {"PROJ_CONFIG": "ConfigRegression",
41 # "TARGET_PLATFORM": "MUSCA_A",
42 # "COMPILER": "ARMCLANG",
43 # "CMAKE_BUILD_TYPE": "Debug"}
44 report=None, # File to produce report
45 parallel_builds=3, # Number of builds to run in parallel
Minos Galanakisea421232019-06-20 17:11:28 +010046 build_threads=3, # Number of threads used per build
47 install=False, # Install libraries after build
48 img_sizes=False, # Use arm-none-eabi-size for size info
49 relative_paths=False): # Store relative paths in report
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010050 self._tbm_build_threads = build_threads
51 self._tbm_conc_builds = parallel_builds
52 self._tbm_install = install
Minos Galanakisea421232019-06-20 17:11:28 +010053 self._tbm_img_sizes = img_sizes
54 self._tbm_relative_paths = relative_paths
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010055
56 # Required by other methods, always set working directory first
57 self._tbm_work_dir = os.path.abspath(os.path.expanduser(work_dir))
58
59 self._tbm_tfm_dir = os.path.abspath(os.path.expanduser(tfm_dir))
60
Karl Zhangaff558a2020-05-15 14:28:23 +010061 print("bm param tfm_dir %s" % tfm_dir)
62 print("bm %s %s %s" % (work_dir, cfg_dict, self._tbm_work_dir))
Minos Galanakisea421232019-06-20 17:11:28 +010063 # Internal flag to tag simple (non combination formatted configs)
64 self.simple_config = False
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010065 self._tbm_report = report
66
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010067 self._tbm_cfg = self.load_config(cfg_dict, self._tbm_work_dir)
Minos Galanakisea421232019-06-20 17:11:28 +010068 self._tbm_build_cfg, \
69 self.tbm_common_cfg = self.parse_config(self._tbm_cfg)
Karl Zhangaff558a2020-05-15 14:28:23 +010070 self._tfb_code_base_updated = False
71 self._tfb_log_f = "CodeBasePrepare.log"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010072
73 super(TFM_Build_Manager, self).__init__(name="TFM_Build_Manager")
74
Xinyu Zhang433771e2022-04-01 16:49:17 +080075 def choose_toolchain(self, compiler):
76 toolchain = ""
77 if "GCC"in compiler:
78 toolchain = "toolchain_GNUARM.cmake"
79 elif "ARMCLANG" in compiler:
80 toolchain = "toolchain_ARMCLANG.cmake"
Xinyu Zhangff5d7712022-01-14 13:48:59 +080081
Xinyu Zhang433771e2022-04-01 16:49:17 +080082 return toolchain
83
84 def get_compiler_name(self, compiler):
85 compiler_name = ""
86 if "GCC"in compiler:
87 compiler_name = "arm-none-eabi-gcc"
88 elif "ARMCLANG" in compiler:
89 compiler_name = "armclang"
90
91 return compiler_name
Xinyu Zhangff5d7712022-01-14 13:48:59 +080092
Xinyu Zhangfc061dd2022-07-26 14:52:56 +080093 def map_extra_params(self, params):
94 extra_params = ""
95 param_list = params.split(", ")
96 for param in param_list:
97 extra_params += mapExtraParams[param]
98 return extra_params
99
Dean Bircha6ede7e2020-03-13 14:00:33 +0000100 def get_config(self):
101 return list(self._tbm_build_cfg.keys())
Dean Birch5cb5a882020-01-24 11:37:13 +0000102
Dean Bircha6ede7e2020-03-13 14:00:33 +0000103 def print_config_environment(self, config, silence_stderr=False):
Dean Birch5cb5a882020-01-24 11:37:13 +0000104 """
105 For a given build configuration from output of print_config
106 method, print environment variables to build.
107 """
108 if config not in self._tbm_build_cfg:
Dean Bircha6ede7e2020-03-13 14:00:33 +0000109 if not silence_stderr:
110 print("Error: no such config {}".format(config), file=sys.stderr)
Dean Birch5cb5a882020-01-24 11:37:13 +0000111 sys.exit(1)
112 config_details = self._tbm_build_cfg[config]
113 argument_list = [
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000114 "CONFIG_NAME={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800115 "TFM_PLATFORM={}",
Xinyu Zhang433771e2022-04-01 16:49:17 +0800116 "COMPILER={}",
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800117 "LIB_MODEL={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800118 "ISOLATION_LEVEL={}",
119 "TEST_REGRESSION={}",
120 "TEST_PSA_API={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000121 "CMAKE_BUILD_TYPE={}",
122 "BL2={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800123 "NS={}",
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800124 "PROFILE={}",
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800125 "PARTITION_PS={}",
Xinyu Zhangfd2e1152021-12-17 18:09:01 +0800126 "EXTRA_PARAMS={}"
Dean Birch5cb5a882020-01-24 11:37:13 +0000127 ]
128 print(
129 "\n".join(argument_list)
130 .format(
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000131 config,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800132 config_details.tfm_platform,
Xinyu Zhang433771e2022-04-01 16:49:17 +0800133 config_details.compiler,
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800134 config_details.lib_model,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800135 config_details.isolation_level,
136 config_details.test_regression,
137 config_details.test_psa_api,
Dean Birch5cb5a882020-01-24 11:37:13 +0000138 config_details.cmake_build_type,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800139 config_details.with_bl2,
140 config_details.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800141 "N.A" if not config_details.profile else config_details.profile,
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800142 config_details.partition_ps,
Xinyu Zhangfd2e1152021-12-17 18:09:01 +0800143 "N.A" if not config_details.extra_params else config_details.extra_params,
Dean Birch5cb5a882020-01-24 11:37:13 +0000144 )
145 .strip()
146 )
147
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000148 def print_build_commands(self, config, silence_stderr=False):
149 config_details = self._tbm_build_cfg[config]
150 codebase_dir = os.path.join(os.getcwd(),"trusted-firmware-m")
Xinyu Zhangb708f572020-09-15 11:43:46 +0800151 build_dir=os.path.join(os.getcwd(),"trusted-firmware-m/build")
Xinyu Zhang433771e2022-04-01 16:49:17 +0800152 build_config = self.get_build_config(config_details, config, \
153 silence=silence_stderr, \
154 build_dir=build_dir, \
155 codebase_dir=codebase_dir)
156 build_commands = [build_config["set_compiler_path"], \
157 build_config["config_template"]]
Xinyu Zhang694eb492020-11-04 18:29:08 +0800158 for command in build_config["build_cmds"]:
159 build_commands.append(command)
Xinyu Zhangb708f572020-09-15 11:43:46 +0800160 print(" ;\n".join(build_commands))
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000161
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100162 def pre_eval(self):
163 """ Tests that need to be run in set-up state """
164 return True
165
166 def pre_exec(self, eval_ret):
167 """ """
168
Minos Galanakisea421232019-06-20 17:11:28 +0100169 def override_tbm_cfg_params(self, config, override_keys, **params):
170 """ Using a dictionay as input, for each key defined in
171 override_keys it will replace the config[key] entries with
172 the key=value parameters provided """
173
174 for key in override_keys:
175 if isinstance(config[key], list):
176 config[key] = [n % params for n in config[key]]
177 elif isinstance(config[key], str):
178 config[key] = config[key] % params
179 else:
180 raise Exception("Config does not contain key %s "
181 "of type %s" % (key, config[key]))
182 return config
183
Karl Zhangaff558a2020-05-15 14:28:23 +0100184 def pre_build(self, build_cfg):
185 print("pre_build start %s \r\nself._tfb_cfg %s\r\n" %
186 (self, build_cfg))
187
188 try:
189 if self._tfb_code_base_updated:
190 print("Code base has been updated")
191 return True
192
193 self._tfb_code_base_updated = True
194
195 if "build_psa_api" in build_cfg:
196 # FF IPC build needs repo manifest update for TFM and PSA arch test
197 if "build_ff_ipc" in build_cfg:
198 print("Checkout to FF IPC code base")
199 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
200 _api_test_manifest = "git checkout . ; python3 tools/scripts/manifest_update.py"
201 if subprocess_log(_api_test_manifest,
202 self._tfb_log_f,
203 append=True,
204 prefix=_api_test_manifest):
205
206 raise Exception("Python Failed please check log: %s" %
207 self._tfb_log_f)
208
209 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py -m tools/tfm_psa_ff_test_manifest_list.yaml append"
210 os.chdir(build_cfg["codebase_root_dir"])
211 if subprocess_log(_api_test_manifest_tfm,
212 self._tfb_log_f,
213 append=True,
214 prefix=_api_test_manifest_tfm):
215
216 raise Exception("Python TFM Failed please check log: %s" %
217 self._tfb_log_f)
218 return True
219
220 print("Checkout to default code base")
221 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
222 _api_test_manifest = "git checkout ."
223 if subprocess_log(_api_test_manifest,
224 self._tfb_log_f,
225 append=True,
226 prefix=_api_test_manifest):
227
228 raise Exception("Python Failed please check log: %s" %
229 self._tfb_log_f)
230
231 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py"
232 os.chdir(build_cfg["codebase_root_dir"])
233 if subprocess_log(_api_test_manifest_tfm,
234 self._tfb_log_f,
235 append=True,
236 prefix=_api_test_manifest_tfm):
237
238 raise Exception("Python TFM Failed please check log: %s" %
239 self._tfb_log_f)
240 finally:
241 print("python pass after builder prepare")
242 os.chdir(build_cfg["codebase_root_dir"] + "/../")
243
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100244 def task_exec(self):
245 """ Create a build pool and execute them in parallel """
246
247 build_pool = []
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100248
Minos Galanakisea421232019-06-20 17:11:28 +0100249 # When a config is flagged as a single build config.
250 # Name is evaluated by config type
251 if self.simple_config:
252
253 build_cfg = deepcopy(self.tbm_common_cfg)
254
255 # Extract the common for all elements of config
256 for key in ["build_cmds", "required_artefacts"]:
257 try:
258 build_cfg[key] = build_cfg[key]["all"]
259 except KeyError:
260 build_cfg[key] = []
261 name = build_cfg["config_type"]
262
263 # Override _tbm_xxx paths in commands
264 # plafrom in not guaranteed without seeds so _tbm_target_platform
265 # is ignored
266 over_dict = {"_tbm_build_dir_": os.path.join(self._tbm_work_dir,
267 name),
268 "_tbm_code_dir_": build_cfg["codebase_root_dir"]}
269
270 build_cfg = self.override_tbm_cfg_params(build_cfg,
271 ["build_cmds",
272 "required_artefacts",
273 "artifact_capture_rex"],
274 **over_dict)
275
276 # Overrides path in expected artefacts
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100277 print("Loading config %s" % name)
Minos Galanakisea421232019-06-20 17:11:28 +0100278
279 build_pool.append(TFM_Builder(
280 name=name,
281 work_dir=self._tbm_work_dir,
282 cfg_dict=build_cfg,
283 build_threads=self._tbm_build_threads,
284 img_sizes=self._tbm_img_sizes,
285 relative_paths=self._tbm_relative_paths))
286 # When a seed pool is provided iterate through the entries
287 # and update platform spefific parameters
288 elif len(self._tbm_build_cfg):
Karl Zhangaff558a2020-05-15 14:28:23 +0100289 print("\r\n_tbm_build_cfg %s\r\n tbm_common_cfg %s\r\n" \
290 % (self._tbm_build_cfg, self.tbm_common_cfg))
Minos Galanakisea421232019-06-20 17:11:28 +0100291 for name, i in self._tbm_build_cfg.items():
292 # Do not modify the original config
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000293 build_cfg = self.get_build_config(i, name)
Karl Zhangaff558a2020-05-15 14:28:23 +0100294 self.pre_build(build_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100295 # Overrides path in expected artefacts
296 print("Loading config %s" % name)
297
298 build_pool.append(TFM_Builder(
299 name=name,
300 work_dir=self._tbm_work_dir,
301 cfg_dict=build_cfg,
302 build_threads=self._tbm_build_threads,
303 img_sizes=self._tbm_img_sizes,
304 relative_paths=self._tbm_relative_paths))
305 else:
306 print("Could not find any configuration. Check the rejection list")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100307
308 status_rep = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100309 build_rep = {}
310 completed_build_count = 0
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100311 print("Build: Running %d parallel build jobs" % self._tbm_conc_builds)
312 for build_pool_slice in list_chunks(build_pool, self._tbm_conc_builds):
313
314 # Start the builds
315 for build in build_pool_slice:
316 # Only produce output for the first build
317 if build_pool_slice.index(build) != 0:
318 build.mute()
319 print("Build: Starting %s" % build.get_name())
320 build.start()
321
322 # Wait for the builds to complete
323 for build in build_pool_slice:
324 # Wait for build to finish
325 build.join()
326 # Similarly print the logs of the other builds as they complete
327 if build_pool_slice.index(build) != 0:
328 build.log()
Minos Galanakisea421232019-06-20 17:11:28 +0100329 completed_build_count += 1
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100330 print("Build: Finished %s" % build.get_name())
Minos Galanakisea421232019-06-20 17:11:28 +0100331 print("Build Progress:")
332 show_progress(completed_build_count, len(build_pool))
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100333
334 # Store status in report
335 status_rep[build.get_name()] = build.get_status()
Minos Galanakisea421232019-06-20 17:11:28 +0100336 build_rep[build.get_name()] = build.report()
337
338 # Include the original input configuration in the report
339
340 metadata = {"input_build_cfg": self._tbm_cfg,
341 "build_dir": self._tbm_work_dir
342 if not self._tbm_relative_paths
343 else resolve_rel_path(self._tbm_work_dir),
344 "time": time()}
345
346 full_rep = {"report": build_rep,
347 "_metadata_": metadata}
348
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100349 # Store the report
350 self.stash("Build Status", status_rep)
351 self.stash("Build Report", full_rep)
352
353 if self._tbm_report:
354 print("Exported build report to file:", self._tbm_report)
355 save_json(self._tbm_report, full_rep)
356
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000357 def get_build_config(self, i, name, silence=False, build_dir=None, codebase_dir=None):
358 psa_build_dir = self._tbm_work_dir + "/" + name + "/BUILD"
359 if not build_dir:
360 build_dir = os.path.join(self._tbm_work_dir, name)
361 else:
362 psa_build_dir = os.path.join(build_dir, "../../psa-arch-tests/api-tests/build")
363 build_cfg = deepcopy(self.tbm_common_cfg)
364 if not codebase_dir:
365 codebase_dir = build_cfg["codebase_root_dir"]
366 else:
367 # Would prefer to do all with the new variable
368 # However, many things use this from build_cfg elsewhere
369 build_cfg["codebase_root_dir"] = codebase_dir
370 # Extract the common for all elements of config
371 for key in ["build_cmds", "required_artefacts"]:
372 try:
373 build_cfg[key] = deepcopy(self.tbm_common_cfg[key]
374 ["all"])
375 except KeyError as E:
376 build_cfg[key] = []
377 # Extract the platform specific elements of config
378 for key in ["build_cmds", "required_artefacts"]:
379 try:
Xinyu Zhang694eb492020-11-04 18:29:08 +0800380 if i.tfm_platform in self.tbm_common_cfg[key].keys() and i.with_ns:
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000381 build_cfg[key] += deepcopy(self.tbm_common_cfg[key]
Xinyu Zhangb708f572020-09-15 11:43:46 +0800382 [i.tfm_platform])
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000383 except Exception as E:
384 pass
Karl Zhang1eed6322020-07-01 15:38:10 +0800385
386 if os.cpu_count() >= 8:
387 #run in a serviver with scripts, parallel build will use CPU numbers
388 thread_no = " -j 2"
389 else:
390 #run in a docker, usually docker with CPUs less than 8
391 thread_no = " -j " + str(os.cpu_count())
Xinyu Zhangb708f572020-09-15 11:43:46 +0800392 build_cfg["build_cmds"][0] += thread_no
Xinyu Zhang433771e2022-04-01 16:49:17 +0800393
394 # Overwrite command lines to set compiler
395 build_cfg["set_compiler_path"] %= {"compiler": i.compiler}
396 build_cfg["set_compiler_path"] += " ;\n{} --version".format(self.get_compiler_name(i.compiler))
397
398 # Overwrite command lines of cmake
Xinyu Zhangb708f572020-09-15 11:43:46 +0800399 overwrite_params = {"codebase_root_dir": build_cfg["codebase_root_dir"],
400 "tfm_platform": i.tfm_platform,
Xinyu Zhang433771e2022-04-01 16:49:17 +0800401 "compiler": self.choose_toolchain(i.compiler),
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800402 "lib_model": i.lib_model,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800403 "isolation_level": i.isolation_level,
404 "test_regression": i.test_regression,
405 "test_psa_api": i.test_psa_api,
406 "cmake_build_type": i.cmake_build_type,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800407 "with_bl2": i.with_bl2,
408 "with_ns": i.with_ns,
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800409 "profile": "" if i.profile=="N.A" else i.profile,
Xinyu Zhang9bfe8a92021-10-28 16:27:12 +0800410 "partition_ps": i.partition_ps,
Xinyu Zhangfc061dd2022-07-26 14:52:56 +0800411 "extra_params": self.map_extra_params(i.extra_params)}
Xinyu Zhanga0086022020-11-10 18:11:12 +0800412 if i.test_psa_api == "IPC":
Xinyu Zhangcd1ed962020-11-11 16:00:52 +0800413 overwrite_params["test_psa_api"] += " -DINCLUDE_PANIC_TESTS=1"
Xinyu Zhang5f9fa962022-04-12 16:54:35 +0800414 if i.test_psa_api == "CRYPTO" and "musca" in i.tfm_platform:
415 overwrite_params["test_psa_api"] += " -DCC312_LEGACY_DRIVER_API_ENABLED=OFF"
Xinyu Zhang6ac0eb02022-03-31 13:19:07 +0800416 if i.tfm_platform == "arm/musca_b1/sse_200":
417 overwrite_params["test_psa_api"] += " -DITS_RAM_FS=ON -DPS_RAM_FS=ON"
Xinyu Zhangaa335912022-07-04 10:28:51 +0800418 if i.tfm_platform == "stm/stm32l562e_dk":
419 overwrite_params["test_psa_api"] += " -DITS_RAM_FS=ON -DPS_RAM_FS=ON"
Xinyu Zhangb708f572020-09-15 11:43:46 +0800420 build_cfg["config_template"] %= overwrite_params
Xinyu Zhang694eb492020-11-04 18:29:08 +0800421 if len(build_cfg["build_cmds"]) > 1:
422 overwrite_build_dir = {"_tbm_build_dir_": build_dir}
423 build_cfg["build_cmds"][1] %= overwrite_build_dir
Xinyu Zhang433771e2022-04-01 16:49:17 +0800424
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000425 return build_cfg
426
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100427 def post_eval(self):
428 """ If a single build failed fail the test """
429 try:
Minos Galanakisea421232019-06-20 17:11:28 +0100430 status_dict = self.unstash("Build Status")
431 if not status_dict:
432 raise Exception()
433 retcode_sum = sum(status_dict.values())
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100434 if retcode_sum != 0:
435 raise Exception()
436 return True
437 except Exception as e:
438 return False
439
440 def post_exec(self, eval_ret):
441 """ Generate a report and fail the script if build == unsuccessfull"""
442
443 self.print_summary()
444 if not eval_ret:
445 print("ERROR: ====> Build Failed! %s" % self.get_name())
446 self.set_status(1)
447 else:
448 print("SUCCESS: ====> Build Complete!")
449 self.set_status(0)
450
451 def get_report(self):
452 """ Expose the internal report to a new object for external classes """
453 return deepcopy(self.unstash("Build Report"))
454
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100455 def load_config(self, config, work_dir):
456 try:
457 # passing config_name param supersseeds fileparam
458 if isinstance(config, dict):
459 ret_cfg = deepcopy(config)
460 elif isinstance(config, str):
461 # If the string does not descrive a file try to look for it in
462 # work directory
463 if not os.path.isfile(config):
464 # remove path from file
465 config_2 = os.path.split(config)[-1]
466 # look in the current working directory
467 config_2 = os.path.join(work_dir, config_2)
468 if not os.path.isfile(config_2):
469 m = "Could not find cfg in %s or %s " % (config,
470 config_2)
471 raise Exception(m)
472 # If fille exists in working directory
473 else:
474 config = config_2
475 ret_cfg = load_json(config)
476
477 else:
478 raise Exception("Need to provide a valid config name or file."
479 "Please use --config/--config-file parameter.")
480 except Exception as e:
481 print("Error:%s \nCould not load a valid config" % e)
482 sys.exit(1)
483
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100484 return ret_cfg
485
486 def parse_config(self, cfg):
487 """ Parse a valid configuration file into a set of build dicts """
488
Minos Galanakisea421232019-06-20 17:11:28 +0100489 ret_cfg = {}
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100490
Minos Galanakisea421232019-06-20 17:11:28 +0100491 # Config entries which are not subject to changes during combinations
492 static_cfg = cfg["common_params"]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100493
Minos Galanakisea421232019-06-20 17:11:28 +0100494 # Converth the code path to absolute path
495 abs_code_dir = static_cfg["codebase_root_dir"]
496 abs_code_dir = os.path.abspath(os.path.expanduser(abs_code_dir))
497 static_cfg["codebase_root_dir"] = abs_code_dir
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100498
Minos Galanakisea421232019-06-20 17:11:28 +0100499 # seed_params is an optional field. Do not proccess if it is missing
500 if "seed_params" in cfg:
501 comb_cfg = cfg["seed_params"]
502 # Generate a list of all possible confugration combinations
503 ret_cfg = TFM_Build_Manager.generate_config_list(comb_cfg,
504 static_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100505
Xinyu Zhang2c63ce72021-07-23 14:01:59 +0800506 # valid is an optional field. Do not proccess if it is missing
507 if "valid" in cfg:
508 # Valid configurations(Need to build)
509 valid_cfg = cfg["valid"]
510 # Add valid configs to build list
511 ret_cfg.update(TFM_Build_Manager.generate_optional_list(
512 comb_cfg,
513 static_cfg,
514 valid_cfg))
515
Minos Galanakisea421232019-06-20 17:11:28 +0100516 # invalid is an optional field. Do not proccess if it is missing
517 if "invalid" in cfg:
518 # Invalid configurations(Do not build)
519 invalid_cfg = cfg["invalid"]
520 # Remove the rejected entries from the test list
Xinyu Zhang0581b082021-05-17 10:46:57 +0800521 rejection_cfg = TFM_Build_Manager.generate_optional_list(
Minos Galanakisea421232019-06-20 17:11:28 +0100522 comb_cfg,
523 static_cfg,
524 invalid_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100525
Minos Galanakisea421232019-06-20 17:11:28 +0100526 # Subtract the two configurations
527 ret_cfg = {k: v for k, v in ret_cfg.items()
528 if k not in rejection_cfg}
529 self.simple_config = False
530 else:
531 self.simple_config = True
532 return ret_cfg, static_cfg
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100533
Minos Galanakisea421232019-06-20 17:11:28 +0100534 # ----- Override bellow methods when subclassing for other projects ----- #
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100535
Minos Galanakisea421232019-06-20 17:11:28 +0100536 def print_summary(self):
537 """ Print an comprehensive list of the build jobs with their status """
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100538
Minos Galanakisea421232019-06-20 17:11:28 +0100539 try:
540 full_rep = self.unstash("Build Report")["report"]
541 fl = ([k for k, v in full_rep.items() if v['status'] == 'Failed'])
542 ps = ([k for k, v in full_rep.items() if v['status'] == 'Success'])
543 except Exception as E:
Karl Zhangaff558a2020-05-15 14:28:23 +0100544 print("No report generated", E)
Minos Galanakisea421232019-06-20 17:11:28 +0100545 return
546 if fl:
547 print_test(t_list=fl, status="failed", tname="Builds")
548 if ps:
549 print_test(t_list=ps, status="passed", tname="Builds")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100550
Minos Galanakisea421232019-06-20 17:11:28 +0100551 @staticmethod
552 def generate_config_list(seed_config, static_config):
553 """ Generate all possible configuration combinations from a group of
554 lists of compiler options"""
555 config_list = []
556
557 if static_config["config_type"] == "tf-m":
558 cfg_name = "TFM_Build_CFG"
559 # Ensure the fieds are sorted in the desired order
560 # seed_config can be a subset of sort order for configurations with
561 # optional parameters.
562 tags = [n for n in static_config["sort_order"]
563 if n in seed_config.keys()]
Karl Zhangaff558a2020-05-15 14:28:23 +0100564 print("!!!!!!!!!!!gen list %s\r\n" % tags)
Minos Galanakisea421232019-06-20 17:11:28 +0100565
566 data = []
567 for key in tags:
568 data.append(seed_config[key])
569 config_list = gen_cfg_combinations(cfg_name,
570 " ".join(tags),
571 *data)
572 else:
573 print("Not information for project type: %s."
574 " Please check config" % static_config["config_type"])
575
576 ret_cfg = {}
577 # Notify the user for the rejected configuations
578 for i in config_list:
Xinyu Zhang1078e812020-10-15 11:52:36 +0800579 # Convert named tuples to string in a brief format
580 config_param = []
581 config_param.append(mapPlatform[list(i)[0]])
Xinyu Zhang433771e2022-04-01 16:49:17 +0800582 config_param.append(list(i)[1].split("_")[0])
Xinyu Zhang73ed2992021-09-15 11:38:23 +0800583 if list(i)[2]: # LIB_MODEL
584 config_param.append("LIB")
585 else:
586 config_param.append("IPC")
Xinyu Zhang1078e812020-10-15 11:52:36 +0800587 config_param.append(list(i)[3]) # ISOLATION_LEVEL
588 if list(i)[4]: # TEST_REGRESSION
589 config_param.append("REG")
590 if list(i)[5] != "OFF": #TEST_PSA_API
591 config_param.append(mapTestPsaApi[list(i)[5]])
592 config_param.append(list(i)[6]) # BUILD_TYPE
Xinyu Zhang589fd052022-04-19 17:54:16 +0800593 if list(i)[7]: # BL2
Xinyu Zhang1078e812020-10-15 11:52:36 +0800594 config_param.append("BL2")
Xinyu Zhang589fd052022-04-19 17:54:16 +0800595 if list(i)[8]: # NS
Xinyu Zhang1078e812020-10-15 11:52:36 +0800596 config_param.append("NS")
Xinyu Zhang589fd052022-04-19 17:54:16 +0800597 if list(i)[9]: # PROFILE
598 config_param.append(mapProfile[list(i)[9]])
599 if list(i)[10] == "OFF": #PARTITION_PS
Xinyu Zhang9fd74242020-10-22 11:30:50 +0800600 config_param.append("PSOFF")
Xinyu Zhang589fd052022-04-19 17:54:16 +0800601 if list(i)[11]: # EXTRA_PARAMS
Xinyu Zhangfc061dd2022-07-26 14:52:56 +0800602 config_param.append(list(i)[11].replace(", ", "_"))
Xinyu Zhang1078e812020-10-15 11:52:36 +0800603 i_str = "_".join(config_param)
Karl Zhangaff558a2020-05-15 14:28:23 +0100604 ret_cfg[i_str] = i
Minos Galanakisea421232019-06-20 17:11:28 +0100605 return ret_cfg
606
607 @staticmethod
Xinyu Zhang0581b082021-05-17 10:46:57 +0800608 def generate_optional_list(seed_config,
609 static_config,
610 optional_list):
611 optional_cfg = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100612
613 if static_config["config_type"] == "tf-m":
614
Xinyu Zhang0581b082021-05-17 10:46:57 +0800615 # If optional list is empty do nothing
616 if not optional_list:
617 return optional_cfg
Minos Galanakisea421232019-06-20 17:11:28 +0100618
619 tags = [n for n in static_config["sort_order"]
620 if n in seed_config.keys()]
621 sorted_default_lst = [seed_config[k] for k in tags]
622
Xinyu Zhang0581b082021-05-17 10:46:57 +0800623 # If tags are not alligned with optional list entries quit
624 if len(tags) != len(optional_list[0]):
625 print(len(tags), len(optional_list[0]))
Minos Galanakisea421232019-06-20 17:11:28 +0100626 print("Error, tags should be assigned to each "
Xinyu Zhang0581b082021-05-17 10:46:57 +0800627 "of the optional inputs")
Minos Galanakisea421232019-06-20 17:11:28 +0100628 return []
629
630 # Replace wildcard ( "*") entries with every
631 # inluded in cfg variant
Xinyu Zhang0581b082021-05-17 10:46:57 +0800632 for k in optional_list:
Minos Galanakisea421232019-06-20 17:11:28 +0100633 # Pad the omitted values with wildcard char *
634 res_list = list(k) + ["*"] * (5 - len(k))
Xinyu Zhang0581b082021-05-17 10:46:57 +0800635 print("Working on optional input: %s" % (res_list))
Minos Galanakisea421232019-06-20 17:11:28 +0100636
637 for n in range(len(res_list)):
638
639 res_list[n] = [res_list[n]] if res_list[n] != "*" \
640 else sorted_default_lst[n]
641
642 # Generate a configuration and a name for the completed array
Xinyu Zhang0581b082021-05-17 10:46:57 +0800643 op_cfg = TFM_Build_Manager.generate_config_list(
Minos Galanakisea421232019-06-20 17:11:28 +0100644 dict(zip(tags, res_list)),
645 static_config)
646
647 # Append the configuration to the existing ones
Xinyu Zhang0581b082021-05-17 10:46:57 +0800648 optional_cfg = dict(optional_cfg, **op_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100649
Xinyu Zhang0581b082021-05-17 10:46:57 +0800650 # Notify the user for the optional configuations
651 for i in optional_cfg.keys():
652 print("Generating optional config %s" % i)
Minos Galanakisea421232019-06-20 17:11:28 +0100653 else:
654 print("Not information for project type: %s."
655 " Please check config" % static_config["config_type"])
Xinyu Zhang0581b082021-05-17 10:46:57 +0800656 return optional_cfg