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