|
| 1 | +""" |
| 2 | +mbed SDK |
| 3 | +Copyright (c) 2011-2013 ARM Limited |
| 4 | +
|
| 5 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +you may not use this file except in compliance with the License. |
| 7 | +You may obtain a copy of the License at |
| 8 | +
|
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +""" |
| 17 | + |
| 18 | +import re |
| 19 | +import tempfile |
| 20 | +import colorama |
| 21 | + |
| 22 | +from copy import copy |
| 23 | +from os.path import join, abspath, exists |
| 24 | +from os import walk |
| 25 | +import fnmatch |
| 26 | + |
| 27 | + |
| 28 | +def get_toolchain_profile(toolchain, profile): |
| 29 | + if profile and (TOOLCHAIN_PROFILES.get(toolchain, None) and |
| 30 | + TOOLCHAIN_PROFILES[toolchain].get(profile)): |
| 31 | + return TOOLCHAIN_PROFILES[toolchain].get(profile) |
| 32 | + |
| 33 | +def find_build_profile(path): |
| 34 | + profile = None |
| 35 | + builds = find_build_ids(path) |
| 36 | + for build in builds: |
| 37 | + if build in MBED_SDK_REV_MAP: |
| 38 | + idx = MBED_SDK_REV_MAP[build] |
| 39 | + |
| 40 | + if idx <= 43: |
| 41 | + profile = 'v1' |
| 42 | + elif idx <= 68: |
| 43 | + profile = 'v2' |
| 44 | + elif idx <= 76: |
| 45 | + profile = 'v3' |
| 46 | + elif idx <= 105: |
| 47 | + profile = 'v4' |
| 48 | + elif idx <= 135: |
| 49 | + profile = 'v5' |
| 50 | + |
| 51 | + return profile |
| 52 | + |
| 53 | +def find_build_ids(path): |
| 54 | + builds = [] |
| 55 | + |
| 56 | + for (root, dirs, files) in walk(path): |
| 57 | + for d in copy(dirs): |
| 58 | + if d.startswith('.'): |
| 59 | + dirs.remove(d) |
| 60 | + |
| 61 | + for filename in filter(lambda s: s.endswith(".bld"), files): |
| 62 | + try: |
| 63 | + url = open(join(root, filename), 'r').read().strip() |
| 64 | + builds.append(re.sub(r'^.+/(.*?)$', r'\1', url)) |
| 65 | + except: |
| 66 | + pass |
| 67 | + |
| 68 | + return builds |
| 69 | + |
| 70 | + |
| 71 | +def find_targets_json(path, depth=1): |
| 72 | + f = 'targets.json' |
| 73 | + if exists(join(path, f)): |
| 74 | + return abspath(join(path, f)) |
| 75 | + |
| 76 | + if depth > 2: |
| 77 | + return None |
| 78 | + |
| 79 | + for root, dirs, files in walk(path): |
| 80 | + for d in copy(dirs): |
| 81 | + if d.startswith('.'): |
| 82 | + dirs.remove(d) |
| 83 | + continue |
| 84 | + |
| 85 | + if exists(join(root, d, f)): |
| 86 | + return abspath(join(root, d, f)) |
| 87 | + else: |
| 88 | + found = find_targets_json(join(root, d), depth+1) |
| 89 | + if found: |
| 90 | + return found |
| 91 | + |
| 92 | + return None |
| 93 | + |
| 94 | + |
| 95 | +# Toolchain profiles for backward compatibility with old mbed SDK library releases |
| 96 | +TOOLCHAIN_PROFILES = { |
| 97 | + 'ARM_STD' : { |
| 98 | + 'v5': { |
| 99 | + 'version': '5.06', |
| 100 | + 'common': ['-c', '--gnu', '-O3', '-Otime', '--split_sections', '--apcs=interwork'], |
| 101 | + 'cxx': ['--cpp', '--no_rtti'], |
| 102 | + 'COMPILE_C_AS_CPP': False, |
| 103 | + }, |
| 104 | + 'v4': { |
| 105 | + 'version': '5.03', |
| 106 | + 'common': ['-c', '--gnu', '-O3', '-Otime', '--split_sections', '--apcs=interwork'], |
| 107 | + 'cxx': ['--cpp', '--no_rtti'], |
| 108 | + 'COMPILE_C_AS_CPP': False, |
| 109 | + }, |
| 110 | + 'v3': { |
| 111 | + 'version': '5.01', |
| 112 | + 'common': ['-c', '--gnu', '-Ospace', '--split_sections', '--apcs=interwork'], |
| 113 | + 'cxx': ['--cpp', '--no_rtti'], |
| 114 | + 'COMPILE_C_AS_CPP': False, |
| 115 | + }, |
| 116 | + 'v2': { |
| 117 | + 'version': '5.01', |
| 118 | + 'common': ['-c', '--gnu', '-Ospace', '--split_sections', '--apcs=interwork'], |
| 119 | + 'cxx': ['--cpp', '--no_rtti'], |
| 120 | + 'COMPILE_C_AS_CPP': False, |
| 121 | + }, |
| 122 | + 'v1': { |
| 123 | + 'version': '4', |
| 124 | + 'common': ['-c', '--gnu', '-Otime', '--split_sections', '--apcs=interwork'], |
| 125 | + 'cxx': ['--cpp'], |
| 126 | + 'COMPILE_C_AS_CPP': True, |
| 127 | + } |
| 128 | + }, |
| 129 | + 'ARM_MICRO' : { |
| 130 | + 'v5': { |
| 131 | + 'version': '5.06', |
| 132 | + 'common': ['-c', '--gnu', '-O3', '-Otime', '--split_sections', '--apcs=interwork'], |
| 133 | + 'cxx': ['--cpp', '--no_rtti'], |
| 134 | + }, |
| 135 | + 'v4': { |
| 136 | + 'version': '5.03', |
| 137 | + 'common': ['-c', '--gnu', '-O3', '-Otime', '--split_sections', '--apcs=interwork'], |
| 138 | + 'cxx': ['--cpp', '--no_rtti'], |
| 139 | + }, |
| 140 | + 'v3': { |
| 141 | + 'version': '5.01', |
| 142 | + 'common': ['-c', '--gnu', '-Ospace', '--split_sections', '--apcs=interwork'], |
| 143 | + 'cxx': ['--cpp', '--no_rtti'], |
| 144 | + }, |
| 145 | + 'v2': { |
| 146 | + 'version': '4', |
| 147 | + 'common': ['-c', '--gnu', '-Ospace', '--split_sections', '--apcs=interwork'], |
| 148 | + 'cxx': ['--cpp', '--no_rtti'], |
| 149 | + 'PATCHED_LIBRARY' : True, |
| 150 | + }, |
| 151 | + 'v1': { |
| 152 | + 'version': '4.1', |
| 153 | + 'common': ['-c', '--gnu', '-Otime', '--split_sections', '--apcs=interwork'], |
| 154 | + 'cxx': ['--cpp'], |
| 155 | + 'COMPILE_C_AS_CPP': True, |
| 156 | + 'PATCHED_LIBRARY' : True, |
| 157 | + } |
| 158 | + }, |
| 159 | + 'GCC_ARM' : { |
| 160 | + 'v5': { |
| 161 | + 'ld': ['-Wl,--gc-sections', '-Wl,--wrap,main'], |
| 162 | + }, |
| 163 | + 'v4': { |
| 164 | + 'ld': ['-Wl,--gc-sections', '-Wl,--wrap,main'], |
| 165 | + }, |
| 166 | + 'v3': { |
| 167 | + 'ld': ['-Wl,--gc-sections', '-Wl,--wrap,main'], |
| 168 | + }, |
| 169 | + 'v2': { |
| 170 | + 'common': ["-c", "-Wall", "-fmessage-length=0", "-fno-exceptions", "-fno-builtin", "-ffunction-sections", "-fdata-sections"], |
| 171 | + 'cxx': ['-std=gnu++98'], |
| 172 | + 'ld': ['-Wl,--gc-sections'], |
| 173 | + }, |
| 174 | + 'v1': { |
| 175 | + 'common': ["-c", "-Wall", "-fmessage-length=0", "-fno-exceptions", "-fno-builtin", "-ffunction-sections", "-fdata-sections"], |
| 176 | + 'cxx': ['-std=gnu++98'], |
| 177 | + 'ld': ['-Wl,--gc-sections'], |
| 178 | + } |
| 179 | + } |
| 180 | +} |
| 181 | + |
| 182 | +MBED_SDK_REV_MAP = { |
| 183 | + '6f4d9ba055b3': 122, |
| 184 | + 'c1a077c0ccc5': 123, |
| 185 | + 'f1e13e937fab': 124, |
| 186 | + 'a974dc8aa35b': 125, |
| 187 | + '4132e2258101': 126, |
| 188 | + '62ea7dd49f26': 127, |
| 189 | + 'e6f9c99959f3': 128, |
| 190 | + '31768d6a83cd': 129, |
| 191 | + '620374818e03': 130, |
| 192 | + 'f4b892cad2b9': 131, |
| 193 | + '9c0c086c88f0': 132, |
| 194 | + 'a1e1b8eadde3': 133, |
| 195 | + '1a303c31ec8f': 134, |
| 196 | + '0b434d521da0': 135, |
| 197 | + '2abc4044d39c': 136, |
| 198 | + 'c2078c12af99': 137, |
| 199 | + '86e42d5e9f93': 138, |
| 200 | + '4ba4acebdbae': 139, |
| 201 | + '608e850de46b': 140, |
| 202 | + 'd616554d63fc': 141, |
| 203 | + '46ffe6167a0b': 142, |
| 204 | + 'c417c1db60ce': 143, |
| 205 | + '6b1076ac9921': 144, |
| 206 | + '6c34061e7c34': 121, |
| 207 | + '7c328cabac7e': 120, |
| 208 | + 'aae6fcc7d9bb': 119, |
| 209 | + '082adc85693f': 118, |
| 210 | + '99a22ba036c9': 117, |
| 211 | + 'c0f6e94411f5': 116, |
| 212 | + '87f2f5183dfb': 115, |
| 213 | + '252557024ec3': 114, |
| 214 | + 'f141b2784e32': 113, |
| 215 | + '6f327212ef96': 112, |
| 216 | + '4336505e4b1c': 111, |
| 217 | + '165afa46840b': 110, |
| 218 | + '9296ab0bfc11': 109, |
| 219 | + '34e6b704fe68': 108, |
| 220 | + '4f6c30876dfa': 107, |
| 221 | + 'ba1f97679dad': 106, |
| 222 | + '8ed44a420e5c': 105, |
| 223 | + 'b9ad9a133dc7': 104, |
| 224 | + 'bad568076d81': 103, |
| 225 | + 'da0ca467f8b5': 102, |
| 226 | + '7cff1c4259d7': 101, |
| 227 | + 'cbbeb26dbd92': 100, |
| 228 | + 'dbbf35b96557': 99, |
| 229 | + '8ab26030e058': 98, |
| 230 | + '433970e64889': 97, |
| 231 | + '487b796308b0': 96, |
| 232 | + '7e07b6fb45cf': 95, |
| 233 | + '9ad691361fac': 94, |
| 234 | + 'e188a91d3eaa': 93, |
| 235 | + '4fc01daae5a5': 92, |
| 236 | + '031413cf7a89': 91, |
| 237 | + 'cb3d968589d8': 90, |
| 238 | + '552587b429a1': 89, |
| 239 | + '9327015d4013': 88, |
| 240 | + '6213f644d804': 87, |
| 241 | + '04dd9b1680ae': 86, |
| 242 | + '024bf7f99721': 85, |
| 243 | + '0b3ab51c8877': 84, |
| 244 | + '8a40adfe8776': 83, |
| 245 | + '6473597d706e': 82, |
| 246 | + '7d30d6019079': 81, |
| 247 | + '8e73be2a2ac1': 80, |
| 248 | + '0c05e21ae27e': 79, |
| 249 | + 'ed8466a608b4': 78, |
| 250 | + '869cf507173a': 77, |
| 251 | + '824293ae5e43': 76, |
| 252 | + 'dc225afb6914': 75, |
| 253 | + 'a842253909c9': 74, |
| 254 | + '1efda918f0ba': 73, |
| 255 | + '4096f863f923': 72, |
| 256 | + '8fabd470bb6e': 71, |
| 257 | + '673126e12c73': 70, |
| 258 | + '4a7918f48478': 69, |
| 259 | + 'f37f3b9c9f0b': 68, |
| 260 | + 'a9913a65894f': 67, |
| 261 | + '9c8f0e3462fb': 66, |
| 262 | + '5798e58a58b1': 65, |
| 263 | + 'e3affc9e7238': 64, |
| 264 | + 'b3110cd2dd17': 63, |
| 265 | + '7e6c9f46b3bd': 62, |
| 266 | + '5e5da4a5990b': 61, |
| 267 | + '3d0ef94e36ec': 60, |
| 268 | + '0883845fe643': 59, |
| 269 | + '0954ebd79f59': 58, |
| 270 | + '0480438fc29c': 57, |
| 271 | + '3753e96f3c8b': 56, |
| 272 | + 'd722ed6a4237': 55, |
| 273 | + '71b101360fb9': 54, |
| 274 | + '63cdd78b2dc1': 53, |
| 275 | + '09236a68d21b': 52, |
| 276 | + 'a076018f59af': 51, |
| 277 | + 'b60934f96c0c': 50, |
| 278 | + 'eeb8a2a33ec9': 49, |
| 279 | + '49c296715c73': 48, |
| 280 | + '134def52cfa0': 47, |
| 281 | + '890817bdcffb': 46, |
| 282 | + '3d775a932e1d': 45, |
| 283 | + '24d45a770a51': 44, |
| 284 | + 'e2ed12d17f06': 43, |
| 285 | + 'cd19af002ccc': 42, |
| 286 | + '10b9abbe79a6': 41, |
| 287 | + '976df7c37ad5': 40, |
| 288 | + '737756e0b479': 39, |
| 289 | + '4c0c40fd0593': 38, |
| 290 | + '14f4805c468c': 37, |
| 291 | + 'b4b9f287a47e': 36, |
| 292 | + '5284544d04b6': 35, |
| 293 | + '7495d544864f': 34, |
| 294 | + '5364839841bd': 33, |
| 295 | + '3b05dd009342': 32, |
| 296 | + 'a7ef757f598c': 31, |
| 297 | + '3991a86798e3': 30, |
| 298 | + '078e4b97a13e': 29, |
| 299 | + '667d61c9177b': 28, |
| 300 | + '7110ebee3484': 27, |
| 301 | + '63bcd7ba4912': 26, |
| 302 | + '9a9732ce53a1': 25, |
| 303 | + 'e2ac27c8e93e': 24, |
| 304 | + '74b8d43b5817': 23, |
| 305 | + '9114680c05da': 22, |
| 306 | + '3944f1e2fa4f': 21, |
| 307 | + '029aa53d7323': 20, |
| 308 | + 'e6be4cd80aad': 19, |
| 309 | + 'b3c9f16cbb96': 18, |
| 310 | + '49a220cc26e0': 17, |
| 311 | + '32af5db564d4': 16, |
| 312 | + 'd1a9de3f4fe0': 15, |
| 313 | + '20a79241b4a0': 14, |
| 314 | + 'a0336ede94ce': 13, |
| 315 | + 'f63353af7be8': 12, |
| 316 | + '1c1ebd0324fa': 11, |
| 317 | + 'fcb9359f0959': 10, |
| 318 | + 'cf0d45ce28a6': 9, |
| 319 | + '00a04e5cd407': 8, |
| 320 | + '15d74db76485': 7, |
| 321 | + '3fd6a337c7cc': 6, |
| 322 | + '62573be585e9': 5, |
| 323 | + '5d1359a283bc': 4, |
| 324 | + 'aefd12a1f1c5': 3, |
| 325 | + '969fc1867111': 2, |
| 326 | + '6b7f447ca868': 1, |
| 327 | + '82220227f4fa': 0, |
| 328 | +} |
0 commit comments