Clone of official tools

Committer:
The Other Jimmy
Date:
Wed Jan 04 11:58:24 2017 -0600
Revision:
32:fef1f96d5e06
Parent:
24:25bff2709c20
Update tools to follow mbed-os tools release 5.3.1

Who changed what in which revision?

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