Clone of official tools

Committer:
The Other Jimmy
Date:
Thu Jul 13 15:26:26 2017 -0500
Revision:
38:399953da035d
Parent:
36:96847d42f010
Child:
40:7d3fa6b99b2b
Update to tools release 5.5.2

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 """
screamer 0:66f3b5499f7f 17
screamer 0:66f3b5499f7f 18 import re
screamer 0:66f3b5499f7f 19 import sys
screamer 24:25bff2709c20 20 from os import stat, walk, getcwd, sep, remove
screamer 0:66f3b5499f7f 21 from copy import copy
screamer 0:66f3b5499f7f 22 from time import time, sleep
screamer 0:66f3b5499f7f 23 from types import ListType
screamer 0:66f3b5499f7f 24 from shutil import copyfile
The Other Jimmy 38:399953da035d 25 from os.path import join, splitext, exists, relpath, dirname, basename, split, abspath, isfile, isdir, normcase
The Other Jimmy 38:399953da035d 26 from itertools import chain
screamer 0:66f3b5499f7f 27 from inspect import getmro
screamer 13:ab47a20b66f0 28 from copy import deepcopy
screamer 13:ab47a20b66f0 29 from tools.config import Config
screamer 24:25bff2709c20 30 from abc import ABCMeta, abstractmethod
The Other Jimmy 31:8ea194f6145b 31 from distutils.spawn import find_executable
screamer 0:66f3b5499f7f 32
screamer 0:66f3b5499f7f 33 from multiprocessing import Pool, cpu_count
screamer 21:4fdf0dd04f6f 34 from tools.utils import run_cmd, mkdir, rel_path, ToolException, NotSupportedException, split_path, compile_worker
The Other Jimmy 31:8ea194f6145b 35 from tools.settings import MBED_ORG_USER
screamer 0:66f3b5499f7f 36 import tools.hooks as hooks
Screamer@Y5070-M.virtuoso 12:f2e8a005c7d3 37 from tools.memap import MemapParser
screamer 0:66f3b5499f7f 38 from hashlib import md5
screamer 7:5af61d55adbe 39 import fnmatch
screamer 0:66f3b5499f7f 40
screamer 0:66f3b5499f7f 41
screamer 0:66f3b5499f7f 42 #Disables multiprocessing if set to higher number than the host machine CPUs
screamer 0:66f3b5499f7f 43 CPU_COUNT_MIN = 1
screamer 21:4fdf0dd04f6f 44 CPU_COEF = 1
screamer 7:5af61d55adbe 45
The Other Jimmy 38:399953da035d 46 class LazyDict(dict):
The Other Jimmy 38:399953da035d 47 def __init__(self):
The Other Jimmy 38:399953da035d 48 self.eager = {}
The Other Jimmy 38:399953da035d 49 self.lazy = {}
The Other Jimmy 38:399953da035d 50
The Other Jimmy 38:399953da035d 51 def add_lazy(self, key, thunk):
The Other Jimmy 38:399953da035d 52 if key in self.eager:
The Other Jimmy 38:399953da035d 53 del self.eager[key]
The Other Jimmy 38:399953da035d 54 self.lazy[key] = thunk
The Other Jimmy 38:399953da035d 55
The Other Jimmy 38:399953da035d 56 def __getitem__(self, key):
The Other Jimmy 38:399953da035d 57 if (key not in self.eager
The Other Jimmy 38:399953da035d 58 and key in self.lazy):
The Other Jimmy 38:399953da035d 59 self.eager[key] = self.lazy[key]()
The Other Jimmy 38:399953da035d 60 del self.lazy[key]
The Other Jimmy 38:399953da035d 61 return self.eager[key]
The Other Jimmy 38:399953da035d 62
The Other Jimmy 38:399953da035d 63 def __setitem__(self, key, value):
The Other Jimmy 38:399953da035d 64 self.eager[key] = value
The Other Jimmy 38:399953da035d 65
The Other Jimmy 38:399953da035d 66 def __delitem__(self, key):
The Other Jimmy 38:399953da035d 67 if key in self.eager:
The Other Jimmy 38:399953da035d 68 del self.eager[key]
The Other Jimmy 38:399953da035d 69 else:
The Other Jimmy 38:399953da035d 70 del self.lazy[key]
The Other Jimmy 38:399953da035d 71
The Other Jimmy 38:399953da035d 72 def __contains__(self, key):
The Other Jimmy 38:399953da035d 73 return key in self.eager or key in self.lazy
The Other Jimmy 38:399953da035d 74
The Other Jimmy 38:399953da035d 75 def __iter__(self):
The Other Jimmy 38:399953da035d 76 return chain(iter(self.eager), iter(self.lazy))
The Other Jimmy 38:399953da035d 77
The Other Jimmy 38:399953da035d 78 def __len__(self):
The Other Jimmy 38:399953da035d 79 return len(self.eager) + len(self.lazy)
The Other Jimmy 38:399953da035d 80
The Other Jimmy 38:399953da035d 81 def __str__(self):
The Other Jimmy 38:399953da035d 82 return "Lazy{%s}" % (
The Other Jimmy 38:399953da035d 83 ", ".join("%r: %r" % (k, v) for k, v in
The Other Jimmy 38:399953da035d 84 chain(self.eager.iteritems(), ((k, "not evaluated")
The Other Jimmy 38:399953da035d 85 for k in self.lazy))))
The Other Jimmy 38:399953da035d 86
The Other Jimmy 38:399953da035d 87 def update(self, other):
The Other Jimmy 38:399953da035d 88 if isinstance(other, LazyDict):
The Other Jimmy 38:399953da035d 89 self.eager.update(other.eager)
The Other Jimmy 38:399953da035d 90 self.lazy.update(other.lazy)
The Other Jimmy 38:399953da035d 91 else:
The Other Jimmy 38:399953da035d 92 self.eager.update(other)
The Other Jimmy 38:399953da035d 93
The Other Jimmy 38:399953da035d 94 def iteritems(self):
The Other Jimmy 38:399953da035d 95 """Warning: This forces the evaluation all of the items in this LazyDict
The Other Jimmy 38:399953da035d 96 that are iterated over."""
The Other Jimmy 38:399953da035d 97 for k, v in self.eager.iteritems():
The Other Jimmy 38:399953da035d 98 yield k, v
The Other Jimmy 38:399953da035d 99 for k in self.lazy.keys():
The Other Jimmy 38:399953da035d 100 yield k, self[k]
The Other Jimmy 38:399953da035d 101
The Other Jimmy 38:399953da035d 102 def apply(self, fn):
The Other Jimmy 38:399953da035d 103 """Delay the application of a computation to all items of the lazy dict.
The Other Jimmy 38:399953da035d 104 Does no computation now. Instead the comuptation is performed when a
The Other Jimmy 38:399953da035d 105 consumer attempts to access a value in this LazyDict"""
The Other Jimmy 38:399953da035d 106 new_lazy = {}
The Other Jimmy 38:399953da035d 107 for k, f in self.lazy.iteritems():
The Other Jimmy 38:399953da035d 108 def closure(f=f):
The Other Jimmy 38:399953da035d 109 return fn(f())
The Other Jimmy 38:399953da035d 110 new_lazy[k] = closure
The Other Jimmy 38:399953da035d 111 for k, v in self.eager.iteritems():
The Other Jimmy 38:399953da035d 112 def closure(v=v):
The Other Jimmy 38:399953da035d 113 return fn(v)
The Other Jimmy 38:399953da035d 114 new_lazy[k] = closure
The Other Jimmy 38:399953da035d 115 self.lazy = new_lazy
The Other Jimmy 38:399953da035d 116 self.eager = {}
The Other Jimmy 38:399953da035d 117
screamer 0:66f3b5499f7f 118 class Resources:
screamer 0:66f3b5499f7f 119 def __init__(self, base_path=None):
screamer 0:66f3b5499f7f 120 self.base_path = base_path
screamer 0:66f3b5499f7f 121
screamer 13:ab47a20b66f0 122 self.file_basepath = {}
screamer 13:ab47a20b66f0 123
screamer 0:66f3b5499f7f 124 self.inc_dirs = []
screamer 0:66f3b5499f7f 125 self.headers = []
screamer 0:66f3b5499f7f 126
screamer 0:66f3b5499f7f 127 self.s_sources = []
screamer 0:66f3b5499f7f 128 self.c_sources = []
screamer 0:66f3b5499f7f 129 self.cpp_sources = []
screamer 0:66f3b5499f7f 130
screamer 0:66f3b5499f7f 131 self.lib_dirs = set([])
screamer 0:66f3b5499f7f 132 self.objects = []
screamer 0:66f3b5499f7f 133 self.libraries = []
screamer 0:66f3b5499f7f 134
screamer 0:66f3b5499f7f 135 # mbed special files
screamer 0:66f3b5499f7f 136 self.lib_builds = []
screamer 0:66f3b5499f7f 137 self.lib_refs = []
screamer 0:66f3b5499f7f 138
screamer 0:66f3b5499f7f 139 self.repo_dirs = []
screamer 0:66f3b5499f7f 140 self.repo_files = []
screamer 0:66f3b5499f7f 141
screamer 0:66f3b5499f7f 142 self.linker_script = None
screamer 0:66f3b5499f7f 143
screamer 0:66f3b5499f7f 144 # Other files
screamer 0:66f3b5499f7f 145 self.hex_files = []
screamer 0:66f3b5499f7f 146 self.bin_files = []
screamer 7:5af61d55adbe 147 self.json_files = []
screamer 7:5af61d55adbe 148
screamer 13:ab47a20b66f0 149 # Features
The Other Jimmy 38:399953da035d 150 self.features = LazyDict()
screamer 13:ab47a20b66f0 151
screamer 7:5af61d55adbe 152 def __add__(self, resources):
screamer 7:5af61d55adbe 153 if resources is None:
screamer 7:5af61d55adbe 154 return self
screamer 7:5af61d55adbe 155 else:
screamer 7:5af61d55adbe 156 return self.add(resources)
screamer 7:5af61d55adbe 157
screamer 7:5af61d55adbe 158 def __radd__(self, resources):
screamer 7:5af61d55adbe 159 if resources is None:
screamer 7:5af61d55adbe 160 return self
screamer 7:5af61d55adbe 161 else:
screamer 7:5af61d55adbe 162 return self.add(resources)
screamer 0:66f3b5499f7f 163
screamer 0:66f3b5499f7f 164 def add(self, resources):
screamer 13:ab47a20b66f0 165 for f,p in resources.file_basepath.items():
screamer 13:ab47a20b66f0 166 self.file_basepath[f] = p
screamer 13:ab47a20b66f0 167
screamer 0:66f3b5499f7f 168 self.inc_dirs += resources.inc_dirs
screamer 0:66f3b5499f7f 169 self.headers += resources.headers
screamer 0:66f3b5499f7f 170
screamer 0:66f3b5499f7f 171 self.s_sources += resources.s_sources
screamer 0:66f3b5499f7f 172 self.c_sources += resources.c_sources
screamer 0:66f3b5499f7f 173 self.cpp_sources += resources.cpp_sources
screamer 0:66f3b5499f7f 174
screamer 0:66f3b5499f7f 175 self.lib_dirs |= resources.lib_dirs
screamer 0:66f3b5499f7f 176 self.objects += resources.objects
screamer 0:66f3b5499f7f 177 self.libraries += resources.libraries
screamer 0:66f3b5499f7f 178
screamer 0:66f3b5499f7f 179 self.lib_builds += resources.lib_builds
screamer 0:66f3b5499f7f 180 self.lib_refs += resources.lib_refs
screamer 0:66f3b5499f7f 181
screamer 0:66f3b5499f7f 182 self.repo_dirs += resources.repo_dirs
screamer 0:66f3b5499f7f 183 self.repo_files += resources.repo_files
screamer 0:66f3b5499f7f 184
screamer 0:66f3b5499f7f 185 if resources.linker_script is not None:
screamer 0:66f3b5499f7f 186 self.linker_script = resources.linker_script
screamer 0:66f3b5499f7f 187
screamer 0:66f3b5499f7f 188 self.hex_files += resources.hex_files
screamer 0:66f3b5499f7f 189 self.bin_files += resources.bin_files
screamer 7:5af61d55adbe 190 self.json_files += resources.json_files
screamer 7:5af61d55adbe 191
screamer 13:ab47a20b66f0 192 self.features.update(resources.features)
screamer 13:ab47a20b66f0 193
screamer 7:5af61d55adbe 194 return self
screamer 0:66f3b5499f7f 195
The Other Jimmy 31:8ea194f6145b 196 def _collect_duplicates(self, dupe_dict, dupe_headers):
The Other Jimmy 31:8ea194f6145b 197 for filename in self.s_sources + self.c_sources + self.cpp_sources:
The Other Jimmy 31:8ea194f6145b 198 objname, _ = splitext(basename(filename))
The Other Jimmy 31:8ea194f6145b 199 dupe_dict.setdefault(objname, set())
The Other Jimmy 31:8ea194f6145b 200 dupe_dict[objname] |= set([filename])
The Other Jimmy 31:8ea194f6145b 201 for filename in self.headers:
The Other Jimmy 31:8ea194f6145b 202 headername = basename(filename)
The Other Jimmy 31:8ea194f6145b 203 dupe_headers.setdefault(headername, set())
The Other Jimmy 31:8ea194f6145b 204 dupe_headers[headername] |= set([headername])
The Other Jimmy 31:8ea194f6145b 205 for res in self.features.values():
The Other Jimmy 31:8ea194f6145b 206 res._collect_duplicates(dupe_dict, dupe_headers)
The Other Jimmy 31:8ea194f6145b 207 return dupe_dict, dupe_headers
The Other Jimmy 31:8ea194f6145b 208
The Other Jimmy 31:8ea194f6145b 209 def detect_duplicates(self, toolchain):
The Other Jimmy 31:8ea194f6145b 210 """Detect all potential ambiguities in filenames and report them with
The Other Jimmy 31:8ea194f6145b 211 a toolchain notification
The Other Jimmy 31:8ea194f6145b 212
The Other Jimmy 31:8ea194f6145b 213 Positional Arguments:
The Other Jimmy 31:8ea194f6145b 214 toolchain - used for notifications
The Other Jimmy 31:8ea194f6145b 215 """
The Other Jimmy 31:8ea194f6145b 216 count = 0
The Other Jimmy 31:8ea194f6145b 217 dupe_dict, dupe_headers = self._collect_duplicates(dict(), dict())
The Other Jimmy 31:8ea194f6145b 218 for objname, filenames in dupe_dict.iteritems():
The Other Jimmy 31:8ea194f6145b 219 if len(filenames) > 1:
The Other Jimmy 31:8ea194f6145b 220 count+=1
The Other Jimmy 31:8ea194f6145b 221 toolchain.tool_error(
The Other Jimmy 31:8ea194f6145b 222 "Object file %s.o is not unique! It could be made from: %s"\
The Other Jimmy 31:8ea194f6145b 223 % (objname, " ".join(filenames)))
The Other Jimmy 31:8ea194f6145b 224 for headername, locations in dupe_headers.iteritems():
The Other Jimmy 31:8ea194f6145b 225 if len(locations) > 1:
The Other Jimmy 31:8ea194f6145b 226 count+=1
The Other Jimmy 31:8ea194f6145b 227 toolchain.tool_error(
The Other Jimmy 31:8ea194f6145b 228 "Header file %s is not unique! It could be: %s" %\
The Other Jimmy 31:8ea194f6145b 229 (headername, " ".join(locations)))
The Other Jimmy 31:8ea194f6145b 230 return count
The Other Jimmy 31:8ea194f6145b 231
The Other Jimmy 31:8ea194f6145b 232
screamer 0:66f3b5499f7f 233 def relative_to(self, base, dot=False):
screamer 0:66f3b5499f7f 234 for field in ['inc_dirs', 'headers', 's_sources', 'c_sources',
screamer 0:66f3b5499f7f 235 'cpp_sources', 'lib_dirs', 'objects', 'libraries',
screamer 7:5af61d55adbe 236 'lib_builds', 'lib_refs', 'repo_dirs', 'repo_files',
screamer 7:5af61d55adbe 237 'hex_files', 'bin_files', 'json_files']:
screamer 0:66f3b5499f7f 238 v = [rel_path(f, base, dot) for f in getattr(self, field)]
screamer 0:66f3b5499f7f 239 setattr(self, field, v)
screamer 13:ab47a20b66f0 240
The Other Jimmy 38:399953da035d 241 def to_apply(feature, base=base, dot=dot):
The Other Jimmy 38:399953da035d 242 feature.relative_to(base, dot)
The Other Jimmy 38:399953da035d 243 self.features.apply(to_apply)
screamer 13:ab47a20b66f0 244
screamer 0:66f3b5499f7f 245 if self.linker_script is not None:
screamer 0:66f3b5499f7f 246 self.linker_script = rel_path(self.linker_script, base, dot)
screamer 0:66f3b5499f7f 247
screamer 0:66f3b5499f7f 248 def win_to_unix(self):
screamer 0:66f3b5499f7f 249 for field in ['inc_dirs', 'headers', 's_sources', 'c_sources',
screamer 0:66f3b5499f7f 250 'cpp_sources', 'lib_dirs', 'objects', 'libraries',
screamer 7:5af61d55adbe 251 'lib_builds', 'lib_refs', 'repo_dirs', 'repo_files',
screamer 7:5af61d55adbe 252 'hex_files', 'bin_files', 'json_files']:
screamer 0:66f3b5499f7f 253 v = [f.replace('\\', '/') for f in getattr(self, field)]
screamer 0:66f3b5499f7f 254 setattr(self, field, v)
screamer 13:ab47a20b66f0 255
The Other Jimmy 38:399953da035d 256 def to_apply(feature):
The Other Jimmy 38:399953da035d 257 feature.win_to_unix()
The Other Jimmy 38:399953da035d 258 self.features.apply(to_apply)
screamer 13:ab47a20b66f0 259
screamer 0:66f3b5499f7f 260 if self.linker_script is not None:
screamer 0:66f3b5499f7f 261 self.linker_script = self.linker_script.replace('\\', '/')
screamer 0:66f3b5499f7f 262
screamer 0:66f3b5499f7f 263 def __str__(self):
screamer 0:66f3b5499f7f 264 s = []
screamer 0:66f3b5499f7f 265
screamer 0:66f3b5499f7f 266 for (label, resources) in (
screamer 0:66f3b5499f7f 267 ('Include Directories', self.inc_dirs),
screamer 0:66f3b5499f7f 268 ('Headers', self.headers),
screamer 0:66f3b5499f7f 269
screamer 0:66f3b5499f7f 270 ('Assembly sources', self.s_sources),
screamer 0:66f3b5499f7f 271 ('C sources', self.c_sources),
screamer 0:66f3b5499f7f 272 ('C++ sources', self.cpp_sources),
screamer 0:66f3b5499f7f 273
screamer 0:66f3b5499f7f 274 ('Library directories', self.lib_dirs),
screamer 0:66f3b5499f7f 275 ('Objects', self.objects),
screamer 0:66f3b5499f7f 276 ('Libraries', self.libraries),
screamer 0:66f3b5499f7f 277
screamer 0:66f3b5499f7f 278 ('Hex files', self.hex_files),
screamer 0:66f3b5499f7f 279 ('Bin files', self.bin_files),
screamer 13:ab47a20b66f0 280
screamer 13:ab47a20b66f0 281 ('Features', self.features),
screamer 0:66f3b5499f7f 282 ):
screamer 0:66f3b5499f7f 283 if resources:
screamer 0:66f3b5499f7f 284 s.append('%s:\n ' % label + '\n '.join(resources))
screamer 0:66f3b5499f7f 285
screamer 0:66f3b5499f7f 286 if self.linker_script:
screamer 0:66f3b5499f7f 287 s.append('Linker Script: ' + self.linker_script)
screamer 0:66f3b5499f7f 288
screamer 0:66f3b5499f7f 289 return '\n'.join(s)
screamer 0:66f3b5499f7f 290
screamer 0:66f3b5499f7f 291 # Support legacy build conventions: the original mbed build system did not have
screamer 0:66f3b5499f7f 292 # standard labels for the "TARGET_" and "TOOLCHAIN_" specific directories, but
screamer 0:66f3b5499f7f 293 # had the knowledge of a list of these directories to be ignored.
screamer 0:66f3b5499f7f 294 LEGACY_IGNORE_DIRS = set([
The Other Jimmy 38:399953da035d 295 'LPC11U24', 'LPC1768', 'LPC2368', 'LPC4088', 'LPC812', 'KL25Z',
screamer 14:ee1b877e6839 296 'ARM', 'uARM', 'IAR',
screamer 14:ee1b877e6839 297 'GCC_ARM', 'GCC_CS', 'GCC_CR', 'GCC_CW', 'GCC_CW_EWL', 'GCC_CW_NEWLIB',
screamer 0:66f3b5499f7f 298 ])
screamer 0:66f3b5499f7f 299 LEGACY_TOOLCHAIN_NAMES = {
screamer 0:66f3b5499f7f 300 'ARM_STD':'ARM', 'ARM_MICRO': 'uARM',
screamer 17:04753e1e329d 301 'GCC_ARM': 'GCC_ARM', 'GCC_CR': 'GCC_CR',
screamer 0:66f3b5499f7f 302 'IAR': 'IAR',
screamer 0:66f3b5499f7f 303 }
screamer 0:66f3b5499f7f 304
screamer 0:66f3b5499f7f 305
screamer 0:66f3b5499f7f 306 class mbedToolchain:
screamer 24:25bff2709c20 307 # Verbose logging
screamer 0:66f3b5499f7f 308 VERBOSE = True
screamer 24:25bff2709c20 309
screamer 24:25bff2709c20 310 # Compile C files as CPP
screamer 21:4fdf0dd04f6f 311 COMPILE_C_AS_CPP = False
screamer 24:25bff2709c20 312
screamer 24:25bff2709c20 313 # Response files for compiling, includes, linking and archiving.
screamer 24:25bff2709c20 314 # Not needed on posix systems where the typical arg limit is 2 megabytes
screamer 21:4fdf0dd04f6f 315 RESPONSE_FILES = True
screamer 0:66f3b5499f7f 316
screamer 0:66f3b5499f7f 317 CORTEX_SYMBOLS = {
screamer 0:66f3b5499f7f 318 "Cortex-M0" : ["__CORTEX_M0", "ARM_MATH_CM0", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 0:66f3b5499f7f 319 "Cortex-M0+": ["__CORTEX_M0PLUS", "ARM_MATH_CM0PLUS", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 17:04753e1e329d 320 "Cortex-M1" : ["__CORTEX_M3", "ARM_MATH_CM1", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 0:66f3b5499f7f 321 "Cortex-M3" : ["__CORTEX_M3", "ARM_MATH_CM3", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 0:66f3b5499f7f 322 "Cortex-M4" : ["__CORTEX_M4", "ARM_MATH_CM4", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 17:04753e1e329d 323 "Cortex-M4F" : ["__CORTEX_M4", "ARM_MATH_CM4", "__FPU_PRESENT=1", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 0:66f3b5499f7f 324 "Cortex-M7" : ["__CORTEX_M7", "ARM_MATH_CM7", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 17:04753e1e329d 325 "Cortex-M7F" : ["__CORTEX_M7", "ARM_MATH_CM7", "__FPU_PRESENT=1", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 17:04753e1e329d 326 "Cortex-M7FD" : ["__CORTEX_M7", "ARM_MATH_CM7", "__FPU_PRESENT=1", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"],
screamer 0:66f3b5499f7f 327 "Cortex-A9" : ["__CORTEX_A9", "ARM_MATH_CA9", "__FPU_PRESENT", "__CMSIS_RTOS", "__EVAL", "__MBED_CMSIS_RTOS_CA9"],
screamer 0:66f3b5499f7f 328 }
screamer 0:66f3b5499f7f 329
screamer 13:ab47a20b66f0 330 MBED_CONFIG_FILE_NAME="mbed_config.h"
screamer 13:ab47a20b66f0 331
The Other Jimmy 36:96847d42f010 332 PROFILE_FILE_NAME = ".profile"
The Other Jimmy 36:96847d42f010 333
screamer 24:25bff2709c20 334 __metaclass__ = ABCMeta
screamer 24:25bff2709c20 335
The Other Jimmy 31:8ea194f6145b 336 profile_template = {'common':[], 'c':[], 'cxx':[], 'asm':[], 'ld':[]}
The Other Jimmy 31:8ea194f6145b 337
The Other Jimmy 36:96847d42f010 338 def __init__(self, target, notify=None, macros=None, silent=False,
The Other Jimmy 36:96847d42f010 339 extra_verbose=False, build_profile=None, build_dir=None):
screamer 0:66f3b5499f7f 340 self.target = target
screamer 0:66f3b5499f7f 341 self.name = self.__class__.__name__
screamer 22:9e85236d8716 342
screamer 13:ab47a20b66f0 343 # compile/assemble/link/binary hooks
screamer 0:66f3b5499f7f 344 self.hook = hooks.Hook(target, self)
screamer 13:ab47a20b66f0 345
screamer 13:ab47a20b66f0 346 # Toolchain flags
The Other Jimmy 31:8ea194f6145b 347 self.flags = deepcopy(build_profile or self.profile_template)
screamer 22:9e85236d8716 348
The Other Jimmy 35:da9c89f8be7d 349 # System libraries provided by the toolchain
The Other Jimmy 35:da9c89f8be7d 350 self.sys_libs = []
The Other Jimmy 35:da9c89f8be7d 351
screamer 13:ab47a20b66f0 352 # User-defined macros
screamer 13:ab47a20b66f0 353 self.macros = macros or []
screamer 22:9e85236d8716 354
screamer 13:ab47a20b66f0 355 # Macros generated from toolchain and target rules/features
screamer 29:1210849dba19 356 self.asm_symbols = None
screamer 29:1210849dba19 357 self.cxx_symbols = None
screamer 22:9e85236d8716 358
screamer 13:ab47a20b66f0 359 # Labels generated from toolchain and target rules/features (used for selective build)
screamer 13:ab47a20b66f0 360 self.labels = None
screamer 22:9e85236d8716 361
screamer 24:25bff2709c20 362 # This will hold the initialized config object
screamer 24:25bff2709c20 363 self.config = None
screamer 24:25bff2709c20 364
screamer 13:ab47a20b66f0 365 # This will hold the configuration data (as returned by Config.get_config_data())
screamer 13:ab47a20b66f0 366 self.config_data = None
screamer 0:66f3b5499f7f 367
screamer 24:25bff2709c20 368 # This will hold the location of the configuration file or None if there's no configuration available
screamer 24:25bff2709c20 369 self.config_file = None
screamer 24:25bff2709c20 370
screamer 24:25bff2709c20 371 # Call guard for "get_config_data" (see the comments of get_config_data for details)
screamer 24:25bff2709c20 372 self.config_processed = False
screamer 24:25bff2709c20 373
screamer 13:ab47a20b66f0 374 # Non-incremental compile
screamer 13:ab47a20b66f0 375 self.build_all = False
screamer 22:9e85236d8716 376
screamer 13:ab47a20b66f0 377 # Build output dir
The Other Jimmy 36:96847d42f010 378 self.build_dir = build_dir
screamer 13:ab47a20b66f0 379 self.timestamp = time()
screamer 13:ab47a20b66f0 380
screamer 13:ab47a20b66f0 381 # Number of concurrent build jobs. 0 means auto (based on host system cores)
screamer 13:ab47a20b66f0 382 self.jobs = 0
screamer 13:ab47a20b66f0 383
screamer 13:ab47a20b66f0 384 # Ignore patterns from .mbedignore files
screamer 13:ab47a20b66f0 385 self.ignore_patterns = []
The Other Jimmy 38:399953da035d 386 self._ignore_regex = re.compile("$^")
screamer 13:ab47a20b66f0 387
screamer 13:ab47a20b66f0 388 # Pre-mbed 2.0 ignore dirs
screamer 21:4fdf0dd04f6f 389 self.legacy_ignore_dirs = (LEGACY_IGNORE_DIRS | TOOLCHAINS) - set([target.name, LEGACY_TOOLCHAIN_NAMES[self.name]])
screamer 0:66f3b5499f7f 390
screamer 13:ab47a20b66f0 391 # Output notify function
screamer 22:9e85236d8716 392 # This function is passed all events, and expected to handle notification of the
screamer 22:9e85236d8716 393 # user, emit the events to a log, etc.
screamer 22:9e85236d8716 394 # The API for all notify methods passed into the notify parameter is as follows:
screamer 22:9e85236d8716 395 # def notify(Event, Silent)
screamer 22:9e85236d8716 396 # Where *Event* is a dict representing the toolchain event that was generated
screamer 22:9e85236d8716 397 # e.g.: a compile succeeded, or a warning was emitted by the compiler
screamer 22:9e85236d8716 398 # or an application was linked
screamer 22:9e85236d8716 399 # *Silent* is a boolean
screamer 0:66f3b5499f7f 400 if notify:
screamer 0:66f3b5499f7f 401 self.notify_fun = notify
screamer 0:66f3b5499f7f 402 elif extra_verbose:
screamer 0:66f3b5499f7f 403 self.notify_fun = self.print_notify_verbose
screamer 0:66f3b5499f7f 404 else:
screamer 0:66f3b5499f7f 405 self.notify_fun = self.print_notify
screamer 22:9e85236d8716 406
screamer 13:ab47a20b66f0 407 # Silent builds (no output)
screamer 13:ab47a20b66f0 408 self.silent = silent
screamer 22:9e85236d8716 409
screamer 13:ab47a20b66f0 410 # Print output buffer
screamer 22:9e85236d8716 411 self.output = str()
screamer 22:9e85236d8716 412 self.map_outputs = list() # Place to store memmap scan results in JSON like data structures
screamer 0:66f3b5499f7f 413
screamer 13:ab47a20b66f0 414 # uVisor spepcific rules
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 415 if 'UVISOR' in self.target.features and 'UVISOR_SUPPORTED' in self.target.extra_labels:
screamer 0:66f3b5499f7f 416 self.target.core = re.sub(r"F$", '', self.target.core)
screamer 24:25bff2709c20 417
screamer 24:25bff2709c20 418 # Stats cache is used to reduce the amount of IO requests to stat
screamer 24:25bff2709c20 419 # header files during dependency change. See need_update()
screamer 17:04753e1e329d 420 self.stat_cache = {}
screamer 17:04753e1e329d 421
screamer 24:25bff2709c20 422 # Used by the mbed Online Build System to build in chrooted environment
screamer 24:25bff2709c20 423 self.CHROOT = None
screamer 24:25bff2709c20 424
screamer 24:25bff2709c20 425 # Call post __init__() hooks before the ARM/GCC_ARM/IAR toolchain __init__() takes over
screamer 14:ee1b877e6839 426 self.init()
screamer 14:ee1b877e6839 427
screamer 24:25bff2709c20 428 # Used for post __init__() hooks
screamer 24:25bff2709c20 429 # THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
screamer 24:25bff2709c20 430 # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
screamer 14:ee1b877e6839 431 def init(self):
screamer 14:ee1b877e6839 432 return True
screamer 0:66f3b5499f7f 433
screamer 0:66f3b5499f7f 434 def get_output(self):
screamer 0:66f3b5499f7f 435 return self.output
screamer 0:66f3b5499f7f 436
screamer 0:66f3b5499f7f 437 def print_notify(self, event, silent=False):
screamer 0:66f3b5499f7f 438 """ Default command line notification
screamer 0:66f3b5499f7f 439 """
screamer 0:66f3b5499f7f 440 msg = None
screamer 0:66f3b5499f7f 441
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 442 if not self.VERBOSE and event['type'] == 'tool_error':
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 443 msg = event['message']
screamer 22:9e85236d8716 444
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 445 elif event['type'] in ['info', 'debug']:
screamer 0:66f3b5499f7f 446 msg = event['message']
screamer 22:9e85236d8716 447
screamer 0:66f3b5499f7f 448 elif event['type'] == 'cc':
screamer 0:66f3b5499f7f 449 event['severity'] = event['severity'].title()
screamer 0:66f3b5499f7f 450 event['file'] = basename(event['file'])
screamer 21:4fdf0dd04f6f 451 msg = '[%(severity)s] %(file)s@%(line)s,%(col)s: %(message)s' % event
screamer 0:66f3b5499f7f 452
screamer 0:66f3b5499f7f 453 elif event['type'] == 'progress':
The Other Jimmy 31:8ea194f6145b 454 if 'percent' in event:
The Other Jimmy 31:8ea194f6145b 455 msg = '{} [{:>5.1f}%]: {}'.format(event['action'].title(),
The Other Jimmy 31:8ea194f6145b 456 event['percent'],
The Other Jimmy 31:8ea194f6145b 457 basename(event['file']))
The Other Jimmy 31:8ea194f6145b 458 else:
The Other Jimmy 31:8ea194f6145b 459 msg = '{}: {}'.format(event['action'].title(),
The Other Jimmy 31:8ea194f6145b 460 basename(event['file']))
screamer 0:66f3b5499f7f 461
screamer 0:66f3b5499f7f 462 if msg:
The Other Jimmy 31:8ea194f6145b 463 if not silent:
The Other Jimmy 31:8ea194f6145b 464 print msg
screamer 0:66f3b5499f7f 465 self.output += msg + "\n"
screamer 0:66f3b5499f7f 466
screamer 0:66f3b5499f7f 467 def print_notify_verbose(self, event, silent=False):
screamer 0:66f3b5499f7f 468 """ Default command line notification with more verbose mode
screamer 0:66f3b5499f7f 469 """
screamer 0:66f3b5499f7f 470 if event['type'] in ['info', 'debug']:
The Other Jimmy 31:8ea194f6145b 471 self.print_notify(event, silent=silent) # standard handle
screamer 0:66f3b5499f7f 472
screamer 0:66f3b5499f7f 473 elif event['type'] == 'cc':
screamer 0:66f3b5499f7f 474 event['severity'] = event['severity'].title()
screamer 0:66f3b5499f7f 475 event['file'] = basename(event['file'])
screamer 0:66f3b5499f7f 476 event['mcu_name'] = "None"
screamer 0:66f3b5499f7f 477 event['target_name'] = event['target_name'].upper() if event['target_name'] else "Unknown"
screamer 0:66f3b5499f7f 478 event['toolchain_name'] = event['toolchain_name'].upper() if event['toolchain_name'] else "Unknown"
screamer 0:66f3b5499f7f 479 msg = '[%(severity)s] %(target_name)s::%(toolchain_name)s::%(file)s@%(line)s: %(message)s' % event
The Other Jimmy 31:8ea194f6145b 480 if not silent:
The Other Jimmy 31:8ea194f6145b 481 print msg
screamer 0:66f3b5499f7f 482 self.output += msg + "\n"
screamer 0:66f3b5499f7f 483
screamer 0:66f3b5499f7f 484 elif event['type'] == 'progress':
screamer 0:66f3b5499f7f 485 self.print_notify(event) # standard handle
screamer 0:66f3b5499f7f 486
screamer 24:25bff2709c20 487 # THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
screamer 24:25bff2709c20 488 # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
screamer 0:66f3b5499f7f 489 def notify(self, event):
screamer 0:66f3b5499f7f 490 """ Little closure for notify functions
screamer 0:66f3b5499f7f 491 """
screamer 22:9e85236d8716 492 event['toolchain'] = self
screamer 0:66f3b5499f7f 493 return self.notify_fun(event, self.silent)
screamer 0:66f3b5499f7f 494
screamer 29:1210849dba19 495 def get_symbols(self, for_asm=False):
screamer 29:1210849dba19 496 if for_asm:
screamer 29:1210849dba19 497 if self.asm_symbols is None:
screamer 29:1210849dba19 498 self.asm_symbols = []
screamer 29:1210849dba19 499
screamer 29:1210849dba19 500 # Cortex CPU symbols
screamer 29:1210849dba19 501 if self.target.core in mbedToolchain.CORTEX_SYMBOLS:
screamer 29:1210849dba19 502 self.asm_symbols.extend(mbedToolchain.CORTEX_SYMBOLS[self.target.core])
screamer 0:66f3b5499f7f 503
screamer 29:1210849dba19 504 # Add target's symbols
screamer 29:1210849dba19 505 self.asm_symbols += self.target.macros
screamer 29:1210849dba19 506 # Add extra symbols passed via 'macros' parameter
screamer 29:1210849dba19 507 self.asm_symbols += self.macros
screamer 29:1210849dba19 508 return list(set(self.asm_symbols)) # Return only unique symbols
screamer 29:1210849dba19 509 else:
screamer 29:1210849dba19 510 if self.cxx_symbols is None:
screamer 29:1210849dba19 511 # Target and Toolchain symbols
screamer 29:1210849dba19 512 labels = self.get_labels()
screamer 29:1210849dba19 513 self.cxx_symbols = ["TARGET_%s" % t for t in labels['TARGET']]
screamer 29:1210849dba19 514 self.cxx_symbols.extend(["TOOLCHAIN_%s" % t for t in labels['TOOLCHAIN']])
screamer 0:66f3b5499f7f 515
screamer 29:1210849dba19 516 # Cortex CPU symbols
screamer 29:1210849dba19 517 if self.target.core in mbedToolchain.CORTEX_SYMBOLS:
screamer 29:1210849dba19 518 self.cxx_symbols.extend(mbedToolchain.CORTEX_SYMBOLS[self.target.core])
screamer 29:1210849dba19 519
screamer 29:1210849dba19 520 # Symbols defined by the on-line build.system
screamer 29:1210849dba19 521 self.cxx_symbols.extend(['MBED_BUILD_TIMESTAMP=%s' % self.timestamp, 'TARGET_LIKE_MBED', '__MBED__=1'])
screamer 29:1210849dba19 522 if MBED_ORG_USER:
screamer 29:1210849dba19 523 self.cxx_symbols.append('MBED_USERNAME=' + MBED_ORG_USER)
screamer 0:66f3b5499f7f 524
screamer 29:1210849dba19 525 # Add target's symbols
screamer 29:1210849dba19 526 self.cxx_symbols += self.target.macros
screamer 29:1210849dba19 527 # Add target's hardware
screamer 29:1210849dba19 528 self.cxx_symbols += ["DEVICE_" + data + "=1" for data in self.target.device_has]
screamer 29:1210849dba19 529 # Add target's features
screamer 29:1210849dba19 530 self.cxx_symbols += ["FEATURE_" + data + "=1" for data in self.target.features]
screamer 29:1210849dba19 531 # Add extra symbols passed via 'macros' parameter
screamer 29:1210849dba19 532 self.cxx_symbols += self.macros
screamer 0:66f3b5499f7f 533
screamer 29:1210849dba19 534 # Form factor variables
screamer 29:1210849dba19 535 if hasattr(self.target, 'supported_form_factors'):
screamer 29:1210849dba19 536 self.cxx_symbols.extend(["TARGET_FF_%s" % t for t in self.target.supported_form_factors])
screamer 0:66f3b5499f7f 537
screamer 29:1210849dba19 538 return list(set(self.cxx_symbols)) # Return only unique symbols
screamer 0:66f3b5499f7f 539
screamer 7:5af61d55adbe 540 # Extend the internal list of macros
screamer 7:5af61d55adbe 541 def add_macros(self, new_macros):
screamer 7:5af61d55adbe 542 self.macros.extend(new_macros)
screamer 7:5af61d55adbe 543
screamer 0:66f3b5499f7f 544 def get_labels(self):
screamer 0:66f3b5499f7f 545 if self.labels is None:
screamer 0:66f3b5499f7f 546 toolchain_labels = [c.__name__ for c in getmro(self.__class__)]
screamer 0:66f3b5499f7f 547 toolchain_labels.remove('mbedToolchain')
screamer 0:66f3b5499f7f 548 self.labels = {
The Other Jimmy 31:8ea194f6145b 549 'TARGET': self.target.labels,
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 550 'FEATURE': self.target.features,
screamer 0:66f3b5499f7f 551 'TOOLCHAIN': toolchain_labels
screamer 0:66f3b5499f7f 552 }
The Other Jimmy 31:8ea194f6145b 553
The Other Jimmy 31:8ea194f6145b 554 # This is a policy decision and it should /really/ be in the config system
The Other Jimmy 31:8ea194f6145b 555 # ATM it's here for backward compatibility
The Other Jimmy 31:8ea194f6145b 556 if ((("-g" in self.flags['common'] or "-g3" in self.flags['common']) and
The Other Jimmy 36:96847d42f010 557 "-O0" in self.flags['common']) or
The Other Jimmy 31:8ea194f6145b 558 ("-r" in self.flags['common'] and
The Other Jimmy 31:8ea194f6145b 559 "-On" in self.flags['common'])):
The Other Jimmy 31:8ea194f6145b 560 self.labels['TARGET'].append("DEBUG")
The Other Jimmy 31:8ea194f6145b 561 else:
The Other Jimmy 31:8ea194f6145b 562 self.labels['TARGET'].append("RELEASE")
screamer 0:66f3b5499f7f 563 return self.labels
screamer 0:66f3b5499f7f 564
screamer 24:25bff2709c20 565
screamer 24:25bff2709c20 566 # Determine whether a source file needs updating/compiling
screamer 0:66f3b5499f7f 567 def need_update(self, target, dependencies):
screamer 0:66f3b5499f7f 568 if self.build_all:
screamer 0:66f3b5499f7f 569 return True
screamer 0:66f3b5499f7f 570
screamer 0:66f3b5499f7f 571 if not exists(target):
screamer 0:66f3b5499f7f 572 return True
screamer 0:66f3b5499f7f 573
screamer 0:66f3b5499f7f 574 target_mod_time = stat(target).st_mtime
screamer 0:66f3b5499f7f 575
screamer 0:66f3b5499f7f 576 for d in dependencies:
screamer 0:66f3b5499f7f 577 # Some objects are not provided with full path and here we do not have
screamer 0:66f3b5499f7f 578 # information about the library paths. Safe option: assume an update
screamer 22:9e85236d8716 579 if not d or not exists(d):
screamer 0:66f3b5499f7f 580 return True
screamer 17:04753e1e329d 581
screamer 22:9e85236d8716 582 if not self.stat_cache.has_key(d):
screamer 17:04753e1e329d 583 self.stat_cache[d] = stat(d).st_mtime
screamer 22:9e85236d8716 584
screamer 22:9e85236d8716 585 if self.stat_cache[d] >= target_mod_time:
screamer 22:9e85236d8716 586 return True
screamer 17:04753e1e329d 587
screamer 0:66f3b5499f7f 588 return False
screamer 0:66f3b5499f7f 589
screamer 7:5af61d55adbe 590 def is_ignored(self, file_path):
The Other Jimmy 35:da9c89f8be7d 591 """Check if file path is ignored by any .mbedignore thus far"""
The Other Jimmy 38:399953da035d 592 return self._ignore_regex.match(normcase(file_path))
screamer 7:5af61d55adbe 593
The Other Jimmy 35:da9c89f8be7d 594 def add_ignore_patterns(self, root, base_path, patterns):
The Other Jimmy 35:da9c89f8be7d 595 """Add a series of patterns to the ignored paths
The Other Jimmy 35:da9c89f8be7d 596
The Other Jimmy 35:da9c89f8be7d 597 Positional arguments:
The Other Jimmy 35:da9c89f8be7d 598 root - the directory containing the ignore file
The Other Jimmy 35:da9c89f8be7d 599 base_path - the location that the scan started from
The Other Jimmy 35:da9c89f8be7d 600 patterns - the list of patterns we will ignore in the future
The Other Jimmy 35:da9c89f8be7d 601 """
The Other Jimmy 35:da9c89f8be7d 602 real_base = relpath(root, base_path)
The Other Jimmy 35:da9c89f8be7d 603 if real_base == ".":
The Other Jimmy 38:399953da035d 604 self.ignore_patterns.extend(normcase(p) for p in patterns)
The Other Jimmy 35:da9c89f8be7d 605 else:
The Other Jimmy 38:399953da035d 606 self.ignore_patterns.extend(normcase(join(real_base, pat)) for pat in patterns)
The Other Jimmy 38:399953da035d 607 self._ignore_regex = re.compile("|".join(fnmatch.translate(p) for p in self.ignore_patterns))
The Other Jimmy 35:da9c89f8be7d 608
screamer 13:ab47a20b66f0 609 # Create a Resources object from the path pointed to by *path* by either traversing a
screamer 13:ab47a20b66f0 610 # a directory structure, when *path* is a directory, or adding *path* to the resources,
screamer 13:ab47a20b66f0 611 # when *path* is a file.
screamer 13:ab47a20b66f0 612 # The parameter *base_path* is used to set the base_path attribute of the Resources
screamer 13:ab47a20b66f0 613 # object and the parameter *exclude_paths* is used by the directory traversal to
screamer 13:ab47a20b66f0 614 # exclude certain paths from the traversal.
screamer 13:ab47a20b66f0 615 def scan_resources(self, path, exclude_paths=None, base_path=None):
screamer 21:4fdf0dd04f6f 616 self.progress("scan", path)
screamer 21:4fdf0dd04f6f 617
screamer 0:66f3b5499f7f 618 resources = Resources(path)
screamer 13:ab47a20b66f0 619 if not base_path:
screamer 13:ab47a20b66f0 620 if isfile(path):
screamer 13:ab47a20b66f0 621 base_path = dirname(path)
screamer 13:ab47a20b66f0 622 else:
screamer 13:ab47a20b66f0 623 base_path = path
screamer 13:ab47a20b66f0 624 resources.base_path = base_path
screamer 0:66f3b5499f7f 625
screamer 13:ab47a20b66f0 626 if isfile(path):
screamer 13:ab47a20b66f0 627 self._add_file(path, resources, base_path, exclude_paths=exclude_paths)
screamer 13:ab47a20b66f0 628 else:
screamer 13:ab47a20b66f0 629 self._add_dir(path, resources, base_path, exclude_paths=exclude_paths)
screamer 13:ab47a20b66f0 630 return resources
screamer 13:ab47a20b66f0 631
screamer 13:ab47a20b66f0 632 # A helper function for scan_resources. _add_dir traverses *path* (assumed to be a
screamer 13:ab47a20b66f0 633 # directory) and heeds the ".mbedignore" files along the way. _add_dir calls _add_file
screamer 13:ab47a20b66f0 634 # on every file it considers adding to the resources object.
screamer 13:ab47a20b66f0 635 def _add_dir(self, path, resources, base_path, exclude_paths=None):
screamer 0:66f3b5499f7f 636 """ os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]])
screamer 0:66f3b5499f7f 637 When topdown is True, the caller can modify the dirnames list in-place
screamer 0:66f3b5499f7f 638 (perhaps using del or slice assignment), and walk() will only recurse into
screamer 0:66f3b5499f7f 639 the subdirectories whose names remain in dirnames; this can be used to prune
screamer 0:66f3b5499f7f 640 the search, impose a specific order of visiting, or even to inform walk()
screamer 0:66f3b5499f7f 641 about directories the caller creates or renames before it resumes walk()
screamer 0:66f3b5499f7f 642 again. Modifying dirnames when topdown is False is ineffective, because in
screamer 0:66f3b5499f7f 643 bottom-up mode the directories in dirnames are generated before dirpath
screamer 0:66f3b5499f7f 644 itself is generated.
screamer 0:66f3b5499f7f 645 """
screamer 13:ab47a20b66f0 646 labels = self.get_labels()
screamer 0:66f3b5499f7f 647 for root, dirs, files in walk(path, followlinks=True):
screamer 7:5af61d55adbe 648 # Check if folder contains .mbedignore
screamer 13:ab47a20b66f0 649 if ".mbedignore" in files:
screamer 7:5af61d55adbe 650 with open (join(root,".mbedignore"), "r") as f:
screamer 7:5af61d55adbe 651 lines=f.readlines()
screamer 7:5af61d55adbe 652 lines = [l.strip() for l in lines] # Strip whitespaces
screamer 7:5af61d55adbe 653 lines = [l for l in lines if l != ""] # Strip empty lines
screamer 7:5af61d55adbe 654 lines = [l for l in lines if not re.match("^#",l)] # Strip comment lines
screamer 13:ab47a20b66f0 655 # Append root path to glob patterns and append patterns to ignore_patterns
The Other Jimmy 35:da9c89f8be7d 656 self.add_ignore_patterns(root, base_path, lines)
screamer 13:ab47a20b66f0 657
screamer 13:ab47a20b66f0 658 # Skip the whole folder if ignored, e.g. .mbedignore containing '*'
The Other Jimmy 36:96847d42f010 659 if (self.is_ignored(join(relpath(root, base_path),"")) or
The Other Jimmy 36:96847d42f010 660 self.build_dir == join(relpath(root, base_path))):
The Other Jimmy 35:da9c89f8be7d 661 dirs[:] = []
screamer 13:ab47a20b66f0 662 continue
screamer 7:5af61d55adbe 663
screamer 0:66f3b5499f7f 664 for d in copy(dirs):
screamer 0:66f3b5499f7f 665 dir_path = join(root, d)
screamer 13:ab47a20b66f0 666 # Add internal repo folders/files. This is needed for exporters
screamer 21:4fdf0dd04f6f 667 if d == '.hg' or d == '.git':
screamer 0:66f3b5499f7f 668 resources.repo_dirs.append(dir_path)
screamer 0:66f3b5499f7f 669
screamer 0:66f3b5499f7f 670 if ((d.startswith('.') or d in self.legacy_ignore_dirs) or
screamer 13:ab47a20b66f0 671 # Ignore targets that do not match the TARGET in extra_labels list
screamer 7:5af61d55adbe 672 (d.startswith('TARGET_') and d[7:] not in labels['TARGET']) or
screamer 13:ab47a20b66f0 673 # Ignore toolchain that do not match the current TOOLCHAIN
screamer 7:5af61d55adbe 674 (d.startswith('TOOLCHAIN_') and d[10:] not in labels['TOOLCHAIN']) or
screamer 13:ab47a20b66f0 675 # Ignore .mbedignore files
The Other Jimmy 35:da9c89f8be7d 676 self.is_ignored(join(relpath(root, base_path), d,"")) or
screamer 13:ab47a20b66f0 677 # Ignore TESTS dir
screamer 7:5af61d55adbe 678 (d == 'TESTS')):
screamer 13:ab47a20b66f0 679 dirs.remove(d)
screamer 13:ab47a20b66f0 680 elif d.startswith('FEATURE_'):
screamer 13:ab47a20b66f0 681 # Recursively scan features but ignore them in the current scan.
screamer 13:ab47a20b66f0 682 # These are dynamically added by the config system if the conditions are matched
The Other Jimmy 38:399953da035d 683 def closure (dir_path=dir_path, base_path=base_path):
The Other Jimmy 38:399953da035d 684 return self.scan_resources(dir_path, base_path=base_path)
The Other Jimmy 38:399953da035d 685 resources.features.add_lazy(d[8:], closure)
screamer 0:66f3b5499f7f 686 dirs.remove(d)
screamer 13:ab47a20b66f0 687 elif exclude_paths:
screamer 0:66f3b5499f7f 688 for exclude_path in exclude_paths:
screamer 0:66f3b5499f7f 689 rel_path = relpath(dir_path, exclude_path)
screamer 0:66f3b5499f7f 690 if not (rel_path.startswith('..')):
screamer 0:66f3b5499f7f 691 dirs.remove(d)
screamer 0:66f3b5499f7f 692 break
screamer 0:66f3b5499f7f 693
screamer 0:66f3b5499f7f 694 # Add root to include paths
The Other Jimmy 36:96847d42f010 695 root = root.rstrip("/")
screamer 0:66f3b5499f7f 696 resources.inc_dirs.append(root)
The Other Jimmy 31:8ea194f6145b 697 resources.file_basepath[root] = base_path
screamer 0:66f3b5499f7f 698
screamer 0:66f3b5499f7f 699 for file in files:
screamer 0:66f3b5499f7f 700 file_path = join(root, file)
screamer 13:ab47a20b66f0 701 self._add_file(file_path, resources, base_path)
screamer 7:5af61d55adbe 702
screamer 13:ab47a20b66f0 703 # A helper function for both scan_resources and _add_dir. _add_file adds one file
screamer 13:ab47a20b66f0 704 # (*file_path*) to the resources object based on the file type.
screamer 13:ab47a20b66f0 705 def _add_file(self, file_path, resources, base_path, exclude_paths=None):
screamer 13:ab47a20b66f0 706 resources.file_basepath[file_path] = base_path
screamer 0:66f3b5499f7f 707
The Other Jimmy 35:da9c89f8be7d 708 if self.is_ignored(relpath(file_path, base_path)):
screamer 13:ab47a20b66f0 709 return
screamer 13:ab47a20b66f0 710
screamer 13:ab47a20b66f0 711 _, ext = splitext(file_path)
screamer 13:ab47a20b66f0 712 ext = ext.lower()
screamer 0:66f3b5499f7f 713
screamer 13:ab47a20b66f0 714 if ext == '.s':
screamer 13:ab47a20b66f0 715 resources.s_sources.append(file_path)
screamer 0:66f3b5499f7f 716
screamer 13:ab47a20b66f0 717 elif ext == '.c':
screamer 13:ab47a20b66f0 718 resources.c_sources.append(file_path)
screamer 0:66f3b5499f7f 719
screamer 13:ab47a20b66f0 720 elif ext == '.cpp':
screamer 13:ab47a20b66f0 721 resources.cpp_sources.append(file_path)
screamer 0:66f3b5499f7f 722
screamer 13:ab47a20b66f0 723 elif ext == '.h' or ext == '.hpp':
screamer 13:ab47a20b66f0 724 resources.headers.append(file_path)
screamer 13:ab47a20b66f0 725
screamer 13:ab47a20b66f0 726 elif ext == '.o':
screamer 13:ab47a20b66f0 727 resources.objects.append(file_path)
screamer 0:66f3b5499f7f 728
screamer 13:ab47a20b66f0 729 elif ext == self.LIBRARY_EXT:
screamer 13:ab47a20b66f0 730 resources.libraries.append(file_path)
screamer 13:ab47a20b66f0 731 resources.lib_dirs.add(dirname(file_path))
screamer 0:66f3b5499f7f 732
screamer 13:ab47a20b66f0 733 elif ext == self.LINKER_EXT:
screamer 13:ab47a20b66f0 734 if resources.linker_script is not None:
screamer 13:ab47a20b66f0 735 self.info("Warning: Multiple linker scripts detected: %s -> %s" % (resources.linker_script, file_path))
screamer 13:ab47a20b66f0 736 resources.linker_script = file_path
screamer 0:66f3b5499f7f 737
screamer 13:ab47a20b66f0 738 elif ext == '.lib':
screamer 13:ab47a20b66f0 739 resources.lib_refs.append(file_path)
screamer 0:66f3b5499f7f 740
screamer 13:ab47a20b66f0 741 elif ext == '.bld':
screamer 13:ab47a20b66f0 742 resources.lib_builds.append(file_path)
screamer 0:66f3b5499f7f 743
The Other Jimmy 31:8ea194f6145b 744 elif basename(file_path) == '.hgignore':
The Other Jimmy 31:8ea194f6145b 745 resources.repo_files.append(file_path)
The Other Jimmy 31:8ea194f6145b 746
The Other Jimmy 31:8ea194f6145b 747 elif basename(file_path) == '.gitignore':
screamer 13:ab47a20b66f0 748 resources.repo_files.append(file_path)
screamer 0:66f3b5499f7f 749
screamer 13:ab47a20b66f0 750 elif ext == '.hex':
screamer 13:ab47a20b66f0 751 resources.hex_files.append(file_path)
screamer 0:66f3b5499f7f 752
screamer 13:ab47a20b66f0 753 elif ext == '.bin':
screamer 13:ab47a20b66f0 754 resources.bin_files.append(file_path)
screamer 0:66f3b5499f7f 755
screamer 13:ab47a20b66f0 756 elif ext == '.json':
screamer 13:ab47a20b66f0 757 resources.json_files.append(file_path)
screamer 7:5af61d55adbe 758
screamer 0:66f3b5499f7f 759
screamer 0:66f3b5499f7f 760 def scan_repository(self, path):
screamer 0:66f3b5499f7f 761 resources = []
screamer 0:66f3b5499f7f 762
screamer 0:66f3b5499f7f 763 for root, dirs, files in walk(path):
screamer 0:66f3b5499f7f 764 # Remove ignored directories
screamer 0:66f3b5499f7f 765 for d in copy(dirs):
screamer 0:66f3b5499f7f 766 if d == '.' or d == '..':
screamer 0:66f3b5499f7f 767 dirs.remove(d)
screamer 0:66f3b5499f7f 768
screamer 0:66f3b5499f7f 769 for file in files:
screamer 0:66f3b5499f7f 770 file_path = join(root, file)
screamer 0:66f3b5499f7f 771 resources.append(file_path)
screamer 0:66f3b5499f7f 772
screamer 0:66f3b5499f7f 773 return resources
screamer 0:66f3b5499f7f 774
screamer 13:ab47a20b66f0 775 def copy_files(self, files_paths, trg_path, resources=None, rel_path=None):
screamer 0:66f3b5499f7f 776 # Handle a single file
screamer 0:66f3b5499f7f 777 if type(files_paths) != ListType: files_paths = [files_paths]
screamer 0:66f3b5499f7f 778
screamer 0:66f3b5499f7f 779 for source in files_paths:
screamer 0:66f3b5499f7f 780 if source is None:
screamer 0:66f3b5499f7f 781 files_paths.remove(source)
screamer 0:66f3b5499f7f 782
screamer 0:66f3b5499f7f 783 for source in files_paths:
screamer 17:04753e1e329d 784 if resources is not None and resources.file_basepath.has_key(source):
screamer 13:ab47a20b66f0 785 relative_path = relpath(source, resources.file_basepath[source])
screamer 13:ab47a20b66f0 786 elif rel_path is not None:
screamer 0:66f3b5499f7f 787 relative_path = relpath(source, rel_path)
screamer 0:66f3b5499f7f 788 else:
screamer 0:66f3b5499f7f 789 _, relative_path = split(source)
screamer 0:66f3b5499f7f 790
screamer 0:66f3b5499f7f 791 target = join(trg_path, relative_path)
screamer 0:66f3b5499f7f 792
screamer 0:66f3b5499f7f 793 if (target != source) and (self.need_update(target, [source])):
screamer 0:66f3b5499f7f 794 self.progress("copy", relative_path)
screamer 0:66f3b5499f7f 795 mkdir(dirname(target))
screamer 0:66f3b5499f7f 796 copyfile(source, target)
screamer 0:66f3b5499f7f 797
screamer 24:25bff2709c20 798 # THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
screamer 24:25bff2709c20 799 # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
screamer 0:66f3b5499f7f 800 def relative_object_path(self, build_path, base_dir, source):
screamer 0:66f3b5499f7f 801 source_dir, name, _ = split_path(source)
screamer 22:9e85236d8716 802
screamer 0:66f3b5499f7f 803 obj_dir = join(build_path, relpath(source_dir, base_dir))
screamer 17:04753e1e329d 804 if obj_dir is not self.prev_dir:
screamer 17:04753e1e329d 805 self.prev_dir = obj_dir
screamer 17:04753e1e329d 806 mkdir(obj_dir)
screamer 0:66f3b5499f7f 807 return join(obj_dir, name + '.o')
screamer 0:66f3b5499f7f 808
screamer 24:25bff2709c20 809 # Generate response file for all includes.
screamer 24:25bff2709c20 810 # ARM, GCC, IAR cross compatible
screamer 0:66f3b5499f7f 811 def get_inc_file(self, includes):
screamer 0:66f3b5499f7f 812 include_file = join(self.build_dir, ".includes_%s.txt" % self.inc_md5)
screamer 0:66f3b5499f7f 813 if not exists(include_file):
screamer 0:66f3b5499f7f 814 with open(include_file, "wb") as f:
screamer 0:66f3b5499f7f 815 cmd_list = []
screamer 0:66f3b5499f7f 816 for c in includes:
screamer 0:66f3b5499f7f 817 if c:
screamer 20:835f6355470d 818 c = c.replace("\\", "/")
screamer 20:835f6355470d 819 if self.CHROOT:
screamer 20:835f6355470d 820 c = c.replace(self.CHROOT, '')
screamer 20:835f6355470d 821 cmd_list.append('-I%s' % c)
screamer 0:66f3b5499f7f 822 string = " ".join(cmd_list)
screamer 0:66f3b5499f7f 823 f.write(string)
screamer 0:66f3b5499f7f 824 return include_file
screamer 0:66f3b5499f7f 825
screamer 24:25bff2709c20 826 # Generate response file for all objects when linking.
screamer 24:25bff2709c20 827 # ARM, GCC, IAR cross compatible
screamer 21:4fdf0dd04f6f 828 def get_link_file(self, cmd):
screamer 21:4fdf0dd04f6f 829 link_file = join(self.build_dir, ".link_files.txt")
screamer 21:4fdf0dd04f6f 830 with open(link_file, "wb") as f:
screamer 21:4fdf0dd04f6f 831 cmd_list = []
screamer 21:4fdf0dd04f6f 832 for c in cmd:
screamer 21:4fdf0dd04f6f 833 if c:
screamer 21:4fdf0dd04f6f 834 c = c.replace("\\", "/")
screamer 21:4fdf0dd04f6f 835 if self.CHROOT:
screamer 21:4fdf0dd04f6f 836 c = c.replace(self.CHROOT, '')
screamer 21:4fdf0dd04f6f 837 cmd_list.append(('"%s"' % c) if not c.startswith('-') else c)
screamer 21:4fdf0dd04f6f 838 string = " ".join(cmd_list)
screamer 21:4fdf0dd04f6f 839 f.write(string)
screamer 21:4fdf0dd04f6f 840 return link_file
screamer 21:4fdf0dd04f6f 841
screamer 24:25bff2709c20 842 # Generate response file for all objects when archiving.
screamer 24:25bff2709c20 843 # ARM, GCC, IAR cross compatible
screamer 21:4fdf0dd04f6f 844 def get_arch_file(self, objects):
screamer 21:4fdf0dd04f6f 845 archive_file = join(self.build_dir, ".archive_files.txt")
screamer 21:4fdf0dd04f6f 846 with open(archive_file, "wb") as f:
screamer 21:4fdf0dd04f6f 847 o_list = []
screamer 21:4fdf0dd04f6f 848 for o in objects:
screamer 21:4fdf0dd04f6f 849 o_list.append('"%s"' % o)
screamer 21:4fdf0dd04f6f 850 string = " ".join(o_list).replace("\\", "/")
screamer 21:4fdf0dd04f6f 851 f.write(string)
screamer 21:4fdf0dd04f6f 852 return archive_file
screamer 21:4fdf0dd04f6f 853
screamer 24:25bff2709c20 854 # THIS METHOD IS BEING CALLED BY THE MBED ONLINE BUILD SYSTEM
screamer 24:25bff2709c20 855 # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
The Other Jimmy 36:96847d42f010 856 def compile_sources(self, resources, inc_dirs=None):
screamer 0:66f3b5499f7f 857 # Web IDE progress bar for project build
screamer 0:66f3b5499f7f 858 files_to_compile = resources.s_sources + resources.c_sources + resources.cpp_sources
screamer 0:66f3b5499f7f 859 self.to_be_compiled = len(files_to_compile)
screamer 0:66f3b5499f7f 860 self.compiled = 0
screamer 0:66f3b5499f7f 861
screamer 21:4fdf0dd04f6f 862 self.cc_verbose("Macros: "+' '.join(['-D%s' % s for s in self.get_symbols()]))
screamer 21:4fdf0dd04f6f 863
screamer 0:66f3b5499f7f 864 inc_paths = resources.inc_dirs
screamer 0:66f3b5499f7f 865 if inc_dirs is not None:
screamer 0:66f3b5499f7f 866 inc_paths.extend(inc_dirs)
screamer 0:66f3b5499f7f 867 # De-duplicate include paths
screamer 0:66f3b5499f7f 868 inc_paths = set(inc_paths)
screamer 0:66f3b5499f7f 869 # Sort include paths for consistency
screamer 0:66f3b5499f7f 870 inc_paths = sorted(set(inc_paths))
screamer 0:66f3b5499f7f 871 # Unique id of all include paths
screamer 0:66f3b5499f7f 872 self.inc_md5 = md5(' '.join(inc_paths)).hexdigest()
screamer 0:66f3b5499f7f 873
screamer 0:66f3b5499f7f 874 objects = []
screamer 0:66f3b5499f7f 875 queue = []
screamer 17:04753e1e329d 876 work_dir = getcwd()
screamer 17:04753e1e329d 877 self.prev_dir = None
screamer 0:66f3b5499f7f 878
screamer 24:25bff2709c20 879 # Generate configuration header (this will update self.build_all if needed)
screamer 24:25bff2709c20 880 self.get_config_header()
The Other Jimmy 36:96847d42f010 881 self.dump_build_profile()
screamer 24:25bff2709c20 882
screamer 0:66f3b5499f7f 883 # Sort compile queue for consistency
screamer 0:66f3b5499f7f 884 files_to_compile.sort()
screamer 0:66f3b5499f7f 885 for source in files_to_compile:
The Other Jimmy 36:96847d42f010 886 object = self.relative_object_path(
The Other Jimmy 36:96847d42f010 887 self.build_dir, resources.file_basepath[source], source)
screamer 0:66f3b5499f7f 888
screamer 0:66f3b5499f7f 889 # Queue mode (multiprocessing)
screamer 0:66f3b5499f7f 890 commands = self.compile_command(source, object, inc_paths)
screamer 0:66f3b5499f7f 891 if commands is not None:
screamer 0:66f3b5499f7f 892 queue.append({
screamer 0:66f3b5499f7f 893 'source': source,
screamer 0:66f3b5499f7f 894 'object': object,
screamer 0:66f3b5499f7f 895 'commands': commands,
screamer 0:66f3b5499f7f 896 'work_dir': work_dir,
screamer 0:66f3b5499f7f 897 'chroot': self.CHROOT
screamer 0:66f3b5499f7f 898 })
screamer 0:66f3b5499f7f 899 else:
The Other Jimmy 31:8ea194f6145b 900 self.compiled += 1
screamer 0:66f3b5499f7f 901 objects.append(object)
screamer 0:66f3b5499f7f 902
screamer 0:66f3b5499f7f 903 # Use queues/multiprocessing if cpu count is higher than setting
screamer 0:66f3b5499f7f 904 jobs = self.jobs if self.jobs else cpu_count()
screamer 0:66f3b5499f7f 905 if jobs > CPU_COUNT_MIN and len(queue) > jobs:
screamer 0:66f3b5499f7f 906 return self.compile_queue(queue, objects)
screamer 0:66f3b5499f7f 907 else:
screamer 0:66f3b5499f7f 908 return self.compile_seq(queue, objects)
screamer 0:66f3b5499f7f 909
screamer 24:25bff2709c20 910 # Compile source files queue in sequential order
screamer 0:66f3b5499f7f 911 def compile_seq(self, queue, objects):
screamer 0:66f3b5499f7f 912 for item in queue:
screamer 0:66f3b5499f7f 913 result = compile_worker(item)
screamer 0:66f3b5499f7f 914
screamer 0:66f3b5499f7f 915 self.compiled += 1
screamer 0:66f3b5499f7f 916 self.progress("compile", item['source'], build_update=True)
screamer 0:66f3b5499f7f 917 for res in result['results']:
screamer 21:4fdf0dd04f6f 918 self.cc_verbose("Compile: %s" % ' '.join(res['command']), result['source'])
screamer 0:66f3b5499f7f 919 self.compile_output([
screamer 0:66f3b5499f7f 920 res['code'],
screamer 0:66f3b5499f7f 921 res['output'],
screamer 0:66f3b5499f7f 922 res['command']
screamer 0:66f3b5499f7f 923 ])
screamer 0:66f3b5499f7f 924 objects.append(result['object'])
screamer 0:66f3b5499f7f 925 return objects
screamer 0:66f3b5499f7f 926
screamer 24:25bff2709c20 927 # Compile source files queue in parallel by creating pool of worker threads
screamer 0:66f3b5499f7f 928 def compile_queue(self, queue, objects):
screamer 21:4fdf0dd04f6f 929 jobs_count = int(self.jobs if self.jobs else cpu_count() * CPU_COEF)
screamer 0:66f3b5499f7f 930 p = Pool(processes=jobs_count)
screamer 0:66f3b5499f7f 931
screamer 0:66f3b5499f7f 932 results = []
screamer 0:66f3b5499f7f 933 for i in range(len(queue)):
screamer 0:66f3b5499f7f 934 results.append(p.apply_async(compile_worker, [queue[i]]))
screamer 17:04753e1e329d 935 p.close()
screamer 0:66f3b5499f7f 936
screamer 0:66f3b5499f7f 937 itr = 0
screamer 17:04753e1e329d 938 while len(results):
screamer 0:66f3b5499f7f 939 itr += 1
screamer 0:66f3b5499f7f 940 if itr > 180000:
screamer 0:66f3b5499f7f 941 p.terminate()
screamer 0:66f3b5499f7f 942 p.join()
screamer 0:66f3b5499f7f 943 raise ToolException("Compile did not finish in 5 minutes")
screamer 0:66f3b5499f7f 944
screamer 17:04753e1e329d 945 sleep(0.01)
screamer 0:66f3b5499f7f 946 pending = 0
screamer 0:66f3b5499f7f 947 for r in results:
screamer 0:66f3b5499f7f 948 if r._ready is True:
screamer 0:66f3b5499f7f 949 try:
screamer 0:66f3b5499f7f 950 result = r.get()
screamer 0:66f3b5499f7f 951 results.remove(r)
screamer 0:66f3b5499f7f 952
screamer 0:66f3b5499f7f 953 self.compiled += 1
screamer 0:66f3b5499f7f 954 self.progress("compile", result['source'], build_update=True)
screamer 0:66f3b5499f7f 955 for res in result['results']:
screamer 21:4fdf0dd04f6f 956 self.cc_verbose("Compile: %s" % ' '.join(res['command']), result['source'])
screamer 0:66f3b5499f7f 957 self.compile_output([
screamer 0:66f3b5499f7f 958 res['code'],
screamer 0:66f3b5499f7f 959 res['output'],
screamer 0:66f3b5499f7f 960 res['command']
screamer 0:66f3b5499f7f 961 ])
screamer 0:66f3b5499f7f 962 objects.append(result['object'])
screamer 0:66f3b5499f7f 963 except ToolException, err:
screamer 27:5461402c33f8 964 if p._taskqueue.queue:
screamer 27:5461402c33f8 965 p._taskqueue.queue.clear()
screamer 29:1210849dba19 966 sleep(0.5)
screamer 0:66f3b5499f7f 967 p.terminate()
screamer 0:66f3b5499f7f 968 p.join()
screamer 0:66f3b5499f7f 969 raise ToolException(err)
screamer 0:66f3b5499f7f 970 else:
screamer 0:66f3b5499f7f 971 pending += 1
screamer 17:04753e1e329d 972 if pending >= jobs_count:
screamer 0:66f3b5499f7f 973 break
screamer 0:66f3b5499f7f 974
screamer 0:66f3b5499f7f 975 results = None
screamer 0:66f3b5499f7f 976 p.join()
screamer 0:66f3b5499f7f 977
screamer 0:66f3b5499f7f 978 return objects
screamer 0:66f3b5499f7f 979
screamer 24:25bff2709c20 980 # Determine the compile command based on type of source file
screamer 0:66f3b5499f7f 981 def compile_command(self, source, object, includes):
screamer 0:66f3b5499f7f 982 # Check dependencies
screamer 0:66f3b5499f7f 983 _, ext = splitext(source)
screamer 0:66f3b5499f7f 984 ext = ext.lower()
screamer 0:66f3b5499f7f 985
screamer 0:66f3b5499f7f 986 if ext == '.c' or ext == '.cpp':
screamer 0:66f3b5499f7f 987 base, _ = splitext(object)
screamer 0:66f3b5499f7f 988 dep_path = base + '.d'
The Other Jimmy 31:8ea194f6145b 989 try:
The Other Jimmy 31:8ea194f6145b 990 deps = self.parse_dependencies(dep_path) if (exists(dep_path)) else []
The Other Jimmy 31:8ea194f6145b 991 except IOError, IndexError:
The Other Jimmy 31:8ea194f6145b 992 deps = []
The Other Jimmy 36:96847d42f010 993 config_file = ([self.config.app_config_location]
The Other Jimmy 36:96847d42f010 994 if self.config.app_config_location else [])
The Other Jimmy 36:96847d42f010 995 deps.extend(config_file)
The Other Jimmy 36:96847d42f010 996 if ext == '.cpp' or self.COMPILE_C_AS_CPP:
The Other Jimmy 36:96847d42f010 997 deps.append(join(self.build_dir, self.PROFILE_FILE_NAME + "-cxx"))
The Other Jimmy 36:96847d42f010 998 else:
The Other Jimmy 36:96847d42f010 999 deps.append(join(self.build_dir, self.PROFILE_FILE_NAME + "-c"))
screamer 0:66f3b5499f7f 1000 if len(deps) == 0 or self.need_update(object, deps):
screamer 21:4fdf0dd04f6f 1001 if ext == '.cpp' or self.COMPILE_C_AS_CPP:
screamer 21:4fdf0dd04f6f 1002 return self.compile_cpp(source, object, includes)
screamer 21:4fdf0dd04f6f 1003 else:
screamer 0:66f3b5499f7f 1004 return self.compile_c(source, object, includes)
screamer 0:66f3b5499f7f 1005 elif ext == '.s':
screamer 0:66f3b5499f7f 1006 deps = [source]
The Other Jimmy 36:96847d42f010 1007 deps.append(join(self.build_dir, self.PROFILE_FILE_NAME + "-asm"))
screamer 0:66f3b5499f7f 1008 if self.need_update(object, deps):
screamer 0:66f3b5499f7f 1009 return self.assemble(source, object, includes)
screamer 0:66f3b5499f7f 1010 else:
screamer 0:66f3b5499f7f 1011 return False
screamer 0:66f3b5499f7f 1012
screamer 0:66f3b5499f7f 1013 return None
screamer 0:66f3b5499f7f 1014
screamer 24:25bff2709c20 1015 @abstractmethod
screamer 24:25bff2709c20 1016 def parse_dependencies(self, dep_path):
screamer 24:25bff2709c20 1017 """Parse the dependency information generated by the compiler.
screamer 24:25bff2709c20 1018
screamer 24:25bff2709c20 1019 Positional arguments:
screamer 24:25bff2709c20 1020 dep_path -- the path to a file generated by a previous run of the compiler
screamer 24:25bff2709c20 1021
screamer 24:25bff2709c20 1022 Return value:
screamer 24:25bff2709c20 1023 A list of all source files that the dependency file indicated were dependencies
screamer 24:25bff2709c20 1024
screamer 24:25bff2709c20 1025 Side effects:
screamer 24:25bff2709c20 1026 None
screamer 24:25bff2709c20 1027 """
screamer 24:25bff2709c20 1028 raise NotImplemented
screamer 24:25bff2709c20 1029
screamer 0:66f3b5499f7f 1030 def is_not_supported_error(self, output):
screamer 0:66f3b5499f7f 1031 return "#error directive: [NOT_SUPPORTED]" in output
screamer 0:66f3b5499f7f 1032
screamer 24:25bff2709c20 1033 @abstractmethod
screamer 24:25bff2709c20 1034 def parse_output(self, output):
screamer 24:25bff2709c20 1035 """Take in compiler output and extract sinlge line warnings and errors from it.
screamer 24:25bff2709c20 1036
screamer 24:25bff2709c20 1037 Positional arguments:
screamer 24:25bff2709c20 1038 output -- a string of all the messages emitted by a run of the compiler
screamer 24:25bff2709c20 1039
screamer 24:25bff2709c20 1040 Return value:
screamer 24:25bff2709c20 1041 None
screamer 24:25bff2709c20 1042
screamer 24:25bff2709c20 1043 Side effects:
screamer 24:25bff2709c20 1044 call self.cc_info or self.notify with a description of the event generated by the compiler
screamer 24:25bff2709c20 1045 """
screamer 24:25bff2709c20 1046 raise NotImplemented
screamer 24:25bff2709c20 1047
screamer 0:66f3b5499f7f 1048 def compile_output(self, output=[]):
screamer 0:66f3b5499f7f 1049 _rc = output[0]
The Other Jimmy 36:96847d42f010 1050 _stderr = output[1].decode("utf-8")
screamer 0:66f3b5499f7f 1051 command = output[2]
screamer 0:66f3b5499f7f 1052
screamer 0:66f3b5499f7f 1053 # Parse output for Warnings and Errors
screamer 0:66f3b5499f7f 1054 self.parse_output(_stderr)
screamer 0:66f3b5499f7f 1055 self.debug("Return: %s"% _rc)
screamer 0:66f3b5499f7f 1056 for error_line in _stderr.splitlines():
screamer 0:66f3b5499f7f 1057 self.debug("Output: %s"% error_line)
screamer 0:66f3b5499f7f 1058
screamer 0:66f3b5499f7f 1059 # Check return code
screamer 0:66f3b5499f7f 1060 if _rc != 0:
screamer 0:66f3b5499f7f 1061 if self.is_not_supported_error(_stderr):
screamer 0:66f3b5499f7f 1062 raise NotSupportedException(_stderr)
screamer 0:66f3b5499f7f 1063 else:
screamer 0:66f3b5499f7f 1064 raise ToolException(_stderr)
screamer 0:66f3b5499f7f 1065
screamer 0:66f3b5499f7f 1066 def build_library(self, objects, dir, name):
screamer 0:66f3b5499f7f 1067 needed_update = False
screamer 0:66f3b5499f7f 1068 lib = self.STD_LIB_NAME % name
screamer 0:66f3b5499f7f 1069 fout = join(dir, lib)
screamer 0:66f3b5499f7f 1070 if self.need_update(fout, objects):
screamer 0:66f3b5499f7f 1071 self.info("Library: %s" % lib)
screamer 0:66f3b5499f7f 1072 self.archive(objects, fout)
screamer 0:66f3b5499f7f 1073 needed_update = True
screamer 0:66f3b5499f7f 1074
screamer 0:66f3b5499f7f 1075 return needed_update
screamer 0:66f3b5499f7f 1076
screamer 0:66f3b5499f7f 1077 def link_program(self, r, tmp_path, name):
screamer 0:66f3b5499f7f 1078 needed_update = False
screamer 0:66f3b5499f7f 1079 ext = 'bin'
screamer 0:66f3b5499f7f 1080 if hasattr(self.target, 'OUTPUT_EXT'):
screamer 0:66f3b5499f7f 1081 ext = self.target.OUTPUT_EXT
screamer 0:66f3b5499f7f 1082
screamer 0:66f3b5499f7f 1083 if hasattr(self.target, 'OUTPUT_NAMING'):
screamer 0:66f3b5499f7f 1084 self.var("binary_naming", self.target.OUTPUT_NAMING)
screamer 0:66f3b5499f7f 1085 if self.target.OUTPUT_NAMING == "8.3":
screamer 0:66f3b5499f7f 1086 name = name[0:8]
screamer 0:66f3b5499f7f 1087 ext = ext[0:3]
screamer 22:9e85236d8716 1088
screamer 0:66f3b5499f7f 1089 # Create destination directory
screamer 0:66f3b5499f7f 1090 head, tail = split(name)
screamer 0:66f3b5499f7f 1091 new_path = join(tmp_path, head)
screamer 0:66f3b5499f7f 1092 mkdir(new_path)
screamer 22:9e85236d8716 1093
screamer 0:66f3b5499f7f 1094 filename = name+'.'+ext
screamer 0:66f3b5499f7f 1095 elf = join(tmp_path, name + '.elf')
The Other Jimmy 36:96847d42f010 1096 bin = None if ext is 'elf' else join(tmp_path, filename)
screamer 7:5af61d55adbe 1097 map = join(tmp_path, name + '.map')
screamer 0:66f3b5499f7f 1098
The Other Jimmy 31:8ea194f6145b 1099 r.objects = sorted(set(r.objects))
The Other Jimmy 36:96847d42f010 1100 config_file = ([self.config.app_config_location]
The Other Jimmy 36:96847d42f010 1101 if self.config.app_config_location else [])
The Other Jimmy 36:96847d42f010 1102 dependencies = r.objects + r.libraries + [r.linker_script] + config_file
The Other Jimmy 36:96847d42f010 1103 dependencies.append(join(self.build_dir, self.PROFILE_FILE_NAME + "-ld"))
The Other Jimmy 36:96847d42f010 1104 if self.need_update(elf, dependencies):
screamer 0:66f3b5499f7f 1105 needed_update = True
screamer 0:66f3b5499f7f 1106 self.progress("link", name)
screamer 0:66f3b5499f7f 1107 self.link(elf, r.objects, r.libraries, r.lib_dirs, r.linker_script)
screamer 0:66f3b5499f7f 1108
The Other Jimmy 36:96847d42f010 1109 if bin and self.need_update(bin, [elf]):
screamer 0:66f3b5499f7f 1110 needed_update = True
screamer 0:66f3b5499f7f 1111 self.progress("elf2bin", name)
screamer 0:66f3b5499f7f 1112 self.binary(r, elf, bin)
screamer 0:66f3b5499f7f 1113
screamer 22:9e85236d8716 1114 self.map_outputs = self.mem_stats(map)
screamer 7:5af61d55adbe 1115
screamer 0:66f3b5499f7f 1116 self.var("compile_succeded", True)
screamer 0:66f3b5499f7f 1117 self.var("binary", filename)
screamer 0:66f3b5499f7f 1118
screamer 0:66f3b5499f7f 1119 return bin, needed_update
screamer 0:66f3b5499f7f 1120
screamer 24:25bff2709c20 1121 # THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
screamer 24:25bff2709c20 1122 # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
screamer 0:66f3b5499f7f 1123 def default_cmd(self, command):
screamer 20:835f6355470d 1124 _stdout, _stderr, _rc = run_cmd(command, work_dir=getcwd(), chroot=self.CHROOT)
screamer 0:66f3b5499f7f 1125 self.debug("Return: %s"% _rc)
screamer 0:66f3b5499f7f 1126
screamer 0:66f3b5499f7f 1127 for output_line in _stdout.splitlines():
screamer 0:66f3b5499f7f 1128 self.debug("Output: %s"% output_line)
screamer 0:66f3b5499f7f 1129 for error_line in _stderr.splitlines():
screamer 0:66f3b5499f7f 1130 self.debug("Errors: %s"% error_line)
screamer 0:66f3b5499f7f 1131
screamer 0:66f3b5499f7f 1132 if _rc != 0:
screamer 0:66f3b5499f7f 1133 for line in _stderr.splitlines():
screamer 0:66f3b5499f7f 1134 self.tool_error(line)
screamer 0:66f3b5499f7f 1135 raise ToolException(_stderr)
screamer 0:66f3b5499f7f 1136
screamer 0:66f3b5499f7f 1137 ### NOTIFICATIONS ###
screamer 0:66f3b5499f7f 1138 def info(self, message):
screamer 0:66f3b5499f7f 1139 self.notify({'type': 'info', 'message': message})
screamer 0:66f3b5499f7f 1140
screamer 24:25bff2709c20 1141 # THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
screamer 24:25bff2709c20 1142 # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
screamer 0:66f3b5499f7f 1143 def debug(self, message):
screamer 0:66f3b5499f7f 1144 if self.VERBOSE:
screamer 0:66f3b5499f7f 1145 if type(message) is ListType:
screamer 0:66f3b5499f7f 1146 message = ' '.join(message)
screamer 0:66f3b5499f7f 1147 message = "[DEBUG] " + message
screamer 0:66f3b5499f7f 1148 self.notify({'type': 'debug', 'message': message})
screamer 0:66f3b5499f7f 1149
screamer 24:25bff2709c20 1150 # THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
screamer 24:25bff2709c20 1151 # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
screamer 21:4fdf0dd04f6f 1152 def cc_info(self, info=None):
screamer 21:4fdf0dd04f6f 1153 if info is not None:
screamer 21:4fdf0dd04f6f 1154 info['type'] = 'cc'
screamer 21:4fdf0dd04f6f 1155 self.notify(info)
screamer 21:4fdf0dd04f6f 1156
screamer 24:25bff2709c20 1157 # THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
screamer 24:25bff2709c20 1158 # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
screamer 21:4fdf0dd04f6f 1159 def cc_verbose(self, message, file=""):
screamer 21:4fdf0dd04f6f 1160 self.debug(message)
screamer 0:66f3b5499f7f 1161
screamer 0:66f3b5499f7f 1162 def progress(self, action, file, build_update=False):
screamer 0:66f3b5499f7f 1163 msg = {'type': 'progress', 'action': action, 'file': file}
screamer 0:66f3b5499f7f 1164 if build_update:
screamer 0:66f3b5499f7f 1165 msg['percent'] = 100. * float(self.compiled) / float(self.to_be_compiled)
screamer 0:66f3b5499f7f 1166 self.notify(msg)
screamer 0:66f3b5499f7f 1167
screamer 0:66f3b5499f7f 1168 def tool_error(self, message):
screamer 0:66f3b5499f7f 1169 self.notify({'type': 'tool_error', 'message': message})
screamer 0:66f3b5499f7f 1170
screamer 0:66f3b5499f7f 1171 def var(self, key, value):
screamer 0:66f3b5499f7f 1172 self.notify({'type': 'var', 'key': key, 'val': value})
screamer 0:66f3b5499f7f 1173
screamer 24:25bff2709c20 1174 # THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
screamer 24:25bff2709c20 1175 # ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
screamer 7:5af61d55adbe 1176 def mem_stats(self, map):
screamer 22:9e85236d8716 1177 """! Creates parser object
screamer 22:9e85236d8716 1178 @param map Path to linker map file to parse and decode
screamer 22:9e85236d8716 1179 @return Memory summary structure with memory usage statistics
screamer 22:9e85236d8716 1180 None if map file can't be opened and processed
screamer 22:9e85236d8716 1181 """
screamer 7:5af61d55adbe 1182 toolchain = self.__class__.__name__
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 1183
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 1184 # Create memap object
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 1185 memap = MemapParser()
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 1186
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 1187 # Parse and decode a map file
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 1188 if memap.parse(abspath(map), toolchain) is False:
Screamer@Y5070-M.virtuoso 9:2d27d77ada5c 1189 self.info("Unknown toolchain for memory statistics %s" % toolchain)
screamer 22:9e85236d8716 1190 return None
screamer 7:5af61d55adbe 1191
The Other Jimmy 31:8ea194f6145b 1192 # Store the memap instance for later use
The Other Jimmy 31:8ea194f6145b 1193 self.memap_instance = memap
screamer 13:ab47a20b66f0 1194
screamer 22:9e85236d8716 1195 # Here we return memory statistics structure (constructed after
screamer 22:9e85236d8716 1196 # call to generate_output) which contains raw data in bytes
screamer 22:9e85236d8716 1197 # about sections + summary
The Other Jimmy 31:8ea194f6145b 1198 return memap.mem_report
screamer 22:9e85236d8716 1199
screamer 13:ab47a20b66f0 1200 # Set the configuration data
screamer 13:ab47a20b66f0 1201 def set_config_data(self, config_data):
screamer 13:ab47a20b66f0 1202 self.config_data = config_data
screamer 13:ab47a20b66f0 1203
screamer 24:25bff2709c20 1204 # Creates the configuration header if needed:
screamer 24:25bff2709c20 1205 # - if there is no configuration data, "mbed_config.h" is not create (or deleted if it exists).
screamer 24:25bff2709c20 1206 # - if there is configuration data and "mbed_config.h" does not exist, it is created.
screamer 24:25bff2709c20 1207 # - if there is configuration data similar to the previous configuration data,
screamer 24:25bff2709c20 1208 # "mbed_config.h" is left untouched.
screamer 24:25bff2709c20 1209 # - if there is new configuration data, "mbed_config.h" is overriden.
screamer 24:25bff2709c20 1210 # The function needs to be called exactly once for the lifetime of this toolchain instance.
screamer 24:25bff2709c20 1211 # The "config_processed" variable (below) ensures this behaviour.
screamer 24:25bff2709c20 1212 # The function returns the location of the configuration file, or None if there is no
screamer 24:25bff2709c20 1213 # configuration data available (and thus no configuration file)
screamer 13:ab47a20b66f0 1214 def get_config_header(self):
screamer 24:25bff2709c20 1215 if self.config_processed: # this function was already called, return its result
screamer 24:25bff2709c20 1216 return self.config_file
screamer 24:25bff2709c20 1217 # The config file is located in the build directory
screamer 24:25bff2709c20 1218 self.config_file = join(self.build_dir, self.MBED_CONFIG_FILE_NAME)
screamer 24:25bff2709c20 1219 # If the file exists, read its current content in prev_data
screamer 24:25bff2709c20 1220 if exists(self.config_file):
screamer 24:25bff2709c20 1221 with open(self.config_file, "rt") as f:
screamer 24:25bff2709c20 1222 prev_data = f.read()
screamer 24:25bff2709c20 1223 else:
screamer 24:25bff2709c20 1224 prev_data = None
screamer 24:25bff2709c20 1225 # Get the current configuration data
screamer 24:25bff2709c20 1226 crt_data = Config.config_to_header(self.config_data) if self.config_data else None
screamer 24:25bff2709c20 1227 # "changed" indicates if a configuration change was detected
screamer 24:25bff2709c20 1228 changed = False
screamer 24:25bff2709c20 1229 if prev_data is not None: # a previous mbed_config.h exists
screamer 24:25bff2709c20 1230 if crt_data is None: # no configuration data, so "mbed_config.h" needs to be removed
screamer 24:25bff2709c20 1231 remove(self.config_file)
screamer 24:25bff2709c20 1232 self.config_file = None # this means "config file not present"
screamer 24:25bff2709c20 1233 changed = True
screamer 24:25bff2709c20 1234 elif crt_data != prev_data: # different content of config file
screamer 24:25bff2709c20 1235 with open(self.config_file, "wt") as f:
screamer 24:25bff2709c20 1236 f.write(crt_data)
screamer 24:25bff2709c20 1237 changed = True
screamer 24:25bff2709c20 1238 else: # a previous mbed_config.h does not exist
screamer 24:25bff2709c20 1239 if crt_data is not None: # there's configuration data available
screamer 24:25bff2709c20 1240 with open(self.config_file, "wt") as f:
screamer 24:25bff2709c20 1241 f.write(crt_data)
screamer 24:25bff2709c20 1242 changed = True
screamer 24:25bff2709c20 1243 else:
screamer 24:25bff2709c20 1244 self.config_file = None # this means "config file not present"
screamer 24:25bff2709c20 1245 # If there was a change in configuration, rebuild everything
screamer 24:25bff2709c20 1246 self.build_all = changed
screamer 24:25bff2709c20 1247 # Make sure that this function will only return the location of the configuration
screamer 24:25bff2709c20 1248 # file for subsequent calls, without trying to manipulate its content in any way.
screamer 24:25bff2709c20 1249 self.config_processed = True
screamer 24:25bff2709c20 1250 return self.config_file
screamer 24:25bff2709c20 1251
The Other Jimmy 36:96847d42f010 1252 def dump_build_profile(self):
The Other Jimmy 36:96847d42f010 1253 """Dump the current build profile and macros into the `.profile` file
The Other Jimmy 36:96847d42f010 1254 in the build directory"""
The Other Jimmy 36:96847d42f010 1255 for key in ["cxx", "c", "asm", "ld"]:
The Other Jimmy 36:96847d42f010 1256 to_dump = (str(self.flags[key]) + str(sorted(self.macros)))
The Other Jimmy 36:96847d42f010 1257 if key in ["cxx", "c"]:
The Other Jimmy 36:96847d42f010 1258 to_dump += str(self.flags['common'])
The Other Jimmy 36:96847d42f010 1259 where = join(self.build_dir, self.PROFILE_FILE_NAME + "-" + key)
The Other Jimmy 36:96847d42f010 1260 self._overwrite_when_not_equal(where, to_dump)
The Other Jimmy 36:96847d42f010 1261
The Other Jimmy 36:96847d42f010 1262 @staticmethod
The Other Jimmy 36:96847d42f010 1263 def _overwrite_when_not_equal(filename, content):
The Other Jimmy 36:96847d42f010 1264 if not exists(filename) or content != open(filename).read():
The Other Jimmy 36:96847d42f010 1265 with open(filename, "wb") as out:
The Other Jimmy 36:96847d42f010 1266 out.write(content)
The Other Jimmy 36:96847d42f010 1267
The Other Jimmy 31:8ea194f6145b 1268 @staticmethod
The Other Jimmy 31:8ea194f6145b 1269 def generic_check_executable(tool_key, executable_name, levels_up,
The Other Jimmy 31:8ea194f6145b 1270 nested_dir=None):
The Other Jimmy 31:8ea194f6145b 1271 """
The Other Jimmy 31:8ea194f6145b 1272 Positional args:
The Other Jimmy 31:8ea194f6145b 1273 tool_key: the key to index TOOLCHAIN_PATHS
The Other Jimmy 31:8ea194f6145b 1274 executable_name: the toolchain's named executable (ex. armcc)
The Other Jimmy 31:8ea194f6145b 1275 levels_up: each toolchain joins the toolchain_path, some
The Other Jimmy 31:8ea194f6145b 1276 variable directories (bin, include), and the executable name,
The Other Jimmy 31:8ea194f6145b 1277 so the TOOLCHAIN_PATH value must be appropriately distanced
The Other Jimmy 31:8ea194f6145b 1278
The Other Jimmy 31:8ea194f6145b 1279 Keyword args:
The Other Jimmy 31:8ea194f6145b 1280 nested_dir: the directory within TOOLCHAIN_PATHS where the executable
The Other Jimmy 31:8ea194f6145b 1281 is found (ex: 'bin' for ARM\bin\armcc (necessary to check for path
The Other Jimmy 31:8ea194f6145b 1282 that will be used by toolchain's compile)
The Other Jimmy 31:8ea194f6145b 1283
The Other Jimmy 31:8ea194f6145b 1284 Returns True if the executable location specified by the user
The Other Jimmy 31:8ea194f6145b 1285 exists and is valid OR the executable can be found on the PATH.
The Other Jimmy 31:8ea194f6145b 1286 Returns False otherwise.
The Other Jimmy 31:8ea194f6145b 1287 """
The Other Jimmy 31:8ea194f6145b 1288 # Search PATH if user did not specify a path or specified path doesn't
The Other Jimmy 31:8ea194f6145b 1289 # exist.
The Other Jimmy 31:8ea194f6145b 1290 if not TOOLCHAIN_PATHS[tool_key] or not exists(TOOLCHAIN_PATHS[tool_key]):
The Other Jimmy 31:8ea194f6145b 1291 exe = find_executable(executable_name)
The Other Jimmy 31:8ea194f6145b 1292 if not exe:
The Other Jimmy 31:8ea194f6145b 1293 return False
The Other Jimmy 31:8ea194f6145b 1294 for level in range(levels_up):
The Other Jimmy 31:8ea194f6145b 1295 # move up the specified number of directories
The Other Jimmy 31:8ea194f6145b 1296 exe = dirname(exe)
The Other Jimmy 31:8ea194f6145b 1297 TOOLCHAIN_PATHS[tool_key] = exe
The Other Jimmy 31:8ea194f6145b 1298 if nested_dir:
The Other Jimmy 31:8ea194f6145b 1299 subdir = join(TOOLCHAIN_PATHS[tool_key], nested_dir,
The Other Jimmy 31:8ea194f6145b 1300 executable_name)
The Other Jimmy 31:8ea194f6145b 1301 else:
The Other Jimmy 31:8ea194f6145b 1302 subdir = join(TOOLCHAIN_PATHS[tool_key],executable_name)
The Other Jimmy 31:8ea194f6145b 1303 # User could have specified a path that exists but does not contain exe
The Other Jimmy 31:8ea194f6145b 1304 return exists(subdir) or exists(subdir +'.exe')
The Other Jimmy 31:8ea194f6145b 1305
The Other Jimmy 31:8ea194f6145b 1306 @abstractmethod
The Other Jimmy 31:8ea194f6145b 1307 def check_executable(self):
The Other Jimmy 31:8ea194f6145b 1308 """Returns True if the executable (armcc) location specified by the
The Other Jimmy 31:8ea194f6145b 1309 user exists OR the executable can be found on the PATH.
The Other Jimmy 31:8ea194f6145b 1310 Returns False otherwise."""
The Other Jimmy 31:8ea194f6145b 1311 raise NotImplemented
The Other Jimmy 31:8ea194f6145b 1312
screamer 24:25bff2709c20 1313 @abstractmethod
screamer 24:25bff2709c20 1314 def get_config_option(self, config_header):
screamer 24:25bff2709c20 1315 """Generate the compiler option that forces the inclusion of the configuration
screamer 24:25bff2709c20 1316 header file.
screamer 24:25bff2709c20 1317
screamer 24:25bff2709c20 1318 Positional arguments:
screamer 24:25bff2709c20 1319 config_header -- The configuration header that will be included within all source files
screamer 24:25bff2709c20 1320
screamer 24:25bff2709c20 1321 Return value:
screamer 24:25bff2709c20 1322 A list of the command line arguments that will force the inclusion the specified header
screamer 24:25bff2709c20 1323
screamer 24:25bff2709c20 1324 Side effects:
screamer 24:25bff2709c20 1325 None
screamer 24:25bff2709c20 1326 """
screamer 24:25bff2709c20 1327 raise NotImplemented
screamer 24:25bff2709c20 1328
screamer 24:25bff2709c20 1329 @abstractmethod
screamer 24:25bff2709c20 1330 def assemble(self, source, object, includes):
screamer 24:25bff2709c20 1331 """Generate the command line that assembles.
screamer 24:25bff2709c20 1332
screamer 24:25bff2709c20 1333 Positional arguments:
screamer 24:25bff2709c20 1334 source -- a file path that is the file to assemble
screamer 24:25bff2709c20 1335 object -- a file path that is the destination object
screamer 24:25bff2709c20 1336 includes -- a list of all directories where header files may be found
screamer 24:25bff2709c20 1337
screamer 24:25bff2709c20 1338 Return value:
screamer 24:25bff2709c20 1339 The complete command line, as a list, that would invoke the assembler
screamer 24:25bff2709c20 1340 on the source file, include all the include paths, and generate
screamer 24:25bff2709c20 1341 the specified object file.
screamer 24:25bff2709c20 1342
screamer 24:25bff2709c20 1343 Side effects:
screamer 24:25bff2709c20 1344 None
screamer 24:25bff2709c20 1345
screamer 24:25bff2709c20 1346 Note:
screamer 24:25bff2709c20 1347 This method should be decorated with @hook_tool.
screamer 24:25bff2709c20 1348 """
screamer 24:25bff2709c20 1349 raise NotImplemented
screamer 24:25bff2709c20 1350
screamer 24:25bff2709c20 1351 @abstractmethod
screamer 24:25bff2709c20 1352 def compile_c(self, source, object, includes):
screamer 24:25bff2709c20 1353 """Generate the command line that compiles a C source file.
screamer 24:25bff2709c20 1354
screamer 24:25bff2709c20 1355 Positional arguments:
screamer 24:25bff2709c20 1356 source -- the C source file to compile
screamer 24:25bff2709c20 1357 object -- the destination object file
screamer 24:25bff2709c20 1358 includes -- a list of all the directories where header files may be found
screamer 24:25bff2709c20 1359
screamer 24:25bff2709c20 1360 Return value:
screamer 24:25bff2709c20 1361 The complete command line, as a list, that would invoke the C compiler
screamer 24:25bff2709c20 1362 on the source file, include all the include paths, and generate the
screamer 24:25bff2709c20 1363 specified object file.
screamer 24:25bff2709c20 1364
screamer 24:25bff2709c20 1365 Side effects:
screamer 24:25bff2709c20 1366 None
screamer 24:25bff2709c20 1367
screamer 24:25bff2709c20 1368 Note:
screamer 24:25bff2709c20 1369 This method should be decorated with @hook_tool.
screamer 24:25bff2709c20 1370 """
screamer 24:25bff2709c20 1371 raise NotImplemented
screamer 24:25bff2709c20 1372
screamer 24:25bff2709c20 1373 @abstractmethod
screamer 24:25bff2709c20 1374 def compile_cpp(self, source, object, includes):
screamer 24:25bff2709c20 1375 """Generate the command line that compiles a C++ source file.
screamer 24:25bff2709c20 1376
screamer 24:25bff2709c20 1377 Positional arguments:
screamer 24:25bff2709c20 1378 source -- the C++ source file to compile
screamer 24:25bff2709c20 1379 object -- the destination object file
screamer 24:25bff2709c20 1380 includes -- a list of all the directories where header files may be found
screamer 24:25bff2709c20 1381
screamer 24:25bff2709c20 1382 Return value:
screamer 24:25bff2709c20 1383 The complete command line, as a list, that would invoke the C++ compiler
screamer 24:25bff2709c20 1384 on the source file, include all the include paths, and generate the
screamer 24:25bff2709c20 1385 specified object file.
screamer 24:25bff2709c20 1386
screamer 24:25bff2709c20 1387 Side effects:
screamer 24:25bff2709c20 1388 None
screamer 24:25bff2709c20 1389
screamer 24:25bff2709c20 1390 Note:
screamer 24:25bff2709c20 1391 This method should be decorated with @hook_tool.
screamer 24:25bff2709c20 1392 """
screamer 24:25bff2709c20 1393 raise NotImplemented
screamer 24:25bff2709c20 1394
screamer 24:25bff2709c20 1395 @abstractmethod
screamer 24:25bff2709c20 1396 def link(self, output, objects, libraries, lib_dirs, mem_map):
screamer 24:25bff2709c20 1397 """Run the linker to create an executable and memory map.
screamer 24:25bff2709c20 1398
screamer 24:25bff2709c20 1399 Positional arguments:
screamer 24:25bff2709c20 1400 output -- the file name to place the executable in
screamer 24:25bff2709c20 1401 objects -- all of the object files to link
screamer 24:25bff2709c20 1402 libraries -- all of the required libraries
screamer 24:25bff2709c20 1403 lib_dirs -- where the required libraries are located
screamer 24:25bff2709c20 1404 mem_map -- the location where the memory map file should be stored
screamer 24:25bff2709c20 1405
screamer 24:25bff2709c20 1406 Return value:
screamer 24:25bff2709c20 1407 None
screamer 24:25bff2709c20 1408
screamer 24:25bff2709c20 1409 Side effect:
screamer 24:25bff2709c20 1410 Runs the linker to produce the executable.
screamer 24:25bff2709c20 1411
screamer 24:25bff2709c20 1412 Note:
screamer 24:25bff2709c20 1413 This method should be decorated with @hook_tool.
screamer 24:25bff2709c20 1414 """
screamer 24:25bff2709c20 1415 raise NotImplemented
screamer 24:25bff2709c20 1416
screamer 24:25bff2709c20 1417 @abstractmethod
screamer 24:25bff2709c20 1418 def archive(self, objects, lib_path):
screamer 24:25bff2709c20 1419 """Run the command line that creates an archive.
screamer 24:25bff2709c20 1420
screamer 24:25bff2709c20 1421 Positional arguhments:
screamer 24:25bff2709c20 1422 objects -- a list of all the object files that should be archived
screamer 24:25bff2709c20 1423 lib_path -- the file name of the resulting library file
screamer 24:25bff2709c20 1424
screamer 24:25bff2709c20 1425 Return value:
screamer 24:25bff2709c20 1426 None
screamer 24:25bff2709c20 1427
screamer 24:25bff2709c20 1428 Side effect:
screamer 24:25bff2709c20 1429 Runs the archiving tool to produce the library file.
screamer 24:25bff2709c20 1430
screamer 24:25bff2709c20 1431 Note:
screamer 24:25bff2709c20 1432 This method should be decorated with @hook_tool.
screamer 24:25bff2709c20 1433 """
screamer 24:25bff2709c20 1434 raise NotImplemented
screamer 24:25bff2709c20 1435
screamer 24:25bff2709c20 1436 @abstractmethod
screamer 24:25bff2709c20 1437 def binary(self, resources, elf, bin):
screamer 24:25bff2709c20 1438 """Run the command line that will Extract a simplified binary file.
screamer 24:25bff2709c20 1439
screamer 24:25bff2709c20 1440 Positional arguments:
screamer 24:25bff2709c20 1441 resources -- A resources object (Is not used in any of the toolchains)
screamer 24:25bff2709c20 1442 elf -- the executable file that is to be converted
screamer 24:25bff2709c20 1443 bin -- the file name of the to be created simplified binary file
screamer 24:25bff2709c20 1444
screamer 24:25bff2709c20 1445 Return value:
screamer 24:25bff2709c20 1446 None
screamer 24:25bff2709c20 1447
screamer 24:25bff2709c20 1448 Side effect:
screamer 24:25bff2709c20 1449 Runs the elf2bin tool to produce the simplified binary file.
screamer 24:25bff2709c20 1450
screamer 24:25bff2709c20 1451 Note:
screamer 24:25bff2709c20 1452 This method should be decorated with @hook_tool.
screamer 24:25bff2709c20 1453 """
screamer 24:25bff2709c20 1454 raise NotImplemented
screamer 13:ab47a20b66f0 1455
The Other Jimmy 36:96847d42f010 1456 @staticmethod
The Other Jimmy 36:96847d42f010 1457 @abstractmethod
The Other Jimmy 36:96847d42f010 1458 def name_mangle(name):
The Other Jimmy 36:96847d42f010 1459 """Mangle a name based on the conventional name mangling of this toolchain
The Other Jimmy 36:96847d42f010 1460
The Other Jimmy 36:96847d42f010 1461 Positional arguments:
The Other Jimmy 36:96847d42f010 1462 name -- the name to mangle
The Other Jimmy 36:96847d42f010 1463
The Other Jimmy 36:96847d42f010 1464 Return:
The Other Jimmy 36:96847d42f010 1465 the mangled name as a string
The Other Jimmy 36:96847d42f010 1466 """
The Other Jimmy 36:96847d42f010 1467 raise NotImplemented
The Other Jimmy 36:96847d42f010 1468
The Other Jimmy 36:96847d42f010 1469 @staticmethod
The Other Jimmy 36:96847d42f010 1470 @abstractmethod
The Other Jimmy 36:96847d42f010 1471 def make_ld_define(name, value):
The Other Jimmy 36:96847d42f010 1472 """Create an argument to the linker that would define a symbol
The Other Jimmy 36:96847d42f010 1473
The Other Jimmy 36:96847d42f010 1474 Positional arguments:
The Other Jimmy 36:96847d42f010 1475 name -- the symbol to define
The Other Jimmy 36:96847d42f010 1476 value -- the value to give the symbol
The Other Jimmy 36:96847d42f010 1477
The Other Jimmy 36:96847d42f010 1478 Return:
The Other Jimmy 36:96847d42f010 1479 The linker flag as a string
The Other Jimmy 36:96847d42f010 1480 """
The Other Jimmy 36:96847d42f010 1481 raise NotImplemented
The Other Jimmy 36:96847d42f010 1482
The Other Jimmy 36:96847d42f010 1483 @staticmethod
The Other Jimmy 36:96847d42f010 1484 @abstractmethod
The Other Jimmy 36:96847d42f010 1485 def redirect_symbol(source, sync, build_dir):
The Other Jimmy 36:96847d42f010 1486 """Redirect a symbol at link time to point at somewhere else
The Other Jimmy 36:96847d42f010 1487
The Other Jimmy 36:96847d42f010 1488 Positional arguments:
The Other Jimmy 36:96847d42f010 1489 source -- the symbol doing the pointing
The Other Jimmy 36:96847d42f010 1490 sync -- the symbol being pointed to
The Other Jimmy 36:96847d42f010 1491 build_dir -- the directory to put "response files" if needed by the toolchain
The Other Jimmy 36:96847d42f010 1492
The Other Jimmy 36:96847d42f010 1493 Side Effects:
The Other Jimmy 36:96847d42f010 1494 Possibly create a file in the build directory
The Other Jimmy 36:96847d42f010 1495
The Other Jimmy 36:96847d42f010 1496 Return:
The Other Jimmy 36:96847d42f010 1497 The linker flag to redirect the symbol, as a string
The Other Jimmy 36:96847d42f010 1498 """
The Other Jimmy 36:96847d42f010 1499 raise NotImplemented
The Other Jimmy 36:96847d42f010 1500
screamer 13:ab47a20b66f0 1501 # Return the list of macros geenrated by the build system
screamer 13:ab47a20b66f0 1502 def get_config_macros(self):
screamer 13:ab47a20b66f0 1503 return Config.config_to_macros(self.config_data) if self.config_data else []
screamer 13:ab47a20b66f0 1504
The Other Jimmy 36:96847d42f010 1505 @property
The Other Jimmy 36:96847d42f010 1506 def report(self):
The Other Jimmy 36:96847d42f010 1507 to_ret = {}
The Other Jimmy 36:96847d42f010 1508 to_ret['c_compiler'] = {'flags': copy(self.flags['c']),
The Other Jimmy 36:96847d42f010 1509 'symbols': self.get_symbols()}
The Other Jimmy 36:96847d42f010 1510 to_ret['cxx_compiler'] = {'flags': copy(self.flags['cxx']),
The Other Jimmy 36:96847d42f010 1511 'symbols': self.get_symbols()}
The Other Jimmy 36:96847d42f010 1512 to_ret['assembler'] = {'flags': copy(self.flags['asm']),
The Other Jimmy 36:96847d42f010 1513 'symbols': self.get_symbols(True)}
The Other Jimmy 36:96847d42f010 1514 to_ret['linker'] = {'flags': copy(self.flags['ld'])}
The Other Jimmy 36:96847d42f010 1515 to_ret.update(self.config.report)
The Other Jimmy 36:96847d42f010 1516 return to_ret
The Other Jimmy 36:96847d42f010 1517
screamer 20:835f6355470d 1518 from tools.settings import ARM_PATH
The Other Jimmy 36:96847d42f010 1519 from tools.settings import GCC_ARM_PATH
screamer 0:66f3b5499f7f 1520 from tools.settings import IAR_PATH
screamer 0:66f3b5499f7f 1521
screamer 20:835f6355470d 1522 TOOLCHAIN_PATHS = {
screamer 20:835f6355470d 1523 'ARM': ARM_PATH,
screamer 20:835f6355470d 1524 'uARM': ARM_PATH,
screamer 0:66f3b5499f7f 1525 'GCC_ARM': GCC_ARM_PATH,
screamer 0:66f3b5499f7f 1526 'IAR': IAR_PATH
screamer 0:66f3b5499f7f 1527 }
screamer 0:66f3b5499f7f 1528
screamer 0:66f3b5499f7f 1529 from tools.toolchains.arm import ARM_STD, ARM_MICRO
The Other Jimmy 36:96847d42f010 1530 from tools.toolchains.gcc import GCC_ARM
screamer 0:66f3b5499f7f 1531 from tools.toolchains.iar import IAR
screamer 0:66f3b5499f7f 1532
screamer 0:66f3b5499f7f 1533 TOOLCHAIN_CLASSES = {
screamer 0:66f3b5499f7f 1534 'ARM': ARM_STD,
screamer 0:66f3b5499f7f 1535 'uARM': ARM_MICRO,
screamer 0:66f3b5499f7f 1536 'GCC_ARM': GCC_ARM,
screamer 0:66f3b5499f7f 1537 'IAR': IAR
screamer 0:66f3b5499f7f 1538 }
screamer 0:66f3b5499f7f 1539
screamer 0:66f3b5499f7f 1540 TOOLCHAINS = set(TOOLCHAIN_CLASSES.keys())