mbed-os for GR-LYCHEE

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

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

Who changed what in which revision?

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