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