Clone of official tools

Committer:
Anders Blomdell
Date:
Thu Feb 04 17:17:13 2021 +0100
Revision:
47:21ae3e5a7128
Parent:
43:2a7da56ebd24
Add a few normpath calls

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 0:66f3b5499f7f 1 """
screamer 0:66f3b5499f7f 2 mbed SDK
screamer 0:66f3b5499f7f 3 Copyright (c) 2011-2013 ARM Limited
screamer 0:66f3b5499f7f 4
screamer 0:66f3b5499f7f 5 Licensed under the Apache License, Version 2.0 (the "License");
screamer 0:66f3b5499f7f 6 you may not use this file except in compliance with the License.
screamer 0:66f3b5499f7f 7 You may obtain a copy of the License at
screamer 0:66f3b5499f7f 8
screamer 0:66f3b5499f7f 9 http://www.apache.org/licenses/LICENSE-2.0
screamer 0:66f3b5499f7f 10
screamer 0:66f3b5499f7f 11 Unless required by applicable law or agreed to in writing, software
screamer 0:66f3b5499f7f 12 distributed under the License is distributed on an "AS IS" BASIS,
screamer 0:66f3b5499f7f 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
screamer 0:66f3b5499f7f 14 See the License for the specific language governing permissions and
screamer 0:66f3b5499f7f 15 limitations under the License.
screamer 0:66f3b5499f7f 16 """
theotherjimmy 43:2a7da56ebd24 17 from __future__ import print_function, division, absolute_import
screamer 0:66f3b5499f7f 18
screamer 0:66f3b5499f7f 19 import re
screamer 0:66f3b5499f7f 20 import sys
theotherjimmy 43:2a7da56ebd24 21 import json
screamer 24:25bff2709c20 22 from os import stat, walk, getcwd, sep, remove
screamer 0:66f3b5499f7f 23 from copy import copy
screamer 0:66f3b5499f7f 24 from time import time, sleep
screamer 0:66f3b5499f7f 25 from shutil import copyfile
theotherjimmy 43:2a7da56ebd24 26 from os.path import (join, splitext, exists, relpath, dirname, basename, split,
theotherjimmy 43:2a7da56ebd24 27 abspath, isfile, isdir, normcase)
screamer 0:66f3b5499f7f 28 from inspect import getmro
screamer 13:ab47a20b66f0 29 from copy import deepcopy
theotherjimmy 43:2a7da56ebd24 30 from collections import namedtuple
screamer 24:25bff2709c20 31 from abc import ABCMeta, abstractmethod
The Other Jimmy 31:8ea194f6145b 32 from distutils.spawn import find_executable
theotherjimmy 43:2a7da56ebd24 33 from multiprocessing import Pool, cpu_count
theotherjimmy 43:2a7da56ebd24 34 from hashlib import md5
screamer 0:66f3b5499f7f 35
theotherjimmy 43:2a7da56ebd24 36 from ..utils import (run_cmd, mkdir, rel_path, ToolException,
theotherjimmy 43:2a7da56ebd24 37 NotSupportedException, split_path, compile_worker)
theotherjimmy 43:2a7da56ebd24 38 from ..settings import MBED_ORG_USER, PRINT_COMPILER_OUTPUT_AS_LINK
theotherjimmy 43:2a7da56ebd24 39 from .. import hooks
theotherjimmy 43:2a7da56ebd24 40 from ..notifier.term import TerminalNotifier
theotherjimmy 43:2a7da56ebd24 41 from ..resources import FileType
theotherjimmy 43:2a7da56ebd24 42 from ..memap import MemapParser
theotherjimmy 43:2a7da56ebd24 43 from ..config import ConfigException
screamer 0:66f3b5499f7f 44
screamer 0:66f3b5499f7f 45
screamer 0:66f3b5499f7f 46 #Disables multiprocessing if set to higher number than the host machine CPUs
screamer 0:66f3b5499f7f 47 CPU_COUNT_MIN = 1
screamer 21:4fdf0dd04f6f 48 CPU_COEF = 1
screamer 7:5af61d55adbe 49
screamer 0:66f3b5499f7f 50 class mbedToolchain:
screamer 24:25bff2709c20 51 # Verbose logging
screamer 0:66f3b5499f7f 52 VERBOSE = True
screamer 24:25bff2709c20 53
screamer 24:25bff2709c20 54 # Compile C files as CPP
screamer 21:4fdf0dd04f6f 55 COMPILE_C_AS_CPP = False
screamer 24:25bff2709c20 56
screamer 24:25bff2709c20 57 # Response files for compiling, includes, linking and archiving.
screamer 24:25bff2709c20 58 # Not needed on posix systems where the typical arg limit is 2 megabytes
screamer 21:4fdf0dd04f6f 59 RESPONSE_FILES = True
screamer 0:66f3b5499f7f 60
screamer 0:66f3b5499f7f 61 CORTEX_SYMBOLS = {
screamer 0:66f3b5499f7f 62 "Cortex-M0" : ["__CORTEX_M0", "ARM_MATH_CM0", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 0:66f3b5499f7f 63 "Cortex-M0+": ["__CORTEX_M0PLUS", "ARM_MATH_CM0PLUS", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 17:04753e1e329d 64 "Cortex-M1" : ["__CORTEX_M3", "ARM_MATH_CM1", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 0:66f3b5499f7f 65 "Cortex-M3" : ["__CORTEX_M3", "ARM_MATH_CM3", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 0:66f3b5499f7f 66 "Cortex-M4" : ["__CORTEX_M4", "ARM_MATH_CM4", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 17:04753e1e329d 67 "Cortex-M4F" : ["__CORTEX_M4", "ARM_MATH_CM4", "__FPU_PRESENT=1", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 0:66f3b5499f7f 68 "Cortex-M7" : ["__CORTEX_M7", "ARM_MATH_CM7", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 17:04753e1e329d 69 "Cortex-M7F" : ["__CORTEX_M7", "ARM_MATH_CM7", "__FPU_PRESENT=1", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 17:04753e1e329d 70 "Cortex-M7FD" : ["__CORTEX_M7", "ARM_MATH_CM7", "__FPU_PRESENT=1", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 0:66f3b5499f7f 71 "Cortex-A9" : ["__CORTEX_A9", "ARM_MATH_CA9", "__FPU_PRESENT", "__CMSIS_RTOS", "__EVAL", "__MBED_CMSIS_RTOS_CA9"],
theotherjimmy 43:2a7da56ebd24 72 "Cortex-M23-NS": ["__CORTEX_M23", "ARM_MATH_ARMV8MBL", "DOMAIN_NS=1", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
theotherjimmy 40:7d3fa6b99b2b 73 "Cortex-M23": ["__CORTEX_M23", "ARM_MATH_ARMV8MBL", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
theotherjimmy 43:2a7da56ebd24 74 "Cortex-M33-NS": ["__CORTEX_M33", "ARM_MATH_ARMV8MML", "DOMAIN_NS=1", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
theotherjimmy 43:2a7da56ebd24 75 "Cortex-M33": ["__CORTEX_M33", "ARM_MATH_ARMV8MML", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
theotherjimmy 43:2a7da56ebd24 76 "Cortex-M33F-NS": ["__CORTEX_M33", "ARM_MATH_ARMV8MML", "DOMAIN_NS=1", "__FPU_PRESENT", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
theotherjimmy 43:2a7da56ebd24 77 "Cortex-M33F": ["__CORTEX_M33", "ARM_MATH_ARMV8MML", "__FPU_PRESENT", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 0:66f3b5499f7f 78 }
screamer 0:66f3b5499f7f 79
screamer 13:ab47a20b66f0 80 MBED_CONFIG_FILE_NAME="mbed_config.h"
screamer 13:ab47a20b66f0 81
The Other Jimmy 36:96847d42f010 82 PROFILE_FILE_NAME = ".profile"
The Other Jimmy 36:96847d42f010 83
screamer 24:25bff2709c20 84 __metaclass__ = ABCMeta
screamer 24:25bff2709c20 85
The Other Jimmy 31:8ea194f6145b 86 profile_template = {'common':[], 'c':[], 'cxx':[], 'asm':[], 'ld':[]}
The Other Jimmy 31:8ea194f6145b 87
theotherjimmy 43:2a7da56ebd24 88 def __init__(self, target, notify=None, macros=None, build_profile=None,
theotherjimmy 43:2a7da56ebd24 89 build_dir=None):
screamer 0:66f3b5499f7f 90 self.target = target
screamer 0:66f3b5499f7f 91 self.name = self.__class__.__name__
screamer 22:9e85236d8716 92
screamer 13:ab47a20b66f0 93 # compile/assemble/link/binary hooks
screamer 0:66f3b5499f7f 94 self.hook = hooks.Hook(target, self)
screamer 13:ab47a20b66f0 95
screamer 13:ab47a20b66f0 96 # Toolchain flags
The Other Jimmy 31:8ea194f6145b 97 self.flags = deepcopy(build_profile or self.profile_template)
screamer 22:9e85236d8716 98
The Other Jimmy 35:da9c89f8be7d 99 # System libraries provided by the toolchain
The Other Jimmy 35:da9c89f8be7d 100 self.sys_libs = []
The Other Jimmy 35:da9c89f8be7d 101
screamer 13:ab47a20b66f0 102 # User-defined macros
screamer 13:ab47a20b66f0 103 self.macros = macros or []
screamer 22:9e85236d8716 104
screamer 13:ab47a20b66f0 105 # Macros generated from toolchain and target rules/features
screamer 29:1210849dba19 106 self.asm_symbols = None
screamer 29:1210849dba19 107 self.cxx_symbols = None
screamer 22:9e85236d8716 108
screamer 13:ab47a20b66f0 109 # Labels generated from toolchain and target rules/features (used for selective build)
screamer 13:ab47a20b66f0 110 self.labels = None
screamer 22:9e85236d8716 111
screamer 24:25bff2709c20 112 # This will hold the initialized config object
screamer 24:25bff2709c20 113 self.config = None
screamer 24:25bff2709c20 114
screamer 13:ab47a20b66f0 115 # This will hold the configuration data (as returned by Config.get_config_data())
screamer 13:ab47a20b66f0 116 self.config_data = None
screamer 0:66f3b5499f7f 117
screamer 24:25bff2709c20 118 # This will hold the location of the configuration file or None if there's no configuration available
screamer 24:25bff2709c20 119 self.config_file = None
screamer 24:25bff2709c20 120
screamer 24:25bff2709c20 121 # Call guard for "get_config_data" (see the comments of get_config_data for details)
screamer 24:25bff2709c20 122 self.config_processed = False
screamer 24:25bff2709c20 123
screamer 13:ab47a20b66f0 124 # Non-incremental compile
screamer 13:ab47a20b66f0 125 self.build_all = False
screamer 22:9e85236d8716 126
screamer 13:ab47a20b66f0 127 # Build output dir
theotherjimmy 43:2a7da56ebd24 128 self.build_dir = abspath(build_dir) if PRINT_COMPILER_OUTPUT_AS_LINK else build_dir
screamer 13:ab47a20b66f0 129 self.timestamp = time()
screamer 13:ab47a20b66f0 130
screamer 13:ab47a20b66f0 131 # Number of concurrent build jobs. 0 means auto (based on host system cores)
screamer 13:ab47a20b66f0 132 self.jobs = 0
screamer 13:ab47a20b66f0 133
screamer 0:66f3b5499f7f 134
screamer 13:ab47a20b66f0 135 # Output notify function
screamer 22:9e85236d8716 136 # This function is passed all events, and expected to handle notification of the
screamer 22:9e85236d8716 137 # user, emit the events to a log, etc.
screamer 22:9e85236d8716 138 # The API for all notify methods passed into the notify parameter is as follows:
screamer 22:9e85236d8716 139 # def notify(Event, Silent)
screamer 22:9e85236d8716 140 # Where *Event* is a dict representing the toolchain event that was generated
screamer 22:9e85236d8716 141 # e.g.: a compile succeeded, or a warning was emitted by the compiler
screamer 22:9e85236d8716 142 # or an application was linked
screamer 22:9e85236d8716 143 # *Silent* is a boolean
screamer 0:66f3b5499f7f 144 if notify:
theotherjimmy 43:2a7da56ebd24 145 self.notify = notify
screamer 0:66f3b5499f7f 146 else:
theotherjimmy 43:2a7da56ebd24 147 self.notify = TerminalNotifier()
screamer 22:9e85236d8716 148
screamer 24:25bff2709c20 149
screamer 24:25bff2709c20 150 # Stats cache is used to reduce the amount of IO requests to stat
screamer 24:25bff2709c20 151 # header files during dependency change. See need_update()
screamer 17:04753e1e329d 152 self.stat_cache = {}
screamer 17:04753e1e329d 153
screamer 24:25bff2709c20 154 # Used by the mbed Online Build System to build in chrooted environment
screamer 24:25bff2709c20 155 self.CHROOT = None
screamer 24:25bff2709c20 156
screamer 24:25bff2709c20 157 # Call post __init__() hooks before the ARM/GCC_ARM/IAR toolchain __init__() takes over
screamer 14:ee1b877e6839 158 self.init()
screamer 14:ee1b877e6839 159
screamer 24:25bff2709c20 160 # Used for post __init__() hooks
screamer 24:25bff2709c20 161 # THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
screamer 24:25bff2709c20 162 # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
screamer 14:ee1b877e6839 163 def init(self):
screamer 14:ee1b877e6839 164 return True
screamer 0:66f3b5499f7f 165
screamer 0:66f3b5499f7f 166 def get_output(self):
theotherjimmy 43:2a7da56ebd24 167 return self.notifier.get_output()
screamer 0:66f3b5499f7f 168
screamer 29:1210849dba19 169 def get_symbols(self, for_asm=False):
screamer 29:1210849dba19 170 if for_asm:
screamer 29:1210849dba19 171 if self.asm_symbols is None:
screamer 29:1210849dba19 172 self.asm_symbols = []
screamer 29:1210849dba19 173
screamer 29:1210849dba19 174 # Cortex CPU symbols
screamer 29:1210849dba19 175 if self.target.core in mbedToolchain.CORTEX_SYMBOLS:
screamer 29:1210849dba19 176 self.asm_symbols.extend(mbedToolchain.CORTEX_SYMBOLS[self.target.core])
screamer 0:66f3b5499f7f 177
screamer 29:1210849dba19 178 # Add target's symbols
screamer 29:1210849dba19 179 self.asm_symbols += self.target.macros
screamer 29:1210849dba19 180 # Add extra symbols passed via 'macros' parameter
screamer 29:1210849dba19 181 self.asm_symbols += self.macros
screamer 29:1210849dba19 182 return list(set(self.asm_symbols)) # Return only unique symbols
screamer 29:1210849dba19 183 else:
screamer 29:1210849dba19 184 if self.cxx_symbols is None:
screamer 29:1210849dba19 185 # Target and Toolchain symbols
screamer 29:1210849dba19 186 labels = self.get_labels()
screamer 29:1210849dba19 187 self.cxx_symbols = ["TARGET_%s" % t for t in labels['TARGET']]
screamer 29:1210849dba19 188 self.cxx_symbols.extend(["TOOLCHAIN_%s" % t for t in labels['TOOLCHAIN']])
screamer 0:66f3b5499f7f 189
screamer 29:1210849dba19 190 # Cortex CPU symbols
screamer 29:1210849dba19 191 if self.target.core in mbedToolchain.CORTEX_SYMBOLS:
screamer 29:1210849dba19 192 self.cxx_symbols.extend(mbedToolchain.CORTEX_SYMBOLS[self.target.core])
screamer 29:1210849dba19 193
screamer 29:1210849dba19 194 # Symbols defined by the on-line build.system
screamer 29:1210849dba19 195 self.cxx_symbols.extend(['MBED_BUILD_TIMESTAMP=%s' % self.timestamp, 'TARGET_LIKE_MBED', '__MBED__=1'])
screamer 29:1210849dba19 196 if MBED_ORG_USER:
screamer 29:1210849dba19 197 self.cxx_symbols.append('MBED_USERNAME=' + MBED_ORG_USER)
screamer 0:66f3b5499f7f 198
screamer 29:1210849dba19 199 # Add target's symbols
screamer 29:1210849dba19 200 self.cxx_symbols += self.target.macros
screamer 29:1210849dba19 201 # Add target's hardware
screamer 29:1210849dba19 202 self.cxx_symbols += ["DEVICE_" + data + "=1" for data in self.target.device_has]
screamer 29:1210849dba19 203 # Add target's features
screamer 29:1210849dba19 204 self.cxx_symbols += ["FEATURE_" + data + "=1" for data in self.target.features]
theotherjimmy 43:2a7da56ebd24 205 # Add target's components
theotherjimmy 43:2a7da56ebd24 206 self.cxx_symbols += ["COMPONENT_" + data + "=1" for data in self.target.components]
screamer 29:1210849dba19 207 # Add extra symbols passed via 'macros' parameter
screamer 29:1210849dba19 208 self.cxx_symbols += self.macros
screamer 0:66f3b5499f7f 209
screamer 29:1210849dba19 210 # Form factor variables
screamer 29:1210849dba19 211 if hasattr(self.target, 'supported_form_factors'):
screamer 29:1210849dba19 212 self.cxx_symbols.extend(["TARGET_FF_%s" % t for t in self.target.supported_form_factors])
screamer 0:66f3b5499f7f 213
screamer 29:1210849dba19 214 return list(set(self.cxx_symbols)) # Return only unique symbols
screamer 0:66f3b5499f7f 215
screamer 7:5af61d55adbe 216 # Extend the internal list of macros
screamer 7:5af61d55adbe 217 def add_macros(self, new_macros):
screamer 7:5af61d55adbe 218 self.macros.extend(new_macros)
screamer 7:5af61d55adbe 219
screamer 0:66f3b5499f7f 220 def get_labels(self):
screamer 0:66f3b5499f7f 221 if self.labels is None:
theotherjimmy 43:2a7da56ebd24 222 toolchain_labels = self._get_toolchain_labels()
screamer 0:66f3b5499f7f 223 self.labels = {
The Other Jimmy 31:8ea194f6145b 224 'TARGET': self.target.labels,
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 225 'FEATURE': self.target.features,
theotherjimmy 43:2a7da56ebd24 226 'COMPONENT': self.target.components,
screamer 0:66f3b5499f7f 227 'TOOLCHAIN': toolchain_labels
screamer 0:66f3b5499f7f 228 }
The Other Jimmy 31:8ea194f6145b 229
The Other Jimmy 31:8ea194f6145b 230 # This is a policy decision and it should /really/ be in the config system
The Other Jimmy 31:8ea194f6145b 231 # ATM it's here for backward compatibility
The Other Jimmy 31:8ea194f6145b 232 if ((("-g" in self.flags['common'] or "-g3" in self.flags['common']) and
The Other Jimmy 36:96847d42f010 233 "-O0" in self.flags['common']) or
The Other Jimmy 31:8ea194f6145b 234 ("-r" in self.flags['common'] and
The Other Jimmy 31:8ea194f6145b 235 "-On" in self.flags['common'])):
The Other Jimmy 31:8ea194f6145b 236 self.labels['TARGET'].append("DEBUG")
The Other Jimmy 31:8ea194f6145b 237 else:
The Other Jimmy 31:8ea194f6145b 238 self.labels['TARGET'].append("RELEASE")
screamer 0:66f3b5499f7f 239 return self.labels
screamer 0:66f3b5499f7f 240
theotherjimmy 43:2a7da56ebd24 241 def _get_toolchain_labels(self):
theotherjimmy 43:2a7da56ebd24 242 toolchain_labels = [c.__name__ for c in getmro(self.__class__)]
theotherjimmy 43:2a7da56ebd24 243 toolchain_labels.remove('mbedToolchain')
theotherjimmy 43:2a7da56ebd24 244 toolchain_labels.remove('object')
theotherjimmy 43:2a7da56ebd24 245 return toolchain_labels
theotherjimmy 43:2a7da56ebd24 246
screamer 24:25bff2709c20 247
screamer 24:25bff2709c20 248 # Determine whether a source file needs updating/compiling
screamer 0:66f3b5499f7f 249 def need_update(self, target, dependencies):
screamer 0:66f3b5499f7f 250 if self.build_all:
screamer 0:66f3b5499f7f 251 return True
screamer 0:66f3b5499f7f 252
screamer 0:66f3b5499f7f 253 if not exists(target):
screamer 0:66f3b5499f7f 254 return True
screamer 0:66f3b5499f7f 255
screamer 0:66f3b5499f7f 256 target_mod_time = stat(target).st_mtime
screamer 0:66f3b5499f7f 257
screamer 0:66f3b5499f7f 258 for d in dependencies:
screamer 0:66f3b5499f7f 259 # Some objects are not provided with full path and here we do not have
screamer 0:66f3b5499f7f 260 # information about the library paths. Safe option: assume an update
screamer 22:9e85236d8716 261 if not d or not exists(d):
screamer 0:66f3b5499f7f 262 return True
theotherjimmy 40:7d3fa6b99b2b 263
theotherjimmy 43:2a7da56ebd24 264 if d not in self.stat_cache:
screamer 17:04753e1e329d 265 self.stat_cache[d] = stat(d).st_mtime
screamer 22:9e85236d8716 266
screamer 22:9e85236d8716 267 if self.stat_cache[d] >= target_mod_time:
screamer 22:9e85236d8716 268 return True
theotherjimmy 40:7d3fa6b99b2b 269
screamer 0:66f3b5499f7f 270 return False
screamer 0:66f3b5499f7f 271
screamer 0:66f3b5499f7f 272
screamer 0:66f3b5499f7f 273 def scan_repository(self, path):
screamer 0:66f3b5499f7f 274 resources = []
screamer 0:66f3b5499f7f 275
screamer 0:66f3b5499f7f 276 for root, dirs, files in walk(path):
screamer 0:66f3b5499f7f 277 # Remove ignored directories
screamer 0:66f3b5499f7f 278 for d in copy(dirs):
screamer 0:66f3b5499f7f 279 if d == '.' or d == '..':
screamer 0:66f3b5499f7f 280 dirs.remove(d)
screamer 0:66f3b5499f7f 281
screamer 0:66f3b5499f7f 282 for file in files:
screamer 0:66f3b5499f7f 283 file_path = join(root, file)
screamer 0:66f3b5499f7f 284 resources.append(file_path)
screamer 0:66f3b5499f7f 285
screamer 0:66f3b5499f7f 286 return resources
screamer 0:66f3b5499f7f 287
theotherjimmy 43:2a7da56ebd24 288 def copy_files(self, files_paths, trg_path, resources=None):
screamer 0:66f3b5499f7f 289 # Handle a single file
theotherjimmy 43:2a7da56ebd24 290 if not isinstance(files_paths, list):
theotherjimmy 43:2a7da56ebd24 291 files_paths = [files_paths]
screamer 0:66f3b5499f7f 292
theotherjimmy 43:2a7da56ebd24 293 for dest, source in files_paths:
theotherjimmy 43:2a7da56ebd24 294 target = join(trg_path, dest)
screamer 0:66f3b5499f7f 295 if (target != source) and (self.need_update(target, [source])):
theotherjimmy 43:2a7da56ebd24 296 self.progress("copy", dest)
screamer 0:66f3b5499f7f 297 mkdir(dirname(target))
screamer 0:66f3b5499f7f 298 copyfile(source, target)
screamer 0:66f3b5499f7f 299
screamer 24:25bff2709c20 300 # THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
screamer 24:25bff2709c20 301 # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
theotherjimmy 43:2a7da56ebd24 302 def relative_object_path(self, build_path, file_ref):
theotherjimmy 43:2a7da56ebd24 303 source_dir, name, _ = split_path(file_ref.name)
screamer 22:9e85236d8716 304
theotherjimmy 43:2a7da56ebd24 305 obj_dir = relpath(join(build_path, source_dir))
screamer 17:04753e1e329d 306 if obj_dir is not self.prev_dir:
screamer 17:04753e1e329d 307 self.prev_dir = obj_dir
screamer 17:04753e1e329d 308 mkdir(obj_dir)
screamer 0:66f3b5499f7f 309 return join(obj_dir, name + '.o')
screamer 0:66f3b5499f7f 310
theotherjimmy 43:2a7da56ebd24 311 def make_option_file(self, options, naming=".options_{}.txt"):
theotherjimmy 43:2a7da56ebd24 312 """ Generate a via file for a pile of defines
theotherjimmy 43:2a7da56ebd24 313 ARM, GCC, IAR cross compatible
theotherjimmy 43:2a7da56ebd24 314 """
theotherjimmy 43:2a7da56ebd24 315 to_write = " ".join(options).encode('utf-8')
theotherjimmy 43:2a7da56ebd24 316 new_md5 = md5(to_write).hexdigest()
theotherjimmy 43:2a7da56ebd24 317 via_file = join(self.build_dir, naming.format(new_md5))
theotherjimmy 43:2a7da56ebd24 318 try:
theotherjimmy 43:2a7da56ebd24 319 with open(via_file, "r") as fd:
theotherjimmy 43:2a7da56ebd24 320 old_md5 = md5(fd.read().encode('utf-8')).hexdigest()
theotherjimmy 43:2a7da56ebd24 321 except IOError:
theotherjimmy 43:2a7da56ebd24 322 old_md5 = None
theotherjimmy 43:2a7da56ebd24 323 if old_md5 != new_md5:
theotherjimmy 43:2a7da56ebd24 324 with open(via_file, "wb") as fd:
theotherjimmy 43:2a7da56ebd24 325 fd.write(to_write)
theotherjimmy 43:2a7da56ebd24 326 return via_file
theotherjimmy 43:2a7da56ebd24 327
screamer 0:66f3b5499f7f 328 def get_inc_file(self, includes):
theotherjimmy 43:2a7da56ebd24 329 """Generate a via file for all includes.
theotherjimmy 43:2a7da56ebd24 330 ARM, GCC, IAR cross compatible
theotherjimmy 43:2a7da56ebd24 331 """
theotherjimmy 43:2a7da56ebd24 332 cmd_list = ("-I{}".format(c.replace("\\", "/")) for c in includes if c)
theotherjimmy 43:2a7da56ebd24 333 if self.CHROOT:
theotherjimmy 43:2a7da56ebd24 334 cmd_list = (c.replace(self.CHROOT, '') for c in cmd_list)
theotherjimmy 43:2a7da56ebd24 335 return self.make_option_file(list(cmd_list), naming=".includes_{}.txt")
screamer 0:66f3b5499f7f 336
screamer 21:4fdf0dd04f6f 337 def get_link_file(self, cmd):
theotherjimmy 43:2a7da56ebd24 338 """Generate a via file for all objects when linking.
theotherjimmy 43:2a7da56ebd24 339 ARM, GCC, IAR cross compatible
theotherjimmy 43:2a7da56ebd24 340 """
theotherjimmy 43:2a7da56ebd24 341 cmd_list = (c.replace("\\", "/") for c in cmd if c)
theotherjimmy 43:2a7da56ebd24 342 if self.CHROOT:
theotherjimmy 43:2a7da56ebd24 343 cmd_list = (c.replace(self.CHROOT, '') for c in cmd_list)
theotherjimmy 43:2a7da56ebd24 344 return self.make_option_file(list(cmd_list), naming=".link_options.txt")
theotherjimmy 40:7d3fa6b99b2b 345
screamer 21:4fdf0dd04f6f 346 def get_arch_file(self, objects):
theotherjimmy 43:2a7da56ebd24 347 """ Generate a via file for all objects when archiving.
theotherjimmy 43:2a7da56ebd24 348 ARM, GCC, IAR cross compatible
theotherjimmy 43:2a7da56ebd24 349 """
theotherjimmy 43:2a7da56ebd24 350 cmd_list = (c.replace("\\", "/") for c in objects if c)
theotherjimmy 43:2a7da56ebd24 351 return self.make_option_file(list(cmd_list), ".archive_files.txt")
screamer 21:4fdf0dd04f6f 352
screamer 24:25bff2709c20 353 # THIS METHOD IS BEING CALLED BY THE MBED ONLINE BUILD SYSTEM
screamer 24:25bff2709c20 354 # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
The Other Jimmy 36:96847d42f010 355 def compile_sources(self, resources, inc_dirs=None):
screamer 0:66f3b5499f7f 356 # Web IDE progress bar for project build
theotherjimmy 43:2a7da56ebd24 357 files_to_compile = (
theotherjimmy 43:2a7da56ebd24 358 resources.get_file_refs(FileType.ASM_SRC) +
theotherjimmy 43:2a7da56ebd24 359 resources.get_file_refs(FileType.C_SRC) +
theotherjimmy 43:2a7da56ebd24 360 resources.get_file_refs(FileType.CPP_SRC)
theotherjimmy 43:2a7da56ebd24 361 )
screamer 0:66f3b5499f7f 362 self.to_be_compiled = len(files_to_compile)
screamer 0:66f3b5499f7f 363 self.compiled = 0
screamer 0:66f3b5499f7f 364
theotherjimmy 43:2a7da56ebd24 365 self.notify.cc_verbose("Macros: "+' '.join(['-D%s' % s for s in self.get_symbols()]))
screamer 21:4fdf0dd04f6f 366
theotherjimmy 43:2a7da56ebd24 367 inc_paths = resources.get_file_paths(FileType.INC_DIR)
screamer 0:66f3b5499f7f 368 if inc_dirs is not None:
theotherjimmy 40:7d3fa6b99b2b 369 if isinstance(inc_dirs, list):
theotherjimmy 40:7d3fa6b99b2b 370 inc_paths.extend(inc_dirs)
theotherjimmy 40:7d3fa6b99b2b 371 else:
theotherjimmy 40:7d3fa6b99b2b 372 inc_paths.append(inc_dirs)
screamer 0:66f3b5499f7f 373 # De-duplicate include paths
screamer 0:66f3b5499f7f 374 inc_paths = set(inc_paths)
screamer 0:66f3b5499f7f 375 # Sort include paths for consistency
screamer 0:66f3b5499f7f 376 inc_paths = sorted(set(inc_paths))
screamer 0:66f3b5499f7f 377 # Unique id of all include paths
theotherjimmy 43:2a7da56ebd24 378 self.inc_md5 = md5(' '.join(inc_paths).encode('utf-8')).hexdigest()
screamer 0:66f3b5499f7f 379
screamer 0:66f3b5499f7f 380 objects = []
screamer 0:66f3b5499f7f 381 queue = []
screamer 17:04753e1e329d 382 work_dir = getcwd()
screamer 17:04753e1e329d 383 self.prev_dir = None
screamer 0:66f3b5499f7f 384
screamer 24:25bff2709c20 385 # Generate configuration header (this will update self.build_all if needed)
screamer 24:25bff2709c20 386 self.get_config_header()
The Other Jimmy 36:96847d42f010 387 self.dump_build_profile()
screamer 24:25bff2709c20 388
screamer 0:66f3b5499f7f 389 # Sort compile queue for consistency
screamer 0:66f3b5499f7f 390 files_to_compile.sort()
screamer 0:66f3b5499f7f 391 for source in files_to_compile:
theotherjimmy 43:2a7da56ebd24 392 object = self.relative_object_path(self.build_dir, source)
screamer 0:66f3b5499f7f 393
screamer 0:66f3b5499f7f 394 # Queue mode (multiprocessing)
theotherjimmy 43:2a7da56ebd24 395 commands = self.compile_command(source.path, object, inc_paths)
screamer 0:66f3b5499f7f 396 if commands is not None:
screamer 0:66f3b5499f7f 397 queue.append({
screamer 0:66f3b5499f7f 398 'source': source,
screamer 0:66f3b5499f7f 399 'object': object,
screamer 0:66f3b5499f7f 400 'commands': commands,
screamer 0:66f3b5499f7f 401 'work_dir': work_dir,
screamer 0:66f3b5499f7f 402 'chroot': self.CHROOT
screamer 0:66f3b5499f7f 403 })
screamer 0:66f3b5499f7f 404 else:
The Other Jimmy 31:8ea194f6145b 405 self.compiled += 1
screamer 0:66f3b5499f7f 406 objects.append(object)
screamer 0:66f3b5499f7f 407
screamer 0:66f3b5499f7f 408 # Use queues/multiprocessing if cpu count is higher than setting
screamer 0:66f3b5499f7f 409 jobs = self.jobs if self.jobs else cpu_count()
screamer 0:66f3b5499f7f 410 if jobs > CPU_COUNT_MIN and len(queue) > jobs:
screamer 0:66f3b5499f7f 411 return self.compile_queue(queue, objects)
screamer 0:66f3b5499f7f 412 else:
screamer 0:66f3b5499f7f 413 return self.compile_seq(queue, objects)
screamer 0:66f3b5499f7f 414
screamer 24:25bff2709c20 415 # Compile source files queue in sequential order
screamer 0:66f3b5499f7f 416 def compile_seq(self, queue, objects):
screamer 0:66f3b5499f7f 417 for item in queue:
screamer 0:66f3b5499f7f 418 result = compile_worker(item)
screamer 0:66f3b5499f7f 419
screamer 0:66f3b5499f7f 420 self.compiled += 1
theotherjimmy 43:2a7da56ebd24 421 self.progress("compile", item['source'].name, build_update=True)
screamer 0:66f3b5499f7f 422 for res in result['results']:
theotherjimmy 43:2a7da56ebd24 423 self.notify.cc_verbose("Compile: %s" % ' '.join(res['command']), result['source'])
screamer 0:66f3b5499f7f 424 self.compile_output([
screamer 0:66f3b5499f7f 425 res['code'],
screamer 0:66f3b5499f7f 426 res['output'],
screamer 0:66f3b5499f7f 427 res['command']
screamer 0:66f3b5499f7f 428 ])
screamer 0:66f3b5499f7f 429 objects.append(result['object'])
screamer 0:66f3b5499f7f 430 return objects
screamer 0:66f3b5499f7f 431
screamer 24:25bff2709c20 432 # Compile source files queue in parallel by creating pool of worker threads
screamer 0:66f3b5499f7f 433 def compile_queue(self, queue, objects):
screamer 21:4fdf0dd04f6f 434 jobs_count = int(self.jobs if self.jobs else cpu_count() * CPU_COEF)
screamer 0:66f3b5499f7f 435 p = Pool(processes=jobs_count)
screamer 0:66f3b5499f7f 436
screamer 0:66f3b5499f7f 437 results = []
screamer 0:66f3b5499f7f 438 for i in range(len(queue)):
screamer 0:66f3b5499f7f 439 results.append(p.apply_async(compile_worker, [queue[i]]))
screamer 17:04753e1e329d 440 p.close()
screamer 0:66f3b5499f7f 441
screamer 0:66f3b5499f7f 442 itr = 0
screamer 17:04753e1e329d 443 while len(results):
screamer 0:66f3b5499f7f 444 itr += 1
screamer 0:66f3b5499f7f 445 if itr > 180000:
screamer 0:66f3b5499f7f 446 p.terminate()
screamer 0:66f3b5499f7f 447 p.join()
screamer 0:66f3b5499f7f 448 raise ToolException("Compile did not finish in 5 minutes")
screamer 0:66f3b5499f7f 449
screamer 17:04753e1e329d 450 sleep(0.01)
screamer 0:66f3b5499f7f 451 pending = 0
screamer 0:66f3b5499f7f 452 for r in results:
theotherjimmy 43:2a7da56ebd24 453 if r.ready():
screamer 0:66f3b5499f7f 454 try:
screamer 0:66f3b5499f7f 455 result = r.get()
screamer 0:66f3b5499f7f 456 results.remove(r)
screamer 0:66f3b5499f7f 457
screamer 0:66f3b5499f7f 458 self.compiled += 1
theotherjimmy 43:2a7da56ebd24 459 self.progress("compile", result['source'].name, build_update=True)
screamer 0:66f3b5499f7f 460 for res in result['results']:
theotherjimmy 43:2a7da56ebd24 461 self.notify.cc_verbose("Compile: %s" % ' '.join(res['command']), result['source'])
screamer 0:66f3b5499f7f 462 self.compile_output([
screamer 0:66f3b5499f7f 463 res['code'],
screamer 0:66f3b5499f7f 464 res['output'],
screamer 0:66f3b5499f7f 465 res['command']
screamer 0:66f3b5499f7f 466 ])
screamer 0:66f3b5499f7f 467 objects.append(result['object'])
theotherjimmy 43:2a7da56ebd24 468 except ToolException as err:
screamer 27:5461402c33f8 469 if p._taskqueue.queue:
screamer 27:5461402c33f8 470 p._taskqueue.queue.clear()
screamer 29:1210849dba19 471 sleep(0.5)
screamer 0:66f3b5499f7f 472 p.terminate()
screamer 0:66f3b5499f7f 473 p.join()
screamer 0:66f3b5499f7f 474 raise ToolException(err)
screamer 0:66f3b5499f7f 475 else:
screamer 0:66f3b5499f7f 476 pending += 1
screamer 17:04753e1e329d 477 if pending >= jobs_count:
screamer 0:66f3b5499f7f 478 break
screamer 0:66f3b5499f7f 479
screamer 0:66f3b5499f7f 480 results = None
screamer 0:66f3b5499f7f 481 p.join()
screamer 0:66f3b5499f7f 482
screamer 0:66f3b5499f7f 483 return objects
screamer 0:66f3b5499f7f 484
screamer 24:25bff2709c20 485 # Determine the compile command based on type of source file
screamer 0:66f3b5499f7f 486 def compile_command(self, source, object, includes):
screamer 0:66f3b5499f7f 487 # Check dependencies
screamer 0:66f3b5499f7f 488 _, ext = splitext(source)
screamer 0:66f3b5499f7f 489 ext = ext.lower()
screamer 0:66f3b5499f7f 490
theotherjimmy 43:2a7da56ebd24 491 source = abspath(source) if PRINT_COMPILER_OUTPUT_AS_LINK else source
theotherjimmy 43:2a7da56ebd24 492
theotherjimmy 43:2a7da56ebd24 493 if ext == '.c' or ext == '.cpp' or ext == '.cc':
screamer 0:66f3b5499f7f 494 base, _ = splitext(object)
screamer 0:66f3b5499f7f 495 dep_path = base + '.d'
The Other Jimmy 31:8ea194f6145b 496 try:
The Other Jimmy 31:8ea194f6145b 497 deps = self.parse_dependencies(dep_path) if (exists(dep_path)) else []
theotherjimmy 43:2a7da56ebd24 498 except (IOError, IndexError):
The Other Jimmy 31:8ea194f6145b 499 deps = []
The Other Jimmy 36:96847d42f010 500 config_file = ([self.config.app_config_location]
The Other Jimmy 36:96847d42f010 501 if self.config.app_config_location else [])
The Other Jimmy 36:96847d42f010 502 deps.extend(config_file)
theotherjimmy 43:2a7da56ebd24 503 if ext != '.c' or self.COMPILE_C_AS_CPP:
The Other Jimmy 36:96847d42f010 504 deps.append(join(self.build_dir, self.PROFILE_FILE_NAME + "-cxx"))
The Other Jimmy 36:96847d42f010 505 else:
The Other Jimmy 36:96847d42f010 506 deps.append(join(self.build_dir, self.PROFILE_FILE_NAME + "-c"))
screamer 0:66f3b5499f7f 507 if len(deps) == 0 or self.need_update(object, deps):
theotherjimmy 43:2a7da56ebd24 508 if ext != '.c' or self.COMPILE_C_AS_CPP:
screamer 21:4fdf0dd04f6f 509 return self.compile_cpp(source, object, includes)
screamer 21:4fdf0dd04f6f 510 else:
screamer 0:66f3b5499f7f 511 return self.compile_c(source, object, includes)
screamer 0:66f3b5499f7f 512 elif ext == '.s':
screamer 0:66f3b5499f7f 513 deps = [source]
The Other Jimmy 36:96847d42f010 514 deps.append(join(self.build_dir, self.PROFILE_FILE_NAME + "-asm"))
screamer 0:66f3b5499f7f 515 if self.need_update(object, deps):
screamer 0:66f3b5499f7f 516 return self.assemble(source, object, includes)
screamer 0:66f3b5499f7f 517 else:
screamer 0:66f3b5499f7f 518 return False
screamer 0:66f3b5499f7f 519
screamer 0:66f3b5499f7f 520 return None
screamer 0:66f3b5499f7f 521
screamer 24:25bff2709c20 522 def parse_dependencies(self, dep_path):
screamer 24:25bff2709c20 523 """Parse the dependency information generated by the compiler.
screamer 24:25bff2709c20 524
screamer 24:25bff2709c20 525 Positional arguments:
screamer 24:25bff2709c20 526 dep_path -- the path to a file generated by a previous run of the compiler
screamer 24:25bff2709c20 527
screamer 24:25bff2709c20 528 Return value:
screamer 24:25bff2709c20 529 A list of all source files that the dependency file indicated were dependencies
screamer 24:25bff2709c20 530
screamer 24:25bff2709c20 531 Side effects:
screamer 24:25bff2709c20 532 None
theotherjimmy 40:7d3fa6b99b2b 533
theotherjimmy 40:7d3fa6b99b2b 534 Note: A default implementation is provided for make-like file formats
screamer 24:25bff2709c20 535 """
theotherjimmy 40:7d3fa6b99b2b 536 dependencies = []
theotherjimmy 40:7d3fa6b99b2b 537 buff = open(dep_path).readlines()
theotherjimmy 40:7d3fa6b99b2b 538 if buff:
theotherjimmy 40:7d3fa6b99b2b 539 buff[0] = re.sub('^(.*?)\: ', '', buff[0])
theotherjimmy 40:7d3fa6b99b2b 540 for line in buff:
theotherjimmy 40:7d3fa6b99b2b 541 filename = line.replace('\\\n', '').strip()
theotherjimmy 43:2a7da56ebd24 542 if filename:
theotherjimmy 40:7d3fa6b99b2b 543 filename = filename.replace('\\ ', '\a')
theotherjimmy 40:7d3fa6b99b2b 544 dependencies.extend(((self.CHROOT if self.CHROOT else '') +
theotherjimmy 40:7d3fa6b99b2b 545 f.replace('\a', ' '))
theotherjimmy 40:7d3fa6b99b2b 546 for f in filename.split(" "))
theotherjimmy 40:7d3fa6b99b2b 547 return list(filter(None, dependencies))
screamer 24:25bff2709c20 548
screamer 0:66f3b5499f7f 549 def is_not_supported_error(self, output):
screamer 0:66f3b5499f7f 550 return "#error directive: [NOT_SUPPORTED]" in output
screamer 0:66f3b5499f7f 551
screamer 24:25bff2709c20 552 @abstractmethod
screamer 24:25bff2709c20 553 def parse_output(self, output):
screamer 24:25bff2709c20 554 """Take in compiler output and extract sinlge line warnings and errors from it.
screamer 24:25bff2709c20 555
screamer 24:25bff2709c20 556 Positional arguments:
screamer 24:25bff2709c20 557 output -- a string of all the messages emitted by a run of the compiler
screamer 24:25bff2709c20 558
screamer 24:25bff2709c20 559 Return value:
screamer 24:25bff2709c20 560 None
screamer 24:25bff2709c20 561
screamer 24:25bff2709c20 562 Side effects:
screamer 24:25bff2709c20 563 call self.cc_info or self.notify with a description of the event generated by the compiler
screamer 24:25bff2709c20 564 """
screamer 24:25bff2709c20 565 raise NotImplemented
screamer 24:25bff2709c20 566
screamer 0:66f3b5499f7f 567 def compile_output(self, output=[]):
screamer 0:66f3b5499f7f 568 _rc = output[0]
The Other Jimmy 36:96847d42f010 569 _stderr = output[1].decode("utf-8")
screamer 0:66f3b5499f7f 570 command = output[2]
screamer 0:66f3b5499f7f 571
screamer 0:66f3b5499f7f 572 # Parse output for Warnings and Errors
screamer 0:66f3b5499f7f 573 self.parse_output(_stderr)
theotherjimmy 43:2a7da56ebd24 574 self.notify.debug("Return: %s"% _rc)
screamer 0:66f3b5499f7f 575 for error_line in _stderr.splitlines():
theotherjimmy 43:2a7da56ebd24 576 self.notify.debug("Output: %s"% error_line)
screamer 0:66f3b5499f7f 577
screamer 0:66f3b5499f7f 578 # Check return code
screamer 0:66f3b5499f7f 579 if _rc != 0:
screamer 0:66f3b5499f7f 580 if self.is_not_supported_error(_stderr):
screamer 0:66f3b5499f7f 581 raise NotSupportedException(_stderr)
screamer 0:66f3b5499f7f 582 else:
screamer 0:66f3b5499f7f 583 raise ToolException(_stderr)
screamer 0:66f3b5499f7f 584
screamer 0:66f3b5499f7f 585 def build_library(self, objects, dir, name):
screamer 0:66f3b5499f7f 586 needed_update = False
screamer 0:66f3b5499f7f 587 lib = self.STD_LIB_NAME % name
screamer 0:66f3b5499f7f 588 fout = join(dir, lib)
screamer 0:66f3b5499f7f 589 if self.need_update(fout, objects):
theotherjimmy 43:2a7da56ebd24 590 self.notify.info("Library: %s" % lib)
screamer 0:66f3b5499f7f 591 self.archive(objects, fout)
screamer 0:66f3b5499f7f 592 needed_update = True
screamer 0:66f3b5499f7f 593
screamer 0:66f3b5499f7f 594 return needed_update
screamer 0:66f3b5499f7f 595
screamer 0:66f3b5499f7f 596 def link_program(self, r, tmp_path, name):
screamer 0:66f3b5499f7f 597 needed_update = False
screamer 0:66f3b5499f7f 598 ext = 'bin'
screamer 0:66f3b5499f7f 599 if hasattr(self.target, 'OUTPUT_EXT'):
screamer 0:66f3b5499f7f 600 ext = self.target.OUTPUT_EXT
screamer 0:66f3b5499f7f 601
screamer 0:66f3b5499f7f 602 if hasattr(self.target, 'OUTPUT_NAMING'):
theotherjimmy 43:2a7da56ebd24 603 self.notify.var("binary_naming", self.target.OUTPUT_NAMING)
screamer 0:66f3b5499f7f 604 if self.target.OUTPUT_NAMING == "8.3":
screamer 0:66f3b5499f7f 605 name = name[0:8]
screamer 0:66f3b5499f7f 606 ext = ext[0:3]
screamer 22:9e85236d8716 607
screamer 0:66f3b5499f7f 608 # Create destination directory
screamer 0:66f3b5499f7f 609 head, tail = split(name)
screamer 0:66f3b5499f7f 610 new_path = join(tmp_path, head)
screamer 0:66f3b5499f7f 611 mkdir(new_path)
screamer 22:9e85236d8716 612
screamer 0:66f3b5499f7f 613 filename = name+'.'+ext
theotherjimmy 43:2a7da56ebd24 614 # Absolute path of the final linked file
theotherjimmy 43:2a7da56ebd24 615 full_path = join(tmp_path, filename)
screamer 0:66f3b5499f7f 616 elf = join(tmp_path, name + '.elf')
theotherjimmy 43:2a7da56ebd24 617 bin = None if ext == 'elf' else full_path
screamer 7:5af61d55adbe 618 map = join(tmp_path, name + '.map')
screamer 0:66f3b5499f7f 619
theotherjimmy 43:2a7da56ebd24 620 objects = sorted(set(r.get_file_paths(FileType.OBJECT)))
The Other Jimmy 36:96847d42f010 621 config_file = ([self.config.app_config_location]
The Other Jimmy 36:96847d42f010 622 if self.config.app_config_location else [])
theotherjimmy 43:2a7da56ebd24 623 linker_script = [path for _, path in r.get_file_refs(FileType.LD_SCRIPT)
theotherjimmy 43:2a7da56ebd24 624 if path.endswith(self.LINKER_EXT)][-1]
theotherjimmy 43:2a7da56ebd24 625 lib_dirs = r.get_file_paths(FileType.LIB_DIR)
theotherjimmy 43:2a7da56ebd24 626 libraries = [l for l in r.get_file_paths(FileType.LIB)
theotherjimmy 43:2a7da56ebd24 627 if l.endswith(self.LIBRARY_EXT)]
theotherjimmy 43:2a7da56ebd24 628 dependencies = objects + libraries + [linker_script] + config_file
The Other Jimmy 36:96847d42f010 629 dependencies.append(join(self.build_dir, self.PROFILE_FILE_NAME + "-ld"))
The Other Jimmy 36:96847d42f010 630 if self.need_update(elf, dependencies):
screamer 0:66f3b5499f7f 631 needed_update = True
screamer 0:66f3b5499f7f 632 self.progress("link", name)
theotherjimmy 43:2a7da56ebd24 633 self.link(elf, objects, libraries, lib_dirs, linker_script)
screamer 0:66f3b5499f7f 634
The Other Jimmy 36:96847d42f010 635 if bin and self.need_update(bin, [elf]):
screamer 0:66f3b5499f7f 636 needed_update = True
screamer 0:66f3b5499f7f 637 self.progress("elf2bin", name)
screamer 0:66f3b5499f7f 638 self.binary(r, elf, bin)
screamer 0:66f3b5499f7f 639
theotherjimmy 40:7d3fa6b99b2b 640 # Initialize memap and process map file. This doesn't generate output.
theotherjimmy 40:7d3fa6b99b2b 641 self.mem_stats(map)
screamer 7:5af61d55adbe 642
theotherjimmy 43:2a7da56ebd24 643 self.notify.var("compile_succeded", True)
theotherjimmy 43:2a7da56ebd24 644 self.notify.var("binary", filename)
screamer 0:66f3b5499f7f 645
theotherjimmy 43:2a7da56ebd24 646 return full_path, needed_update
screamer 0:66f3b5499f7f 647
screamer 24:25bff2709c20 648 # THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
screamer 24:25bff2709c20 649 # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
screamer 0:66f3b5499f7f 650 def default_cmd(self, command):
screamer 20:835f6355470d 651 _stdout, _stderr, _rc = run_cmd(command, work_dir=getcwd(), chroot=self.CHROOT)
theotherjimmy 43:2a7da56ebd24 652 self.notify.debug("Return: %s"% _rc)
screamer 0:66f3b5499f7f 653
screamer 0:66f3b5499f7f 654 for output_line in _stdout.splitlines():
theotherjimmy 43:2a7da56ebd24 655 self.notify.debug("Output: %s"% output_line)
screamer 0:66f3b5499f7f 656 for error_line in _stderr.splitlines():
theotherjimmy 43:2a7da56ebd24 657 self.notify.debug("Errors: %s"% error_line)
screamer 0:66f3b5499f7f 658
screamer 0:66f3b5499f7f 659 if _rc != 0:
screamer 0:66f3b5499f7f 660 for line in _stderr.splitlines():
theotherjimmy 43:2a7da56ebd24 661 self.notify.tool_error(line)
screamer 0:66f3b5499f7f 662 raise ToolException(_stderr)
screamer 0:66f3b5499f7f 663
screamer 0:66f3b5499f7f 664 def progress(self, action, file, build_update=False):
screamer 0:66f3b5499f7f 665 if build_update:
theotherjimmy 43:2a7da56ebd24 666 percent = 100. * float(self.compiled) / float(self.to_be_compiled)
theotherjimmy 43:2a7da56ebd24 667 else:
theotherjimmy 43:2a7da56ebd24 668 percent = None
theotherjimmy 43:2a7da56ebd24 669 self.notify.progress(action, file, percent)
screamer 0:66f3b5499f7f 670
screamer 24:25bff2709c20 671 # THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
screamer 24:25bff2709c20 672 # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
screamer 7:5af61d55adbe 673 def mem_stats(self, map):
screamer 22:9e85236d8716 674 """! Creates parser object
screamer 22:9e85236d8716 675 @param map Path to linker map file to parse and decode
theotherjimmy 40:7d3fa6b99b2b 676 @return None
screamer 22:9e85236d8716 677 """
screamer 7:5af61d55adbe 678 toolchain = self.__class__.__name__
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 679
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 680 # Create memap object
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 681 memap = MemapParser()
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 682
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 683 # Parse and decode a map file
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 684 if memap.parse(abspath(map), toolchain) is False:
theotherjimmy 43:2a7da56ebd24 685 self.notify.info("Unknown toolchain for memory statistics %s" % toolchain)
screamer 22:9e85236d8716 686 return None
screamer 7:5af61d55adbe 687
The Other Jimmy 31:8ea194f6145b 688 # Store the memap instance for later use
The Other Jimmy 31:8ea194f6145b 689 self.memap_instance = memap
screamer 13:ab47a20b66f0 690
theotherjimmy 40:7d3fa6b99b2b 691 # Note: memory statistics are not returned.
theotherjimmy 40:7d3fa6b99b2b 692 # Need call to generate_output later (depends on depth & output format)
theotherjimmy 40:7d3fa6b99b2b 693
theotherjimmy 40:7d3fa6b99b2b 694 return None
screamer 22:9e85236d8716 695
theotherjimmy 43:2a7da56ebd24 696 def _add_defines_from_region(self, region, suffixes=['_ADDR', '_SIZE']):
theotherjimmy 43:2a7da56ebd24 697 for define in [(region.name.upper() + suffixes[0], region.start),
theotherjimmy 43:2a7da56ebd24 698 (region.name.upper() + suffixes[1], region.size)]:
theotherjimmy 43:2a7da56ebd24 699 define_string = "-D%s=0x%x" % define
theotherjimmy 43:2a7da56ebd24 700 self.cc.append(define_string)
theotherjimmy 43:2a7da56ebd24 701 self.cppc.append(define_string)
theotherjimmy 43:2a7da56ebd24 702 self.flags["common"].append(define_string)
theotherjimmy 43:2a7da56ebd24 703
theotherjimmy 43:2a7da56ebd24 704 def _add_all_regions(self, region_list, active_region_name):
theotherjimmy 43:2a7da56ebd24 705 for region in region_list:
theotherjimmy 43:2a7da56ebd24 706 self._add_defines_from_region(region)
theotherjimmy 43:2a7da56ebd24 707 if region.active:
theotherjimmy 43:2a7da56ebd24 708 for define in [
theotherjimmy 43:2a7da56ebd24 709 ("%s_START" % active_region_name, "0x%x" % region.start),
theotherjimmy 43:2a7da56ebd24 710 ("%s_SIZE" % active_region_name, "0x%x" % region.size)
theotherjimmy 43:2a7da56ebd24 711 ]:
theotherjimmy 43:2a7da56ebd24 712 define_string = self.make_ld_define(*define)
theotherjimmy 43:2a7da56ebd24 713 self.ld.append(define_string)
theotherjimmy 43:2a7da56ebd24 714 self.flags["ld"].append(define_string)
theotherjimmy 43:2a7da56ebd24 715 self.notify.info(" Region %s: size 0x%x, offset 0x%x"
theotherjimmy 43:2a7da56ebd24 716 % (region.name, region.size, region.start))
theotherjimmy 43:2a7da56ebd24 717
theotherjimmy 43:2a7da56ebd24 718 def add_regions(self):
theotherjimmy 43:2a7da56ebd24 719 """Add regions to the build profile, if there are any.
theotherjimmy 43:2a7da56ebd24 720 """
theotherjimmy 43:2a7da56ebd24 721 if self.config.has_regions:
theotherjimmy 43:2a7da56ebd24 722 regions = list(self.config.regions)
theotherjimmy 43:2a7da56ebd24 723 self.notify.info("Using ROM region%s %s in this build." % (
theotherjimmy 43:2a7da56ebd24 724 "s" if len(regions) > 1 else "",
theotherjimmy 43:2a7da56ebd24 725 ", ".join(r.name for r in regions)
theotherjimmy 43:2a7da56ebd24 726 ))
theotherjimmy 43:2a7da56ebd24 727 self._add_all_regions(regions, "MBED_APP")
theotherjimmy 43:2a7da56ebd24 728 if self.config.has_ram_regions:
theotherjimmy 43:2a7da56ebd24 729 regions = list(self.config.ram_regions)
theotherjimmy 43:2a7da56ebd24 730 self.notify.info("Using RAM region%s %s in this build." % (
theotherjimmy 43:2a7da56ebd24 731 "s" if len(regions) > 1 else "",
theotherjimmy 43:2a7da56ebd24 732 ", ".join(r.name for r in regions)
theotherjimmy 43:2a7da56ebd24 733 ))
theotherjimmy 43:2a7da56ebd24 734 self._add_all_regions(regions, "MBED_RAM")
theotherjimmy 43:2a7da56ebd24 735 try:
theotherjimmy 43:2a7da56ebd24 736 rom_start, rom_size = self.config.rom
theotherjimmy 43:2a7da56ebd24 737 Region = namedtuple("Region", "name start size")
theotherjimmy 43:2a7da56ebd24 738 self._add_defines_from_region(
theotherjimmy 43:2a7da56ebd24 739 Region("MBED_ROM", rom_start, rom_size),
theotherjimmy 43:2a7da56ebd24 740 suffixes=["_START", "_SIZE"]
theotherjimmy 43:2a7da56ebd24 741 )
theotherjimmy 43:2a7da56ebd24 742 except ConfigException:
theotherjimmy 43:2a7da56ebd24 743 pass
theotherjimmy 43:2a7da56ebd24 744
screamer 13:ab47a20b66f0 745 # Set the configuration data
screamer 13:ab47a20b66f0 746 def set_config_data(self, config_data):
screamer 13:ab47a20b66f0 747 self.config_data = config_data
theotherjimmy 43:2a7da56ebd24 748 # new configuration data can change labels, so clear the cache
theotherjimmy 43:2a7da56ebd24 749 self.labels = None
theotherjimmy 43:2a7da56ebd24 750 # pass info about softdevice presence to linker (see NRF52)
theotherjimmy 43:2a7da56ebd24 751 if "SOFTDEVICE_PRESENT" in config_data[1]:
theotherjimmy 43:2a7da56ebd24 752 define_string = self.make_ld_define("SOFTDEVICE_PRESENT", config_data[1]["SOFTDEVICE_PRESENT"].macro_value)
theotherjimmy 43:2a7da56ebd24 753 self.ld.append(define_string)
theotherjimmy 43:2a7da56ebd24 754 self.flags["ld"].append(define_string)
theotherjimmy 43:2a7da56ebd24 755 self.add_regions()
screamer 13:ab47a20b66f0 756
screamer 24:25bff2709c20 757 # Creates the configuration header if needed:
screamer 24:25bff2709c20 758 # - if there is no configuration data, "mbed_config.h" is not create (or deleted if it exists).
screamer 24:25bff2709c20 759 # - if there is configuration data and "mbed_config.h" does not exist, it is created.
screamer 24:25bff2709c20 760 # - if there is configuration data similar to the previous configuration data,
screamer 24:25bff2709c20 761 # "mbed_config.h" is left untouched.
screamer 24:25bff2709c20 762 # - if there is new configuration data, "mbed_config.h" is overriden.
screamer 24:25bff2709c20 763 # The function needs to be called exactly once for the lifetime of this toolchain instance.
screamer 24:25bff2709c20 764 # The "config_processed" variable (below) ensures this behaviour.
screamer 24:25bff2709c20 765 # The function returns the location of the configuration file, or None if there is no
screamer 24:25bff2709c20 766 # configuration data available (and thus no configuration file)
screamer 13:ab47a20b66f0 767 def get_config_header(self):
screamer 24:25bff2709c20 768 if self.config_processed: # this function was already called, return its result
screamer 24:25bff2709c20 769 return self.config_file
screamer 24:25bff2709c20 770 # The config file is located in the build directory
screamer 24:25bff2709c20 771 self.config_file = join(self.build_dir, self.MBED_CONFIG_FILE_NAME)
screamer 24:25bff2709c20 772 # If the file exists, read its current content in prev_data
screamer 24:25bff2709c20 773 if exists(self.config_file):
theotherjimmy 43:2a7da56ebd24 774 with open(self.config_file, "r") as f:
screamer 24:25bff2709c20 775 prev_data = f.read()
screamer 24:25bff2709c20 776 else:
screamer 24:25bff2709c20 777 prev_data = None
screamer 24:25bff2709c20 778 # Get the current configuration data
theotherjimmy 40:7d3fa6b99b2b 779 crt_data = self.config.config_to_header(self.config_data) if self.config_data else None
screamer 24:25bff2709c20 780 # "changed" indicates if a configuration change was detected
screamer 24:25bff2709c20 781 changed = False
screamer 24:25bff2709c20 782 if prev_data is not None: # a previous mbed_config.h exists
screamer 24:25bff2709c20 783 if crt_data is None: # no configuration data, so "mbed_config.h" needs to be removed
screamer 24:25bff2709c20 784 remove(self.config_file)
screamer 24:25bff2709c20 785 self.config_file = None # this means "config file not present"
screamer 24:25bff2709c20 786 changed = True
screamer 24:25bff2709c20 787 elif crt_data != prev_data: # different content of config file
theotherjimmy 43:2a7da56ebd24 788 with open(self.config_file, "w") as f:
screamer 24:25bff2709c20 789 f.write(crt_data)
screamer 24:25bff2709c20 790 changed = True
screamer 24:25bff2709c20 791 else: # a previous mbed_config.h does not exist
screamer 24:25bff2709c20 792 if crt_data is not None: # there's configuration data available
theotherjimmy 43:2a7da56ebd24 793 with open(self.config_file, "w") as f:
screamer 24:25bff2709c20 794 f.write(crt_data)
screamer 24:25bff2709c20 795 changed = True
screamer 24:25bff2709c20 796 else:
screamer 24:25bff2709c20 797 self.config_file = None # this means "config file not present"
screamer 24:25bff2709c20 798 # If there was a change in configuration, rebuild everything
screamer 24:25bff2709c20 799 self.build_all = changed
screamer 24:25bff2709c20 800 # Make sure that this function will only return the location of the configuration
screamer 24:25bff2709c20 801 # file for subsequent calls, without trying to manipulate its content in any way.
screamer 24:25bff2709c20 802 self.config_processed = True
screamer 24:25bff2709c20 803 return self.config_file
screamer 24:25bff2709c20 804
The Other Jimmy 36:96847d42f010 805 def dump_build_profile(self):
The Other Jimmy 36:96847d42f010 806 """Dump the current build profile and macros into the `.profile` file
The Other Jimmy 36:96847d42f010 807 in the build directory"""
The Other Jimmy 36:96847d42f010 808 for key in ["cxx", "c", "asm", "ld"]:
theotherjimmy 43:2a7da56ebd24 809 to_dump = {
theotherjimmy 43:2a7da56ebd24 810 "flags": sorted(self.flags[key]),
theotherjimmy 43:2a7da56ebd24 811 "macros": sorted(self.macros),
theotherjimmy 43:2a7da56ebd24 812 "symbols": sorted(self.get_symbols(for_asm=(key == "asm"))),
theotherjimmy 43:2a7da56ebd24 813 }
The Other Jimmy 36:96847d42f010 814 if key in ["cxx", "c"]:
theotherjimmy 43:2a7da56ebd24 815 to_dump["symbols"].remove('MBED_BUILD_TIMESTAMP=%s' % self.timestamp)
theotherjimmy 43:2a7da56ebd24 816 to_dump["flags"].extend(sorted(self.flags['common']))
The Other Jimmy 36:96847d42f010 817 where = join(self.build_dir, self.PROFILE_FILE_NAME + "-" + key)
theotherjimmy 43:2a7da56ebd24 818 self._overwrite_when_not_equal(where, json.dumps(
theotherjimmy 43:2a7da56ebd24 819 to_dump, sort_keys=True, indent=4))
The Other Jimmy 36:96847d42f010 820
The Other Jimmy 36:96847d42f010 821 @staticmethod
The Other Jimmy 36:96847d42f010 822 def _overwrite_when_not_equal(filename, content):
The Other Jimmy 36:96847d42f010 823 if not exists(filename) or content != open(filename).read():
theotherjimmy 43:2a7da56ebd24 824 with open(filename, "w") as out:
The Other Jimmy 36:96847d42f010 825 out.write(content)
The Other Jimmy 36:96847d42f010 826
The Other Jimmy 31:8ea194f6145b 827 @staticmethod
The Other Jimmy 31:8ea194f6145b 828 def generic_check_executable(tool_key, executable_name, levels_up,
The Other Jimmy 31:8ea194f6145b 829 nested_dir=None):
The Other Jimmy 31:8ea194f6145b 830 """
The Other Jimmy 31:8ea194f6145b 831 Positional args:
The Other Jimmy 31:8ea194f6145b 832 tool_key: the key to index TOOLCHAIN_PATHS
The Other Jimmy 31:8ea194f6145b 833 executable_name: the toolchain's named executable (ex. armcc)
The Other Jimmy 31:8ea194f6145b 834 levels_up: each toolchain joins the toolchain_path, some
The Other Jimmy 31:8ea194f6145b 835 variable directories (bin, include), and the executable name,
The Other Jimmy 31:8ea194f6145b 836 so the TOOLCHAIN_PATH value must be appropriately distanced
The Other Jimmy 31:8ea194f6145b 837
The Other Jimmy 31:8ea194f6145b 838 Keyword args:
The Other Jimmy 31:8ea194f6145b 839 nested_dir: the directory within TOOLCHAIN_PATHS where the executable
The Other Jimmy 31:8ea194f6145b 840 is found (ex: 'bin' for ARM\bin\armcc (necessary to check for path
The Other Jimmy 31:8ea194f6145b 841 that will be used by toolchain's compile)
The Other Jimmy 31:8ea194f6145b 842
The Other Jimmy 31:8ea194f6145b 843 Returns True if the executable location specified by the user
The Other Jimmy 31:8ea194f6145b 844 exists and is valid OR the executable can be found on the PATH.
The Other Jimmy 31:8ea194f6145b 845 Returns False otherwise.
The Other Jimmy 31:8ea194f6145b 846 """
The Other Jimmy 31:8ea194f6145b 847 # Search PATH if user did not specify a path or specified path doesn't
The Other Jimmy 31:8ea194f6145b 848 # exist.
The Other Jimmy 31:8ea194f6145b 849 if not TOOLCHAIN_PATHS[tool_key] or not exists(TOOLCHAIN_PATHS[tool_key]):
The Other Jimmy 31:8ea194f6145b 850 exe = find_executable(executable_name)
The Other Jimmy 31:8ea194f6145b 851 if not exe:
The Other Jimmy 31:8ea194f6145b 852 return False
The Other Jimmy 31:8ea194f6145b 853 for level in range(levels_up):
The Other Jimmy 31:8ea194f6145b 854 # move up the specified number of directories
The Other Jimmy 31:8ea194f6145b 855 exe = dirname(exe)
The Other Jimmy 31:8ea194f6145b 856 TOOLCHAIN_PATHS[tool_key] = exe
The Other Jimmy 31:8ea194f6145b 857 if nested_dir:
The Other Jimmy 31:8ea194f6145b 858 subdir = join(TOOLCHAIN_PATHS[tool_key], nested_dir,
The Other Jimmy 31:8ea194f6145b 859 executable_name)
The Other Jimmy 31:8ea194f6145b 860 else:
The Other Jimmy 31:8ea194f6145b 861 subdir = join(TOOLCHAIN_PATHS[tool_key],executable_name)
The Other Jimmy 31:8ea194f6145b 862 # User could have specified a path that exists but does not contain exe
The Other Jimmy 31:8ea194f6145b 863 return exists(subdir) or exists(subdir +'.exe')
The Other Jimmy 31:8ea194f6145b 864
The Other Jimmy 31:8ea194f6145b 865 @abstractmethod
The Other Jimmy 31:8ea194f6145b 866 def check_executable(self):
The Other Jimmy 31:8ea194f6145b 867 """Returns True if the executable (armcc) location specified by the
The Other Jimmy 31:8ea194f6145b 868 user exists OR the executable can be found on the PATH.
The Other Jimmy 31:8ea194f6145b 869 Returns False otherwise."""
The Other Jimmy 31:8ea194f6145b 870 raise NotImplemented
The Other Jimmy 31:8ea194f6145b 871
screamer 24:25bff2709c20 872 @abstractmethod
screamer 24:25bff2709c20 873 def get_config_option(self, config_header):
screamer 24:25bff2709c20 874 """Generate the compiler option that forces the inclusion of the configuration
screamer 24:25bff2709c20 875 header file.
screamer 24:25bff2709c20 876
screamer 24:25bff2709c20 877 Positional arguments:
screamer 24:25bff2709c20 878 config_header -- The configuration header that will be included within all source files
screamer 24:25bff2709c20 879
screamer 24:25bff2709c20 880 Return value:
screamer 24:25bff2709c20 881 A list of the command line arguments that will force the inclusion the specified header
screamer 24:25bff2709c20 882
screamer 24:25bff2709c20 883 Side effects:
screamer 24:25bff2709c20 884 None
screamer 24:25bff2709c20 885 """
screamer 24:25bff2709c20 886 raise NotImplemented
screamer 24:25bff2709c20 887
screamer 24:25bff2709c20 888 @abstractmethod
theotherjimmy 40:7d3fa6b99b2b 889 def get_compile_options(self, defines, includes, for_asm=False):
theotherjimmy 40:7d3fa6b99b2b 890 """Generate the compiler options from the defines and includes
theotherjimmy 40:7d3fa6b99b2b 891
theotherjimmy 40:7d3fa6b99b2b 892 Positional arguments:
theotherjimmy 40:7d3fa6b99b2b 893 defines -- The preprocessor macros defined on the command line
theotherjimmy 40:7d3fa6b99b2b 894 includes -- The include file search paths
theotherjimmy 40:7d3fa6b99b2b 895
theotherjimmy 40:7d3fa6b99b2b 896 Keyword arguments:
theotherjimmy 40:7d3fa6b99b2b 897 for_asm -- generate the assembler options instead of the compiler options
theotherjimmy 40:7d3fa6b99b2b 898
theotherjimmy 40:7d3fa6b99b2b 899 Return value:
theotherjimmy 40:7d3fa6b99b2b 900 A list of the command line arguments that will force the inclusion the specified header
theotherjimmy 40:7d3fa6b99b2b 901
theotherjimmy 40:7d3fa6b99b2b 902 Side effects:
theotherjimmy 40:7d3fa6b99b2b 903 None
theotherjimmy 40:7d3fa6b99b2b 904 """
theotherjimmy 40:7d3fa6b99b2b 905 raise NotImplemented
theotherjimmy 40:7d3fa6b99b2b 906
theotherjimmy 40:7d3fa6b99b2b 907 @abstractmethod
screamer 24:25bff2709c20 908 def assemble(self, source, object, includes):
screamer 24:25bff2709c20 909 """Generate the command line that assembles.
screamer 24:25bff2709c20 910
screamer 24:25bff2709c20 911 Positional arguments:
screamer 24:25bff2709c20 912 source -- a file path that is the file to assemble
screamer 24:25bff2709c20 913 object -- a file path that is the destination object
screamer 24:25bff2709c20 914 includes -- a list of all directories where header files may be found
screamer 24:25bff2709c20 915
screamer 24:25bff2709c20 916 Return value:
screamer 24:25bff2709c20 917 The complete command line, as a list, that would invoke the assembler
screamer 24:25bff2709c20 918 on the source file, include all the include paths, and generate
screamer 24:25bff2709c20 919 the specified object file.
screamer 24:25bff2709c20 920
screamer 24:25bff2709c20 921 Side effects:
screamer 24:25bff2709c20 922 None
screamer 24:25bff2709c20 923
screamer 24:25bff2709c20 924 Note:
screamer 24:25bff2709c20 925 This method should be decorated with @hook_tool.
screamer 24:25bff2709c20 926 """
screamer 24:25bff2709c20 927 raise NotImplemented
screamer 24:25bff2709c20 928
screamer 24:25bff2709c20 929 @abstractmethod
screamer 24:25bff2709c20 930 def compile_c(self, source, object, includes):
screamer 24:25bff2709c20 931 """Generate the command line that compiles a C source file.
screamer 24:25bff2709c20 932
screamer 24:25bff2709c20 933 Positional arguments:
screamer 24:25bff2709c20 934 source -- the C source file to compile
screamer 24:25bff2709c20 935 object -- the destination object file
screamer 24:25bff2709c20 936 includes -- a list of all the directories where header files may be found
screamer 24:25bff2709c20 937
screamer 24:25bff2709c20 938 Return value:
screamer 24:25bff2709c20 939 The complete command line, as a list, that would invoke the C compiler
screamer 24:25bff2709c20 940 on the source file, include all the include paths, and generate the
screamer 24:25bff2709c20 941 specified object file.
screamer 24:25bff2709c20 942
screamer 24:25bff2709c20 943 Side effects:
screamer 24:25bff2709c20 944 None
screamer 24:25bff2709c20 945
screamer 24:25bff2709c20 946 Note:
screamer 24:25bff2709c20 947 This method should be decorated with @hook_tool.
screamer 24:25bff2709c20 948 """
screamer 24:25bff2709c20 949 raise NotImplemented
screamer 24:25bff2709c20 950
screamer 24:25bff2709c20 951 @abstractmethod
screamer 24:25bff2709c20 952 def compile_cpp(self, source, object, includes):
screamer 24:25bff2709c20 953 """Generate the command line that compiles a C++ source file.
screamer 24:25bff2709c20 954
screamer 24:25bff2709c20 955 Positional arguments:
screamer 24:25bff2709c20 956 source -- the C++ source file to compile
screamer 24:25bff2709c20 957 object -- the destination object file
screamer 24:25bff2709c20 958 includes -- a list of all the directories where header files may be found
screamer 24:25bff2709c20 959
screamer 24:25bff2709c20 960 Return value:
screamer 24:25bff2709c20 961 The complete command line, as a list, that would invoke the C++ compiler
screamer 24:25bff2709c20 962 on the source file, include all the include paths, and generate the
screamer 24:25bff2709c20 963 specified object file.
screamer 24:25bff2709c20 964
screamer 24:25bff2709c20 965 Side effects:
screamer 24:25bff2709c20 966 None
screamer 24:25bff2709c20 967
screamer 24:25bff2709c20 968 Note:
screamer 24:25bff2709c20 969 This method should be decorated with @hook_tool.
screamer 24:25bff2709c20 970 """
screamer 24:25bff2709c20 971 raise NotImplemented
screamer 24:25bff2709c20 972
screamer 24:25bff2709c20 973 @abstractmethod
screamer 24:25bff2709c20 974 def link(self, output, objects, libraries, lib_dirs, mem_map):
screamer 24:25bff2709c20 975 """Run the linker to create an executable and memory map.
screamer 24:25bff2709c20 976
screamer 24:25bff2709c20 977 Positional arguments:
screamer 24:25bff2709c20 978 output -- the file name to place the executable in
screamer 24:25bff2709c20 979 objects -- all of the object files to link
screamer 24:25bff2709c20 980 libraries -- all of the required libraries
screamer 24:25bff2709c20 981 lib_dirs -- where the required libraries are located
screamer 24:25bff2709c20 982 mem_map -- the location where the memory map file should be stored
screamer 24:25bff2709c20 983
screamer 24:25bff2709c20 984 Return value:
screamer 24:25bff2709c20 985 None
screamer 24:25bff2709c20 986
screamer 24:25bff2709c20 987 Side effect:
screamer 24:25bff2709c20 988 Runs the linker to produce the executable.
screamer 24:25bff2709c20 989
screamer 24:25bff2709c20 990 Note:
screamer 24:25bff2709c20 991 This method should be decorated with @hook_tool.
screamer 24:25bff2709c20 992 """
screamer 24:25bff2709c20 993 raise NotImplemented
screamer 24:25bff2709c20 994
screamer 24:25bff2709c20 995 @abstractmethod
screamer 24:25bff2709c20 996 def archive(self, objects, lib_path):
screamer 24:25bff2709c20 997 """Run the command line that creates an archive.
screamer 24:25bff2709c20 998
screamer 24:25bff2709c20 999 Positional arguhments:
screamer 24:25bff2709c20 1000 objects -- a list of all the object files that should be archived
screamer 24:25bff2709c20 1001 lib_path -- the file name of the resulting library file
screamer 24:25bff2709c20 1002
screamer 24:25bff2709c20 1003 Return value:
screamer 24:25bff2709c20 1004 None
screamer 24:25bff2709c20 1005
screamer 24:25bff2709c20 1006 Side effect:
screamer 24:25bff2709c20 1007 Runs the archiving tool to produce the library file.
screamer 24:25bff2709c20 1008
screamer 24:25bff2709c20 1009 Note:
screamer 24:25bff2709c20 1010 This method should be decorated with @hook_tool.
screamer 24:25bff2709c20 1011 """
screamer 24:25bff2709c20 1012 raise NotImplemented
screamer 24:25bff2709c20 1013
screamer 24:25bff2709c20 1014 @abstractmethod
screamer 24:25bff2709c20 1015 def binary(self, resources, elf, bin):
screamer 24:25bff2709c20 1016 """Run the command line that will Extract a simplified binary file.
screamer 24:25bff2709c20 1017
screamer 24:25bff2709c20 1018 Positional arguments:
screamer 24:25bff2709c20 1019 resources -- A resources object (Is not used in any of the toolchains)
screamer 24:25bff2709c20 1020 elf -- the executable file that is to be converted
screamer 24:25bff2709c20 1021 bin -- the file name of the to be created simplified binary file
screamer 24:25bff2709c20 1022
screamer 24:25bff2709c20 1023 Return value:
screamer 24:25bff2709c20 1024 None
screamer 24:25bff2709c20 1025
screamer 24:25bff2709c20 1026 Side effect:
screamer 24:25bff2709c20 1027 Runs the elf2bin tool to produce the simplified binary file.
screamer 24:25bff2709c20 1028
screamer 24:25bff2709c20 1029 Note:
screamer 24:25bff2709c20 1030 This method should be decorated with @hook_tool.
screamer 24:25bff2709c20 1031 """
screamer 24:25bff2709c20 1032 raise NotImplemented
screamer 13:ab47a20b66f0 1033
The Other Jimmy 36:96847d42f010 1034 @staticmethod
The Other Jimmy 36:96847d42f010 1035 @abstractmethod
The Other Jimmy 36:96847d42f010 1036 def name_mangle(name):
The Other Jimmy 36:96847d42f010 1037 """Mangle a name based on the conventional name mangling of this toolchain
The Other Jimmy 36:96847d42f010 1038
The Other Jimmy 36:96847d42f010 1039 Positional arguments:
The Other Jimmy 36:96847d42f010 1040 name -- the name to mangle
The Other Jimmy 36:96847d42f010 1041
The Other Jimmy 36:96847d42f010 1042 Return:
The Other Jimmy 36:96847d42f010 1043 the mangled name as a string
The Other Jimmy 36:96847d42f010 1044 """
The Other Jimmy 36:96847d42f010 1045 raise NotImplemented
The Other Jimmy 36:96847d42f010 1046
The Other Jimmy 36:96847d42f010 1047 @staticmethod
The Other Jimmy 36:96847d42f010 1048 @abstractmethod
The Other Jimmy 36:96847d42f010 1049 def make_ld_define(name, value):
The Other Jimmy 36:96847d42f010 1050 """Create an argument to the linker that would define a symbol
The Other Jimmy 36:96847d42f010 1051
The Other Jimmy 36:96847d42f010 1052 Positional arguments:
The Other Jimmy 36:96847d42f010 1053 name -- the symbol to define
The Other Jimmy 36:96847d42f010 1054 value -- the value to give the symbol
The Other Jimmy 36:96847d42f010 1055
The Other Jimmy 36:96847d42f010 1056 Return:
The Other Jimmy 36:96847d42f010 1057 The linker flag as a string
The Other Jimmy 36:96847d42f010 1058 """
The Other Jimmy 36:96847d42f010 1059 raise NotImplemented
The Other Jimmy 36:96847d42f010 1060
The Other Jimmy 36:96847d42f010 1061 @staticmethod
The Other Jimmy 36:96847d42f010 1062 @abstractmethod
The Other Jimmy 36:96847d42f010 1063 def redirect_symbol(source, sync, build_dir):
The Other Jimmy 36:96847d42f010 1064 """Redirect a symbol at link time to point at somewhere else
The Other Jimmy 36:96847d42f010 1065
The Other Jimmy 36:96847d42f010 1066 Positional arguments:
The Other Jimmy 36:96847d42f010 1067 source -- the symbol doing the pointing
The Other Jimmy 36:96847d42f010 1068 sync -- the symbol being pointed to
The Other Jimmy 36:96847d42f010 1069 build_dir -- the directory to put "response files" if needed by the toolchain
The Other Jimmy 36:96847d42f010 1070
The Other Jimmy 36:96847d42f010 1071 Side Effects:
The Other Jimmy 36:96847d42f010 1072 Possibly create a file in the build directory
The Other Jimmy 36:96847d42f010 1073
The Other Jimmy 36:96847d42f010 1074 Return:
The Other Jimmy 36:96847d42f010 1075 The linker flag to redirect the symbol, as a string
The Other Jimmy 36:96847d42f010 1076 """
The Other Jimmy 36:96847d42f010 1077 raise NotImplemented
The Other Jimmy 36:96847d42f010 1078
screamer 13:ab47a20b66f0 1079 # Return the list of macros geenrated by the build system
screamer 13:ab47a20b66f0 1080 def get_config_macros(self):
theotherjimmy 40:7d3fa6b99b2b 1081 return self.config.config_to_macros(self.config_data) if self.config_data else []
screamer 13:ab47a20b66f0 1082
theotherjimmy 43:2a7da56ebd24 1083 @abstractmethod
theotherjimmy 43:2a7da56ebd24 1084 def version_check(self):
theotherjimmy 43:2a7da56ebd24 1085 """Check the version of a compiler being used and raise a
theotherjimmy 43:2a7da56ebd24 1086 NotSupportedException when it's incorrect.
theotherjimmy 43:2a7da56ebd24 1087 """
theotherjimmy 43:2a7da56ebd24 1088 raise NotImplemented
theotherjimmy 43:2a7da56ebd24 1089
The Other Jimmy 36:96847d42f010 1090 @property
The Other Jimmy 36:96847d42f010 1091 def report(self):
The Other Jimmy 36:96847d42f010 1092 to_ret = {}
The Other Jimmy 36:96847d42f010 1093 to_ret['c_compiler'] = {'flags': copy(self.flags['c']),
The Other Jimmy 36:96847d42f010 1094 'symbols': self.get_symbols()}
The Other Jimmy 36:96847d42f010 1095 to_ret['cxx_compiler'] = {'flags': copy(self.flags['cxx']),
The Other Jimmy 36:96847d42f010 1096 'symbols': self.get_symbols()}
The Other Jimmy 36:96847d42f010 1097 to_ret['assembler'] = {'flags': copy(self.flags['asm']),
The Other Jimmy 36:96847d42f010 1098 'symbols': self.get_symbols(True)}
The Other Jimmy 36:96847d42f010 1099 to_ret['linker'] = {'flags': copy(self.flags['ld'])}
The Other Jimmy 36:96847d42f010 1100 to_ret.update(self.config.report)
The Other Jimmy 36:96847d42f010 1101 return to_ret
The Other Jimmy 36:96847d42f010 1102
theotherjimmy 40:7d3fa6b99b2b 1103 from tools.settings import ARM_PATH, ARMC6_PATH, GCC_ARM_PATH, IAR_PATH
screamer 0:66f3b5499f7f 1104
screamer 20:835f6355470d 1105 TOOLCHAIN_PATHS = {
screamer 20:835f6355470d 1106 'ARM': ARM_PATH,
screamer 20:835f6355470d 1107 'uARM': ARM_PATH,
theotherjimmy 40:7d3fa6b99b2b 1108 'ARMC6': ARMC6_PATH,
screamer 0:66f3b5499f7f 1109 'GCC_ARM': GCC_ARM_PATH,
screamer 0:66f3b5499f7f 1110 'IAR': IAR_PATH
screamer 0:66f3b5499f7f 1111 }
screamer 0:66f3b5499f7f 1112
theotherjimmy 40:7d3fa6b99b2b 1113 from tools.toolchains.arm import ARM_STD, ARM_MICRO, ARMC6
The Other Jimmy 36:96847d42f010 1114 from tools.toolchains.gcc import GCC_ARM
screamer 0:66f3b5499f7f 1115 from tools.toolchains.iar import IAR
screamer 0:66f3b5499f7f 1116
screamer 0:66f3b5499f7f 1117 TOOLCHAIN_CLASSES = {
theotherjimmy 43:2a7da56ebd24 1118 u'ARM': ARM_STD,
theotherjimmy 43:2a7da56ebd24 1119 u'uARM': ARM_MICRO,
theotherjimmy 43:2a7da56ebd24 1120 u'ARMC6': ARMC6,
theotherjimmy 43:2a7da56ebd24 1121 u'GCC_ARM': GCC_ARM,
theotherjimmy 43:2a7da56ebd24 1122 u'IAR': IAR
screamer 0:66f3b5499f7f 1123 }
screamer 0:66f3b5499f7f 1124
screamer 0:66f3b5499f7f 1125 TOOLCHAINS = set(TOOLCHAIN_CLASSES.keys())