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