mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:f782d9c66c49 1 """
dkato 0:f782d9c66c49 2 mbed SDK
dkato 0:f782d9c66c49 3 Copyright (c) 2011-2016 ARM Limited
dkato 0:f782d9c66c49 4
dkato 0:f782d9c66c49 5 Licensed under the Apache License, Version 2.0 (the "License");
dkato 0:f782d9c66c49 6 you may not use this file except in compliance with the License.
dkato 0:f782d9c66c49 7 You may obtain a copy of the License at
dkato 0:f782d9c66c49 8
dkato 0:f782d9c66c49 9 http://www.apache.org/licenses/LICENSE-2.0
dkato 0:f782d9c66c49 10
dkato 0:f782d9c66c49 11 Unless required by applicable law or agreed to in writing, software
dkato 0:f782d9c66c49 12 distributed under the License is distributed on an "AS IS" BASIS,
dkato 0:f782d9c66c49 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dkato 0:f782d9c66c49 14 See the License for the specific language governing permissions and
dkato 0:f782d9c66c49 15 limitations under the License.
dkato 0:f782d9c66c49 16 """
dkato 0:f782d9c66c49 17
dkato 0:f782d9c66c49 18 import re
dkato 0:f782d9c66c49 19 import tempfile
dkato 0:f782d9c66c49 20 from types import ListType
dkato 0:f782d9c66c49 21 from shutil import rmtree
dkato 0:f782d9c66c49 22 from os.path import join, exists, dirname, basename, abspath, normpath, splitext
dkato 0:f782d9c66c49 23 from os import linesep, remove, makedirs
dkato 0:f782d9c66c49 24 from time import time
dkato 0:f782d9c66c49 25 from intelhex import IntelHex
dkato 0:f782d9c66c49 26
dkato 0:f782d9c66c49 27 from tools.utils import mkdir, run_cmd, run_cmd_ext, NotSupportedException,\
dkato 0:f782d9c66c49 28 ToolException, InvalidReleaseTargetException, intelhex_offset
dkato 0:f782d9c66c49 29 from tools.paths import MBED_CMSIS_PATH, MBED_TARGETS_PATH, MBED_LIBRARIES,\
dkato 0:f782d9c66c49 30 MBED_HEADER, MBED_DRIVERS, MBED_PLATFORM, MBED_HAL, MBED_CONFIG_FILE,\
dkato 0:f782d9c66c49 31 MBED_LIBRARIES_DRIVERS, MBED_LIBRARIES_PLATFORM, MBED_LIBRARIES_HAL,\
dkato 0:f782d9c66c49 32 BUILD_DIR
dkato 0:f782d9c66c49 33 from tools.targets import TARGET_NAMES, TARGET_MAP
dkato 0:f782d9c66c49 34 from tools.libraries import Library
dkato 0:f782d9c66c49 35 from tools.toolchains import TOOLCHAIN_CLASSES
dkato 0:f782d9c66c49 36 from jinja2 import FileSystemLoader
dkato 0:f782d9c66c49 37 from jinja2.environment import Environment
dkato 0:f782d9c66c49 38 from tools.config import Config
dkato 0:f782d9c66c49 39
dkato 0:f782d9c66c49 40 RELEASE_VERSIONS = ['2', '5']
dkato 0:f782d9c66c49 41
dkato 0:f782d9c66c49 42 def prep_report(report, target_name, toolchain_name, id_name):
dkato 0:f782d9c66c49 43 """Setup report keys
dkato 0:f782d9c66c49 44
dkato 0:f782d9c66c49 45 Positional arguments:
dkato 0:f782d9c66c49 46 report - the report to fill
dkato 0:f782d9c66c49 47 target_name - the target being used
dkato 0:f782d9c66c49 48 toolchain_name - the toolchain being used
dkato 0:f782d9c66c49 49 id_name - the name of the executable or library being built
dkato 0:f782d9c66c49 50 """
dkato 0:f782d9c66c49 51 if not target_name in report:
dkato 0:f782d9c66c49 52 report[target_name] = {}
dkato 0:f782d9c66c49 53
dkato 0:f782d9c66c49 54 if not toolchain_name in report[target_name]:
dkato 0:f782d9c66c49 55 report[target_name][toolchain_name] = {}
dkato 0:f782d9c66c49 56
dkato 0:f782d9c66c49 57 if not id_name in report[target_name][toolchain_name]:
dkato 0:f782d9c66c49 58 report[target_name][toolchain_name][id_name] = []
dkato 0:f782d9c66c49 59
dkato 0:f782d9c66c49 60 def prep_properties(properties, target_name, toolchain_name, vendor_label):
dkato 0:f782d9c66c49 61 """Setup test properties
dkato 0:f782d9c66c49 62
dkato 0:f782d9c66c49 63 Positional arguments:
dkato 0:f782d9c66c49 64 properties - the dict to fill
dkato 0:f782d9c66c49 65 target_name - the target the test is targeting
dkato 0:f782d9c66c49 66 toolchain_name - the toolchain that will compile the test
dkato 0:f782d9c66c49 67 vendor_label - the vendor
dkato 0:f782d9c66c49 68 """
dkato 0:f782d9c66c49 69 if not target_name in properties:
dkato 0:f782d9c66c49 70 properties[target_name] = {}
dkato 0:f782d9c66c49 71
dkato 0:f782d9c66c49 72 if not toolchain_name in properties[target_name]:
dkato 0:f782d9c66c49 73 properties[target_name][toolchain_name] = {}
dkato 0:f782d9c66c49 74
dkato 0:f782d9c66c49 75 properties[target_name][toolchain_name]["target"] = target_name
dkato 0:f782d9c66c49 76 properties[target_name][toolchain_name]["vendor"] = vendor_label
dkato 0:f782d9c66c49 77 properties[target_name][toolchain_name]["toolchain"] = toolchain_name
dkato 0:f782d9c66c49 78
dkato 0:f782d9c66c49 79 def create_result(target_name, toolchain_name, id_name, description):
dkato 0:f782d9c66c49 80 """Create a result dictionary
dkato 0:f782d9c66c49 81
dkato 0:f782d9c66c49 82 Positional arguments:
dkato 0:f782d9c66c49 83 target_name - the target being built for
dkato 0:f782d9c66c49 84 toolchain_name - the toolchain doing the building
dkato 0:f782d9c66c49 85 id_name - the name of the executable or library being built
dkato 0:f782d9c66c49 86 description - a human readable description of what's going on
dkato 0:f782d9c66c49 87 """
dkato 0:f782d9c66c49 88 cur_result = {}
dkato 0:f782d9c66c49 89 cur_result["target_name"] = target_name
dkato 0:f782d9c66c49 90 cur_result["toolchain_name"] = toolchain_name
dkato 0:f782d9c66c49 91 cur_result["id"] = id_name
dkato 0:f782d9c66c49 92 cur_result["description"] = description
dkato 0:f782d9c66c49 93 cur_result["elapsed_time"] = 0
dkato 0:f782d9c66c49 94 cur_result["output"] = ""
dkato 0:f782d9c66c49 95
dkato 0:f782d9c66c49 96 return cur_result
dkato 0:f782d9c66c49 97
dkato 0:f782d9c66c49 98 def add_result_to_report(report, result):
dkato 0:f782d9c66c49 99 """Add a single result to a report dictionary
dkato 0:f782d9c66c49 100
dkato 0:f782d9c66c49 101 Positional arguments:
dkato 0:f782d9c66c49 102 report - the report to append to
dkato 0:f782d9c66c49 103 result - the result to append
dkato 0:f782d9c66c49 104 """
dkato 0:f782d9c66c49 105 target = result["target_name"]
dkato 0:f782d9c66c49 106 toolchain = result["toolchain_name"]
dkato 0:f782d9c66c49 107 id_name = result['id']
dkato 0:f782d9c66c49 108 result_wrap = {0: result}
dkato 0:f782d9c66c49 109 report[target][toolchain][id_name].append(result_wrap)
dkato 0:f782d9c66c49 110
dkato 0:f782d9c66c49 111 def get_config(src_paths, target, toolchain_name):
dkato 0:f782d9c66c49 112 """Get the configuration object for a target-toolchain combination
dkato 0:f782d9c66c49 113
dkato 0:f782d9c66c49 114 Positional arguments:
dkato 0:f782d9c66c49 115 src_paths - paths to scan for the configuration files
dkato 0:f782d9c66c49 116 target - the device we are building for
dkato 0:f782d9c66c49 117 toolchain_name - the string that identifies the build tools
dkato 0:f782d9c66c49 118 """
dkato 0:f782d9c66c49 119 # Convert src_paths to a list if needed
dkato 0:f782d9c66c49 120 if type(src_paths) != ListType:
dkato 0:f782d9c66c49 121 src_paths = [src_paths]
dkato 0:f782d9c66c49 122
dkato 0:f782d9c66c49 123 # Pass all params to the unified prepare_resources()
dkato 0:f782d9c66c49 124 toolchain = prepare_toolchain(src_paths, None, target, toolchain_name)
dkato 0:f782d9c66c49 125
dkato 0:f782d9c66c49 126 # Scan src_path for config files
dkato 0:f782d9c66c49 127 resources = toolchain.scan_resources(src_paths[0])
dkato 0:f782d9c66c49 128 for path in src_paths[1:]:
dkato 0:f782d9c66c49 129 resources.add(toolchain.scan_resources(path))
dkato 0:f782d9c66c49 130
dkato 0:f782d9c66c49 131 # Update configuration files until added features creates no changes
dkato 0:f782d9c66c49 132 prev_features = set()
dkato 0:f782d9c66c49 133 while True:
dkato 0:f782d9c66c49 134 # Update the configuration with any .json files found while scanning
dkato 0:f782d9c66c49 135 toolchain.config.add_config_files(resources.json_files)
dkato 0:f782d9c66c49 136
dkato 0:f782d9c66c49 137 # Add features while we find new ones
dkato 0:f782d9c66c49 138 features = set(toolchain.config.get_features())
dkato 0:f782d9c66c49 139 if features == prev_features:
dkato 0:f782d9c66c49 140 break
dkato 0:f782d9c66c49 141
dkato 0:f782d9c66c49 142 for feature in features:
dkato 0:f782d9c66c49 143 if feature in resources.features:
dkato 0:f782d9c66c49 144 resources += resources.features[feature]
dkato 0:f782d9c66c49 145
dkato 0:f782d9c66c49 146 prev_features = features
dkato 0:f782d9c66c49 147 toolchain.config.validate_config()
dkato 0:f782d9c66c49 148
dkato 0:f782d9c66c49 149 cfg, macros = toolchain.config.get_config_data()
dkato 0:f782d9c66c49 150 features = toolchain.config.get_features()
dkato 0:f782d9c66c49 151 return cfg, macros, features
dkato 0:f782d9c66c49 152
dkato 0:f782d9c66c49 153 def is_official_target(target_name, version):
dkato 0:f782d9c66c49 154 """ Returns True, None if a target is part of the official release for the
dkato 0:f782d9c66c49 155 given version. Return False, 'reason' if a target is not part of the
dkato 0:f782d9c66c49 156 official release for the given version.
dkato 0:f782d9c66c49 157
dkato 0:f782d9c66c49 158 Positional arguments:
dkato 0:f782d9c66c49 159 target_name - Name if the target (ex. 'K64F')
dkato 0:f782d9c66c49 160 version - The release version string. Should be a string contained within
dkato 0:f782d9c66c49 161 RELEASE_VERSIONS
dkato 0:f782d9c66c49 162 """
dkato 0:f782d9c66c49 163
dkato 0:f782d9c66c49 164 result = True
dkato 0:f782d9c66c49 165 reason = None
dkato 0:f782d9c66c49 166 target = TARGET_MAP[target_name]
dkato 0:f782d9c66c49 167
dkato 0:f782d9c66c49 168 if hasattr(target, 'release_versions') \
dkato 0:f782d9c66c49 169 and version in target.release_versions:
dkato 0:f782d9c66c49 170 if version == '2':
dkato 0:f782d9c66c49 171 # For version 2, either ARM or uARM toolchain support is required
dkato 0:f782d9c66c49 172 required_toolchains = set(['ARM', 'uARM'])
dkato 0:f782d9c66c49 173
dkato 0:f782d9c66c49 174 if not len(required_toolchains.intersection(
dkato 0:f782d9c66c49 175 set(target.supported_toolchains))) > 0:
dkato 0:f782d9c66c49 176 result = False
dkato 0:f782d9c66c49 177 reason = ("Target '%s' must support " % target.name) + \
dkato 0:f782d9c66c49 178 ("one of the folowing toolchains to be included in the") + \
dkato 0:f782d9c66c49 179 ((" mbed 2.0 official release: %s" + linesep) %
dkato 0:f782d9c66c49 180 ", ".join(required_toolchains)) + \
dkato 0:f782d9c66c49 181 ("Currently it is only configured to support the ") + \
dkato 0:f782d9c66c49 182 ("following toolchains: %s" %
dkato 0:f782d9c66c49 183 ", ".join(target.supported_toolchains))
dkato 0:f782d9c66c49 184
dkato 0:f782d9c66c49 185 elif version == '5':
dkato 0:f782d9c66c49 186 # For version 5, ARM, GCC_ARM, and IAR toolchain support is required
dkato 0:f782d9c66c49 187 required_toolchains = set(['ARM', 'GCC_ARM', 'IAR'])
dkato 0:f782d9c66c49 188 required_toolchains_sorted = list(required_toolchains)
dkato 0:f782d9c66c49 189 required_toolchains_sorted.sort()
dkato 0:f782d9c66c49 190 supported_toolchains = set(target.supported_toolchains)
dkato 0:f782d9c66c49 191 supported_toolchains_sorted = list(supported_toolchains)
dkato 0:f782d9c66c49 192 supported_toolchains_sorted.sort()
dkato 0:f782d9c66c49 193
dkato 0:f782d9c66c49 194 if not required_toolchains.issubset(supported_toolchains):
dkato 0:f782d9c66c49 195 result = False
dkato 0:f782d9c66c49 196 reason = ("Target '%s' must support " % target.name) + \
dkato 0:f782d9c66c49 197 ("ALL of the folowing toolchains to be included in the") + \
dkato 0:f782d9c66c49 198 ((" mbed OS 5.0 official release: %s" + linesep) %
dkato 0:f782d9c66c49 199 ", ".join(required_toolchains_sorted)) + \
dkato 0:f782d9c66c49 200 ("Currently it is only configured to support the ") + \
dkato 0:f782d9c66c49 201 ("following toolchains: %s" %
dkato 0:f782d9c66c49 202 ", ".join(supported_toolchains_sorted))
dkato 0:f782d9c66c49 203
dkato 0:f782d9c66c49 204 elif not target.default_lib == 'std':
dkato 0:f782d9c66c49 205 result = False
dkato 0:f782d9c66c49 206 reason = ("Target '%s' must set the " % target.name) + \
dkato 0:f782d9c66c49 207 ("'default_lib' to 'std' to be included in the ") + \
dkato 0:f782d9c66c49 208 ("mbed OS 5.0 official release." + linesep) + \
dkato 0:f782d9c66c49 209 ("Currently it is set to '%s'" % target.default_lib)
dkato 0:f782d9c66c49 210
dkato 0:f782d9c66c49 211 else:
dkato 0:f782d9c66c49 212 result = False
dkato 0:f782d9c66c49 213 reason = ("Target '%s' has set an invalid release version of '%s'" %
dkato 0:f782d9c66c49 214 version) + \
dkato 0:f782d9c66c49 215 ("Please choose from the following release versions: %s" %
dkato 0:f782d9c66c49 216 ', '.join(RELEASE_VERSIONS))
dkato 0:f782d9c66c49 217
dkato 0:f782d9c66c49 218 else:
dkato 0:f782d9c66c49 219 result = False
dkato 0:f782d9c66c49 220 if not hasattr(target, 'release_versions'):
dkato 0:f782d9c66c49 221 reason = "Target '%s' " % target.name
dkato 0:f782d9c66c49 222 reason += "does not have the 'release_versions' key set"
dkato 0:f782d9c66c49 223 elif not version in target.release_versions:
dkato 0:f782d9c66c49 224 reason = "Target '%s' does not contain the version '%s' " % \
dkato 0:f782d9c66c49 225 (target.name, version)
dkato 0:f782d9c66c49 226 reason += "in its 'release_versions' key"
dkato 0:f782d9c66c49 227
dkato 0:f782d9c66c49 228 return result, reason
dkato 0:f782d9c66c49 229
dkato 0:f782d9c66c49 230 def transform_release_toolchains(toolchains, version):
dkato 0:f782d9c66c49 231 """ Given a list of toolchains and a release version, return a list of
dkato 0:f782d9c66c49 232 only the supported toolchains for that release
dkato 0:f782d9c66c49 233
dkato 0:f782d9c66c49 234 Positional arguments:
dkato 0:f782d9c66c49 235 toolchains - The list of toolchains
dkato 0:f782d9c66c49 236 version - The release version string. Should be a string contained within
dkato 0:f782d9c66c49 237 RELEASE_VERSIONS
dkato 0:f782d9c66c49 238 """
dkato 0:f782d9c66c49 239 if version == '5':
dkato 0:f782d9c66c49 240 return ['ARM', 'GCC_ARM', 'IAR']
dkato 0:f782d9c66c49 241 else:
dkato 0:f782d9c66c49 242 return toolchains
dkato 0:f782d9c66c49 243
dkato 0:f782d9c66c49 244
dkato 0:f782d9c66c49 245 def get_mbed_official_release(version):
dkato 0:f782d9c66c49 246 """ Given a release version string, return a tuple that contains a target
dkato 0:f782d9c66c49 247 and the supported toolchains for that release.
dkato 0:f782d9c66c49 248 Ex. Given '2', return (('LPC1768', ('ARM', 'GCC_ARM')),
dkato 0:f782d9c66c49 249 ('K64F', ('ARM', 'GCC_ARM')), ...)
dkato 0:f782d9c66c49 250
dkato 0:f782d9c66c49 251 Positional arguments:
dkato 0:f782d9c66c49 252 version - The version string. Should be a string contained within
dkato 0:f782d9c66c49 253 RELEASE_VERSIONS
dkato 0:f782d9c66c49 254 """
dkato 0:f782d9c66c49 255
dkato 0:f782d9c66c49 256 mbed_official_release = (
dkato 0:f782d9c66c49 257 tuple(
dkato 0:f782d9c66c49 258 tuple(
dkato 0:f782d9c66c49 259 [
dkato 0:f782d9c66c49 260 TARGET_MAP[target].name,
dkato 0:f782d9c66c49 261 tuple(transform_release_toolchains(
dkato 0:f782d9c66c49 262 TARGET_MAP[target].supported_toolchains, version))
dkato 0:f782d9c66c49 263 ]
dkato 0:f782d9c66c49 264 ) for target in TARGET_NAMES \
dkato 0:f782d9c66c49 265 if (hasattr(TARGET_MAP[target], 'release_versions')
dkato 0:f782d9c66c49 266 and version in TARGET_MAP[target].release_versions)
dkato 0:f782d9c66c49 267 )
dkato 0:f782d9c66c49 268 )
dkato 0:f782d9c66c49 269
dkato 0:f782d9c66c49 270 for target in mbed_official_release:
dkato 0:f782d9c66c49 271 is_official, reason = is_official_target(target[0], version)
dkato 0:f782d9c66c49 272
dkato 0:f782d9c66c49 273 if not is_official:
dkato 0:f782d9c66c49 274 raise InvalidReleaseTargetException(reason)
dkato 0:f782d9c66c49 275
dkato 0:f782d9c66c49 276 return mbed_official_release
dkato 0:f782d9c66c49 277
dkato 0:f782d9c66c49 278 def add_regions_to_profile(profile, config, toolchain_class):
dkato 0:f782d9c66c49 279 """Add regions to the build profile, if there are any.
dkato 0:f782d9c66c49 280
dkato 0:f782d9c66c49 281 Positional Arguments:
dkato 0:f782d9c66c49 282 profile - the profile to update
dkato 0:f782d9c66c49 283 config - the configuration object that owns the region
dkato 0:f782d9c66c49 284 toolchain_class - the class of the toolchain being used
dkato 0:f782d9c66c49 285 """
dkato 0:f782d9c66c49 286 regions = list(config.regions)
dkato 0:f782d9c66c49 287 for region in regions:
dkato 0:f782d9c66c49 288 for define in [(region.name.upper() + "_ADDR", region.start),
dkato 0:f782d9c66c49 289 (region.name.upper() + "_SIZE", region.size)]:
dkato 0:f782d9c66c49 290 profile["common"].append("-D%s=0x%x" % define)
dkato 0:f782d9c66c49 291 active_region = [r for r in regions if r.active][0]
dkato 0:f782d9c66c49 292 for define in [("MBED_APP_START", active_region.start),
dkato 0:f782d9c66c49 293 ("MBED_APP_SIZE", active_region.size)]:
dkato 0:f782d9c66c49 294 profile["ld"].append(toolchain_class.make_ld_define(*define))
dkato 0:f782d9c66c49 295
dkato 0:f782d9c66c49 296 print("Using regions in this build:")
dkato 0:f782d9c66c49 297 for region in regions:
dkato 0:f782d9c66c49 298 print(" Region %s size 0x%x, offset 0x%x"
dkato 0:f782d9c66c49 299 % (region.name, region.size, region.start))
dkato 0:f782d9c66c49 300
dkato 0:f782d9c66c49 301
dkato 0:f782d9c66c49 302 def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
dkato 0:f782d9c66c49 303 macros=None, clean=False, jobs=1,
dkato 0:f782d9c66c49 304 notify=None, silent=False, verbose=False,
dkato 0:f782d9c66c49 305 extra_verbose=False, config=None,
dkato 0:f782d9c66c49 306 app_config=None, build_profile=None):
dkato 0:f782d9c66c49 307 """ Prepares resource related objects - toolchain, target, config
dkato 0:f782d9c66c49 308
dkato 0:f782d9c66c49 309 Positional arguments:
dkato 0:f782d9c66c49 310 src_paths - the paths to source directories
dkato 0:f782d9c66c49 311 target - ['LPC1768', 'LPC11U24', 'LPC2368', etc.]
dkato 0:f782d9c66c49 312 toolchain_name - ['ARM', 'uARM', 'GCC_ARM', 'GCC_CR']
dkato 0:f782d9c66c49 313
dkato 0:f782d9c66c49 314 Keyword arguments:
dkato 0:f782d9c66c49 315 macros - additional macros
dkato 0:f782d9c66c49 316 clean - Rebuild everything if True
dkato 0:f782d9c66c49 317 jobs - how many compilers we can run at once
dkato 0:f782d9c66c49 318 notify - Notify function for logs
dkato 0:f782d9c66c49 319 silent - suppress printing of progress indicators
dkato 0:f782d9c66c49 320 verbose - Write the actual tools command lines used if True
dkato 0:f782d9c66c49 321 extra_verbose - even more output!
dkato 0:f782d9c66c49 322 config - a Config object to use instead of creating one
dkato 0:f782d9c66c49 323 app_config - location of a chosen mbed_app.json file
dkato 0:f782d9c66c49 324 build_profile - a dict of flags that will be passed to the compiler
dkato 0:f782d9c66c49 325 """
dkato 0:f782d9c66c49 326
dkato 0:f782d9c66c49 327 # We need to remove all paths which are repeated to avoid
dkato 0:f782d9c66c49 328 # multiple compilations and linking with the same objects
dkato 0:f782d9c66c49 329 src_paths = [src_paths[0]] + list(set(src_paths[1:]))
dkato 0:f782d9c66c49 330
dkato 0:f782d9c66c49 331 # If the configuration object was not yet created, create it now
dkato 0:f782d9c66c49 332 config = config or Config(target, src_paths, app_config=app_config)
dkato 0:f782d9c66c49 333 target = config.target
dkato 0:f782d9c66c49 334 try:
dkato 0:f782d9c66c49 335 cur_tc = TOOLCHAIN_CLASSES[toolchain_name]
dkato 0:f782d9c66c49 336 except KeyError:
dkato 0:f782d9c66c49 337 raise KeyError("Toolchain %s not supported" % toolchain_name)
dkato 0:f782d9c66c49 338 if config.has_regions:
dkato 0:f782d9c66c49 339 add_regions_to_profile(build_profile, config, cur_tc)
dkato 0:f782d9c66c49 340
dkato 0:f782d9c66c49 341 # Toolchain instance
dkato 0:f782d9c66c49 342 toolchain = cur_tc(target, notify, macros, silent, build_dir=build_dir,
dkato 0:f782d9c66c49 343 extra_verbose=extra_verbose, build_profile=build_profile)
dkato 0:f782d9c66c49 344
dkato 0:f782d9c66c49 345 toolchain.config = config
dkato 0:f782d9c66c49 346 toolchain.jobs = jobs
dkato 0:f782d9c66c49 347 toolchain.build_all = clean
dkato 0:f782d9c66c49 348 toolchain.VERBOSE = verbose
dkato 0:f782d9c66c49 349
dkato 0:f782d9c66c49 350 return toolchain
dkato 0:f782d9c66c49 351
dkato 0:f782d9c66c49 352 def merge_region_list(region_list, destination, padding=b'\xFF'):
dkato 0:f782d9c66c49 353 """Merege the region_list into a single image
dkato 0:f782d9c66c49 354
dkato 0:f782d9c66c49 355 Positional Arguments:
dkato 0:f782d9c66c49 356 region_list - list of regions, which should contain filenames
dkato 0:f782d9c66c49 357 destination - file name to write all regions to
dkato 0:f782d9c66c49 358 padding - bytes to fill gapps with
dkato 0:f782d9c66c49 359 """
dkato 0:f782d9c66c49 360 merged = IntelHex()
dkato 0:f782d9c66c49 361
dkato 0:f782d9c66c49 362 print("Merging Regions:")
dkato 0:f782d9c66c49 363
dkato 0:f782d9c66c49 364 for region in region_list:
dkato 0:f782d9c66c49 365 if region.active and not region.filename:
dkato 0:f782d9c66c49 366 raise ToolException("Active region has no contents: No file found.")
dkato 0:f782d9c66c49 367 if region.filename:
dkato 0:f782d9c66c49 368 print(" Filling region %s with %s" % (region.name, region.filename))
dkato 0:f782d9c66c49 369 part = intelhex_offset(region.filename, offset=region.start)
dkato 0:f782d9c66c49 370 part_size = (part.maxaddr() - part.minaddr()) + 1
dkato 0:f782d9c66c49 371 if part_size > region.size:
dkato 0:f782d9c66c49 372 raise ToolException("Contents of region %s does not fit"
dkato 0:f782d9c66c49 373 % region.name)
dkato 0:f782d9c66c49 374 merged.merge(part)
dkato 0:f782d9c66c49 375 pad_size = region.size - part_size
dkato 0:f782d9c66c49 376 if pad_size > 0 and region != region_list[-1]:
dkato 0:f782d9c66c49 377 print(" Padding region %s with 0x%x bytes" % (region.name, pad_size))
dkato 0:f782d9c66c49 378 merged.puts(merged.maxaddr() + 1, padding * pad_size)
dkato 0:f782d9c66c49 379
dkato 0:f782d9c66c49 380 if not exists(dirname(destination)):
dkato 0:f782d9c66c49 381 makedirs(dirname(destination))
dkato 0:f782d9c66c49 382 print("Space used after regions merged: 0x%x" %
dkato 0:f782d9c66c49 383 (merged.maxaddr() - merged.minaddr() + 1))
dkato 0:f782d9c66c49 384 with open(destination, "wb+") as output:
dkato 0:f782d9c66c49 385 merged.tofile(output, format='bin')
dkato 0:f782d9c66c49 386
dkato 0:f782d9c66c49 387 def scan_resources(src_paths, toolchain, dependencies_paths=None,
dkato 0:f782d9c66c49 388 inc_dirs=None, base_path=None):
dkato 0:f782d9c66c49 389 """ Scan resources using initialized toolcain
dkato 0:f782d9c66c49 390
dkato 0:f782d9c66c49 391 Positional arguments
dkato 0:f782d9c66c49 392 src_paths - the paths to source directories
dkato 0:f782d9c66c49 393 toolchain - valid toolchain object
dkato 0:f782d9c66c49 394 dependencies_paths - dependency paths that we should scan for include dirs
dkato 0:f782d9c66c49 395 inc_dirs - additional include directories which should be added to
dkato 0:f782d9c66c49 396 the scanner resources
dkato 0:f782d9c66c49 397 """
dkato 0:f782d9c66c49 398
dkato 0:f782d9c66c49 399 # Scan src_path
dkato 0:f782d9c66c49 400 resources = toolchain.scan_resources(src_paths[0], base_path=base_path)
dkato 0:f782d9c66c49 401 for path in src_paths[1:]:
dkato 0:f782d9c66c49 402 resources.add(toolchain.scan_resources(path, base_path=base_path))
dkato 0:f782d9c66c49 403
dkato 0:f782d9c66c49 404 # Scan dependency paths for include dirs
dkato 0:f782d9c66c49 405 if dependencies_paths is not None:
dkato 0:f782d9c66c49 406 for path in dependencies_paths:
dkato 0:f782d9c66c49 407 lib_resources = toolchain.scan_resources(path)
dkato 0:f782d9c66c49 408 resources.inc_dirs.extend(lib_resources.inc_dirs)
dkato 0:f782d9c66c49 409
dkato 0:f782d9c66c49 410 # Add additional include directories if passed
dkato 0:f782d9c66c49 411 if inc_dirs:
dkato 0:f782d9c66c49 412 if type(inc_dirs) == ListType:
dkato 0:f782d9c66c49 413 resources.inc_dirs.extend(inc_dirs)
dkato 0:f782d9c66c49 414 else:
dkato 0:f782d9c66c49 415 resources.inc_dirs.append(inc_dirs)
dkato 0:f782d9c66c49 416
dkato 0:f782d9c66c49 417 # Load resources into the config system which might expand/modify resources
dkato 0:f782d9c66c49 418 # based on config data
dkato 0:f782d9c66c49 419 resources = toolchain.config.load_resources(resources)
dkato 0:f782d9c66c49 420
dkato 0:f782d9c66c49 421 # Set the toolchain's configuration data
dkato 0:f782d9c66c49 422 toolchain.set_config_data(toolchain.config.get_config_data())
dkato 0:f782d9c66c49 423
dkato 0:f782d9c66c49 424 return resources
dkato 0:f782d9c66c49 425
dkato 0:f782d9c66c49 426 def build_project(src_paths, build_path, target, toolchain_name,
dkato 0:f782d9c66c49 427 libraries_paths=None, linker_script=None,
dkato 0:f782d9c66c49 428 clean=False, notify=None, verbose=False, name=None,
dkato 0:f782d9c66c49 429 macros=None, inc_dirs=None, jobs=1, silent=False,
dkato 0:f782d9c66c49 430 report=None, properties=None, project_id=None,
dkato 0:f782d9c66c49 431 project_description=None, extra_verbose=False, config=None,
dkato 0:f782d9c66c49 432 app_config=None, build_profile=None):
dkato 0:f782d9c66c49 433 """ Build a project. A project may be a test or a user program.
dkato 0:f782d9c66c49 434
dkato 0:f782d9c66c49 435 Positional arguments:
dkato 0:f782d9c66c49 436 src_paths - a path or list of paths that contain all files needed to build
dkato 0:f782d9c66c49 437 the project
dkato 0:f782d9c66c49 438 build_path - the directory where all of the object files will be placed
dkato 0:f782d9c66c49 439 target - the MCU or board that the project will compile for
dkato 0:f782d9c66c49 440 toolchain_name - the name of the build tools
dkato 0:f782d9c66c49 441
dkato 0:f782d9c66c49 442 Keyword arguments:
dkato 0:f782d9c66c49 443 libraries_paths - The location of libraries to include when linking
dkato 0:f782d9c66c49 444 linker_script - the file that drives the linker to do it's job
dkato 0:f782d9c66c49 445 clean - Rebuild everything if True
dkato 0:f782d9c66c49 446 notify - Notify function for logs
dkato 0:f782d9c66c49 447 verbose - Write the actual tools command lines used if True
dkato 0:f782d9c66c49 448 name - the name of the project
dkato 0:f782d9c66c49 449 macros - additional macros
dkato 0:f782d9c66c49 450 inc_dirs - additional directories where include files may be found
dkato 0:f782d9c66c49 451 jobs - how many compilers we can run at once
dkato 0:f782d9c66c49 452 silent - suppress printing of progress indicators
dkato 0:f782d9c66c49 453 report - a dict where a result may be appended
dkato 0:f782d9c66c49 454 properties - UUUUHHHHH beats me
dkato 0:f782d9c66c49 455 project_id - the name put in the report
dkato 0:f782d9c66c49 456 project_description - the human-readable version of what this thing does
dkato 0:f782d9c66c49 457 extra_verbose - even more output!
dkato 0:f782d9c66c49 458 config - a Config object to use instead of creating one
dkato 0:f782d9c66c49 459 app_config - location of a chosen mbed_app.json file
dkato 0:f782d9c66c49 460 build_profile - a dict of flags that will be passed to the compiler
dkato 0:f782d9c66c49 461 """
dkato 0:f782d9c66c49 462
dkato 0:f782d9c66c49 463 # Convert src_path to a list if needed
dkato 0:f782d9c66c49 464 if type(src_paths) != ListType:
dkato 0:f782d9c66c49 465 src_paths = [src_paths]
dkato 0:f782d9c66c49 466 # Extend src_paths wiht libraries_paths
dkato 0:f782d9c66c49 467 if libraries_paths is not None:
dkato 0:f782d9c66c49 468 src_paths.extend(libraries_paths)
dkato 0:f782d9c66c49 469 inc_dirs.extend(map(dirname, libraries_paths))
dkato 0:f782d9c66c49 470
dkato 0:f782d9c66c49 471 # Build Directory
dkato 0:f782d9c66c49 472 if clean and exists(build_path):
dkato 0:f782d9c66c49 473 rmtree(build_path)
dkato 0:f782d9c66c49 474 mkdir(build_path)
dkato 0:f782d9c66c49 475
dkato 0:f782d9c66c49 476 # Pass all params to the unified prepare_toolchain()
dkato 0:f782d9c66c49 477 toolchain = prepare_toolchain(
dkato 0:f782d9c66c49 478 src_paths, build_path, target, toolchain_name, macros=macros,
dkato 0:f782d9c66c49 479 clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose,
dkato 0:f782d9c66c49 480 extra_verbose=extra_verbose, config=config, app_config=app_config,
dkato 0:f782d9c66c49 481 build_profile=build_profile)
dkato 0:f782d9c66c49 482
dkato 0:f782d9c66c49 483 # The first path will give the name to the library
dkato 0:f782d9c66c49 484 if name is None:
dkato 0:f782d9c66c49 485 name = basename(normpath(abspath(src_paths[0])))
dkato 0:f782d9c66c49 486 toolchain.info("Building project %s (%s, %s)" %
dkato 0:f782d9c66c49 487 (name, toolchain.target.name, toolchain_name))
dkato 0:f782d9c66c49 488
dkato 0:f782d9c66c49 489 # Initialize reporting
dkato 0:f782d9c66c49 490 if report != None:
dkato 0:f782d9c66c49 491 start = time()
dkato 0:f782d9c66c49 492 # If project_id is specified, use that over the default name
dkato 0:f782d9c66c49 493 id_name = project_id.upper() if project_id else name.upper()
dkato 0:f782d9c66c49 494 description = project_description if project_description else name
dkato 0:f782d9c66c49 495 vendor_label = toolchain.target.extra_labels[0]
dkato 0:f782d9c66c49 496 prep_report(report, toolchain.target.name, toolchain_name, id_name)
dkato 0:f782d9c66c49 497 cur_result = create_result(toolchain.target.name, toolchain_name,
dkato 0:f782d9c66c49 498 id_name, description)
dkato 0:f782d9c66c49 499 if properties != None:
dkato 0:f782d9c66c49 500 prep_properties(properties, toolchain.target.name, toolchain_name,
dkato 0:f782d9c66c49 501 vendor_label)
dkato 0:f782d9c66c49 502
dkato 0:f782d9c66c49 503 try:
dkato 0:f782d9c66c49 504 # Call unified scan_resources
dkato 0:f782d9c66c49 505 resources = scan_resources(src_paths, toolchain, inc_dirs=inc_dirs)
dkato 0:f782d9c66c49 506
dkato 0:f782d9c66c49 507 # Change linker script if specified
dkato 0:f782d9c66c49 508 if linker_script is not None:
dkato 0:f782d9c66c49 509 resources.linker_script = linker_script
dkato 0:f782d9c66c49 510
dkato 0:f782d9c66c49 511 # Compile Sources
dkato 0:f782d9c66c49 512 objects = toolchain.compile_sources(resources, resources.inc_dirs)
dkato 0:f782d9c66c49 513 resources.objects.extend(objects)
dkato 0:f782d9c66c49 514
dkato 0:f782d9c66c49 515 # Link Program
dkato 0:f782d9c66c49 516 if toolchain.config.has_regions:
dkato 0:f782d9c66c49 517 res, _ = toolchain.link_program(resources, build_path, name + "_application")
dkato 0:f782d9c66c49 518 region_list = list(toolchain.config.regions)
dkato 0:f782d9c66c49 519 region_list = [r._replace(filename=res) if r.active else r
dkato 0:f782d9c66c49 520 for r in region_list]
dkato 0:f782d9c66c49 521 res = join(build_path, name) + ".bin"
dkato 0:f782d9c66c49 522 merge_region_list(region_list, res)
dkato 0:f782d9c66c49 523 else:
dkato 0:f782d9c66c49 524 res, _ = toolchain.link_program(resources, build_path, name)
dkato 0:f782d9c66c49 525
dkato 0:f782d9c66c49 526 memap_instance = getattr(toolchain, 'memap_instance', None)
dkato 0:f782d9c66c49 527 memap_table = ''
dkato 0:f782d9c66c49 528 if memap_instance:
dkato 0:f782d9c66c49 529 # Write output to stdout in text (pretty table) format
dkato 0:f782d9c66c49 530 memap_table = memap_instance.generate_output('table')
dkato 0:f782d9c66c49 531
dkato 0:f782d9c66c49 532 if not silent:
dkato 0:f782d9c66c49 533 print memap_table
dkato 0:f782d9c66c49 534
dkato 0:f782d9c66c49 535 # Write output to file in JSON format
dkato 0:f782d9c66c49 536 map_out = join(build_path, name + "_map.json")
dkato 0:f782d9c66c49 537 memap_instance.generate_output('json', map_out)
dkato 0:f782d9c66c49 538
dkato 0:f782d9c66c49 539 # Write output to file in CSV format for the CI
dkato 0:f782d9c66c49 540 map_csv = join(build_path, name + "_map.csv")
dkato 0:f782d9c66c49 541 memap_instance.generate_output('csv-ci', map_csv)
dkato 0:f782d9c66c49 542
dkato 0:f782d9c66c49 543 resources.detect_duplicates(toolchain)
dkato 0:f782d9c66c49 544
dkato 0:f782d9c66c49 545 if report != None:
dkato 0:f782d9c66c49 546 end = time()
dkato 0:f782d9c66c49 547 cur_result["elapsed_time"] = end - start
dkato 0:f782d9c66c49 548 cur_result["output"] = toolchain.get_output() + memap_table
dkato 0:f782d9c66c49 549 cur_result["result"] = "OK"
dkato 0:f782d9c66c49 550 cur_result["memory_usage"] = toolchain.map_outputs
dkato 0:f782d9c66c49 551
dkato 0:f782d9c66c49 552 add_result_to_report(report, cur_result)
dkato 0:f782d9c66c49 553
dkato 0:f782d9c66c49 554 return res
dkato 0:f782d9c66c49 555
dkato 0:f782d9c66c49 556 except Exception as exc:
dkato 0:f782d9c66c49 557 if report != None:
dkato 0:f782d9c66c49 558 end = time()
dkato 0:f782d9c66c49 559
dkato 0:f782d9c66c49 560 if isinstance(exc, NotSupportedException):
dkato 0:f782d9c66c49 561 cur_result["result"] = "NOT_SUPPORTED"
dkato 0:f782d9c66c49 562 else:
dkato 0:f782d9c66c49 563 cur_result["result"] = "FAIL"
dkato 0:f782d9c66c49 564
dkato 0:f782d9c66c49 565 cur_result["elapsed_time"] = end - start
dkato 0:f782d9c66c49 566
dkato 0:f782d9c66c49 567 toolchain_output = toolchain.get_output()
dkato 0:f782d9c66c49 568 if toolchain_output:
dkato 0:f782d9c66c49 569 cur_result["output"] += toolchain_output
dkato 0:f782d9c66c49 570
dkato 0:f782d9c66c49 571 add_result_to_report(report, cur_result)
dkato 0:f782d9c66c49 572
dkato 0:f782d9c66c49 573 # Let Exception propagate
dkato 0:f782d9c66c49 574 raise
dkato 0:f782d9c66c49 575
dkato 0:f782d9c66c49 576 def build_library(src_paths, build_path, target, toolchain_name,
dkato 0:f782d9c66c49 577 dependencies_paths=None, name=None, clean=False,
dkato 0:f782d9c66c49 578 archive=True, notify=None, verbose=False, macros=None,
dkato 0:f782d9c66c49 579 inc_dirs=None, jobs=1, silent=False, report=None,
dkato 0:f782d9c66c49 580 properties=None, extra_verbose=False, project_id=None,
dkato 0:f782d9c66c49 581 remove_config_header_file=False, app_config=None,
dkato 0:f782d9c66c49 582 build_profile=None):
dkato 0:f782d9c66c49 583 """ Build a library
dkato 0:f782d9c66c49 584
dkato 0:f782d9c66c49 585 Positional arguments:
dkato 0:f782d9c66c49 586 src_paths - a path or list of paths that contain all files needed to build
dkato 0:f782d9c66c49 587 the library
dkato 0:f782d9c66c49 588 build_path - the directory where all of the object files will be placed
dkato 0:f782d9c66c49 589 target - the MCU or board that the project will compile for
dkato 0:f782d9c66c49 590 toolchain_name - the name of the build tools
dkato 0:f782d9c66c49 591
dkato 0:f782d9c66c49 592 Keyword arguments:
dkato 0:f782d9c66c49 593 dependencies_paths - The location of libraries to include when linking
dkato 0:f782d9c66c49 594 name - the name of the library
dkato 0:f782d9c66c49 595 clean - Rebuild everything if True
dkato 0:f782d9c66c49 596 archive - whether the library will create an archive file
dkato 0:f782d9c66c49 597 notify - Notify function for logs
dkato 0:f782d9c66c49 598 verbose - Write the actual tools command lines used if True
dkato 0:f782d9c66c49 599 macros - additional macros
dkato 0:f782d9c66c49 600 inc_dirs - additional directories where include files may be found
dkato 0:f782d9c66c49 601 jobs - how many compilers we can run at once
dkato 0:f782d9c66c49 602 silent - suppress printing of progress indicators
dkato 0:f782d9c66c49 603 report - a dict where a result may be appended
dkato 0:f782d9c66c49 604 properties - UUUUHHHHH beats me
dkato 0:f782d9c66c49 605 extra_verbose - even more output!
dkato 0:f782d9c66c49 606 project_id - the name that goes in the report
dkato 0:f782d9c66c49 607 remove_config_header_file - delete config header file when done building
dkato 0:f782d9c66c49 608 app_config - location of a chosen mbed_app.json file
dkato 0:f782d9c66c49 609 build_profile - a dict of flags that will be passed to the compiler
dkato 0:f782d9c66c49 610 """
dkato 0:f782d9c66c49 611
dkato 0:f782d9c66c49 612 # Convert src_path to a list if needed
dkato 0:f782d9c66c49 613 if type(src_paths) != ListType:
dkato 0:f782d9c66c49 614 src_paths = [src_paths]
dkato 0:f782d9c66c49 615
dkato 0:f782d9c66c49 616 # Build path
dkato 0:f782d9c66c49 617 if archive:
dkato 0:f782d9c66c49 618 # Use temp path when building archive
dkato 0:f782d9c66c49 619 tmp_path = join(build_path, '.temp')
dkato 0:f782d9c66c49 620 mkdir(tmp_path)
dkato 0:f782d9c66c49 621 else:
dkato 0:f782d9c66c49 622 tmp_path = build_path
dkato 0:f782d9c66c49 623
dkato 0:f782d9c66c49 624 # Clean the build directory
dkato 0:f782d9c66c49 625 if clean and exists(tmp_path):
dkato 0:f782d9c66c49 626 rmtree(tmp_path)
dkato 0:f782d9c66c49 627 mkdir(tmp_path)
dkato 0:f782d9c66c49 628
dkato 0:f782d9c66c49 629 # Pass all params to the unified prepare_toolchain()
dkato 0:f782d9c66c49 630 toolchain = prepare_toolchain(
dkato 0:f782d9c66c49 631 src_paths, build_path, target, toolchain_name, macros=macros,
dkato 0:f782d9c66c49 632 clean=clean, jobs=jobs, notify=notify, silent=silent,
dkato 0:f782d9c66c49 633 verbose=verbose, extra_verbose=extra_verbose, app_config=app_config,
dkato 0:f782d9c66c49 634 build_profile=build_profile)
dkato 0:f782d9c66c49 635
dkato 0:f782d9c66c49 636 # The first path will give the name to the library
dkato 0:f782d9c66c49 637 if name is None:
dkato 0:f782d9c66c49 638 name = basename(normpath(abspath(src_paths[0])))
dkato 0:f782d9c66c49 639 toolchain.info("Building library %s (%s, %s)" %
dkato 0:f782d9c66c49 640 (name, toolchain.target.name, toolchain_name))
dkato 0:f782d9c66c49 641
dkato 0:f782d9c66c49 642 # Initialize reporting
dkato 0:f782d9c66c49 643 if report != None:
dkato 0:f782d9c66c49 644 start = time()
dkato 0:f782d9c66c49 645 # If project_id is specified, use that over the default name
dkato 0:f782d9c66c49 646 id_name = project_id.upper() if project_id else name.upper()
dkato 0:f782d9c66c49 647 description = name
dkato 0:f782d9c66c49 648 vendor_label = toolchain.target.extra_labels[0]
dkato 0:f782d9c66c49 649 prep_report(report, toolchain.target.name, toolchain_name, id_name)
dkato 0:f782d9c66c49 650 cur_result = create_result(toolchain.target.name, toolchain_name,
dkato 0:f782d9c66c49 651 id_name, description)
dkato 0:f782d9c66c49 652 if properties != None:
dkato 0:f782d9c66c49 653 prep_properties(properties, toolchain.target.name, toolchain_name,
dkato 0:f782d9c66c49 654 vendor_label)
dkato 0:f782d9c66c49 655
dkato 0:f782d9c66c49 656 for src_path in src_paths:
dkato 0:f782d9c66c49 657 if not exists(src_path):
dkato 0:f782d9c66c49 658 error_msg = "The library source folder does not exist: %s", src_path
dkato 0:f782d9c66c49 659 if report != None:
dkato 0:f782d9c66c49 660 cur_result["output"] = error_msg
dkato 0:f782d9c66c49 661 cur_result["result"] = "FAIL"
dkato 0:f782d9c66c49 662 add_result_to_report(report, cur_result)
dkato 0:f782d9c66c49 663 raise Exception(error_msg)
dkato 0:f782d9c66c49 664
dkato 0:f782d9c66c49 665 try:
dkato 0:f782d9c66c49 666 # Call unified scan_resources
dkato 0:f782d9c66c49 667 resources = scan_resources(src_paths, toolchain,
dkato 0:f782d9c66c49 668 dependencies_paths=dependencies_paths,
dkato 0:f782d9c66c49 669 inc_dirs=inc_dirs)
dkato 0:f782d9c66c49 670
dkato 0:f782d9c66c49 671
dkato 0:f782d9c66c49 672 # Copy headers, objects and static libraries - all files needed for
dkato 0:f782d9c66c49 673 # static lib
dkato 0:f782d9c66c49 674 toolchain.copy_files(resources.headers, build_path, resources=resources)
dkato 0:f782d9c66c49 675 toolchain.copy_files(resources.objects, build_path, resources=resources)
dkato 0:f782d9c66c49 676 toolchain.copy_files(resources.libraries, build_path,
dkato 0:f782d9c66c49 677 resources=resources)
dkato 0:f782d9c66c49 678 toolchain.copy_files(resources.json_files, build_path,
dkato 0:f782d9c66c49 679 resources=resources)
dkato 0:f782d9c66c49 680 if resources.linker_script:
dkato 0:f782d9c66c49 681 toolchain.copy_files(resources.linker_script, build_path,
dkato 0:f782d9c66c49 682 resources=resources)
dkato 0:f782d9c66c49 683
dkato 0:f782d9c66c49 684 if resources.hex_files:
dkato 0:f782d9c66c49 685 toolchain.copy_files(resources.hex_files, build_path,
dkato 0:f782d9c66c49 686 resources=resources)
dkato 0:f782d9c66c49 687
dkato 0:f782d9c66c49 688 # Compile Sources
dkato 0:f782d9c66c49 689 objects = toolchain.compile_sources(resources, resources.inc_dirs)
dkato 0:f782d9c66c49 690 resources.objects.extend(objects)
dkato 0:f782d9c66c49 691
dkato 0:f782d9c66c49 692 if archive:
dkato 0:f782d9c66c49 693 toolchain.build_library(objects, build_path, name)
dkato 0:f782d9c66c49 694
dkato 0:f782d9c66c49 695 if remove_config_header_file:
dkato 0:f782d9c66c49 696 config_header_path = toolchain.get_config_header()
dkato 0:f782d9c66c49 697 if config_header_path:
dkato 0:f782d9c66c49 698 remove(config_header_path)
dkato 0:f782d9c66c49 699
dkato 0:f782d9c66c49 700 if report != None:
dkato 0:f782d9c66c49 701 end = time()
dkato 0:f782d9c66c49 702 cur_result["elapsed_time"] = end - start
dkato 0:f782d9c66c49 703 cur_result["output"] = toolchain.get_output()
dkato 0:f782d9c66c49 704 cur_result["result"] = "OK"
dkato 0:f782d9c66c49 705
dkato 0:f782d9c66c49 706
dkato 0:f782d9c66c49 707 add_result_to_report(report, cur_result)
dkato 0:f782d9c66c49 708 return True
dkato 0:f782d9c66c49 709
dkato 0:f782d9c66c49 710 except Exception as exc:
dkato 0:f782d9c66c49 711 if report != None:
dkato 0:f782d9c66c49 712 end = time()
dkato 0:f782d9c66c49 713
dkato 0:f782d9c66c49 714 if isinstance(exc, ToolException):
dkato 0:f782d9c66c49 715 cur_result["result"] = "FAIL"
dkato 0:f782d9c66c49 716 elif isinstance(exc, NotSupportedException):
dkato 0:f782d9c66c49 717 cur_result["result"] = "NOT_SUPPORTED"
dkato 0:f782d9c66c49 718
dkato 0:f782d9c66c49 719 cur_result["elapsed_time"] = end - start
dkato 0:f782d9c66c49 720
dkato 0:f782d9c66c49 721 toolchain_output = toolchain.get_output()
dkato 0:f782d9c66c49 722 if toolchain_output:
dkato 0:f782d9c66c49 723 cur_result["output"] += toolchain_output
dkato 0:f782d9c66c49 724
dkato 0:f782d9c66c49 725 add_result_to_report(report, cur_result)
dkato 0:f782d9c66c49 726
dkato 0:f782d9c66c49 727 # Let Exception propagate
dkato 0:f782d9c66c49 728 raise
dkato 0:f782d9c66c49 729
dkato 0:f782d9c66c49 730 ######################
dkato 0:f782d9c66c49 731 ### Legacy methods ###
dkato 0:f782d9c66c49 732 ######################
dkato 0:f782d9c66c49 733
dkato 0:f782d9c66c49 734 def mbed2_obj_path(target_name, toolchain_name):
dkato 0:f782d9c66c49 735 real_tc_name = TOOLCHAIN_CLASSES[toolchain_name].__name__
dkato 0:f782d9c66c49 736 return join("TARGET_" + target_name, "TOOLCHAIN_" + real_tc_name)
dkato 0:f782d9c66c49 737
dkato 0:f782d9c66c49 738 def build_lib(lib_id, target, toolchain_name, verbose=False,
dkato 0:f782d9c66c49 739 clean=False, macros=None, notify=None, jobs=1, silent=False,
dkato 0:f782d9c66c49 740 report=None, properties=None, extra_verbose=False,
dkato 0:f782d9c66c49 741 build_profile=None):
dkato 0:f782d9c66c49 742 """ Legacy method for building mbed libraries
dkato 0:f782d9c66c49 743
dkato 0:f782d9c66c49 744 Positional arguments:
dkato 0:f782d9c66c49 745 lib_id - the library's unique identifier
dkato 0:f782d9c66c49 746 target - the MCU or board that the project will compile for
dkato 0:f782d9c66c49 747 toolchain_name - the name of the build tools
dkato 0:f782d9c66c49 748
dkato 0:f782d9c66c49 749 Keyword arguments:
dkato 0:f782d9c66c49 750 clean - Rebuild everything if True
dkato 0:f782d9c66c49 751 verbose - Write the actual tools command lines used if True
dkato 0:f782d9c66c49 752 macros - additional macros
dkato 0:f782d9c66c49 753 notify - Notify function for logs
dkato 0:f782d9c66c49 754 jobs - how many compilers we can run at once
dkato 0:f782d9c66c49 755 silent - suppress printing of progress indicators
dkato 0:f782d9c66c49 756 report - a dict where a result may be appended
dkato 0:f782d9c66c49 757 properties - UUUUHHHHH beats me
dkato 0:f782d9c66c49 758 extra_verbose - even more output!
dkato 0:f782d9c66c49 759 build_profile - a dict of flags that will be passed to the compiler
dkato 0:f782d9c66c49 760 """
dkato 0:f782d9c66c49 761 lib = Library(lib_id)
dkato 0:f782d9c66c49 762 if not lib.is_supported(target, toolchain_name):
dkato 0:f782d9c66c49 763 print('Library "%s" is not yet supported on target %s with toolchain %s'
dkato 0:f782d9c66c49 764 % (lib_id, target.name, toolchain_name))
dkato 0:f782d9c66c49 765 return False
dkato 0:f782d9c66c49 766
dkato 0:f782d9c66c49 767 # We need to combine macros from parameter list with macros from library
dkato 0:f782d9c66c49 768 # definition
dkato 0:f782d9c66c49 769 lib_macros = lib.macros if lib.macros else []
dkato 0:f782d9c66c49 770 if macros:
dkato 0:f782d9c66c49 771 macros.extend(lib_macros)
dkato 0:f782d9c66c49 772 else:
dkato 0:f782d9c66c49 773 macros = lib_macros
dkato 0:f782d9c66c49 774
dkato 0:f782d9c66c49 775 src_paths = lib.source_dir
dkato 0:f782d9c66c49 776 build_path = lib.build_dir
dkato 0:f782d9c66c49 777 dependencies_paths = lib.dependencies
dkato 0:f782d9c66c49 778 inc_dirs = lib.inc_dirs
dkato 0:f782d9c66c49 779 inc_dirs_ext = lib.inc_dirs_ext
dkato 0:f782d9c66c49 780
dkato 0:f782d9c66c49 781 if type(src_paths) != ListType:
dkato 0:f782d9c66c49 782 src_paths = [src_paths]
dkato 0:f782d9c66c49 783
dkato 0:f782d9c66c49 784 # The first path will give the name to the library
dkato 0:f782d9c66c49 785 name = basename(src_paths[0])
dkato 0:f782d9c66c49 786
dkato 0:f782d9c66c49 787 if report != None:
dkato 0:f782d9c66c49 788 start = time()
dkato 0:f782d9c66c49 789 id_name = name.upper()
dkato 0:f782d9c66c49 790 description = name
dkato 0:f782d9c66c49 791 vendor_label = target.extra_labels[0]
dkato 0:f782d9c66c49 792 cur_result = None
dkato 0:f782d9c66c49 793 prep_report(report, target.name, toolchain_name, id_name)
dkato 0:f782d9c66c49 794 cur_result = create_result(target.name, toolchain_name, id_name,
dkato 0:f782d9c66c49 795 description)
dkato 0:f782d9c66c49 796
dkato 0:f782d9c66c49 797 if properties != None:
dkato 0:f782d9c66c49 798 prep_properties(properties, target.name, toolchain_name,
dkato 0:f782d9c66c49 799 vendor_label)
dkato 0:f782d9c66c49 800
dkato 0:f782d9c66c49 801 for src_path in src_paths:
dkato 0:f782d9c66c49 802 if not exists(src_path):
dkato 0:f782d9c66c49 803 error_msg = "The library source folder does not exist: %s", src_path
dkato 0:f782d9c66c49 804
dkato 0:f782d9c66c49 805 if report != None:
dkato 0:f782d9c66c49 806 cur_result["output"] = error_msg
dkato 0:f782d9c66c49 807 cur_result["result"] = "FAIL"
dkato 0:f782d9c66c49 808 add_result_to_report(report, cur_result)
dkato 0:f782d9c66c49 809
dkato 0:f782d9c66c49 810 raise Exception(error_msg)
dkato 0:f782d9c66c49 811
dkato 0:f782d9c66c49 812 try:
dkato 0:f782d9c66c49 813 # Toolchain instance
dkato 0:f782d9c66c49 814 # Create the desired build directory structure
dkato 0:f782d9c66c49 815 bin_path = join(build_path, mbed2_obj_path(target.name, toolchain_name))
dkato 0:f782d9c66c49 816 mkdir(bin_path)
dkato 0:f782d9c66c49 817 tmp_path = join(build_path, '.temp', mbed2_obj_path(target.name,
dkato 0:f782d9c66c49 818 toolchain_name))
dkato 0:f782d9c66c49 819 mkdir(tmp_path)
dkato 0:f782d9c66c49 820
dkato 0:f782d9c66c49 821 toolchain = prepare_toolchain(
dkato 0:f782d9c66c49 822 src_paths, tmp_path, target, toolchain_name, macros=macros,
dkato 0:f782d9c66c49 823 notify=notify, silent=silent, extra_verbose=extra_verbose,
dkato 0:f782d9c66c49 824 build_profile=build_profile, jobs=jobs, clean=clean)
dkato 0:f782d9c66c49 825
dkato 0:f782d9c66c49 826 toolchain.info("Building library %s (%s, %s)" %
dkato 0:f782d9c66c49 827 (name.upper(), target.name, toolchain_name))
dkato 0:f782d9c66c49 828
dkato 0:f782d9c66c49 829 # Take into account the library configuration (MBED_CONFIG_FILE)
dkato 0:f782d9c66c49 830 config = toolchain.config
dkato 0:f782d9c66c49 831 config.add_config_files([MBED_CONFIG_FILE])
dkato 0:f782d9c66c49 832
dkato 0:f782d9c66c49 833 # Scan Resources
dkato 0:f782d9c66c49 834 resources = []
dkato 0:f782d9c66c49 835 for src_path in src_paths:
dkato 0:f782d9c66c49 836 resources.append(toolchain.scan_resources(src_path))
dkato 0:f782d9c66c49 837
dkato 0:f782d9c66c49 838 # Add extra include directories / files which are required by library
dkato 0:f782d9c66c49 839 # This files usually are not in the same directory as source files so
dkato 0:f782d9c66c49 840 # previous scan will not include them
dkato 0:f782d9c66c49 841 if inc_dirs_ext is not None:
dkato 0:f782d9c66c49 842 for inc_ext in inc_dirs_ext:
dkato 0:f782d9c66c49 843 resources.append(toolchain.scan_resources(inc_ext))
dkato 0:f782d9c66c49 844
dkato 0:f782d9c66c49 845 # Dependencies Include Paths
dkato 0:f782d9c66c49 846 dependencies_include_dir = []
dkato 0:f782d9c66c49 847 if dependencies_paths is not None:
dkato 0:f782d9c66c49 848 for path in dependencies_paths:
dkato 0:f782d9c66c49 849 lib_resources = toolchain.scan_resources(path)
dkato 0:f782d9c66c49 850 dependencies_include_dir.extend(lib_resources.inc_dirs)
dkato 0:f782d9c66c49 851 dependencies_include_dir.extend(map(dirname, lib_resources.inc_dirs))
dkato 0:f782d9c66c49 852
dkato 0:f782d9c66c49 853 if inc_dirs:
dkato 0:f782d9c66c49 854 dependencies_include_dir.extend(inc_dirs)
dkato 0:f782d9c66c49 855
dkato 0:f782d9c66c49 856 # Add other discovered configuration data to the configuration object
dkato 0:f782d9c66c49 857 for res in resources:
dkato 0:f782d9c66c49 858 config.load_resources(res)
dkato 0:f782d9c66c49 859 toolchain.set_config_data(toolchain.config.get_config_data())
dkato 0:f782d9c66c49 860
dkato 0:f782d9c66c49 861
dkato 0:f782d9c66c49 862 # Copy Headers
dkato 0:f782d9c66c49 863 for resource in resources:
dkato 0:f782d9c66c49 864 toolchain.copy_files(resource.headers, build_path,
dkato 0:f782d9c66c49 865 resources=resource)
dkato 0:f782d9c66c49 866
dkato 0:f782d9c66c49 867 dependencies_include_dir.extend(
dkato 0:f782d9c66c49 868 toolchain.scan_resources(build_path).inc_dirs)
dkato 0:f782d9c66c49 869
dkato 0:f782d9c66c49 870 # Compile Sources
dkato 0:f782d9c66c49 871 objects = []
dkato 0:f782d9c66c49 872 for resource in resources:
dkato 0:f782d9c66c49 873 objects.extend(toolchain.compile_sources(resource, dependencies_include_dir))
dkato 0:f782d9c66c49 874
dkato 0:f782d9c66c49 875 needed_update = toolchain.build_library(objects, bin_path, name)
dkato 0:f782d9c66c49 876
dkato 0:f782d9c66c49 877 if report != None and needed_update:
dkato 0:f782d9c66c49 878 end = time()
dkato 0:f782d9c66c49 879 cur_result["elapsed_time"] = end - start
dkato 0:f782d9c66c49 880 cur_result["output"] = toolchain.get_output()
dkato 0:f782d9c66c49 881 cur_result["result"] = "OK"
dkato 0:f782d9c66c49 882
dkato 0:f782d9c66c49 883 add_result_to_report(report, cur_result)
dkato 0:f782d9c66c49 884 return True
dkato 0:f782d9c66c49 885
dkato 0:f782d9c66c49 886 except Exception:
dkato 0:f782d9c66c49 887 if report != None:
dkato 0:f782d9c66c49 888 end = time()
dkato 0:f782d9c66c49 889 cur_result["result"] = "FAIL"
dkato 0:f782d9c66c49 890 cur_result["elapsed_time"] = end - start
dkato 0:f782d9c66c49 891
dkato 0:f782d9c66c49 892 toolchain_output = toolchain.get_output()
dkato 0:f782d9c66c49 893 if toolchain_output:
dkato 0:f782d9c66c49 894 cur_result["output"] += toolchain_output
dkato 0:f782d9c66c49 895
dkato 0:f782d9c66c49 896 add_result_to_report(report, cur_result)
dkato 0:f782d9c66c49 897
dkato 0:f782d9c66c49 898 # Let Exception propagate
dkato 0:f782d9c66c49 899 raise
dkato 0:f782d9c66c49 900
dkato 0:f782d9c66c49 901 # We do have unique legacy conventions about how we build and package the mbed
dkato 0:f782d9c66c49 902 # library
dkato 0:f782d9c66c49 903 def build_mbed_libs(target, toolchain_name, verbose=False,
dkato 0:f782d9c66c49 904 clean=False, macros=None, notify=None, jobs=1, silent=False,
dkato 0:f782d9c66c49 905 report=None, properties=None, extra_verbose=False,
dkato 0:f782d9c66c49 906 build_profile=None):
dkato 0:f782d9c66c49 907 """ Function returns True is library was built and false if building was
dkato 0:f782d9c66c49 908 skipped
dkato 0:f782d9c66c49 909
dkato 0:f782d9c66c49 910 Positional arguments:
dkato 0:f782d9c66c49 911 target - the MCU or board that the project will compile for
dkato 0:f782d9c66c49 912 toolchain_name - the name of the build tools
dkato 0:f782d9c66c49 913
dkato 0:f782d9c66c49 914 Keyword arguments:
dkato 0:f782d9c66c49 915 verbose - Write the actual tools command lines used if True
dkato 0:f782d9c66c49 916 clean - Rebuild everything if True
dkato 0:f782d9c66c49 917 macros - additional macros
dkato 0:f782d9c66c49 918 notify - Notify function for logs
dkato 0:f782d9c66c49 919 jobs - how many compilers we can run at once
dkato 0:f782d9c66c49 920 silent - suppress printing of progress indicators
dkato 0:f782d9c66c49 921 report - a dict where a result may be appended
dkato 0:f782d9c66c49 922 properties - UUUUHHHHH beats me
dkato 0:f782d9c66c49 923 extra_verbose - even more output!
dkato 0:f782d9c66c49 924 build_profile - a dict of flags that will be passed to the compiler
dkato 0:f782d9c66c49 925 """
dkato 0:f782d9c66c49 926
dkato 0:f782d9c66c49 927 if report != None:
dkato 0:f782d9c66c49 928 start = time()
dkato 0:f782d9c66c49 929 id_name = "MBED"
dkato 0:f782d9c66c49 930 description = "mbed SDK"
dkato 0:f782d9c66c49 931 vendor_label = target.extra_labels[0]
dkato 0:f782d9c66c49 932 cur_result = None
dkato 0:f782d9c66c49 933 prep_report(report, target.name, toolchain_name, id_name)
dkato 0:f782d9c66c49 934 cur_result = create_result(target.name, toolchain_name, id_name,
dkato 0:f782d9c66c49 935 description)
dkato 0:f782d9c66c49 936
dkato 0:f782d9c66c49 937 if properties != None:
dkato 0:f782d9c66c49 938 prep_properties(properties, target.name, toolchain_name,
dkato 0:f782d9c66c49 939 vendor_label)
dkato 0:f782d9c66c49 940
dkato 0:f782d9c66c49 941 # Check toolchain support
dkato 0:f782d9c66c49 942 if toolchain_name not in target.supported_toolchains:
dkato 0:f782d9c66c49 943 supported_toolchains_text = ", ".join(target.supported_toolchains)
dkato 0:f782d9c66c49 944 print('%s target is not yet supported by toolchain %s' %
dkato 0:f782d9c66c49 945 (target.name, toolchain_name))
dkato 0:f782d9c66c49 946 print('%s target supports %s toolchain%s' %
dkato 0:f782d9c66c49 947 (target.name, supported_toolchains_text, 's'
dkato 0:f782d9c66c49 948 if len(target.supported_toolchains) > 1 else ''))
dkato 0:f782d9c66c49 949
dkato 0:f782d9c66c49 950 if report != None:
dkato 0:f782d9c66c49 951 cur_result["result"] = "SKIP"
dkato 0:f782d9c66c49 952 add_result_to_report(report, cur_result)
dkato 0:f782d9c66c49 953
dkato 0:f782d9c66c49 954 return False
dkato 0:f782d9c66c49 955
dkato 0:f782d9c66c49 956 try:
dkato 0:f782d9c66c49 957 # Source and Build Paths
dkato 0:f782d9c66c49 958 build_target = join(MBED_LIBRARIES, "TARGET_" + target.name)
dkato 0:f782d9c66c49 959 build_toolchain = join(MBED_LIBRARIES, mbed2_obj_path(target.name, toolchain_name))
dkato 0:f782d9c66c49 960 mkdir(build_toolchain)
dkato 0:f782d9c66c49 961
dkato 0:f782d9c66c49 962 # Toolchain
dkato 0:f782d9c66c49 963 tmp_path = join(MBED_LIBRARIES, '.temp', mbed2_obj_path(target.name, toolchain_name))
dkato 0:f782d9c66c49 964 mkdir(tmp_path)
dkato 0:f782d9c66c49 965
dkato 0:f782d9c66c49 966 toolchain = prepare_toolchain(
dkato 0:f782d9c66c49 967 [""], tmp_path, target, toolchain_name, macros=macros,
dkato 0:f782d9c66c49 968 notify=notify, silent=silent, extra_verbose=extra_verbose,
dkato 0:f782d9c66c49 969 build_profile=build_profile, jobs=jobs, clean=clean)
dkato 0:f782d9c66c49 970
dkato 0:f782d9c66c49 971 # Take into account the library configuration (MBED_CONFIG_FILE)
dkato 0:f782d9c66c49 972 config = toolchain.config
dkato 0:f782d9c66c49 973 config.add_config_files([MBED_CONFIG_FILE])
dkato 0:f782d9c66c49 974 toolchain.set_config_data(toolchain.config.get_config_data())
dkato 0:f782d9c66c49 975
dkato 0:f782d9c66c49 976 # CMSIS
dkato 0:f782d9c66c49 977 toolchain.info("Building library %s (%s, %s)" %
dkato 0:f782d9c66c49 978 ('CMSIS', target.name, toolchain_name))
dkato 0:f782d9c66c49 979 cmsis_src = MBED_CMSIS_PATH
dkato 0:f782d9c66c49 980 resources = toolchain.scan_resources(cmsis_src)
dkato 0:f782d9c66c49 981
dkato 0:f782d9c66c49 982 toolchain.copy_files(resources.headers, build_target)
dkato 0:f782d9c66c49 983 toolchain.copy_files(resources.linker_script, build_toolchain)
dkato 0:f782d9c66c49 984 toolchain.copy_files(resources.bin_files, build_toolchain)
dkato 0:f782d9c66c49 985
dkato 0:f782d9c66c49 986 objects = toolchain.compile_sources(resources, tmp_path)
dkato 0:f782d9c66c49 987 toolchain.copy_files(objects, build_toolchain)
dkato 0:f782d9c66c49 988
dkato 0:f782d9c66c49 989 # mbed
dkato 0:f782d9c66c49 990 toolchain.info("Building library %s (%s, %s)" %
dkato 0:f782d9c66c49 991 ('MBED', target.name, toolchain_name))
dkato 0:f782d9c66c49 992
dkato 0:f782d9c66c49 993 # Common Headers
dkato 0:f782d9c66c49 994 toolchain.copy_files([MBED_HEADER], MBED_LIBRARIES)
dkato 0:f782d9c66c49 995 library_incdirs = [dirname(MBED_LIBRARIES), MBED_LIBRARIES]
dkato 0:f782d9c66c49 996
dkato 0:f782d9c66c49 997 for dir, dest in [(MBED_DRIVERS, MBED_LIBRARIES_DRIVERS),
dkato 0:f782d9c66c49 998 (MBED_PLATFORM, MBED_LIBRARIES_PLATFORM),
dkato 0:f782d9c66c49 999 (MBED_HAL, MBED_LIBRARIES_HAL)]:
dkato 0:f782d9c66c49 1000 resources = toolchain.scan_resources(dir)
dkato 0:f782d9c66c49 1001 toolchain.copy_files(resources.headers, dest)
dkato 0:f782d9c66c49 1002 library_incdirs.append(dest)
dkato 0:f782d9c66c49 1003
dkato 0:f782d9c66c49 1004 # Target specific sources
dkato 0:f782d9c66c49 1005 hal_src = MBED_TARGETS_PATH
dkato 0:f782d9c66c49 1006 hal_implementation = toolchain.scan_resources(hal_src)
dkato 0:f782d9c66c49 1007 toolchain.copy_files(hal_implementation.headers +
dkato 0:f782d9c66c49 1008 hal_implementation.hex_files +
dkato 0:f782d9c66c49 1009 hal_implementation.libraries +
dkato 0:f782d9c66c49 1010 [MBED_CONFIG_FILE],
dkato 0:f782d9c66c49 1011 build_target, resources=hal_implementation)
dkato 0:f782d9c66c49 1012 toolchain.copy_files(hal_implementation.linker_script, build_toolchain)
dkato 0:f782d9c66c49 1013 toolchain.copy_files(hal_implementation.bin_files, build_toolchain)
dkato 0:f782d9c66c49 1014 incdirs = toolchain.scan_resources(build_target).inc_dirs
dkato 0:f782d9c66c49 1015 objects = toolchain.compile_sources(hal_implementation,
dkato 0:f782d9c66c49 1016 library_incdirs + incdirs)
dkato 0:f782d9c66c49 1017 toolchain.copy_files(objects, build_toolchain)
dkato 0:f782d9c66c49 1018
dkato 0:f782d9c66c49 1019 # Common Sources
dkato 0:f782d9c66c49 1020 mbed_resources = None
dkato 0:f782d9c66c49 1021 for dir in [MBED_DRIVERS, MBED_PLATFORM, MBED_HAL]:
dkato 0:f782d9c66c49 1022 mbed_resources += toolchain.scan_resources(dir)
dkato 0:f782d9c66c49 1023
dkato 0:f782d9c66c49 1024 objects = toolchain.compile_sources(mbed_resources,
dkato 0:f782d9c66c49 1025 library_incdirs + incdirs)
dkato 0:f782d9c66c49 1026
dkato 0:f782d9c66c49 1027 # A number of compiled files need to be copied as objects as opposed to
dkato 0:f782d9c66c49 1028 # way the linker search for symbols in archives. These are:
dkato 0:f782d9c66c49 1029 # - retarget.o: to make sure that the C standard lib symbols get
dkato 0:f782d9c66c49 1030 # overridden
dkato 0:f782d9c66c49 1031 # - board.o: mbed_die is weak
dkato 0:f782d9c66c49 1032 # - mbed_overrides.o: this contains platform overrides of various
dkato 0:f782d9c66c49 1033 # weak SDK functions
dkato 0:f782d9c66c49 1034 separate_names, separate_objects = ['retarget.o', 'board.o',
dkato 0:f782d9c66c49 1035 'mbed_overrides.o'], []
dkato 0:f782d9c66c49 1036
dkato 0:f782d9c66c49 1037 for obj in objects:
dkato 0:f782d9c66c49 1038 for name in separate_names:
dkato 0:f782d9c66c49 1039 if obj.endswith(name):
dkato 0:f782d9c66c49 1040 separate_objects.append(obj)
dkato 0:f782d9c66c49 1041
dkato 0:f782d9c66c49 1042 for obj in separate_objects:
dkato 0:f782d9c66c49 1043 objects.remove(obj)
dkato 0:f782d9c66c49 1044
dkato 0:f782d9c66c49 1045 toolchain.build_library(objects, build_toolchain, "mbed")
dkato 0:f782d9c66c49 1046
dkato 0:f782d9c66c49 1047 for obj in separate_objects:
dkato 0:f782d9c66c49 1048 toolchain.copy_files(obj, build_toolchain)
dkato 0:f782d9c66c49 1049
dkato 0:f782d9c66c49 1050 if report != None:
dkato 0:f782d9c66c49 1051 end = time()
dkato 0:f782d9c66c49 1052 cur_result["elapsed_time"] = end - start
dkato 0:f782d9c66c49 1053 cur_result["output"] = toolchain.get_output()
dkato 0:f782d9c66c49 1054 cur_result["result"] = "OK"
dkato 0:f782d9c66c49 1055
dkato 0:f782d9c66c49 1056 add_result_to_report(report, cur_result)
dkato 0:f782d9c66c49 1057
dkato 0:f782d9c66c49 1058 return True
dkato 0:f782d9c66c49 1059
dkato 0:f782d9c66c49 1060 except Exception as exc:
dkato 0:f782d9c66c49 1061 if report != None:
dkato 0:f782d9c66c49 1062 end = time()
dkato 0:f782d9c66c49 1063 cur_result["result"] = "FAIL"
dkato 0:f782d9c66c49 1064 cur_result["elapsed_time"] = end - start
dkato 0:f782d9c66c49 1065
dkato 0:f782d9c66c49 1066 toolchain_output = toolchain.get_output()
dkato 0:f782d9c66c49 1067 if toolchain_output:
dkato 0:f782d9c66c49 1068 cur_result["output"] += toolchain_output
dkato 0:f782d9c66c49 1069
dkato 0:f782d9c66c49 1070 cur_result["output"] += str(exc)
dkato 0:f782d9c66c49 1071
dkato 0:f782d9c66c49 1072 add_result_to_report(report, cur_result)
dkato 0:f782d9c66c49 1073
dkato 0:f782d9c66c49 1074 # Let Exception propagate
dkato 0:f782d9c66c49 1075 raise
dkato 0:f782d9c66c49 1076
dkato 0:f782d9c66c49 1077
dkato 0:f782d9c66c49 1078 def get_unique_supported_toolchains(release_targets=None):
dkato 0:f782d9c66c49 1079 """ Get list of all unique toolchains supported by targets
dkato 0:f782d9c66c49 1080
dkato 0:f782d9c66c49 1081 Keyword arguments:
dkato 0:f782d9c66c49 1082 release_targets - tuple structure returned from get_mbed_official_release().
dkato 0:f782d9c66c49 1083 If release_targets is not specified, then it queries all
dkato 0:f782d9c66c49 1084 known targets
dkato 0:f782d9c66c49 1085 """
dkato 0:f782d9c66c49 1086 unique_supported_toolchains = []
dkato 0:f782d9c66c49 1087
dkato 0:f782d9c66c49 1088 if not release_targets:
dkato 0:f782d9c66c49 1089 for target in TARGET_NAMES:
dkato 0:f782d9c66c49 1090 for toolchain in TARGET_MAP[target].supported_toolchains:
dkato 0:f782d9c66c49 1091 if toolchain not in unique_supported_toolchains:
dkato 0:f782d9c66c49 1092 unique_supported_toolchains.append(toolchain)
dkato 0:f782d9c66c49 1093 else:
dkato 0:f782d9c66c49 1094 for target in release_targets:
dkato 0:f782d9c66c49 1095 for toolchain in target[1]:
dkato 0:f782d9c66c49 1096 if toolchain not in unique_supported_toolchains:
dkato 0:f782d9c66c49 1097 unique_supported_toolchains.append(toolchain)
dkato 0:f782d9c66c49 1098
dkato 0:f782d9c66c49 1099 return unique_supported_toolchains
dkato 0:f782d9c66c49 1100
dkato 0:f782d9c66c49 1101
dkato 0:f782d9c66c49 1102 def mcu_toolchain_matrix(verbose_html=False, platform_filter=None,
dkato 0:f782d9c66c49 1103 release_version='5'):
dkato 0:f782d9c66c49 1104 """ Shows target map using prettytable
dkato 0:f782d9c66c49 1105
dkato 0:f782d9c66c49 1106 Keyword arguments:
dkato 0:f782d9c66c49 1107 verbose_html - emit html instead of a simple table
dkato 0:f782d9c66c49 1108 platform_filter - remove results that match the string
dkato 0:f782d9c66c49 1109 release_version - get the matrix for this major version number
dkato 0:f782d9c66c49 1110 """
dkato 0:f782d9c66c49 1111 # Only use it in this function so building works without extra modules
dkato 0:f782d9c66c49 1112 from prettytable import PrettyTable
dkato 0:f782d9c66c49 1113
dkato 0:f782d9c66c49 1114 if isinstance(release_version, basestring):
dkato 0:f782d9c66c49 1115 # Force release_version to lowercase if it is a string
dkato 0:f782d9c66c49 1116 release_version = release_version.lower()
dkato 0:f782d9c66c49 1117 else:
dkato 0:f782d9c66c49 1118 # Otherwise default to printing all known targets and toolchains
dkato 0:f782d9c66c49 1119 release_version = 'all'
dkato 0:f782d9c66c49 1120
dkato 0:f782d9c66c49 1121
dkato 0:f782d9c66c49 1122 version_release_targets = {}
dkato 0:f782d9c66c49 1123 version_release_target_names = {}
dkato 0:f782d9c66c49 1124
dkato 0:f782d9c66c49 1125 for version in RELEASE_VERSIONS:
dkato 0:f782d9c66c49 1126 version_release_targets[version] = get_mbed_official_release(version)
dkato 0:f782d9c66c49 1127 version_release_target_names[version] = [x[0] for x in
dkato 0:f782d9c66c49 1128 version_release_targets[
dkato 0:f782d9c66c49 1129 version]]
dkato 0:f782d9c66c49 1130
dkato 0:f782d9c66c49 1131 if release_version in RELEASE_VERSIONS:
dkato 0:f782d9c66c49 1132 release_targets = version_release_targets[release_version]
dkato 0:f782d9c66c49 1133 else:
dkato 0:f782d9c66c49 1134 release_targets = None
dkato 0:f782d9c66c49 1135
dkato 0:f782d9c66c49 1136 unique_supported_toolchains = get_unique_supported_toolchains(
dkato 0:f782d9c66c49 1137 release_targets)
dkato 0:f782d9c66c49 1138 prepend_columns = ["Target"] + ["mbed OS %s" % x for x in RELEASE_VERSIONS]
dkato 0:f782d9c66c49 1139
dkato 0:f782d9c66c49 1140 # All tests status table print
dkato 0:f782d9c66c49 1141 columns = prepend_columns + unique_supported_toolchains
dkato 0:f782d9c66c49 1142 table_printer = PrettyTable(columns)
dkato 0:f782d9c66c49 1143 # Align table
dkato 0:f782d9c66c49 1144 for col in columns:
dkato 0:f782d9c66c49 1145 table_printer.align[col] = "c"
dkato 0:f782d9c66c49 1146 table_printer.align["Target"] = "l"
dkato 0:f782d9c66c49 1147
dkato 0:f782d9c66c49 1148 perm_counter = 0
dkato 0:f782d9c66c49 1149 target_counter = 0
dkato 0:f782d9c66c49 1150
dkato 0:f782d9c66c49 1151 target_names = []
dkato 0:f782d9c66c49 1152
dkato 0:f782d9c66c49 1153 if release_targets:
dkato 0:f782d9c66c49 1154 target_names = [x[0] for x in release_targets]
dkato 0:f782d9c66c49 1155 else:
dkato 0:f782d9c66c49 1156 target_names = TARGET_NAMES
dkato 0:f782d9c66c49 1157
dkato 0:f782d9c66c49 1158 for target in sorted(target_names):
dkato 0:f782d9c66c49 1159 if platform_filter is not None:
dkato 0:f782d9c66c49 1160 # FIlter out platforms using regex
dkato 0:f782d9c66c49 1161 if re.search(platform_filter, target) is None:
dkato 0:f782d9c66c49 1162 continue
dkato 0:f782d9c66c49 1163 target_counter += 1
dkato 0:f782d9c66c49 1164
dkato 0:f782d9c66c49 1165 row = [target] # First column is platform name
dkato 0:f782d9c66c49 1166
dkato 0:f782d9c66c49 1167 for version in RELEASE_VERSIONS:
dkato 0:f782d9c66c49 1168 if target in version_release_target_names[version]:
dkato 0:f782d9c66c49 1169 text = "Supported"
dkato 0:f782d9c66c49 1170 else:
dkato 0:f782d9c66c49 1171 text = "-"
dkato 0:f782d9c66c49 1172 row.append(text)
dkato 0:f782d9c66c49 1173
dkato 0:f782d9c66c49 1174 for unique_toolchain in unique_supported_toolchains:
dkato 0:f782d9c66c49 1175 if unique_toolchain in TARGET_MAP[target].supported_toolchains:
dkato 0:f782d9c66c49 1176 text = "Supported"
dkato 0:f782d9c66c49 1177 perm_counter += 1
dkato 0:f782d9c66c49 1178 else:
dkato 0:f782d9c66c49 1179 text = "-"
dkato 0:f782d9c66c49 1180
dkato 0:f782d9c66c49 1181 row.append(text)
dkato 0:f782d9c66c49 1182 table_printer.add_row(row)
dkato 0:f782d9c66c49 1183
dkato 0:f782d9c66c49 1184 result = table_printer.get_html_string() if verbose_html \
dkato 0:f782d9c66c49 1185 else table_printer.get_string()
dkato 0:f782d9c66c49 1186 result += "\n"
dkato 0:f782d9c66c49 1187 result += "Supported targets: %d\n"% (target_counter)
dkato 0:f782d9c66c49 1188 if target_counter == 1:
dkato 0:f782d9c66c49 1189 result += "Supported toolchains: %d"% (perm_counter)
dkato 0:f782d9c66c49 1190 return result
dkato 0:f782d9c66c49 1191
dkato 0:f782d9c66c49 1192
dkato 0:f782d9c66c49 1193 def get_target_supported_toolchains(target):
dkato 0:f782d9c66c49 1194 """ Returns target supported toolchains list
dkato 0:f782d9c66c49 1195
dkato 0:f782d9c66c49 1196 Positional arguments:
dkato 0:f782d9c66c49 1197 target - the target to get the supported toolchains of
dkato 0:f782d9c66c49 1198 """
dkato 0:f782d9c66c49 1199 return TARGET_MAP[target].supported_toolchains if target in TARGET_MAP \
dkato 0:f782d9c66c49 1200 else None
dkato 0:f782d9c66c49 1201
dkato 0:f782d9c66c49 1202
dkato 0:f782d9c66c49 1203 def print_build_results(result_list, build_name):
dkato 0:f782d9c66c49 1204 """ Generate result string for build results
dkato 0:f782d9c66c49 1205
dkato 0:f782d9c66c49 1206 Positional arguments:
dkato 0:f782d9c66c49 1207 result_list - the list of results to print
dkato 0:f782d9c66c49 1208 build_name - the name of the build we are printing result for
dkato 0:f782d9c66c49 1209 """
dkato 0:f782d9c66c49 1210 result = ""
dkato 0:f782d9c66c49 1211 if len(result_list) > 0:
dkato 0:f782d9c66c49 1212 result += build_name + "\n"
dkato 0:f782d9c66c49 1213 result += "\n".join([" * %s" % f for f in result_list])
dkato 0:f782d9c66c49 1214 result += "\n"
dkato 0:f782d9c66c49 1215 return result
dkato 0:f782d9c66c49 1216
dkato 0:f782d9c66c49 1217 def print_build_memory_usage(report):
dkato 0:f782d9c66c49 1218 """ Generate result table with memory usage values for build results
dkato 0:f782d9c66c49 1219 Aggregates (puts together) reports obtained from self.get_memory_summary()
dkato 0:f782d9c66c49 1220
dkato 0:f782d9c66c49 1221 Positional arguments:
dkato 0:f782d9c66c49 1222 report - Report generated during build procedure.
dkato 0:f782d9c66c49 1223 """
dkato 0:f782d9c66c49 1224 from prettytable import PrettyTable
dkato 0:f782d9c66c49 1225 columns_text = ['name', 'target', 'toolchain']
dkato 0:f782d9c66c49 1226 columns_int = ['static_ram', 'stack', 'heap', 'total_ram', 'total_flash']
dkato 0:f782d9c66c49 1227 table = PrettyTable(columns_text + columns_int)
dkato 0:f782d9c66c49 1228
dkato 0:f782d9c66c49 1229 for col in columns_text:
dkato 0:f782d9c66c49 1230 table.align[col] = 'l'
dkato 0:f782d9c66c49 1231
dkato 0:f782d9c66c49 1232 for col in columns_int:
dkato 0:f782d9c66c49 1233 table.align[col] = 'r'
dkato 0:f782d9c66c49 1234
dkato 0:f782d9c66c49 1235 for target in report:
dkato 0:f782d9c66c49 1236 for toolchain in report[target]:
dkato 0:f782d9c66c49 1237 for name in report[target][toolchain]:
dkato 0:f782d9c66c49 1238 for dlist in report[target][toolchain][name]:
dkato 0:f782d9c66c49 1239 for dlistelem in dlist:
dkato 0:f782d9c66c49 1240 # Get 'memory_usage' record and build table with
dkato 0:f782d9c66c49 1241 # statistics
dkato 0:f782d9c66c49 1242 record = dlist[dlistelem]
dkato 0:f782d9c66c49 1243 if 'memory_usage' in record and record['memory_usage']:
dkato 0:f782d9c66c49 1244 # Note that summary should be in the last record of
dkato 0:f782d9c66c49 1245 # 'memory_usage' section. This is why we are
dkato 0:f782d9c66c49 1246 # grabbing last "[-1]" record.
dkato 0:f782d9c66c49 1247 row = [
dkato 0:f782d9c66c49 1248 record['description'],
dkato 0:f782d9c66c49 1249 record['target_name'],
dkato 0:f782d9c66c49 1250 record['toolchain_name'],
dkato 0:f782d9c66c49 1251 record['memory_usage'][-1]['summary'][
dkato 0:f782d9c66c49 1252 'static_ram'],
dkato 0:f782d9c66c49 1253 record['memory_usage'][-1]['summary']['stack'],
dkato 0:f782d9c66c49 1254 record['memory_usage'][-1]['summary']['heap'],
dkato 0:f782d9c66c49 1255 record['memory_usage'][-1]['summary'][
dkato 0:f782d9c66c49 1256 'total_ram'],
dkato 0:f782d9c66c49 1257 record['memory_usage'][-1]['summary'][
dkato 0:f782d9c66c49 1258 'total_flash'],
dkato 0:f782d9c66c49 1259 ]
dkato 0:f782d9c66c49 1260 table.add_row(row)
dkato 0:f782d9c66c49 1261
dkato 0:f782d9c66c49 1262 result = "Memory map breakdown for built projects (values in Bytes):\n"
dkato 0:f782d9c66c49 1263 result += table.get_string(sortby='name')
dkato 0:f782d9c66c49 1264 return result
dkato 0:f782d9c66c49 1265
dkato 0:f782d9c66c49 1266 def write_build_report(build_report, template_filename, filename):
dkato 0:f782d9c66c49 1267 """Write a build report to disk using a template file
dkato 0:f782d9c66c49 1268
dkato 0:f782d9c66c49 1269 Positional arguments:
dkato 0:f782d9c66c49 1270 build_report - a report generated by the build system
dkato 0:f782d9c66c49 1271 template_filename - a file that contains the template for the style of build
dkato 0:f782d9c66c49 1272 report
dkato 0:f782d9c66c49 1273 filename - the location on disk to write the file to
dkato 0:f782d9c66c49 1274 """
dkato 0:f782d9c66c49 1275 build_report_failing = []
dkato 0:f782d9c66c49 1276 build_report_passing = []
dkato 0:f782d9c66c49 1277
dkato 0:f782d9c66c49 1278 for report in build_report:
dkato 0:f782d9c66c49 1279 if len(report["failing"]) > 0:
dkato 0:f782d9c66c49 1280 build_report_failing.append(report)
dkato 0:f782d9c66c49 1281 else:
dkato 0:f782d9c66c49 1282 build_report_passing.append(report)
dkato 0:f782d9c66c49 1283
dkato 0:f782d9c66c49 1284 env = Environment(extensions=['jinja2.ext.with_'])
dkato 0:f782d9c66c49 1285 env.loader = FileSystemLoader('ci_templates')
dkato 0:f782d9c66c49 1286 template = env.get_template(template_filename)
dkato 0:f782d9c66c49 1287
dkato 0:f782d9c66c49 1288 with open(filename, 'w+') as placeholder:
dkato 0:f782d9c66c49 1289 placeholder.write(template.render(
dkato 0:f782d9c66c49 1290 failing_builds=build_report_failing,
dkato 0:f782d9c66c49 1291 passing_builds=build_report_passing))