Clone of official tools
toolchains/__init__.py@13:ab47a20b66f0, 2016-07-14 (annotated)
- Committer:
- screamer
- Date:
- Thu Jul 14 20:21:19 2016 +0100
- Revision:
- 13:ab47a20b66f0
- Parent:
- 12:f2e8a005c7d3
- Child:
- 14:ee1b877e6839
Apply latest tools
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 | 7:5af61d55adbe | 20 | from os import stat, walk, getcwd, sep |
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 | 0:66f3b5499f7f | 29 | |
screamer | 0:66f3b5499f7f | 30 | from multiprocessing import Pool, cpu_count |
screamer | 0:66f3b5499f7f | 31 | from tools.utils import run_cmd, mkdir, rel_path, ToolException, NotSupportedException, split_path |
screamer | 0:66f3b5499f7f | 32 | from tools.settings import BUILD_OPTIONS, MBED_ORG_USER |
screamer | 0:66f3b5499f7f | 33 | import tools.hooks as hooks |
Screamer@Y5070-M.virtuoso | 12:f2e8a005c7d3 | 34 | from tools.memap import MemapParser |
screamer | 0:66f3b5499f7f | 35 | from hashlib import md5 |
screamer | 7:5af61d55adbe | 36 | import fnmatch |
screamer | 0:66f3b5499f7f | 37 | |
screamer | 0:66f3b5499f7f | 38 | |
screamer | 0:66f3b5499f7f | 39 | #Disables multiprocessing if set to higher number than the host machine CPUs |
screamer | 0:66f3b5499f7f | 40 | CPU_COUNT_MIN = 1 |
screamer | 0:66f3b5499f7f | 41 | |
screamer | 0:66f3b5499f7f | 42 | def compile_worker(job): |
screamer | 0:66f3b5499f7f | 43 | results = [] |
screamer | 0:66f3b5499f7f | 44 | for command in job['commands']: |
screamer | 13:ab47a20b66f0 | 45 | try: |
screamer | 13:ab47a20b66f0 | 46 | _, _stderr, _rc = run_cmd(command, job['work_dir']) |
screamer | 13:ab47a20b66f0 | 47 | except KeyboardInterrupt as e: |
screamer | 13:ab47a20b66f0 | 48 | raise ToolException |
screamer | 13:ab47a20b66f0 | 49 | |
screamer | 0:66f3b5499f7f | 50 | results.append({ |
screamer | 0:66f3b5499f7f | 51 | 'code': _rc, |
screamer | 0:66f3b5499f7f | 52 | 'output': _stderr, |
screamer | 0:66f3b5499f7f | 53 | 'command': command |
screamer | 0:66f3b5499f7f | 54 | }) |
screamer | 0:66f3b5499f7f | 55 | |
screamer | 0:66f3b5499f7f | 56 | return { |
screamer | 0:66f3b5499f7f | 57 | 'source': job['source'], |
screamer | 0:66f3b5499f7f | 58 | 'object': job['object'], |
screamer | 0:66f3b5499f7f | 59 | 'commands': job['commands'], |
screamer | 0:66f3b5499f7f | 60 | 'results': results |
screamer | 0:66f3b5499f7f | 61 | } |
screamer | 0:66f3b5499f7f | 62 | |
screamer | 7:5af61d55adbe | 63 | |
screamer | 0:66f3b5499f7f | 64 | class Resources: |
screamer | 0:66f3b5499f7f | 65 | def __init__(self, base_path=None): |
screamer | 0:66f3b5499f7f | 66 | self.base_path = base_path |
screamer | 0:66f3b5499f7f | 67 | |
screamer | 13:ab47a20b66f0 | 68 | self.file_basepath = {} |
screamer | 13:ab47a20b66f0 | 69 | |
screamer | 0:66f3b5499f7f | 70 | self.inc_dirs = [] |
screamer | 0:66f3b5499f7f | 71 | self.headers = [] |
screamer | 0:66f3b5499f7f | 72 | |
screamer | 0:66f3b5499f7f | 73 | self.s_sources = [] |
screamer | 0:66f3b5499f7f | 74 | self.c_sources = [] |
screamer | 0:66f3b5499f7f | 75 | self.cpp_sources = [] |
screamer | 0:66f3b5499f7f | 76 | |
screamer | 0:66f3b5499f7f | 77 | self.lib_dirs = set([]) |
screamer | 0:66f3b5499f7f | 78 | self.objects = [] |
screamer | 0:66f3b5499f7f | 79 | self.libraries = [] |
screamer | 0:66f3b5499f7f | 80 | |
screamer | 0:66f3b5499f7f | 81 | # mbed special files |
screamer | 0:66f3b5499f7f | 82 | self.lib_builds = [] |
screamer | 0:66f3b5499f7f | 83 | self.lib_refs = [] |
screamer | 0:66f3b5499f7f | 84 | |
screamer | 0:66f3b5499f7f | 85 | self.repo_dirs = [] |
screamer | 0:66f3b5499f7f | 86 | self.repo_files = [] |
screamer | 0:66f3b5499f7f | 87 | |
screamer | 0:66f3b5499f7f | 88 | self.linker_script = None |
screamer | 0:66f3b5499f7f | 89 | |
screamer | 0:66f3b5499f7f | 90 | # Other files |
screamer | 0:66f3b5499f7f | 91 | self.hex_files = [] |
screamer | 0:66f3b5499f7f | 92 | self.bin_files = [] |
screamer | 7:5af61d55adbe | 93 | self.json_files = [] |
screamer | 7:5af61d55adbe | 94 | |
screamer | 13:ab47a20b66f0 | 95 | # Features |
screamer | 13:ab47a20b66f0 | 96 | self.features = {} |
screamer | 13:ab47a20b66f0 | 97 | |
screamer | 7:5af61d55adbe | 98 | def __add__(self, resources): |
screamer | 7:5af61d55adbe | 99 | if resources is None: |
screamer | 7:5af61d55adbe | 100 | return self |
screamer | 7:5af61d55adbe | 101 | else: |
screamer | 7:5af61d55adbe | 102 | return self.add(resources) |
screamer | 7:5af61d55adbe | 103 | |
screamer | 7:5af61d55adbe | 104 | def __radd__(self, resources): |
screamer | 7:5af61d55adbe | 105 | if resources is None: |
screamer | 7:5af61d55adbe | 106 | return self |
screamer | 7:5af61d55adbe | 107 | else: |
screamer | 7:5af61d55adbe | 108 | return self.add(resources) |
screamer | 0:66f3b5499f7f | 109 | |
screamer | 0:66f3b5499f7f | 110 | def add(self, resources): |
screamer | 13:ab47a20b66f0 | 111 | for f,p in resources.file_basepath.items(): |
screamer | 13:ab47a20b66f0 | 112 | self.file_basepath[f] = p |
screamer | 13:ab47a20b66f0 | 113 | |
screamer | 0:66f3b5499f7f | 114 | self.inc_dirs += resources.inc_dirs |
screamer | 0:66f3b5499f7f | 115 | self.headers += resources.headers |
screamer | 0:66f3b5499f7f | 116 | |
screamer | 0:66f3b5499f7f | 117 | self.s_sources += resources.s_sources |
screamer | 0:66f3b5499f7f | 118 | self.c_sources += resources.c_sources |
screamer | 0:66f3b5499f7f | 119 | self.cpp_sources += resources.cpp_sources |
screamer | 0:66f3b5499f7f | 120 | |
screamer | 0:66f3b5499f7f | 121 | self.lib_dirs |= resources.lib_dirs |
screamer | 0:66f3b5499f7f | 122 | self.objects += resources.objects |
screamer | 0:66f3b5499f7f | 123 | self.libraries += resources.libraries |
screamer | 0:66f3b5499f7f | 124 | |
screamer | 0:66f3b5499f7f | 125 | self.lib_builds += resources.lib_builds |
screamer | 0:66f3b5499f7f | 126 | self.lib_refs += resources.lib_refs |
screamer | 0:66f3b5499f7f | 127 | |
screamer | 0:66f3b5499f7f | 128 | self.repo_dirs += resources.repo_dirs |
screamer | 0:66f3b5499f7f | 129 | self.repo_files += resources.repo_files |
screamer | 0:66f3b5499f7f | 130 | |
screamer | 0:66f3b5499f7f | 131 | if resources.linker_script is not None: |
screamer | 0:66f3b5499f7f | 132 | self.linker_script = resources.linker_script |
screamer | 0:66f3b5499f7f | 133 | |
screamer | 0:66f3b5499f7f | 134 | self.hex_files += resources.hex_files |
screamer | 0:66f3b5499f7f | 135 | self.bin_files += resources.bin_files |
screamer | 7:5af61d55adbe | 136 | self.json_files += resources.json_files |
screamer | 7:5af61d55adbe | 137 | |
screamer | 13:ab47a20b66f0 | 138 | self.features.update(resources.features) |
screamer | 13:ab47a20b66f0 | 139 | |
screamer | 7:5af61d55adbe | 140 | return self |
screamer | 0:66f3b5499f7f | 141 | |
screamer | 0:66f3b5499f7f | 142 | def relative_to(self, base, dot=False): |
screamer | 0:66f3b5499f7f | 143 | for field in ['inc_dirs', 'headers', 's_sources', 'c_sources', |
screamer | 0:66f3b5499f7f | 144 | 'cpp_sources', 'lib_dirs', 'objects', 'libraries', |
screamer | 7:5af61d55adbe | 145 | 'lib_builds', 'lib_refs', 'repo_dirs', 'repo_files', |
screamer | 7:5af61d55adbe | 146 | 'hex_files', 'bin_files', 'json_files']: |
screamer | 0:66f3b5499f7f | 147 | v = [rel_path(f, base, dot) for f in getattr(self, field)] |
screamer | 0:66f3b5499f7f | 148 | setattr(self, field, v) |
screamer | 13:ab47a20b66f0 | 149 | |
screamer | 13:ab47a20b66f0 | 150 | self.features = {k: f.relative_to(base, dot) for k, f in self.features.iteritems() if f} |
screamer | 13:ab47a20b66f0 | 151 | |
screamer | 0:66f3b5499f7f | 152 | if self.linker_script is not None: |
screamer | 0:66f3b5499f7f | 153 | self.linker_script = rel_path(self.linker_script, base, dot) |
screamer | 0:66f3b5499f7f | 154 | |
screamer | 0:66f3b5499f7f | 155 | def win_to_unix(self): |
screamer | 0:66f3b5499f7f | 156 | for field in ['inc_dirs', 'headers', 's_sources', 'c_sources', |
screamer | 0:66f3b5499f7f | 157 | 'cpp_sources', 'lib_dirs', 'objects', 'libraries', |
screamer | 7:5af61d55adbe | 158 | 'lib_builds', 'lib_refs', 'repo_dirs', 'repo_files', |
screamer | 7:5af61d55adbe | 159 | 'hex_files', 'bin_files', 'json_files']: |
screamer | 0:66f3b5499f7f | 160 | v = [f.replace('\\', '/') for f in getattr(self, field)] |
screamer | 0:66f3b5499f7f | 161 | setattr(self, field, v) |
screamer | 13:ab47a20b66f0 | 162 | |
screamer | 13:ab47a20b66f0 | 163 | self.features = {k: f.win_to_unix() for k, f in self.features.iteritems() if f} |
screamer | 13:ab47a20b66f0 | 164 | |
screamer | 0:66f3b5499f7f | 165 | if self.linker_script is not None: |
screamer | 0:66f3b5499f7f | 166 | self.linker_script = self.linker_script.replace('\\', '/') |
screamer | 0:66f3b5499f7f | 167 | |
screamer | 0:66f3b5499f7f | 168 | def __str__(self): |
screamer | 0:66f3b5499f7f | 169 | s = [] |
screamer | 0:66f3b5499f7f | 170 | |
screamer | 0:66f3b5499f7f | 171 | for (label, resources) in ( |
screamer | 0:66f3b5499f7f | 172 | ('Include Directories', self.inc_dirs), |
screamer | 0:66f3b5499f7f | 173 | ('Headers', self.headers), |
screamer | 0:66f3b5499f7f | 174 | |
screamer | 0:66f3b5499f7f | 175 | ('Assembly sources', self.s_sources), |
screamer | 0:66f3b5499f7f | 176 | ('C sources', self.c_sources), |
screamer | 0:66f3b5499f7f | 177 | ('C++ sources', self.cpp_sources), |
screamer | 0:66f3b5499f7f | 178 | |
screamer | 0:66f3b5499f7f | 179 | ('Library directories', self.lib_dirs), |
screamer | 0:66f3b5499f7f | 180 | ('Objects', self.objects), |
screamer | 0:66f3b5499f7f | 181 | ('Libraries', self.libraries), |
screamer | 0:66f3b5499f7f | 182 | |
screamer | 0:66f3b5499f7f | 183 | ('Hex files', self.hex_files), |
screamer | 0:66f3b5499f7f | 184 | ('Bin files', self.bin_files), |
screamer | 13:ab47a20b66f0 | 185 | |
screamer | 13:ab47a20b66f0 | 186 | ('Features', self.features), |
screamer | 0:66f3b5499f7f | 187 | ): |
screamer | 0:66f3b5499f7f | 188 | if resources: |
screamer | 0:66f3b5499f7f | 189 | s.append('%s:\n ' % label + '\n '.join(resources)) |
screamer | 0:66f3b5499f7f | 190 | |
screamer | 0:66f3b5499f7f | 191 | if self.linker_script: |
screamer | 0:66f3b5499f7f | 192 | s.append('Linker Script: ' + self.linker_script) |
screamer | 0:66f3b5499f7f | 193 | |
screamer | 0:66f3b5499f7f | 194 | return '\n'.join(s) |
screamer | 0:66f3b5499f7f | 195 | |
screamer | 0:66f3b5499f7f | 196 | # Support legacy build conventions: the original mbed build system did not have |
screamer | 0:66f3b5499f7f | 197 | # standard labels for the "TARGET_" and "TOOLCHAIN_" specific directories, but |
screamer | 0:66f3b5499f7f | 198 | # had the knowledge of a list of these directories to be ignored. |
screamer | 0:66f3b5499f7f | 199 | LEGACY_IGNORE_DIRS = set([ |
screamer | 0:66f3b5499f7f | 200 | 'LPC11U24', 'LPC1768', 'LPC2368', 'LPC4088', 'LPC812', 'KL25Z', |
screamer | 13:ab47a20b66f0 | 201 | 'ARM', 'GCC_ARM', 'GCC_CR', 'IAR', 'uARM' |
screamer | 0:66f3b5499f7f | 202 | ]) |
screamer | 0:66f3b5499f7f | 203 | LEGACY_TOOLCHAIN_NAMES = { |
screamer | 0:66f3b5499f7f | 204 | 'ARM_STD':'ARM', 'ARM_MICRO': 'uARM', |
screamer | 13:ab47a20b66f0 | 205 | 'GCC_ARM': 'GCC_ARM', 'GCC_CR': 'GCC_CR', |
screamer | 0:66f3b5499f7f | 206 | 'IAR': 'IAR', |
screamer | 0:66f3b5499f7f | 207 | } |
screamer | 0:66f3b5499f7f | 208 | |
screamer | 0:66f3b5499f7f | 209 | |
screamer | 0:66f3b5499f7f | 210 | class mbedToolchain: |
screamer | 0:66f3b5499f7f | 211 | VERBOSE = True |
screamer | 0:66f3b5499f7f | 212 | |
screamer | 0:66f3b5499f7f | 213 | CORTEX_SYMBOLS = { |
screamer | 0:66f3b5499f7f | 214 | "Cortex-M0" : ["__CORTEX_M0", "ARM_MATH_CM0", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"], |
screamer | 0:66f3b5499f7f | 215 | "Cortex-M0+": ["__CORTEX_M0PLUS", "ARM_MATH_CM0PLUS", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"], |
screamer | 13:ab47a20b66f0 | 216 | "Cortex-M1" : ["__CORTEX_M3", "ARM_MATH_CM1", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"], |
screamer | 0:66f3b5499f7f | 217 | "Cortex-M3" : ["__CORTEX_M3", "ARM_MATH_CM3", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"], |
screamer | 0:66f3b5499f7f | 218 | "Cortex-M4" : ["__CORTEX_M4", "ARM_MATH_CM4", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"], |
screamer | 0:66f3b5499f7f | 219 | "Cortex-M4F" : ["__CORTEX_M4", "ARM_MATH_CM4", "__FPU_PRESENT=1", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"], |
screamer | 0:66f3b5499f7f | 220 | "Cortex-M7" : ["__CORTEX_M7", "ARM_MATH_CM7", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"], |
screamer | 0:66f3b5499f7f | 221 | "Cortex-M7F" : ["__CORTEX_M7", "ARM_MATH_CM7", "__FPU_PRESENT=1", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"], |
screamer | 13:ab47a20b66f0 | 222 | "Cortex-M7FD" : ["__CORTEX_M7", "ARM_MATH_CM7", "__FPU_PRESENT=1", "__CMSIS_RTOS", "__MBED_CMSIS_RTOS_CM"], |
screamer | 0:66f3b5499f7f | 223 | "Cortex-A9" : ["__CORTEX_A9", "ARM_MATH_CA9", "__FPU_PRESENT", "__CMSIS_RTOS", "__EVAL", "__MBED_CMSIS_RTOS_CA9"], |
screamer | 0:66f3b5499f7f | 224 | } |
screamer | 13:ab47a20b66f0 | 225 | |
screamer | 0:66f3b5499f7f | 226 | |
screamer | 0:66f3b5499f7f | 227 | GOANNA_FORMAT = "[Goanna] warning [%FILENAME%:%LINENO%] - [%CHECKNAME%(%SEVERITY%)] %MESSAGE%" |
screamer | 0:66f3b5499f7f | 228 | GOANNA_DIAGNOSTIC_PATTERN = re.compile(r'"\[Goanna\] (?P<severity>warning) \[(?P<file>[^:]+):(?P<line>\d+)\] \- (?P<message>.*)"') |
screamer | 0:66f3b5499f7f | 229 | |
screamer | 13:ab47a20b66f0 | 230 | MBED_CONFIG_FILE_NAME="mbed_config.h" |
screamer | 13:ab47a20b66f0 | 231 | |
screamer | 13:ab47a20b66f0 | 232 | def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False): |
screamer | 0:66f3b5499f7f | 233 | self.target = target |
screamer | 0:66f3b5499f7f | 234 | self.name = self.__class__.__name__ |
screamer | 13:ab47a20b66f0 | 235 | |
screamer | 13:ab47a20b66f0 | 236 | # compile/assemble/link/binary hooks |
screamer | 0:66f3b5499f7f | 237 | self.hook = hooks.Hook(target, self) |
screamer | 13:ab47a20b66f0 | 238 | |
screamer | 13:ab47a20b66f0 | 239 | # Toolchain flags |
screamer | 13:ab47a20b66f0 | 240 | self.flags = deepcopy(self.DEFAULT_FLAGS) |
screamer | 13:ab47a20b66f0 | 241 | |
screamer | 13:ab47a20b66f0 | 242 | # User-defined macros |
screamer | 13:ab47a20b66f0 | 243 | self.macros = macros or [] |
screamer | 13:ab47a20b66f0 | 244 | |
screamer | 13:ab47a20b66f0 | 245 | # Macros generated from toolchain and target rules/features |
screamer | 13:ab47a20b66f0 | 246 | self.symbols = None |
screamer | 13:ab47a20b66f0 | 247 | |
screamer | 13:ab47a20b66f0 | 248 | # Labels generated from toolchain and target rules/features (used for selective build) |
screamer | 13:ab47a20b66f0 | 249 | self.labels = None |
screamer | 13:ab47a20b66f0 | 250 | |
screamer | 13:ab47a20b66f0 | 251 | # This will hold the configuration data (as returned by Config.get_config_data()) |
screamer | 13:ab47a20b66f0 | 252 | self.config_data = None |
screamer | 0:66f3b5499f7f | 253 | |
screamer | 13:ab47a20b66f0 | 254 | # Non-incremental compile |
screamer | 13:ab47a20b66f0 | 255 | self.build_all = False |
screamer | 13:ab47a20b66f0 | 256 | |
screamer | 13:ab47a20b66f0 | 257 | # Build output dir |
screamer | 13:ab47a20b66f0 | 258 | self.build_dir = None |
screamer | 13:ab47a20b66f0 | 259 | self.timestamp = time() |
screamer | 13:ab47a20b66f0 | 260 | |
screamer | 13:ab47a20b66f0 | 261 | # Output build naming based on target+toolchain combo (mbed 2.0 builds) |
screamer | 13:ab47a20b66f0 | 262 | self.obj_path = join("TARGET_"+target.name, "TOOLCHAIN_"+self.name) |
screamer | 13:ab47a20b66f0 | 263 | |
screamer | 13:ab47a20b66f0 | 264 | # Number of concurrent build jobs. 0 means auto (based on host system cores) |
screamer | 13:ab47a20b66f0 | 265 | self.jobs = 0 |
screamer | 13:ab47a20b66f0 | 266 | |
screamer | 13:ab47a20b66f0 | 267 | self.CHROOT = None |
screamer | 13:ab47a20b66f0 | 268 | |
screamer | 13:ab47a20b66f0 | 269 | # Ignore patterns from .mbedignore files |
screamer | 13:ab47a20b66f0 | 270 | self.ignore_patterns = [] |
screamer | 13:ab47a20b66f0 | 271 | |
screamer | 13:ab47a20b66f0 | 272 | # Pre-mbed 2.0 ignore dirs |
screamer | 0:66f3b5499f7f | 273 | self.legacy_ignore_dirs = LEGACY_IGNORE_DIRS - set([target.name, LEGACY_TOOLCHAIN_NAMES[self.name]]) |
screamer | 0:66f3b5499f7f | 274 | |
screamer | 13:ab47a20b66f0 | 275 | # Output notify function |
screamer | 0:66f3b5499f7f | 276 | if notify: |
screamer | 0:66f3b5499f7f | 277 | self.notify_fun = notify |
screamer | 0:66f3b5499f7f | 278 | elif extra_verbose: |
screamer | 0:66f3b5499f7f | 279 | self.notify_fun = self.print_notify_verbose |
screamer | 0:66f3b5499f7f | 280 | else: |
screamer | 0:66f3b5499f7f | 281 | self.notify_fun = self.print_notify |
screamer | 13:ab47a20b66f0 | 282 | |
screamer | 13:ab47a20b66f0 | 283 | # Silent builds (no output) |
screamer | 13:ab47a20b66f0 | 284 | self.silent = silent |
screamer | 13:ab47a20b66f0 | 285 | |
screamer | 13:ab47a20b66f0 | 286 | # Print output buffer |
screamer | 13:ab47a20b66f0 | 287 | self.output = "" |
screamer | 0:66f3b5499f7f | 288 | |
screamer | 13:ab47a20b66f0 | 289 | # Build options passed by -o flag |
screamer | 0:66f3b5499f7f | 290 | self.options = options if options is not None else [] |
screamer | 0:66f3b5499f7f | 291 | |
screamer | 13:ab47a20b66f0 | 292 | # Build options passed by settings.py or mbed_settings.py |
screamer | 0:66f3b5499f7f | 293 | self.options.extend(BUILD_OPTIONS) |
screamer | 13:ab47a20b66f0 | 294 | |
screamer | 0:66f3b5499f7f | 295 | if self.options: |
screamer | 0:66f3b5499f7f | 296 | self.info("Build Options: %s" % (', '.join(self.options))) |
screamer | 13:ab47a20b66f0 | 297 | |
screamer | 13:ab47a20b66f0 | 298 | # uVisor spepcific rules |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 299 | if 'UVISOR' in self.target.features and 'UVISOR_SUPPORTED' in self.target.extra_labels: |
screamer | 0:66f3b5499f7f | 300 | self.target.core = re.sub(r"F$", '', self.target.core) |
screamer | 0:66f3b5499f7f | 301 | |
screamer | 0:66f3b5499f7f | 302 | def get_output(self): |
screamer | 0:66f3b5499f7f | 303 | return self.output |
screamer | 0:66f3b5499f7f | 304 | |
screamer | 0:66f3b5499f7f | 305 | def print_notify(self, event, silent=False): |
screamer | 0:66f3b5499f7f | 306 | """ Default command line notification |
screamer | 0:66f3b5499f7f | 307 | """ |
screamer | 0:66f3b5499f7f | 308 | msg = None |
screamer | 0:66f3b5499f7f | 309 | |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 310 | if not self.VERBOSE and event['type'] == 'tool_error': |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 311 | msg = event['message'] |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 312 | |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 313 | elif event['type'] in ['info', 'debug']: |
screamer | 0:66f3b5499f7f | 314 | msg = event['message'] |
screamer | 13:ab47a20b66f0 | 315 | |
screamer | 0:66f3b5499f7f | 316 | elif event['type'] == 'cc': |
screamer | 0:66f3b5499f7f | 317 | event['severity'] = event['severity'].title() |
screamer | 0:66f3b5499f7f | 318 | event['file'] = basename(event['file']) |
screamer | 0:66f3b5499f7f | 319 | msg = '[%(severity)s] %(file)s@%(line)s: %(message)s' % event |
screamer | 0:66f3b5499f7f | 320 | |
screamer | 0:66f3b5499f7f | 321 | elif event['type'] == 'progress': |
screamer | 0:66f3b5499f7f | 322 | if not silent: |
screamer | 0:66f3b5499f7f | 323 | msg = '%s: %s' % (event['action'].title(), basename(event['file'])) |
screamer | 0:66f3b5499f7f | 324 | |
screamer | 0:66f3b5499f7f | 325 | if msg: |
screamer | 0:66f3b5499f7f | 326 | print msg |
screamer | 0:66f3b5499f7f | 327 | self.output += msg + "\n" |
screamer | 0:66f3b5499f7f | 328 | |
screamer | 0:66f3b5499f7f | 329 | def print_notify_verbose(self, event, silent=False): |
screamer | 0:66f3b5499f7f | 330 | """ Default command line notification with more verbose mode |
screamer | 0:66f3b5499f7f | 331 | """ |
screamer | 0:66f3b5499f7f | 332 | if event['type'] in ['info', 'debug']: |
screamer | 0:66f3b5499f7f | 333 | self.print_notify(event) # standard handle |
screamer | 0:66f3b5499f7f | 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 | 0:66f3b5499f7f | 338 | event['mcu_name'] = "None" |
screamer | 0:66f3b5499f7f | 339 | event['toolchain'] = "None" |
screamer | 0:66f3b5499f7f | 340 | event['target_name'] = event['target_name'].upper() if event['target_name'] else "Unknown" |
screamer | 0:66f3b5499f7f | 341 | event['toolchain_name'] = event['toolchain_name'].upper() if event['toolchain_name'] else "Unknown" |
screamer | 0:66f3b5499f7f | 342 | msg = '[%(severity)s] %(target_name)s::%(toolchain_name)s::%(file)s@%(line)s: %(message)s' % event |
screamer | 0:66f3b5499f7f | 343 | print msg |
screamer | 0:66f3b5499f7f | 344 | self.output += msg + "\n" |
screamer | 0:66f3b5499f7f | 345 | |
screamer | 0:66f3b5499f7f | 346 | elif event['type'] == 'progress': |
screamer | 0:66f3b5499f7f | 347 | self.print_notify(event) # standard handle |
screamer | 0:66f3b5499f7f | 348 | |
screamer | 0:66f3b5499f7f | 349 | def notify(self, event): |
screamer | 0:66f3b5499f7f | 350 | """ Little closure for notify functions |
screamer | 0:66f3b5499f7f | 351 | """ |
screamer | 0:66f3b5499f7f | 352 | return self.notify_fun(event, self.silent) |
screamer | 0:66f3b5499f7f | 353 | |
screamer | 0:66f3b5499f7f | 354 | def goanna_parse_line(self, line): |
screamer | 0:66f3b5499f7f | 355 | if "analyze" in self.options: |
screamer | 0:66f3b5499f7f | 356 | return self.GOANNA_DIAGNOSTIC_PATTERN.match(line) |
screamer | 0:66f3b5499f7f | 357 | else: |
screamer | 0:66f3b5499f7f | 358 | return None |
screamer | 0:66f3b5499f7f | 359 | |
screamer | 0:66f3b5499f7f | 360 | def get_symbols(self): |
screamer | 0:66f3b5499f7f | 361 | if self.symbols is None: |
screamer | 0:66f3b5499f7f | 362 | # Target and Toolchain symbols |
screamer | 0:66f3b5499f7f | 363 | labels = self.get_labels() |
screamer | 0:66f3b5499f7f | 364 | self.symbols = ["TARGET_%s" % t for t in labels['TARGET']] |
screamer | 0:66f3b5499f7f | 365 | self.symbols.extend(["TOOLCHAIN_%s" % t for t in labels['TOOLCHAIN']]) |
screamer | 0:66f3b5499f7f | 366 | |
screamer | 0:66f3b5499f7f | 367 | # Cortex CPU symbols |
screamer | 0:66f3b5499f7f | 368 | if self.target.core in mbedToolchain.CORTEX_SYMBOLS: |
screamer | 0:66f3b5499f7f | 369 | self.symbols.extend(mbedToolchain.CORTEX_SYMBOLS[self.target.core]) |
screamer | 0:66f3b5499f7f | 370 | |
screamer | 0:66f3b5499f7f | 371 | # Symbols defined by the on-line build.system |
screamer | 0:66f3b5499f7f | 372 | self.symbols.extend(['MBED_BUILD_TIMESTAMP=%s' % self.timestamp, 'TARGET_LIKE_MBED', '__MBED__=1']) |
screamer | 0:66f3b5499f7f | 373 | if MBED_ORG_USER: |
screamer | 0:66f3b5499f7f | 374 | self.symbols.append('MBED_USERNAME=' + MBED_ORG_USER) |
screamer | 0:66f3b5499f7f | 375 | |
screamer | 0:66f3b5499f7f | 376 | # Add target's symbols |
screamer | 0:66f3b5499f7f | 377 | self.symbols += self.target.macros |
screamer | 7:5af61d55adbe | 378 | # Add target's hardware |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 379 | self.symbols += ["DEVICE_" + data + "=1" for data in self.target.device_has] |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 380 | # Add target's features |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 381 | self.symbols += ["FEATURE_" + data + "=1" for data in self.target.features] |
screamer | 0:66f3b5499f7f | 382 | # Add extra symbols passed via 'macros' parameter |
screamer | 0:66f3b5499f7f | 383 | self.symbols += self.macros |
screamer | 0:66f3b5499f7f | 384 | |
screamer | 0:66f3b5499f7f | 385 | # Form factor variables |
screamer | 0:66f3b5499f7f | 386 | if hasattr(self.target, 'supported_form_factors'): |
screamer | 0:66f3b5499f7f | 387 | self.symbols.extend(["TARGET_FF_%s" % t for t in self.target.supported_form_factors]) |
screamer | 0:66f3b5499f7f | 388 | |
screamer | 0:66f3b5499f7f | 389 | return list(set(self.symbols)) # Return only unique symbols |
screamer | 0:66f3b5499f7f | 390 | |
screamer | 7:5af61d55adbe | 391 | # Extend the internal list of macros |
screamer | 7:5af61d55adbe | 392 | def add_macros(self, new_macros): |
screamer | 7:5af61d55adbe | 393 | self.macros.extend(new_macros) |
screamer | 7:5af61d55adbe | 394 | |
screamer | 0:66f3b5499f7f | 395 | def get_labels(self): |
screamer | 0:66f3b5499f7f | 396 | if self.labels is None: |
screamer | 0:66f3b5499f7f | 397 | toolchain_labels = [c.__name__ for c in getmro(self.__class__)] |
screamer | 0:66f3b5499f7f | 398 | toolchain_labels.remove('mbedToolchain') |
screamer | 0:66f3b5499f7f | 399 | self.labels = { |
screamer | 0:66f3b5499f7f | 400 | 'TARGET': self.target.get_labels() + ["DEBUG" if "debug-info" in self.options else "RELEASE"], |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 401 | 'FEATURE': self.target.features, |
screamer | 0:66f3b5499f7f | 402 | 'TOOLCHAIN': toolchain_labels |
screamer | 0:66f3b5499f7f | 403 | } |
screamer | 0:66f3b5499f7f | 404 | return self.labels |
screamer | 0:66f3b5499f7f | 405 | |
screamer | 0:66f3b5499f7f | 406 | def need_update(self, target, dependencies): |
screamer | 0:66f3b5499f7f | 407 | if self.build_all: |
screamer | 0:66f3b5499f7f | 408 | return True |
screamer | 0:66f3b5499f7f | 409 | |
screamer | 0:66f3b5499f7f | 410 | if not exists(target): |
screamer | 0:66f3b5499f7f | 411 | return True |
screamer | 0:66f3b5499f7f | 412 | |
screamer | 0:66f3b5499f7f | 413 | target_mod_time = stat(target).st_mtime |
screamer | 0:66f3b5499f7f | 414 | |
screamer | 0:66f3b5499f7f | 415 | for d in dependencies: |
screamer | 0:66f3b5499f7f | 416 | |
screamer | 0:66f3b5499f7f | 417 | # Some objects are not provided with full path and here we do not have |
screamer | 0:66f3b5499f7f | 418 | # information about the library paths. Safe option: assume an update |
screamer | 0:66f3b5499f7f | 419 | if not d or not exists(d): |
screamer | 0:66f3b5499f7f | 420 | return True |
screamer | 0:66f3b5499f7f | 421 | |
screamer | 0:66f3b5499f7f | 422 | if stat(d).st_mtime >= target_mod_time: |
screamer | 0:66f3b5499f7f | 423 | return True |
screamer | 0:66f3b5499f7f | 424 | |
screamer | 0:66f3b5499f7f | 425 | return False |
screamer | 0:66f3b5499f7f | 426 | |
screamer | 7:5af61d55adbe | 427 | def is_ignored(self, file_path): |
screamer | 13:ab47a20b66f0 | 428 | for pattern in self.ignore_patterns: |
screamer | 7:5af61d55adbe | 429 | if fnmatch.fnmatch(file_path, pattern): |
screamer | 7:5af61d55adbe | 430 | return True |
screamer | 7:5af61d55adbe | 431 | return False |
screamer | 7:5af61d55adbe | 432 | |
screamer | 13:ab47a20b66f0 | 433 | # Create a Resources object from the path pointed to by *path* by either traversing a |
screamer | 13:ab47a20b66f0 | 434 | # a directory structure, when *path* is a directory, or adding *path* to the resources, |
screamer | 13:ab47a20b66f0 | 435 | # when *path* is a file. |
screamer | 13:ab47a20b66f0 | 436 | # The parameter *base_path* is used to set the base_path attribute of the Resources |
screamer | 13:ab47a20b66f0 | 437 | # object and the parameter *exclude_paths* is used by the directory traversal to |
screamer | 13:ab47a20b66f0 | 438 | # exclude certain paths from the traversal. |
screamer | 13:ab47a20b66f0 | 439 | def scan_resources(self, path, exclude_paths=None, base_path=None): |
screamer | 0:66f3b5499f7f | 440 | resources = Resources(path) |
screamer | 13:ab47a20b66f0 | 441 | if not base_path: |
screamer | 13:ab47a20b66f0 | 442 | if isfile(path): |
screamer | 13:ab47a20b66f0 | 443 | base_path = dirname(path) |
screamer | 13:ab47a20b66f0 | 444 | else: |
screamer | 13:ab47a20b66f0 | 445 | base_path = path |
screamer | 13:ab47a20b66f0 | 446 | resources.base_path = base_path |
screamer | 0:66f3b5499f7f | 447 | |
screamer | 13:ab47a20b66f0 | 448 | if isfile(path): |
screamer | 13:ab47a20b66f0 | 449 | self._add_file(path, resources, base_path, exclude_paths=exclude_paths) |
screamer | 13:ab47a20b66f0 | 450 | else: |
screamer | 13:ab47a20b66f0 | 451 | self._add_dir(path, resources, base_path, exclude_paths=exclude_paths) |
screamer | 13:ab47a20b66f0 | 452 | return resources |
screamer | 13:ab47a20b66f0 | 453 | |
screamer | 13:ab47a20b66f0 | 454 | # A helper function for scan_resources. _add_dir traverses *path* (assumed to be a |
screamer | 13:ab47a20b66f0 | 455 | # directory) and heeds the ".mbedignore" files along the way. _add_dir calls _add_file |
screamer | 13:ab47a20b66f0 | 456 | # on every file it considers adding to the resources object. |
screamer | 13:ab47a20b66f0 | 457 | def _add_dir(self, path, resources, base_path, exclude_paths=None): |
screamer | 0:66f3b5499f7f | 458 | """ os.walk(top[, topdown=True[, onerror=None[, followlinks=False]]]) |
screamer | 0:66f3b5499f7f | 459 | When topdown is True, the caller can modify the dirnames list in-place |
screamer | 0:66f3b5499f7f | 460 | (perhaps using del or slice assignment), and walk() will only recurse into |
screamer | 0:66f3b5499f7f | 461 | the subdirectories whose names remain in dirnames; this can be used to prune |
screamer | 0:66f3b5499f7f | 462 | the search, impose a specific order of visiting, or even to inform walk() |
screamer | 0:66f3b5499f7f | 463 | about directories the caller creates or renames before it resumes walk() |
screamer | 0:66f3b5499f7f | 464 | again. Modifying dirnames when topdown is False is ineffective, because in |
screamer | 0:66f3b5499f7f | 465 | bottom-up mode the directories in dirnames are generated before dirpath |
screamer | 0:66f3b5499f7f | 466 | itself is generated. |
screamer | 0:66f3b5499f7f | 467 | """ |
screamer | 13:ab47a20b66f0 | 468 | labels = self.get_labels() |
screamer | 0:66f3b5499f7f | 469 | for root, dirs, files in walk(path, followlinks=True): |
screamer | 7:5af61d55adbe | 470 | # Check if folder contains .mbedignore |
screamer | 13:ab47a20b66f0 | 471 | if ".mbedignore" in files: |
screamer | 7:5af61d55adbe | 472 | with open (join(root,".mbedignore"), "r") as f: |
screamer | 7:5af61d55adbe | 473 | lines=f.readlines() |
screamer | 7:5af61d55adbe | 474 | lines = [l.strip() for l in lines] # Strip whitespaces |
screamer | 7:5af61d55adbe | 475 | lines = [l for l in lines if l != ""] # Strip empty lines |
screamer | 7:5af61d55adbe | 476 | lines = [l for l in lines if not re.match("^#",l)] # Strip comment lines |
screamer | 13:ab47a20b66f0 | 477 | # Append root path to glob patterns and append patterns to ignore_patterns |
screamer | 13:ab47a20b66f0 | 478 | self.ignore_patterns.extend([join(root,line.strip()) for line in lines]) |
screamer | 13:ab47a20b66f0 | 479 | |
screamer | 13:ab47a20b66f0 | 480 | # Skip the whole folder if ignored, e.g. .mbedignore containing '*' |
screamer | 13:ab47a20b66f0 | 481 | if self.is_ignored(join(root,"")): |
screamer | 13:ab47a20b66f0 | 482 | continue |
screamer | 7:5af61d55adbe | 483 | |
screamer | 0:66f3b5499f7f | 484 | for d in copy(dirs): |
screamer | 0:66f3b5499f7f | 485 | dir_path = join(root, d) |
screamer | 13:ab47a20b66f0 | 486 | # Add internal repo folders/files. This is needed for exporters |
screamer | 0:66f3b5499f7f | 487 | if d == '.hg': |
screamer | 0:66f3b5499f7f | 488 | resources.repo_dirs.append(dir_path) |
screamer | 0:66f3b5499f7f | 489 | resources.repo_files.extend(self.scan_repository(dir_path)) |
screamer | 0:66f3b5499f7f | 490 | |
screamer | 0:66f3b5499f7f | 491 | if ((d.startswith('.') or d in self.legacy_ignore_dirs) or |
screamer | 13:ab47a20b66f0 | 492 | # Ignore targets that do not match the TARGET in extra_labels list |
screamer | 7:5af61d55adbe | 493 | (d.startswith('TARGET_') and d[7:] not in labels['TARGET']) or |
screamer | 13:ab47a20b66f0 | 494 | # Ignore toolchain that do not match the current TOOLCHAIN |
screamer | 7:5af61d55adbe | 495 | (d.startswith('TOOLCHAIN_') and d[10:] not in labels['TOOLCHAIN']) or |
screamer | 13:ab47a20b66f0 | 496 | # Ignore .mbedignore files |
screamer | 13:ab47a20b66f0 | 497 | self.is_ignored(join(dir_path,"")) or |
screamer | 13:ab47a20b66f0 | 498 | # Ignore TESTS dir |
screamer | 7:5af61d55adbe | 499 | (d == 'TESTS')): |
screamer | 13:ab47a20b66f0 | 500 | dirs.remove(d) |
screamer | 13:ab47a20b66f0 | 501 | elif d.startswith('FEATURE_'): |
screamer | 13:ab47a20b66f0 | 502 | # Recursively scan features but ignore them in the current scan. |
screamer | 13:ab47a20b66f0 | 503 | # These are dynamically added by the config system if the conditions are matched |
screamer | 13:ab47a20b66f0 | 504 | resources.features[d[8:]] = self.scan_resources(dir_path, base_path=base_path) |
screamer | 0:66f3b5499f7f | 505 | dirs.remove(d) |
screamer | 13:ab47a20b66f0 | 506 | elif exclude_paths: |
screamer | 0:66f3b5499f7f | 507 | for exclude_path in exclude_paths: |
screamer | 0:66f3b5499f7f | 508 | rel_path = relpath(dir_path, exclude_path) |
screamer | 0:66f3b5499f7f | 509 | if not (rel_path.startswith('..')): |
screamer | 0:66f3b5499f7f | 510 | dirs.remove(d) |
screamer | 0:66f3b5499f7f | 511 | break |
screamer | 0:66f3b5499f7f | 512 | |
screamer | 0:66f3b5499f7f | 513 | # Add root to include paths |
screamer | 0:66f3b5499f7f | 514 | resources.inc_dirs.append(root) |
screamer | 0:66f3b5499f7f | 515 | |
screamer | 0:66f3b5499f7f | 516 | for file in files: |
screamer | 0:66f3b5499f7f | 517 | file_path = join(root, file) |
screamer | 13:ab47a20b66f0 | 518 | self._add_file(file_path, resources, base_path) |
screamer | 7:5af61d55adbe | 519 | |
screamer | 13:ab47a20b66f0 | 520 | # A helper function for both scan_resources and _add_dir. _add_file adds one file |
screamer | 13:ab47a20b66f0 | 521 | # (*file_path*) to the resources object based on the file type. |
screamer | 13:ab47a20b66f0 | 522 | def _add_file(self, file_path, resources, base_path, exclude_paths=None): |
screamer | 13:ab47a20b66f0 | 523 | resources.file_basepath[file_path] = base_path |
screamer | 0:66f3b5499f7f | 524 | |
screamer | 13:ab47a20b66f0 | 525 | if self.is_ignored(file_path): |
screamer | 13:ab47a20b66f0 | 526 | return |
screamer | 13:ab47a20b66f0 | 527 | |
screamer | 13:ab47a20b66f0 | 528 | _, ext = splitext(file_path) |
screamer | 13:ab47a20b66f0 | 529 | ext = ext.lower() |
screamer | 0:66f3b5499f7f | 530 | |
screamer | 13:ab47a20b66f0 | 531 | if ext == '.s': |
screamer | 13:ab47a20b66f0 | 532 | resources.s_sources.append(file_path) |
screamer | 0:66f3b5499f7f | 533 | |
screamer | 13:ab47a20b66f0 | 534 | elif ext == '.c': |
screamer | 13:ab47a20b66f0 | 535 | resources.c_sources.append(file_path) |
screamer | 0:66f3b5499f7f | 536 | |
screamer | 13:ab47a20b66f0 | 537 | elif ext == '.cpp': |
screamer | 13:ab47a20b66f0 | 538 | resources.cpp_sources.append(file_path) |
screamer | 0:66f3b5499f7f | 539 | |
screamer | 13:ab47a20b66f0 | 540 | elif ext == '.h' or ext == '.hpp': |
screamer | 13:ab47a20b66f0 | 541 | resources.headers.append(file_path) |
screamer | 13:ab47a20b66f0 | 542 | |
screamer | 13:ab47a20b66f0 | 543 | elif ext == '.o': |
screamer | 13:ab47a20b66f0 | 544 | resources.objects.append(file_path) |
screamer | 0:66f3b5499f7f | 545 | |
screamer | 13:ab47a20b66f0 | 546 | elif ext == self.LIBRARY_EXT: |
screamer | 13:ab47a20b66f0 | 547 | resources.libraries.append(file_path) |
screamer | 13:ab47a20b66f0 | 548 | resources.lib_dirs.add(dirname(file_path)) |
screamer | 0:66f3b5499f7f | 549 | |
screamer | 13:ab47a20b66f0 | 550 | elif ext == self.LINKER_EXT: |
screamer | 13:ab47a20b66f0 | 551 | if resources.linker_script is not None: |
screamer | 13:ab47a20b66f0 | 552 | self.info("Warning: Multiple linker scripts detected: %s -> %s" % (resources.linker_script, file_path)) |
screamer | 13:ab47a20b66f0 | 553 | resources.linker_script = file_path |
screamer | 0:66f3b5499f7f | 554 | |
screamer | 13:ab47a20b66f0 | 555 | elif ext == '.lib': |
screamer | 13:ab47a20b66f0 | 556 | resources.lib_refs.append(file_path) |
screamer | 0:66f3b5499f7f | 557 | |
screamer | 13:ab47a20b66f0 | 558 | elif ext == '.bld': |
screamer | 13:ab47a20b66f0 | 559 | resources.lib_builds.append(file_path) |
screamer | 0:66f3b5499f7f | 560 | |
screamer | 13:ab47a20b66f0 | 561 | elif file == '.hgignore': |
screamer | 13:ab47a20b66f0 | 562 | resources.repo_files.append(file_path) |
screamer | 0:66f3b5499f7f | 563 | |
screamer | 13:ab47a20b66f0 | 564 | elif ext == '.hex': |
screamer | 13:ab47a20b66f0 | 565 | resources.hex_files.append(file_path) |
screamer | 0:66f3b5499f7f | 566 | |
screamer | 13:ab47a20b66f0 | 567 | elif ext == '.bin': |
screamer | 13:ab47a20b66f0 | 568 | resources.bin_files.append(file_path) |
screamer | 0:66f3b5499f7f | 569 | |
screamer | 13:ab47a20b66f0 | 570 | elif ext == '.json': |
screamer | 13:ab47a20b66f0 | 571 | resources.json_files.append(file_path) |
screamer | 7:5af61d55adbe | 572 | |
screamer | 0:66f3b5499f7f | 573 | |
screamer | 0:66f3b5499f7f | 574 | def scan_repository(self, path): |
screamer | 0:66f3b5499f7f | 575 | resources = [] |
screamer | 0:66f3b5499f7f | 576 | |
screamer | 0:66f3b5499f7f | 577 | for root, dirs, files in walk(path): |
screamer | 0:66f3b5499f7f | 578 | # Remove ignored directories |
screamer | 0:66f3b5499f7f | 579 | for d in copy(dirs): |
screamer | 0:66f3b5499f7f | 580 | if d == '.' or d == '..': |
screamer | 0:66f3b5499f7f | 581 | dirs.remove(d) |
screamer | 0:66f3b5499f7f | 582 | |
screamer | 0:66f3b5499f7f | 583 | for file in files: |
screamer | 0:66f3b5499f7f | 584 | file_path = join(root, file) |
screamer | 0:66f3b5499f7f | 585 | resources.append(file_path) |
screamer | 0:66f3b5499f7f | 586 | |
screamer | 0:66f3b5499f7f | 587 | return resources |
screamer | 0:66f3b5499f7f | 588 | |
screamer | 13:ab47a20b66f0 | 589 | def copy_files(self, files_paths, trg_path, resources=None, rel_path=None): |
screamer | 0:66f3b5499f7f | 590 | |
screamer | 0:66f3b5499f7f | 591 | # Handle a single file |
screamer | 0:66f3b5499f7f | 592 | if type(files_paths) != ListType: files_paths = [files_paths] |
screamer | 0:66f3b5499f7f | 593 | |
screamer | 0:66f3b5499f7f | 594 | for source in files_paths: |
screamer | 0:66f3b5499f7f | 595 | if source is None: |
screamer | 0:66f3b5499f7f | 596 | files_paths.remove(source) |
screamer | 0:66f3b5499f7f | 597 | |
screamer | 0:66f3b5499f7f | 598 | for source in files_paths: |
screamer | 13:ab47a20b66f0 | 599 | if resources is not None and resources.file_basepath.has_key(source): |
screamer | 13:ab47a20b66f0 | 600 | relative_path = relpath(source, resources.file_basepath[source]) |
screamer | 13:ab47a20b66f0 | 601 | elif rel_path is not None: |
screamer | 0:66f3b5499f7f | 602 | relative_path = relpath(source, rel_path) |
screamer | 0:66f3b5499f7f | 603 | else: |
screamer | 0:66f3b5499f7f | 604 | _, relative_path = split(source) |
screamer | 0:66f3b5499f7f | 605 | |
screamer | 0:66f3b5499f7f | 606 | target = join(trg_path, relative_path) |
screamer | 0:66f3b5499f7f | 607 | |
screamer | 0:66f3b5499f7f | 608 | if (target != source) and (self.need_update(target, [source])): |
screamer | 0:66f3b5499f7f | 609 | self.progress("copy", relative_path) |
screamer | 0:66f3b5499f7f | 610 | mkdir(dirname(target)) |
screamer | 0:66f3b5499f7f | 611 | copyfile(source, target) |
screamer | 0:66f3b5499f7f | 612 | |
screamer | 0:66f3b5499f7f | 613 | def relative_object_path(self, build_path, base_dir, source): |
screamer | 0:66f3b5499f7f | 614 | source_dir, name, _ = split_path(source) |
screamer | 0:66f3b5499f7f | 615 | |
screamer | 0:66f3b5499f7f | 616 | obj_dir = join(build_path, relpath(source_dir, base_dir)) |
screamer | 0:66f3b5499f7f | 617 | mkdir(obj_dir) |
screamer | 0:66f3b5499f7f | 618 | return join(obj_dir, name + '.o') |
screamer | 0:66f3b5499f7f | 619 | |
screamer | 0:66f3b5499f7f | 620 | def get_inc_file(self, includes): |
screamer | 0:66f3b5499f7f | 621 | include_file = join(self.build_dir, ".includes_%s.txt" % self.inc_md5) |
screamer | 0:66f3b5499f7f | 622 | if not exists(include_file): |
screamer | 0:66f3b5499f7f | 623 | with open(include_file, "wb") as f: |
screamer | 0:66f3b5499f7f | 624 | cmd_list = [] |
screamer | 0:66f3b5499f7f | 625 | for c in includes: |
screamer | 0:66f3b5499f7f | 626 | if c: |
screamer | 0:66f3b5499f7f | 627 | cmd_list.append(('-I%s' % c).replace("\\", "/")) |
screamer | 0:66f3b5499f7f | 628 | string = " ".join(cmd_list) |
screamer | 0:66f3b5499f7f | 629 | f.write(string) |
screamer | 0:66f3b5499f7f | 630 | return include_file |
screamer | 0:66f3b5499f7f | 631 | |
screamer | 0:66f3b5499f7f | 632 | def compile_sources(self, resources, build_path, inc_dirs=None): |
screamer | 0:66f3b5499f7f | 633 | # Web IDE progress bar for project build |
screamer | 0:66f3b5499f7f | 634 | files_to_compile = resources.s_sources + resources.c_sources + resources.cpp_sources |
screamer | 0:66f3b5499f7f | 635 | self.to_be_compiled = len(files_to_compile) |
screamer | 0:66f3b5499f7f | 636 | self.compiled = 0 |
screamer | 0:66f3b5499f7f | 637 | |
screamer | 0:66f3b5499f7f | 638 | inc_paths = resources.inc_dirs |
screamer | 0:66f3b5499f7f | 639 | if inc_dirs is not None: |
screamer | 0:66f3b5499f7f | 640 | inc_paths.extend(inc_dirs) |
screamer | 0:66f3b5499f7f | 641 | # De-duplicate include paths |
screamer | 0:66f3b5499f7f | 642 | inc_paths = set(inc_paths) |
screamer | 0:66f3b5499f7f | 643 | # Sort include paths for consistency |
screamer | 0:66f3b5499f7f | 644 | inc_paths = sorted(set(inc_paths)) |
screamer | 0:66f3b5499f7f | 645 | # Unique id of all include paths |
screamer | 0:66f3b5499f7f | 646 | self.inc_md5 = md5(' '.join(inc_paths)).hexdigest() |
screamer | 0:66f3b5499f7f | 647 | # Where to store response files |
screamer | 0:66f3b5499f7f | 648 | self.build_dir = build_path |
screamer | 0:66f3b5499f7f | 649 | |
screamer | 0:66f3b5499f7f | 650 | objects = [] |
screamer | 0:66f3b5499f7f | 651 | queue = [] |
screamer | 0:66f3b5499f7f | 652 | prev_dir = None |
screamer | 0:66f3b5499f7f | 653 | |
screamer | 0:66f3b5499f7f | 654 | # Sort compile queue for consistency |
screamer | 0:66f3b5499f7f | 655 | files_to_compile.sort() |
screamer | 0:66f3b5499f7f | 656 | work_dir = getcwd() |
screamer | 0:66f3b5499f7f | 657 | |
screamer | 0:66f3b5499f7f | 658 | for source in files_to_compile: |
screamer | 0:66f3b5499f7f | 659 | _, name, _ = split_path(source) |
screamer | 13:ab47a20b66f0 | 660 | object = self.relative_object_path(build_path, resources.file_basepath[source], source) |
screamer | 0:66f3b5499f7f | 661 | |
screamer | 0:66f3b5499f7f | 662 | # Queue mode (multiprocessing) |
screamer | 0:66f3b5499f7f | 663 | commands = self.compile_command(source, object, inc_paths) |
screamer | 0:66f3b5499f7f | 664 | if commands is not None: |
screamer | 0:66f3b5499f7f | 665 | queue.append({ |
screamer | 0:66f3b5499f7f | 666 | 'source': source, |
screamer | 0:66f3b5499f7f | 667 | 'object': object, |
screamer | 0:66f3b5499f7f | 668 | 'commands': commands, |
screamer | 0:66f3b5499f7f | 669 | 'work_dir': work_dir, |
screamer | 0:66f3b5499f7f | 670 | 'chroot': self.CHROOT |
screamer | 0:66f3b5499f7f | 671 | }) |
screamer | 0:66f3b5499f7f | 672 | else: |
screamer | 0:66f3b5499f7f | 673 | objects.append(object) |
screamer | 0:66f3b5499f7f | 674 | |
screamer | 0:66f3b5499f7f | 675 | # Use queues/multiprocessing if cpu count is higher than setting |
screamer | 0:66f3b5499f7f | 676 | jobs = self.jobs if self.jobs else cpu_count() |
screamer | 0:66f3b5499f7f | 677 | if jobs > CPU_COUNT_MIN and len(queue) > jobs: |
screamer | 0:66f3b5499f7f | 678 | return self.compile_queue(queue, objects) |
screamer | 0:66f3b5499f7f | 679 | else: |
screamer | 0:66f3b5499f7f | 680 | return self.compile_seq(queue, objects) |
screamer | 0:66f3b5499f7f | 681 | |
screamer | 0:66f3b5499f7f | 682 | def compile_seq(self, queue, objects): |
screamer | 0:66f3b5499f7f | 683 | for item in queue: |
screamer | 0:66f3b5499f7f | 684 | result = compile_worker(item) |
screamer | 0:66f3b5499f7f | 685 | |
screamer | 0:66f3b5499f7f | 686 | self.compiled += 1 |
screamer | 0:66f3b5499f7f | 687 | self.progress("compile", item['source'], build_update=True) |
screamer | 0:66f3b5499f7f | 688 | for res in result['results']: |
screamer | 0:66f3b5499f7f | 689 | self.debug("Command: %s" % ' '.join(res['command'])) |
screamer | 0:66f3b5499f7f | 690 | self.compile_output([ |
screamer | 0:66f3b5499f7f | 691 | res['code'], |
screamer | 0:66f3b5499f7f | 692 | res['output'], |
screamer | 0:66f3b5499f7f | 693 | res['command'] |
screamer | 0:66f3b5499f7f | 694 | ]) |
screamer | 0:66f3b5499f7f | 695 | objects.append(result['object']) |
screamer | 0:66f3b5499f7f | 696 | return objects |
screamer | 0:66f3b5499f7f | 697 | |
screamer | 0:66f3b5499f7f | 698 | def compile_queue(self, queue, objects): |
screamer | 0:66f3b5499f7f | 699 | jobs_count = int(self.jobs if self.jobs else cpu_count()) |
screamer | 0:66f3b5499f7f | 700 | p = Pool(processes=jobs_count) |
screamer | 0:66f3b5499f7f | 701 | |
screamer | 0:66f3b5499f7f | 702 | results = [] |
screamer | 0:66f3b5499f7f | 703 | for i in range(len(queue)): |
screamer | 0:66f3b5499f7f | 704 | results.append(p.apply_async(compile_worker, [queue[i]])) |
screamer | 0:66f3b5499f7f | 705 | |
screamer | 0:66f3b5499f7f | 706 | itr = 0 |
screamer | 0:66f3b5499f7f | 707 | while True: |
screamer | 0:66f3b5499f7f | 708 | itr += 1 |
screamer | 0:66f3b5499f7f | 709 | if itr > 180000: |
screamer | 0:66f3b5499f7f | 710 | p.terminate() |
screamer | 0:66f3b5499f7f | 711 | p.join() |
screamer | 0:66f3b5499f7f | 712 | raise ToolException("Compile did not finish in 5 minutes") |
screamer | 0:66f3b5499f7f | 713 | |
screamer | 0:66f3b5499f7f | 714 | pending = 0 |
screamer | 0:66f3b5499f7f | 715 | for r in results: |
screamer | 0:66f3b5499f7f | 716 | if r._ready is True: |
screamer | 0:66f3b5499f7f | 717 | try: |
screamer | 0:66f3b5499f7f | 718 | result = r.get() |
screamer | 0:66f3b5499f7f | 719 | results.remove(r) |
screamer | 0:66f3b5499f7f | 720 | |
screamer | 0:66f3b5499f7f | 721 | self.compiled += 1 |
screamer | 0:66f3b5499f7f | 722 | self.progress("compile", result['source'], build_update=True) |
screamer | 0:66f3b5499f7f | 723 | for res in result['results']: |
screamer | 0:66f3b5499f7f | 724 | self.debug("Command: %s" % ' '.join(res['command'])) |
screamer | 0:66f3b5499f7f | 725 | self.compile_output([ |
screamer | 0:66f3b5499f7f | 726 | res['code'], |
screamer | 0:66f3b5499f7f | 727 | res['output'], |
screamer | 0:66f3b5499f7f | 728 | res['command'] |
screamer | 0:66f3b5499f7f | 729 | ]) |
screamer | 0:66f3b5499f7f | 730 | objects.append(result['object']) |
screamer | 0:66f3b5499f7f | 731 | except ToolException, err: |
screamer | 0:66f3b5499f7f | 732 | p.terminate() |
screamer | 0:66f3b5499f7f | 733 | p.join() |
screamer | 0:66f3b5499f7f | 734 | raise ToolException(err) |
screamer | 0:66f3b5499f7f | 735 | else: |
screamer | 0:66f3b5499f7f | 736 | pending += 1 |
screamer | 0:66f3b5499f7f | 737 | if pending > jobs_count: |
screamer | 0:66f3b5499f7f | 738 | break |
screamer | 0:66f3b5499f7f | 739 | |
screamer | 0:66f3b5499f7f | 740 | |
screamer | 0:66f3b5499f7f | 741 | if len(results) == 0: |
screamer | 0:66f3b5499f7f | 742 | break |
screamer | 0:66f3b5499f7f | 743 | |
screamer | 0:66f3b5499f7f | 744 | sleep(0.01) |
screamer | 0:66f3b5499f7f | 745 | |
screamer | 0:66f3b5499f7f | 746 | results = None |
screamer | 0:66f3b5499f7f | 747 | p.terminate() |
screamer | 0:66f3b5499f7f | 748 | p.join() |
screamer | 0:66f3b5499f7f | 749 | |
screamer | 0:66f3b5499f7f | 750 | return objects |
screamer | 0:66f3b5499f7f | 751 | |
screamer | 0:66f3b5499f7f | 752 | def compile_command(self, source, object, includes): |
screamer | 0:66f3b5499f7f | 753 | # Check dependencies |
screamer | 0:66f3b5499f7f | 754 | _, ext = splitext(source) |
screamer | 0:66f3b5499f7f | 755 | ext = ext.lower() |
screamer | 0:66f3b5499f7f | 756 | |
screamer | 0:66f3b5499f7f | 757 | if ext == '.c' or ext == '.cpp': |
screamer | 0:66f3b5499f7f | 758 | base, _ = splitext(object) |
screamer | 0:66f3b5499f7f | 759 | dep_path = base + '.d' |
screamer | 0:66f3b5499f7f | 760 | deps = self.parse_dependencies(dep_path) if (exists(dep_path)) else [] |
screamer | 0:66f3b5499f7f | 761 | if len(deps) == 0 or self.need_update(object, deps): |
screamer | 0:66f3b5499f7f | 762 | if ext == '.c': |
screamer | 0:66f3b5499f7f | 763 | return self.compile_c(source, object, includes) |
screamer | 0:66f3b5499f7f | 764 | else: |
screamer | 0:66f3b5499f7f | 765 | return self.compile_cpp(source, object, includes) |
screamer | 0:66f3b5499f7f | 766 | elif ext == '.s': |
screamer | 0:66f3b5499f7f | 767 | deps = [source] |
screamer | 0:66f3b5499f7f | 768 | if self.need_update(object, deps): |
screamer | 0:66f3b5499f7f | 769 | return self.assemble(source, object, includes) |
screamer | 0:66f3b5499f7f | 770 | else: |
screamer | 0:66f3b5499f7f | 771 | return False |
screamer | 0:66f3b5499f7f | 772 | |
screamer | 0:66f3b5499f7f | 773 | return None |
screamer | 0:66f3b5499f7f | 774 | |
screamer | 0:66f3b5499f7f | 775 | def is_not_supported_error(self, output): |
screamer | 0:66f3b5499f7f | 776 | return "#error directive: [NOT_SUPPORTED]" in output |
screamer | 0:66f3b5499f7f | 777 | |
screamer | 0:66f3b5499f7f | 778 | def compile_output(self, output=[]): |
screamer | 0:66f3b5499f7f | 779 | _rc = output[0] |
screamer | 0:66f3b5499f7f | 780 | _stderr = output[1] |
screamer | 0:66f3b5499f7f | 781 | command = output[2] |
screamer | 0:66f3b5499f7f | 782 | |
screamer | 0:66f3b5499f7f | 783 | # Parse output for Warnings and Errors |
screamer | 0:66f3b5499f7f | 784 | self.parse_output(_stderr) |
screamer | 0:66f3b5499f7f | 785 | self.debug("Return: %s"% _rc) |
screamer | 0:66f3b5499f7f | 786 | for error_line in _stderr.splitlines(): |
screamer | 0:66f3b5499f7f | 787 | self.debug("Output: %s"% error_line) |
screamer | 0:66f3b5499f7f | 788 | |
screamer | 0:66f3b5499f7f | 789 | |
screamer | 0:66f3b5499f7f | 790 | # Check return code |
screamer | 0:66f3b5499f7f | 791 | if _rc != 0: |
screamer | 0:66f3b5499f7f | 792 | for line in _stderr.splitlines(): |
screamer | 0:66f3b5499f7f | 793 | self.tool_error(line) |
screamer | 0:66f3b5499f7f | 794 | |
screamer | 0:66f3b5499f7f | 795 | if self.is_not_supported_error(_stderr): |
screamer | 0:66f3b5499f7f | 796 | raise NotSupportedException(_stderr) |
screamer | 0:66f3b5499f7f | 797 | else: |
screamer | 0:66f3b5499f7f | 798 | raise ToolException(_stderr) |
screamer | 0:66f3b5499f7f | 799 | |
screamer | 0:66f3b5499f7f | 800 | def build_library(self, objects, dir, name): |
screamer | 0:66f3b5499f7f | 801 | needed_update = False |
screamer | 0:66f3b5499f7f | 802 | lib = self.STD_LIB_NAME % name |
screamer | 0:66f3b5499f7f | 803 | fout = join(dir, lib) |
screamer | 0:66f3b5499f7f | 804 | if self.need_update(fout, objects): |
screamer | 0:66f3b5499f7f | 805 | self.info("Library: %s" % lib) |
screamer | 0:66f3b5499f7f | 806 | self.archive(objects, fout) |
screamer | 0:66f3b5499f7f | 807 | needed_update = True |
screamer | 0:66f3b5499f7f | 808 | |
screamer | 0:66f3b5499f7f | 809 | return needed_update |
screamer | 0:66f3b5499f7f | 810 | |
screamer | 0:66f3b5499f7f | 811 | def link_program(self, r, tmp_path, name): |
screamer | 0:66f3b5499f7f | 812 | needed_update = False |
screamer | 0:66f3b5499f7f | 813 | ext = 'bin' |
screamer | 0:66f3b5499f7f | 814 | if hasattr(self.target, 'OUTPUT_EXT'): |
screamer | 0:66f3b5499f7f | 815 | ext = self.target.OUTPUT_EXT |
screamer | 0:66f3b5499f7f | 816 | |
screamer | 0:66f3b5499f7f | 817 | if hasattr(self.target, 'OUTPUT_NAMING'): |
screamer | 0:66f3b5499f7f | 818 | self.var("binary_naming", self.target.OUTPUT_NAMING) |
screamer | 0:66f3b5499f7f | 819 | if self.target.OUTPUT_NAMING == "8.3": |
screamer | 0:66f3b5499f7f | 820 | name = name[0:8] |
screamer | 0:66f3b5499f7f | 821 | ext = ext[0:3] |
screamer | 0:66f3b5499f7f | 822 | |
screamer | 0:66f3b5499f7f | 823 | # Create destination directory |
screamer | 0:66f3b5499f7f | 824 | head, tail = split(name) |
screamer | 0:66f3b5499f7f | 825 | new_path = join(tmp_path, head) |
screamer | 0:66f3b5499f7f | 826 | mkdir(new_path) |
screamer | 0:66f3b5499f7f | 827 | |
screamer | 0:66f3b5499f7f | 828 | filename = name+'.'+ext |
screamer | 0:66f3b5499f7f | 829 | elf = join(tmp_path, name + '.elf') |
screamer | 0:66f3b5499f7f | 830 | bin = join(tmp_path, filename) |
screamer | 7:5af61d55adbe | 831 | map = join(tmp_path, name + '.map') |
screamer | 0:66f3b5499f7f | 832 | |
screamer | 0:66f3b5499f7f | 833 | if self.need_update(elf, r.objects + r.libraries + [r.linker_script]): |
screamer | 0:66f3b5499f7f | 834 | needed_update = True |
screamer | 0:66f3b5499f7f | 835 | self.progress("link", name) |
screamer | 0:66f3b5499f7f | 836 | self.link(elf, r.objects, r.libraries, r.lib_dirs, r.linker_script) |
screamer | 0:66f3b5499f7f | 837 | |
screamer | 0:66f3b5499f7f | 838 | if self.need_update(bin, [elf]): |
screamer | 0:66f3b5499f7f | 839 | needed_update = True |
screamer | 0:66f3b5499f7f | 840 | self.progress("elf2bin", name) |
screamer | 0:66f3b5499f7f | 841 | |
screamer | 0:66f3b5499f7f | 842 | self.binary(r, elf, bin) |
screamer | 0:66f3b5499f7f | 843 | |
screamer | 7:5af61d55adbe | 844 | self.mem_stats(map) |
screamer | 7:5af61d55adbe | 845 | |
screamer | 0:66f3b5499f7f | 846 | self.var("compile_succeded", True) |
screamer | 0:66f3b5499f7f | 847 | self.var("binary", filename) |
screamer | 0:66f3b5499f7f | 848 | |
screamer | 0:66f3b5499f7f | 849 | return bin, needed_update |
screamer | 0:66f3b5499f7f | 850 | |
screamer | 0:66f3b5499f7f | 851 | def default_cmd(self, command): |
screamer | 0:66f3b5499f7f | 852 | self.debug("Command: %s"% ' '.join(command)) |
screamer | 0:66f3b5499f7f | 853 | _stdout, _stderr, _rc = run_cmd(command) |
screamer | 13:ab47a20b66f0 | 854 | |
screamer | 0:66f3b5499f7f | 855 | self.debug("Return: %s"% _rc) |
screamer | 0:66f3b5499f7f | 856 | |
screamer | 0:66f3b5499f7f | 857 | for output_line in _stdout.splitlines(): |
screamer | 0:66f3b5499f7f | 858 | self.debug("Output: %s"% output_line) |
screamer | 0:66f3b5499f7f | 859 | for error_line in _stderr.splitlines(): |
screamer | 0:66f3b5499f7f | 860 | self.debug("Errors: %s"% error_line) |
screamer | 0:66f3b5499f7f | 861 | |
screamer | 0:66f3b5499f7f | 862 | if _rc != 0: |
screamer | 0:66f3b5499f7f | 863 | for line in _stderr.splitlines(): |
screamer | 0:66f3b5499f7f | 864 | self.tool_error(line) |
screamer | 0:66f3b5499f7f | 865 | raise ToolException(_stderr) |
screamer | 0:66f3b5499f7f | 866 | |
screamer | 0:66f3b5499f7f | 867 | ### NOTIFICATIONS ### |
screamer | 0:66f3b5499f7f | 868 | def info(self, message): |
screamer | 0:66f3b5499f7f | 869 | self.notify({'type': 'info', 'message': message}) |
screamer | 0:66f3b5499f7f | 870 | |
screamer | 0:66f3b5499f7f | 871 | def debug(self, message): |
screamer | 0:66f3b5499f7f | 872 | if self.VERBOSE: |
screamer | 0:66f3b5499f7f | 873 | if type(message) is ListType: |
screamer | 0:66f3b5499f7f | 874 | message = ' '.join(message) |
screamer | 0:66f3b5499f7f | 875 | message = "[DEBUG] " + message |
screamer | 0:66f3b5499f7f | 876 | self.notify({'type': 'debug', 'message': message}) |
screamer | 0:66f3b5499f7f | 877 | |
screamer | 0:66f3b5499f7f | 878 | def cc_info(self, severity, file, line, message, target_name=None, toolchain_name=None): |
screamer | 0:66f3b5499f7f | 879 | self.notify({'type': 'cc', |
screamer | 0:66f3b5499f7f | 880 | 'severity': severity, |
screamer | 0:66f3b5499f7f | 881 | 'file': file, |
screamer | 0:66f3b5499f7f | 882 | 'line': line, |
screamer | 0:66f3b5499f7f | 883 | 'message': message, |
screamer | 0:66f3b5499f7f | 884 | 'target_name': target_name, |
screamer | 0:66f3b5499f7f | 885 | 'toolchain_name': toolchain_name}) |
screamer | 0:66f3b5499f7f | 886 | |
screamer | 0:66f3b5499f7f | 887 | def progress(self, action, file, build_update=False): |
screamer | 0:66f3b5499f7f | 888 | msg = {'type': 'progress', 'action': action, 'file': file} |
screamer | 0:66f3b5499f7f | 889 | if build_update: |
screamer | 0:66f3b5499f7f | 890 | msg['percent'] = 100. * float(self.compiled) / float(self.to_be_compiled) |
screamer | 0:66f3b5499f7f | 891 | self.notify(msg) |
screamer | 0:66f3b5499f7f | 892 | |
screamer | 0:66f3b5499f7f | 893 | def tool_error(self, message): |
screamer | 0:66f3b5499f7f | 894 | self.notify({'type': 'tool_error', 'message': message}) |
screamer | 0:66f3b5499f7f | 895 | |
screamer | 0:66f3b5499f7f | 896 | def var(self, key, value): |
screamer | 0:66f3b5499f7f | 897 | self.notify({'type': 'var', 'key': key, 'val': value}) |
screamer | 0:66f3b5499f7f | 898 | |
screamer | 7:5af61d55adbe | 899 | def mem_stats(self, map): |
screamer | 7:5af61d55adbe | 900 | # Creates parser object |
screamer | 7:5af61d55adbe | 901 | toolchain = self.__class__.__name__ |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 902 | |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 903 | # Create memap object |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 904 | memap = MemapParser() |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 905 | |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 906 | # Parse and decode a map file |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 907 | if memap.parse(abspath(map), toolchain) is False: |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 908 | self.info("Unknown toolchain for memory statistics %s" % toolchain) |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 909 | return |
screamer | 7:5af61d55adbe | 910 | |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 911 | # Write output to stdout in text (pretty table) format |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 912 | memap.generate_output('table') |
screamer | 7:5af61d55adbe | 913 | |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 914 | # Write output to file in JSON format |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 915 | map_out = splitext(map)[0] + "_map.json" |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 916 | memap.generate_output('json', map_out) |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 917 | |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 918 | # Write output to file in CSV format for the CI |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 919 | map_csv = splitext(map)[0] + "_map.csv" |
Screamer@Y5070-M.virtuoso | 9:2d27d77ada5c | 920 | memap.generate_output('csv-ci', map_csv) |
screamer | 13:ab47a20b66f0 | 921 | |
screamer | 13:ab47a20b66f0 | 922 | # Set the configuration data |
screamer | 13:ab47a20b66f0 | 923 | def set_config_data(self, config_data): |
screamer | 13:ab47a20b66f0 | 924 | self.config_data = config_data |
screamer | 13:ab47a20b66f0 | 925 | |
screamer | 13:ab47a20b66f0 | 926 | # Return the location of the config header. This function will create the config |
screamer | 13:ab47a20b66f0 | 927 | # header first if needed. The header will be written in a file called "mbed_conf.h" |
screamer | 13:ab47a20b66f0 | 928 | # located in the project's build directory. |
screamer | 13:ab47a20b66f0 | 929 | # If config headers are not used (self.config_header_content is None), the function |
screamer | 13:ab47a20b66f0 | 930 | # returns None |
screamer | 13:ab47a20b66f0 | 931 | def get_config_header(self): |
screamer | 13:ab47a20b66f0 | 932 | if self.config_data is None: |
screamer | 13:ab47a20b66f0 | 933 | return None |
screamer | 13:ab47a20b66f0 | 934 | config_file = join(self.build_dir, self.MBED_CONFIG_FILE_NAME) |
screamer | 13:ab47a20b66f0 | 935 | if not exists(config_file): |
screamer | 13:ab47a20b66f0 | 936 | with open(config_file, "wt") as f: |
screamer | 13:ab47a20b66f0 | 937 | f.write(Config.config_to_header(self.config_data)) |
screamer | 13:ab47a20b66f0 | 938 | return config_file |
screamer | 13:ab47a20b66f0 | 939 | |
screamer | 13:ab47a20b66f0 | 940 | # Return the list of macros geenrated by the build system |
screamer | 13:ab47a20b66f0 | 941 | def get_config_macros(self): |
screamer | 13:ab47a20b66f0 | 942 | return Config.config_to_macros(self.config_data) if self.config_data else [] |
screamer | 13:ab47a20b66f0 | 943 | |
screamer | 0:66f3b5499f7f | 944 | from tools.settings import ARM_BIN |
screamer | 0:66f3b5499f7f | 945 | from tools.settings import GCC_ARM_PATH, GCC_CR_PATH |
screamer | 0:66f3b5499f7f | 946 | from tools.settings import IAR_PATH |
screamer | 0:66f3b5499f7f | 947 | |
screamer | 0:66f3b5499f7f | 948 | TOOLCHAIN_BIN_PATH = { |
screamer | 0:66f3b5499f7f | 949 | 'ARM': ARM_BIN, |
screamer | 0:66f3b5499f7f | 950 | 'uARM': ARM_BIN, |
screamer | 0:66f3b5499f7f | 951 | 'GCC_ARM': GCC_ARM_PATH, |
screamer | 0:66f3b5499f7f | 952 | 'GCC_CR': GCC_CR_PATH, |
screamer | 0:66f3b5499f7f | 953 | 'IAR': IAR_PATH |
screamer | 0:66f3b5499f7f | 954 | } |
screamer | 0:66f3b5499f7f | 955 | |
screamer | 0:66f3b5499f7f | 956 | from tools.toolchains.arm import ARM_STD, ARM_MICRO |
screamer | 0:66f3b5499f7f | 957 | from tools.toolchains.gcc import GCC_ARM, GCC_CR |
screamer | 0:66f3b5499f7f | 958 | from tools.toolchains.iar import IAR |
screamer | 0:66f3b5499f7f | 959 | |
screamer | 0:66f3b5499f7f | 960 | TOOLCHAIN_CLASSES = { |
screamer | 0:66f3b5499f7f | 961 | 'ARM': ARM_STD, |
screamer | 0:66f3b5499f7f | 962 | 'uARM': ARM_MICRO, |
screamer | 0:66f3b5499f7f | 963 | 'GCC_ARM': GCC_ARM, |
screamer | 0:66f3b5499f7f | 964 | 'GCC_CR': GCC_CR, |
screamer | 0:66f3b5499f7f | 965 | 'IAR': IAR |
screamer | 0:66f3b5499f7f | 966 | } |
screamer | 0:66f3b5499f7f | 967 | |
screamer | 0:66f3b5499f7f | 968 | TOOLCHAINS = set(TOOLCHAIN_CLASSES.keys()) |