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