5.2.1 - Updated I2C files

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Committer:
jacobjohnson
Date:
Mon Feb 27 17:45:05 2017 +0000
Revision:
1:f30bdcd2b33b
Parent:
0:098463de4c5d
changed the inputscale from 1 to 7 in analogin_api.c.  This will need to be changed later, and accessed from the main level, but for now this allows the  adc to read a value from 0 to 3.7V, instead of just up to 1V.;

Who changed what in which revision?

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