blob: a05edb16a287e410b193ab22d3340da3e3f38dd8 [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
8
9__copyright__ = """
10/*
11 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
12 *
13 * SPDX-License-Identifier: BSD-3-Clause
14 *
15 */
16 """
17__author__ = "Minos Galanakis"
18__email__ = "minos.galanakis@linaro.org"
19__project__ = "Trusted Firmware-M Open CI"
20__status__ = "stable"
Minos Galanakisea421232019-06-20 17:11:28 +010021__version__ = "1.1"
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
28from .utils import gen_cfg_combinations, list_chunks, load_json,\
Minos Galanakisea421232019-06-20 17:11:28 +010029 save_json, print_test, show_progress, \
30 resolve_rel_path
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010031from .structured_task import structuredTask
32from .tfm_builder import TFM_Builder
33
34
35class TFM_Build_Manager(structuredTask):
36 """ Class that will load a configuration out of a json file, schedule
37 the builds, and produce a report """
38
39 def __init__(self,
40 tfm_dir, # TFM root directory
41 work_dir, # Current working directory(ie logs)
42 cfg_dict, # Input config dictionary of the following form
43 # input_dict = {"PROJ_CONFIG": "ConfigRegression",
44 # "TARGET_PLATFORM": "MUSCA_A",
45 # "COMPILER": "ARMCLANG",
46 # "CMAKE_BUILD_TYPE": "Debug"}
47 report=None, # File to produce report
48 parallel_builds=3, # Number of builds to run in parallel
Minos Galanakisea421232019-06-20 17:11:28 +010049 build_threads=3, # Number of threads used per build
50 install=False, # Install libraries after build
51 img_sizes=False, # Use arm-none-eabi-size for size info
52 relative_paths=False): # Store relative paths in report
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010053 self._tbm_build_threads = build_threads
54 self._tbm_conc_builds = parallel_builds
55 self._tbm_install = install
Minos Galanakisea421232019-06-20 17:11:28 +010056 self._tbm_img_sizes = img_sizes
57 self._tbm_relative_paths = relative_paths
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010058
59 # Required by other methods, always set working directory first
60 self._tbm_work_dir = os.path.abspath(os.path.expanduser(work_dir))
61
62 self._tbm_tfm_dir = os.path.abspath(os.path.expanduser(tfm_dir))
63
Karl Zhangaff558a2020-05-15 14:28:23 +010064 print("bm param tfm_dir %s" % tfm_dir)
65 print("bm %s %s %s" % (work_dir, cfg_dict, self._tbm_work_dir))
Minos Galanakisea421232019-06-20 17:11:28 +010066 # Internal flag to tag simple (non combination formatted configs)
67 self.simple_config = False
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010068 self._tbm_report = report
69
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010070 self._tbm_cfg = self.load_config(cfg_dict, self._tbm_work_dir)
Minos Galanakisea421232019-06-20 17:11:28 +010071 self._tbm_build_cfg, \
72 self.tbm_common_cfg = self.parse_config(self._tbm_cfg)
Karl Zhangaff558a2020-05-15 14:28:23 +010073 self._tfb_code_base_updated = False
74 self._tfb_log_f = "CodeBasePrepare.log"
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +010075
76 super(TFM_Build_Manager, self).__init__(name="TFM_Build_Manager")
77
Dean Bircha6ede7e2020-03-13 14:00:33 +000078 def get_config(self):
79 return list(self._tbm_build_cfg.keys())
Dean Birch5cb5a882020-01-24 11:37:13 +000080
Dean Bircha6ede7e2020-03-13 14:00:33 +000081 def print_config_environment(self, config, silence_stderr=False):
Dean Birch5cb5a882020-01-24 11:37:13 +000082 """
83 For a given build configuration from output of print_config
84 method, print environment variables to build.
85 """
86 if config not in self._tbm_build_cfg:
Dean Bircha6ede7e2020-03-13 14:00:33 +000087 if not silence_stderr:
88 print("Error: no such config {}".format(config), file=sys.stderr)
Dean Birch5cb5a882020-01-24 11:37:13 +000089 sys.exit(1)
90 config_details = self._tbm_build_cfg[config]
91 argument_list = [
Dean Birchd0f9f8c2020-03-26 11:10:33 +000092 "CONFIG_NAME={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +080093 "TFM_PLATFORM={}",
94 "TOOLCHAIN_FILE={}",
95 "PSA_API={}",
96 "ISOLATION_LEVEL={}",
97 "TEST_REGRESSION={}",
98 "TEST_PSA_API={}",
Dean Birch5cb5a882020-01-24 11:37:13 +000099 "CMAKE_BUILD_TYPE={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800100 "OTP={}",
Dean Birch5cb5a882020-01-24 11:37:13 +0000101 "BL2={}",
Xinyu Zhangb708f572020-09-15 11:43:46 +0800102 "NS={}",
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800103 "PROFILE={}"
Dean Birch5cb5a882020-01-24 11:37:13 +0000104 ]
105 print(
106 "\n".join(argument_list)
107 .format(
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000108 config,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800109 config_details.tfm_platform,
110 config_details.toolchain_file,
111 config_details.psa_api,
112 config_details.isolation_level,
113 config_details.test_regression,
114 config_details.test_psa_api,
Dean Birch5cb5a882020-01-24 11:37:13 +0000115 config_details.cmake_build_type,
Xinyu Zhangb708f572020-09-15 11:43:46 +0800116 config_details.with_otp,
117 config_details.with_bl2,
118 config_details.with_ns,
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800119 "N.A" if not config_details.profile else config_details.profile
Dean Birch5cb5a882020-01-24 11:37:13 +0000120 )
121 .strip()
122 )
123
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000124 def print_build_commands(self, config, silence_stderr=False):
125 config_details = self._tbm_build_cfg[config]
126 codebase_dir = os.path.join(os.getcwd(),"trusted-firmware-m")
Xinyu Zhangb708f572020-09-15 11:43:46 +0800127 build_dir=os.path.join(os.getcwd(),"trusted-firmware-m/build")
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000128 build_config = self.get_build_config(config_details, config, silence=silence_stderr, build_dir=build_dir, codebase_dir=codebase_dir)
Xinyu Zhangb708f572020-09-15 11:43:46 +0800129 build_commands = [build_config["config_template"], build_config["build_cmds"][0]]
130 print(" ;\n".join(build_commands))
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000131
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100132 def pre_eval(self):
133 """ Tests that need to be run in set-up state """
134 return True
135
136 def pre_exec(self, eval_ret):
137 """ """
138
Minos Galanakisea421232019-06-20 17:11:28 +0100139 def override_tbm_cfg_params(self, config, override_keys, **params):
140 """ Using a dictionay as input, for each key defined in
141 override_keys it will replace the config[key] entries with
142 the key=value parameters provided """
143
144 for key in override_keys:
145 if isinstance(config[key], list):
146 config[key] = [n % params for n in config[key]]
147 elif isinstance(config[key], str):
148 config[key] = config[key] % params
149 else:
150 raise Exception("Config does not contain key %s "
151 "of type %s" % (key, config[key]))
152 return config
153
Karl Zhangaff558a2020-05-15 14:28:23 +0100154 def pre_build(self, build_cfg):
155 print("pre_build start %s \r\nself._tfb_cfg %s\r\n" %
156 (self, build_cfg))
157
158 try:
159 if self._tfb_code_base_updated:
160 print("Code base has been updated")
161 return True
162
163 self._tfb_code_base_updated = True
164
165 if "build_psa_api" in build_cfg:
166 # FF IPC build needs repo manifest update for TFM and PSA arch test
167 if "build_ff_ipc" in build_cfg:
168 print("Checkout to FF IPC code base")
169 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
170 _api_test_manifest = "git checkout . ; python3 tools/scripts/manifest_update.py"
171 if subprocess_log(_api_test_manifest,
172 self._tfb_log_f,
173 append=True,
174 prefix=_api_test_manifest):
175
176 raise Exception("Python Failed please check log: %s" %
177 self._tfb_log_f)
178
179 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py -m tools/tfm_psa_ff_test_manifest_list.yaml append"
180 os.chdir(build_cfg["codebase_root_dir"])
181 if subprocess_log(_api_test_manifest_tfm,
182 self._tfb_log_f,
183 append=True,
184 prefix=_api_test_manifest_tfm):
185
186 raise Exception("Python TFM Failed please check log: %s" %
187 self._tfb_log_f)
188 return True
189
190 print("Checkout to default code base")
191 os.chdir(build_cfg["codebase_root_dir"] + "/../psa-arch-tests/api-tests")
192 _api_test_manifest = "git checkout ."
193 if subprocess_log(_api_test_manifest,
194 self._tfb_log_f,
195 append=True,
196 prefix=_api_test_manifest):
197
198 raise Exception("Python Failed please check log: %s" %
199 self._tfb_log_f)
200
201 _api_test_manifest_tfm = "python3 tools/tfm_parse_manifest_list.py"
202 os.chdir(build_cfg["codebase_root_dir"])
203 if subprocess_log(_api_test_manifest_tfm,
204 self._tfb_log_f,
205 append=True,
206 prefix=_api_test_manifest_tfm):
207
208 raise Exception("Python TFM Failed please check log: %s" %
209 self._tfb_log_f)
210 finally:
211 print("python pass after builder prepare")
212 os.chdir(build_cfg["codebase_root_dir"] + "/../")
213
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100214 def task_exec(self):
215 """ Create a build pool and execute them in parallel """
216
217 build_pool = []
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100218
Minos Galanakisea421232019-06-20 17:11:28 +0100219 # When a config is flagged as a single build config.
220 # Name is evaluated by config type
221 if self.simple_config:
222
223 build_cfg = deepcopy(self.tbm_common_cfg)
224
225 # Extract the common for all elements of config
226 for key in ["build_cmds", "required_artefacts"]:
227 try:
228 build_cfg[key] = build_cfg[key]["all"]
229 except KeyError:
230 build_cfg[key] = []
231 name = build_cfg["config_type"]
232
233 # Override _tbm_xxx paths in commands
234 # plafrom in not guaranteed without seeds so _tbm_target_platform
235 # is ignored
236 over_dict = {"_tbm_build_dir_": os.path.join(self._tbm_work_dir,
237 name),
238 "_tbm_code_dir_": build_cfg["codebase_root_dir"]}
239
240 build_cfg = self.override_tbm_cfg_params(build_cfg,
241 ["build_cmds",
242 "required_artefacts",
243 "artifact_capture_rex"],
244 **over_dict)
245
246 # Overrides path in expected artefacts
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100247 print("Loading config %s" % name)
Minos Galanakisea421232019-06-20 17:11:28 +0100248
249 build_pool.append(TFM_Builder(
250 name=name,
251 work_dir=self._tbm_work_dir,
252 cfg_dict=build_cfg,
253 build_threads=self._tbm_build_threads,
254 img_sizes=self._tbm_img_sizes,
255 relative_paths=self._tbm_relative_paths))
256 # When a seed pool is provided iterate through the entries
257 # and update platform spefific parameters
258 elif len(self._tbm_build_cfg):
Karl Zhangaff558a2020-05-15 14:28:23 +0100259 print("\r\n_tbm_build_cfg %s\r\n tbm_common_cfg %s\r\n" \
260 % (self._tbm_build_cfg, self.tbm_common_cfg))
Minos Galanakisea421232019-06-20 17:11:28 +0100261 for name, i in self._tbm_build_cfg.items():
262 # Do not modify the original config
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000263 build_cfg = self.get_build_config(i, name)
Karl Zhangaff558a2020-05-15 14:28:23 +0100264 self.pre_build(build_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100265 # Overrides path in expected artefacts
266 print("Loading config %s" % name)
267
268 build_pool.append(TFM_Builder(
269 name=name,
270 work_dir=self._tbm_work_dir,
271 cfg_dict=build_cfg,
272 build_threads=self._tbm_build_threads,
273 img_sizes=self._tbm_img_sizes,
274 relative_paths=self._tbm_relative_paths))
275 else:
276 print("Could not find any configuration. Check the rejection list")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100277
278 status_rep = {}
Minos Galanakisea421232019-06-20 17:11:28 +0100279 build_rep = {}
280 completed_build_count = 0
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100281 print("Build: Running %d parallel build jobs" % self._tbm_conc_builds)
282 for build_pool_slice in list_chunks(build_pool, self._tbm_conc_builds):
283
284 # Start the builds
285 for build in build_pool_slice:
286 # Only produce output for the first build
287 if build_pool_slice.index(build) != 0:
288 build.mute()
289 print("Build: Starting %s" % build.get_name())
290 build.start()
291
292 # Wait for the builds to complete
293 for build in build_pool_slice:
294 # Wait for build to finish
295 build.join()
296 # Similarly print the logs of the other builds as they complete
297 if build_pool_slice.index(build) != 0:
298 build.log()
Minos Galanakisea421232019-06-20 17:11:28 +0100299 completed_build_count += 1
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100300 print("Build: Finished %s" % build.get_name())
Minos Galanakisea421232019-06-20 17:11:28 +0100301 print("Build Progress:")
302 show_progress(completed_build_count, len(build_pool))
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100303
304 # Store status in report
305 status_rep[build.get_name()] = build.get_status()
Minos Galanakisea421232019-06-20 17:11:28 +0100306 build_rep[build.get_name()] = build.report()
307
308 # Include the original input configuration in the report
309
310 metadata = {"input_build_cfg": self._tbm_cfg,
311 "build_dir": self._tbm_work_dir
312 if not self._tbm_relative_paths
313 else resolve_rel_path(self._tbm_work_dir),
314 "time": time()}
315
316 full_rep = {"report": build_rep,
317 "_metadata_": metadata}
318
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100319 # Store the report
320 self.stash("Build Status", status_rep)
321 self.stash("Build Report", full_rep)
322
323 if self._tbm_report:
324 print("Exported build report to file:", self._tbm_report)
325 save_json(self._tbm_report, full_rep)
326
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000327 def get_build_config(self, i, name, silence=False, build_dir=None, codebase_dir=None):
328 psa_build_dir = self._tbm_work_dir + "/" + name + "/BUILD"
329 if not build_dir:
330 build_dir = os.path.join(self._tbm_work_dir, name)
331 else:
332 psa_build_dir = os.path.join(build_dir, "../../psa-arch-tests/api-tests/build")
333 build_cfg = deepcopy(self.tbm_common_cfg)
334 if not codebase_dir:
335 codebase_dir = build_cfg["codebase_root_dir"]
336 else:
337 # Would prefer to do all with the new variable
338 # However, many things use this from build_cfg elsewhere
339 build_cfg["codebase_root_dir"] = codebase_dir
340 # Extract the common for all elements of config
341 for key in ["build_cmds", "required_artefacts"]:
342 try:
343 build_cfg[key] = deepcopy(self.tbm_common_cfg[key]
344 ["all"])
345 except KeyError as E:
346 build_cfg[key] = []
347 # Extract the platform specific elements of config
348 for key in ["build_cmds", "required_artefacts"]:
349 try:
Xinyu Zhangb708f572020-09-15 11:43:46 +0800350 if i.tfm_platform in self.tbm_common_cfg[key].keys():
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000351 build_cfg[key] += deepcopy(self.tbm_common_cfg[key]
Xinyu Zhangb708f572020-09-15 11:43:46 +0800352 [i.tfm_platform])
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000353 except Exception as E:
354 pass
Karl Zhang1eed6322020-07-01 15:38:10 +0800355
356 if os.cpu_count() >= 8:
357 #run in a serviver with scripts, parallel build will use CPU numbers
358 thread_no = " -j 2"
359 else:
360 #run in a docker, usually docker with CPUs less than 8
361 thread_no = " -j " + str(os.cpu_count())
Xinyu Zhangb708f572020-09-15 11:43:46 +0800362 build_cfg["build_cmds"][0] += thread_no
363 overwrite_params = {"codebase_root_dir": build_cfg["codebase_root_dir"],
364 "tfm_platform": i.tfm_platform,
365 "toolchain_file": i.toolchain_file,
366 "psa_api": i.psa_api,
367 "isolation_level": i.isolation_level,
368 "test_regression": i.test_regression,
369 "test_psa_api": i.test_psa_api,
370 "cmake_build_type": i.cmake_build_type,
371 "with_otp": i.with_otp,
372 "with_bl2": i.with_bl2,
373 "with_ns": i.with_ns,
Xinyu Zhang29adbbb2020-09-29 11:29:18 +0800374 "profile": "" if i.profile=="N.A" else i.profile}
Xinyu Zhangb708f572020-09-15 11:43:46 +0800375 build_cfg["config_template"] %= overwrite_params
Dean Birchd0f9f8c2020-03-26 11:10:33 +0000376 return build_cfg
377
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100378 def post_eval(self):
379 """ If a single build failed fail the test """
380 try:
Minos Galanakisea421232019-06-20 17:11:28 +0100381 status_dict = self.unstash("Build Status")
382 if not status_dict:
383 raise Exception()
384 retcode_sum = sum(status_dict.values())
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100385 if retcode_sum != 0:
386 raise Exception()
387 return True
388 except Exception as e:
389 return False
390
391 def post_exec(self, eval_ret):
392 """ Generate a report and fail the script if build == unsuccessfull"""
393
394 self.print_summary()
395 if not eval_ret:
396 print("ERROR: ====> Build Failed! %s" % self.get_name())
397 self.set_status(1)
398 else:
399 print("SUCCESS: ====> Build Complete!")
400 self.set_status(0)
401
402 def get_report(self):
403 """ Expose the internal report to a new object for external classes """
404 return deepcopy(self.unstash("Build Report"))
405
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100406 def load_config(self, config, work_dir):
407 try:
408 # passing config_name param supersseeds fileparam
409 if isinstance(config, dict):
410 ret_cfg = deepcopy(config)
411 elif isinstance(config, str):
412 # If the string does not descrive a file try to look for it in
413 # work directory
414 if not os.path.isfile(config):
415 # remove path from file
416 config_2 = os.path.split(config)[-1]
417 # look in the current working directory
418 config_2 = os.path.join(work_dir, config_2)
419 if not os.path.isfile(config_2):
420 m = "Could not find cfg in %s or %s " % (config,
421 config_2)
422 raise Exception(m)
423 # If fille exists in working directory
424 else:
425 config = config_2
426 ret_cfg = load_json(config)
427
428 else:
429 raise Exception("Need to provide a valid config name or file."
430 "Please use --config/--config-file parameter.")
431 except Exception as e:
432 print("Error:%s \nCould not load a valid config" % e)
433 sys.exit(1)
434
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100435 return ret_cfg
436
437 def parse_config(self, cfg):
438 """ Parse a valid configuration file into a set of build dicts """
439
Minos Galanakisea421232019-06-20 17:11:28 +0100440 ret_cfg = {}
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100441
Minos Galanakisea421232019-06-20 17:11:28 +0100442 # Config entries which are not subject to changes during combinations
443 static_cfg = cfg["common_params"]
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100444
Minos Galanakisea421232019-06-20 17:11:28 +0100445 # Converth the code path to absolute path
446 abs_code_dir = static_cfg["codebase_root_dir"]
447 abs_code_dir = os.path.abspath(os.path.expanduser(abs_code_dir))
448 static_cfg["codebase_root_dir"] = abs_code_dir
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100449
Minos Galanakisea421232019-06-20 17:11:28 +0100450 # seed_params is an optional field. Do not proccess if it is missing
451 if "seed_params" in cfg:
452 comb_cfg = cfg["seed_params"]
453 # Generate a list of all possible confugration combinations
454 ret_cfg = TFM_Build_Manager.generate_config_list(comb_cfg,
455 static_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100456
Minos Galanakisea421232019-06-20 17:11:28 +0100457 # invalid is an optional field. Do not proccess if it is missing
458 if "invalid" in cfg:
459 # Invalid configurations(Do not build)
460 invalid_cfg = cfg["invalid"]
461 # Remove the rejected entries from the test list
462 rejection_cfg = TFM_Build_Manager.generate_rejection_list(
463 comb_cfg,
464 static_cfg,
465 invalid_cfg)
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100466
Minos Galanakisea421232019-06-20 17:11:28 +0100467 # Subtract the two configurations
468 ret_cfg = {k: v for k, v in ret_cfg.items()
469 if k not in rejection_cfg}
470 self.simple_config = False
471 else:
472 self.simple_config = True
473 return ret_cfg, static_cfg
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100474
Minos Galanakisea421232019-06-20 17:11:28 +0100475 # ----- Override bellow methods when subclassing for other projects ----- #
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100476
Minos Galanakisea421232019-06-20 17:11:28 +0100477 def print_summary(self):
478 """ Print an comprehensive list of the build jobs with their status """
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100479
Minos Galanakisea421232019-06-20 17:11:28 +0100480 try:
481 full_rep = self.unstash("Build Report")["report"]
482 fl = ([k for k, v in full_rep.items() if v['status'] == 'Failed'])
483 ps = ([k for k, v in full_rep.items() if v['status'] == 'Success'])
484 except Exception as E:
Karl Zhangaff558a2020-05-15 14:28:23 +0100485 print("No report generated", E)
Minos Galanakisea421232019-06-20 17:11:28 +0100486 return
487 if fl:
488 print_test(t_list=fl, status="failed", tname="Builds")
489 if ps:
490 print_test(t_list=ps, status="passed", tname="Builds")
Minos Galanakisf4ca6ac2017-12-11 02:39:21 +0100491
Minos Galanakisea421232019-06-20 17:11:28 +0100492 @staticmethod
493 def generate_config_list(seed_config, static_config):
494 """ Generate all possible configuration combinations from a group of
495 lists of compiler options"""
496 config_list = []
497
498 if static_config["config_type"] == "tf-m":
499 cfg_name = "TFM_Build_CFG"
500 # Ensure the fieds are sorted in the desired order
501 # seed_config can be a subset of sort order for configurations with
502 # optional parameters.
503 tags = [n for n in static_config["sort_order"]
504 if n in seed_config.keys()]
Karl Zhangaff558a2020-05-15 14:28:23 +0100505 print("!!!!!!!!!!!gen list %s\r\n" % tags)
Minos Galanakisea421232019-06-20 17:11:28 +0100506
507 data = []
508 for key in tags:
509 data.append(seed_config[key])
510 config_list = gen_cfg_combinations(cfg_name,
511 " ".join(tags),
512 *data)
513 else:
514 print("Not information for project type: %s."
515 " Please check config" % static_config["config_type"])
516
517 ret_cfg = {}
518 # Notify the user for the rejected configuations
519 for i in config_list:
520 # Convert named tuples to string with boolean support
521 i_str = "_".join(map(lambda x: repr(x)
522 if isinstance(x, bool) else x, list(i)))
Karl Zhangaff558a2020-05-15 14:28:23 +0100523 ret_cfg[i_str] = i
Minos Galanakisea421232019-06-20 17:11:28 +0100524 return ret_cfg
525
526 @staticmethod
527 def generate_rejection_list(seed_config,
528 static_config,
529 rejection_list):
530 rejection_cfg = {}
531
532 if static_config["config_type"] == "tf-m":
533
534 # If rejection list is empty do nothing
535 if not rejection_list:
536 return rejection_cfg
537
538 tags = [n for n in static_config["sort_order"]
539 if n in seed_config.keys()]
540 sorted_default_lst = [seed_config[k] for k in tags]
541
542 # If tags are not alligned with rejection list entries quit
543 if len(tags) != len(rejection_list[0]):
544 print(len(tags), len(rejection_list[0]))
545 print("Error, tags should be assigned to each "
546 "of the rejection inputs")
547 return []
548
549 # Replace wildcard ( "*") entries with every
550 # inluded in cfg variant
551 for k in rejection_list:
552 # Pad the omitted values with wildcard char *
553 res_list = list(k) + ["*"] * (5 - len(k))
554 print("Working on rejection input: %s" % (res_list))
555
556 for n in range(len(res_list)):
557
558 res_list[n] = [res_list[n]] if res_list[n] != "*" \
559 else sorted_default_lst[n]
560
561 # Generate a configuration and a name for the completed array
562 rj_cfg = TFM_Build_Manager.generate_config_list(
563 dict(zip(tags, res_list)),
564 static_config)
565
566 # Append the configuration to the existing ones
Dean Birchf6aa3da2020-01-24 12:29:38 +0000567 rejection_cfg = dict(rejection_cfg, **rj_cfg)
Minos Galanakisea421232019-06-20 17:11:28 +0100568
569 # Notfy the user for the rejected configuations
570 for i in rejection_cfg.keys():
571 print("Rejecting config %s" % i)
572 else:
573 print("Not information for project type: %s."
574 " Please check config" % static_config["config_type"])
575 return rejection_cfg