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