Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | """ build_helper.py: |
| 4 | |
| 5 | Build helper instantiates a build manager with user provided arguments, |
| 6 | or default ones. |
| 7 | """ |
| 8 | |
| 9 | from __future__ import print_function |
| 10 | |
| 11 | __copyright__ = """ |
| 12 | /* |
| 13 | * Copyright (c) 2018-2019, Arm Limited. All rights reserved. |
| 14 | * |
| 15 | * SPDX-License-Identifier: BSD-3-Clause |
| 16 | * |
| 17 | */ |
| 18 | """ |
| 19 | __author__ = "Minos Galanakis" |
| 20 | __email__ = "minos.galanakis@linaro.org" |
| 21 | __project__ = "Trusted Firmware-M Open CI" |
| 22 | __status__ = "stable" |
| 23 | __version__ = "1.0" |
| 24 | |
| 25 | import os |
| 26 | import sys |
| 27 | import time |
| 28 | import argparse |
| 29 | import datetime |
| 30 | from build_helper_configs import config_AN521 |
| 31 | |
| 32 | try: |
| 33 | from tfm_ci_pylib.utils import get_cmd_args, load_json |
| 34 | from tfm_ci_pylib.tfm_build_manager import TFM_Build_Manager |
| 35 | except ImportError: |
| 36 | dir_path = os.path.dirname(os.path.realpath(__file__)) |
| 37 | sys.path.append(os.path.join(dir_path, "../")) |
| 38 | from tfm_ci_pylib.utils import get_cmd_args, load_json |
| 39 | from tfm_ci_pylib.tfm_build_manager import TFM_Build_Manager |
| 40 | |
| 41 | |
| 42 | def build(tfm_dir, build_dir, buid_report_f, build_config): |
| 43 | """ Instantiate a build manager class and build all configurations """ |
| 44 | |
| 45 | start_time = time.time() |
| 46 | |
| 47 | bm = TFM_Build_Manager(tfm_dir=tfm_dir, |
| 48 | work_dir=build_dir, |
| 49 | cfg_dict=build_config, |
| 50 | report=buid_report_f, |
| 51 | install=True) |
| 52 | bm.start() |
| 53 | bm.join() |
| 54 | build_report = bm.get_report() |
| 55 | elapsed = time.time() - start_time |
| 56 | elapsed = str(datetime.timedelta(seconds=elapsed)) |
| 57 | print("=============== Time Elapsed: %s ===================" % elapsed) |
| 58 | return bm.get_status(), build_report |
| 59 | |
| 60 | |
| 61 | def main(user_args): |
| 62 | """ Main logic """ |
| 63 | |
| 64 | if user_args.config_f: |
| 65 | try: |
| 66 | build_config = load_json(user_args.config_f) |
| 67 | except Exception as e: |
| 68 | print("Failed to load config %s. Exception: %s" % (build_config, |
| 69 | e.msg)) |
| 70 | sys.exit(1) |
| 71 | else: |
| 72 | build_config = config_AN521 |
| 73 | # Build everything |
| 74 | build_status, build_report = build(user_args.tfm_dir, |
| 75 | user_args.build_dir, |
| 76 | user_args.report, |
| 77 | build_config) |
| 78 | |
| 79 | if not build_report: |
| 80 | print("Build Report Empty, check build status") |
| 81 | sys.exit(1) |
| 82 | |
| 83 | if build_status: |
| 84 | print("Build Failed") |
| 85 | sys.exit(1) |
| 86 | # pprint(build_report) |
| 87 | print("Build Complete!") |
| 88 | sys.exit(0) |
| 89 | |
| 90 | |
| 91 | if __name__ == "__main__": |
| 92 | |
| 93 | # Calcuate the workspace root directory relative to the script location |
| 94 | # Equivalent to realpath $(dirname ./build_helper/build_helper.py)/../../ |
| 95 | root_path = os.path.dirname(os.path.realpath(__file__)) |
| 96 | for i in range(2): |
| 97 | root_path = os.path.split(root_path)[0] |
| 98 | |
| 99 | parser = argparse.ArgumentParser(description="") |
| 100 | parser.add_argument("-b", "--build_dir", |
| 101 | dest="build_dir", |
| 102 | action="store", |
| 103 | default="./builds", |
| 104 | help="Where to generate the artifacts") |
| 105 | parser.add_argument("-c", "--config_file", |
| 106 | dest="config_f", |
| 107 | action="store", |
| 108 | help="Manual configuration override file (JSON)") |
| 109 | parser.add_argument("-r", "--report", |
| 110 | dest="report", |
| 111 | action="store", |
| 112 | help="JSON file containing build report") |
| 113 | parser.add_argument("-t", "--tfm_dir", |
| 114 | dest="tfm_dir", |
| 115 | action="store", |
| 116 | default=os.path.join(root_path, "tf-m"), |
| 117 | help="TFM directory") |
| 118 | |
| 119 | main(get_cmd_args(parser=parser)) |