Clone of official tools

Committer:
The Other Jimmy
Date:
Thu Jun 22 11:12:28 2017 -0500
Revision:
36:96847d42f010
Parent:
35:da9c89f8be7d
Child:
40:7d3fa6b99b2b
Tools release 5.5.1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
The Other Jimmy 31:8ea194f6145b 1 """The generic interface for all exporters.
screamer 0:66f3b5499f7f 2 """
The Other Jimmy 31:8ea194f6145b 3 # mbed SDK
The Other Jimmy 31:8ea194f6145b 4 # Copyright (c) 2011-2016 ARM Limited
The Other Jimmy 31:8ea194f6145b 5 #
The Other Jimmy 31:8ea194f6145b 6 # Licensed under the Apache License, Version 2.0 (the "License");
The Other Jimmy 31:8ea194f6145b 7 # you may not use this file except in compliance with the License.
The Other Jimmy 31:8ea194f6145b 8 # You may obtain a copy of the License at
The Other Jimmy 31:8ea194f6145b 9 #
The Other Jimmy 31:8ea194f6145b 10 # http://www.apache.org/licenses/LICENSE-2.0
The Other Jimmy 31:8ea194f6145b 11 #
The Other Jimmy 31:8ea194f6145b 12 # Unless required by applicable law or agreed to in writing, software
The Other Jimmy 31:8ea194f6145b 13 # distributed under the License is distributed on an "AS IS" BASIS,
The Other Jimmy 31:8ea194f6145b 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
The Other Jimmy 31:8ea194f6145b 15 # See the License for the specific language governing permissions and
The Other Jimmy 31:8ea194f6145b 16 # limitations under the License.
screamer 0:66f3b5499f7f 17
The Other Jimmy 36:96847d42f010 18 import sys
The Other Jimmy 36:96847d42f010 19 from os.path import join, abspath, dirname, exists
The Other Jimmy 36:96847d42f010 20 from os.path import basename, relpath, normpath, splitext
The Other Jimmy 36:96847d42f010 21 from os import makedirs, walk
The Other Jimmy 36:96847d42f010 22 import copy
The Other Jimmy 36:96847d42f010 23 from shutil import rmtree, copyfile
The Other Jimmy 36:96847d42f010 24 import zipfile
The Other Jimmy 36:96847d42f010 25 ROOT = abspath(join(dirname(__file__), ".."))
The Other Jimmy 36:96847d42f010 26 sys.path.insert(0, ROOT)
The Other Jimmy 36:96847d42f010 27
The Other Jimmy 36:96847d42f010 28 from tools.build_api import prepare_toolchain
The Other Jimmy 36:96847d42f010 29 from tools.build_api import scan_resources
The Other Jimmy 36:96847d42f010 30 from tools.toolchains import Resources, mbedToolchain
The Other Jimmy 36:96847d42f010 31 from tools.export import lpcxpresso, ds5_5, iar, makefile
The Other Jimmy 35:da9c89f8be7d 32 from tools.export import embitz, coide, kds, simplicity, atmelstudio
The Other Jimmy 36:96847d42f010 33 from tools.export import sw4stm32, e2studio, zip, cmsis, uvision, cdt, vscode
The Other Jimmy 36:96847d42f010 34 from tools.export import gnuarmeclipse
The Other Jimmy 36:96847d42f010 35 from tools.export import qtcreator
The Other Jimmy 36:96847d42f010 36 from tools.targets import TARGET_NAMES, set_targets_json_location
The Other Jimmy 36:96847d42f010 37 from tools.build_profiles import find_build_profile, find_targets_json
The Other Jimmy 36:96847d42f010 38 from tools.build_profiles import get_toolchain_profile
screamer 0:66f3b5499f7f 39
screamer 0:66f3b5499f7f 40 EXPORTERS = {
The Other Jimmy 31:8ea194f6145b 41 'uvision5': uvision.Uvision,
The Other Jimmy 31:8ea194f6145b 42 'uvision': uvision.Uvision,
The Other Jimmy 36:96847d42f010 43 'lpcxpresso': lpcxpresso.LPCXpresso,
The Other Jimmy 31:8ea194f6145b 44 'gcc_arm': makefile.GccArm,
The Other Jimmy 31:8ea194f6145b 45 'make_gcc_arm': makefile.GccArm,
The Other Jimmy 31:8ea194f6145b 46 'make_armc5': makefile.Armc5,
The Other Jimmy 31:8ea194f6145b 47 'make_iar': makefile.IAR,
screamer 0:66f3b5499f7f 48 'ds5_5': ds5_5.DS5_5,
The Other Jimmy 31:8ea194f6145b 49 'iar': iar.IAR,
The Other Jimmy 35:da9c89f8be7d 50 'embitz' : embitz.EmBitz,
screamer 0:66f3b5499f7f 51 'coide' : coide.CoIDE,
screamer 0:66f3b5499f7f 52 'kds' : kds.KDS,
The Other Jimmy 35:da9c89f8be7d 53 'simplicityv3' : simplicity.SimplicityV3,
screamer 0:66f3b5499f7f 54 'atmelstudio' : atmelstudio.AtmelStudio,
screamer 0:66f3b5499f7f 55 'sw4stm32' : sw4stm32.Sw4STM32,
screamer 13:ab47a20b66f0 56 'e2studio' : e2studio.E2Studio,
The Other Jimmy 31:8ea194f6145b 57 'eclipse_gcc_arm' : cdt.EclipseGcc,
The Other Jimmy 31:8ea194f6145b 58 'eclipse_iar' : cdt.EclipseIAR,
The Other Jimmy 31:8ea194f6145b 59 'eclipse_armc5' : cdt.EclipseArmc5,
The Other Jimmy 36:96847d42f010 60 'gnuarmeclipse': gnuarmeclipse.GNUARMEclipse,
The Other Jimmy 36:96847d42f010 61 'qtcreator': qtcreator.QtCreator,
The Other Jimmy 31:8ea194f6145b 62 'zip' : zip.ZIP,
The Other Jimmy 36:96847d42f010 63 'cmsis' : cmsis.CMSIS,
The Other Jimmy 36:96847d42f010 64 'vscode_gcc_arm' : vscode.VSCodeGcc,
The Other Jimmy 36:96847d42f010 65 'vscode_iar' : vscode.VSCodeIAR,
The Other Jimmy 36:96847d42f010 66 'vscode_armc5' : vscode.VSCodeArmc5
screamer 0:66f3b5499f7f 67 }
screamer 0:66f3b5499f7f 68
screamer 0:66f3b5499f7f 69 ERROR_MESSAGE_UNSUPPORTED_TOOLCHAIN = """
screamer 0:66f3b5499f7f 70 Sorry, the target %s is not currently supported on the %s toolchain.
screamer 0:66f3b5499f7f 71 Please refer to <a href='/handbook/Exporting-to-offline-toolchains' target='_blank'>Exporting to offline toolchains</a> for more information.
screamer 0:66f3b5499f7f 72 """
screamer 0:66f3b5499f7f 73
screamer 0:66f3b5499f7f 74 ERROR_MESSAGE_NOT_EXPORT_LIBS = """
screamer 0:66f3b5499f7f 75 To export this project please <a href='http://mbed.org/compiler/?import=http://mbed.org/users/mbed_official/code/mbed-export/k&mode=lib' target='_blank'>import the export version of the mbed library</a>.
screamer 0:66f3b5499f7f 76 """
screamer 0:66f3b5499f7f 77
The Other Jimmy 36:96847d42f010 78 def mcu_ide_list():
The Other Jimmy 36:96847d42f010 79 """Shows list of exportable ides
The Other Jimmy 36:96847d42f010 80
The Other Jimmy 36:96847d42f010 81 """
The Other Jimmy 36:96847d42f010 82 supported_ides = sorted(EXPORTERS.keys())
The Other Jimmy 36:96847d42f010 83 return "\n".join(supported_ides)
The Other Jimmy 36:96847d42f010 84
The Other Jimmy 36:96847d42f010 85
The Other Jimmy 31:8ea194f6145b 86 def mcu_ide_matrix(verbose_html=False):
The Other Jimmy 31:8ea194f6145b 87 """Shows target map using prettytable
screamer 0:66f3b5499f7f 88
The Other Jimmy 31:8ea194f6145b 89 Keyword argumets:
The Other Jimmy 31:8ea194f6145b 90 verbose_html - print the matrix in html format
screamer 0:66f3b5499f7f 91 """
The Other Jimmy 31:8ea194f6145b 92 supported_ides = sorted(EXPORTERS.keys())
The Other Jimmy 31:8ea194f6145b 93 # Only use it in this function so building works without extra modules
The Other Jimmy 31:8ea194f6145b 94 from prettytable import PrettyTable, ALL
screamer 0:66f3b5499f7f 95
screamer 0:66f3b5499f7f 96 # All tests status table print
The Other Jimmy 31:8ea194f6145b 97 table_printer = PrettyTable(["Platform"] + supported_ides)
screamer 0:66f3b5499f7f 98 # Align table
The Other Jimmy 31:8ea194f6145b 99 for col in supported_ides:
The Other Jimmy 31:8ea194f6145b 100 table_printer.align[col] = "c"
The Other Jimmy 31:8ea194f6145b 101 table_printer.align["Platform"] = "l"
screamer 0:66f3b5499f7f 102
screamer 0:66f3b5499f7f 103 perm_counter = 0
screamer 0:66f3b5499f7f 104 for target in sorted(TARGET_NAMES):
screamer 0:66f3b5499f7f 105 row = [target] # First column is platform name
screamer 0:66f3b5499f7f 106 for ide in supported_ides:
screamer 0:66f3b5499f7f 107 text = "-"
screamer 0:66f3b5499f7f 108 if target in EXPORTERS[ide].TARGETS:
screamer 0:66f3b5499f7f 109 if verbose_html:
screamer 0:66f3b5499f7f 110 text = "&#10003;"
screamer 0:66f3b5499f7f 111 else:
screamer 0:66f3b5499f7f 112 text = "x"
screamer 0:66f3b5499f7f 113 perm_counter += 1
screamer 0:66f3b5499f7f 114 row.append(text)
The Other Jimmy 31:8ea194f6145b 115 table_printer.add_row(row)
screamer 0:66f3b5499f7f 116
The Other Jimmy 31:8ea194f6145b 117 table_printer.border = True
The Other Jimmy 31:8ea194f6145b 118 table_printer.vrules = ALL
The Other Jimmy 31:8ea194f6145b 119 table_printer.hrules = ALL
screamer 0:66f3b5499f7f 120 # creates a html page in a shorter format suitable for readme.md
The Other Jimmy 31:8ea194f6145b 121 if verbose_html:
The Other Jimmy 31:8ea194f6145b 122 result = table_printer.get_html_string()
The Other Jimmy 31:8ea194f6145b 123 else:
The Other Jimmy 31:8ea194f6145b 124 result = table_printer.get_string()
screamer 0:66f3b5499f7f 125 result += "\n"
screamer 0:66f3b5499f7f 126 result += "Total IDEs: %d\n"% (len(supported_ides))
The Other Jimmy 31:8ea194f6145b 127 if verbose_html:
The Other Jimmy 31:8ea194f6145b 128 result += "<br>"
The Other Jimmy 31:8ea194f6145b 129 result += "Total platforms: %d\n"% (len(TARGET_NAMES))
The Other Jimmy 31:8ea194f6145b 130 if verbose_html:
The Other Jimmy 31:8ea194f6145b 131 result += "<br>"
screamer 0:66f3b5499f7f 132 result += "Total permutations: %d"% (perm_counter)
The Other Jimmy 31:8ea194f6145b 133 if verbose_html:
The Other Jimmy 31:8ea194f6145b 134 result = result.replace("&amp;", "&")
screamer 0:66f3b5499f7f 135 return result
The Other Jimmy 36:96847d42f010 136
The Other Jimmy 36:96847d42f010 137
The Other Jimmy 36:96847d42f010 138 def get_exporter_toolchain(ide):
The Other Jimmy 36:96847d42f010 139 """ Return the exporter class and the toolchain string as a tuple
The Other Jimmy 36:96847d42f010 140
The Other Jimmy 36:96847d42f010 141 Positional arguments:
The Other Jimmy 36:96847d42f010 142 ide - the ide name of an exporter
The Other Jimmy 36:96847d42f010 143 """
The Other Jimmy 36:96847d42f010 144 return EXPORTERS[ide], EXPORTERS[ide].TOOLCHAIN
The Other Jimmy 36:96847d42f010 145
The Other Jimmy 36:96847d42f010 146
The Other Jimmy 36:96847d42f010 147 def rewrite_basepath(file_name, resources, export_path, loc):
The Other Jimmy 36:96847d42f010 148 """ Replace the basepath of filename with export_path
The Other Jimmy 36:96847d42f010 149
The Other Jimmy 36:96847d42f010 150 Positional arguments:
The Other Jimmy 36:96847d42f010 151 file_name - the absolute path to a file
The Other Jimmy 36:96847d42f010 152 resources - the resources object that the file came from
The Other Jimmy 36:96847d42f010 153 export_path - the final destination of the file after export
The Other Jimmy 36:96847d42f010 154 """
The Other Jimmy 36:96847d42f010 155 new_f = join(loc, relpath(file_name, resources.file_basepath[file_name]))
The Other Jimmy 36:96847d42f010 156 resources.file_basepath[new_f] = export_path
The Other Jimmy 36:96847d42f010 157 return new_f
The Other Jimmy 36:96847d42f010 158
The Other Jimmy 36:96847d42f010 159
The Other Jimmy 36:96847d42f010 160 def subtract_basepath(resources, export_path, loc=""):
The Other Jimmy 36:96847d42f010 161 """ Rewrite all of the basepaths with the export_path
The Other Jimmy 36:96847d42f010 162
The Other Jimmy 36:96847d42f010 163 Positional arguments:
The Other Jimmy 36:96847d42f010 164 resources - the resource object to rewrite the basepaths of
The Other Jimmy 36:96847d42f010 165 export_path - the final destination of the resources with respect to the
The Other Jimmy 36:96847d42f010 166 generated project files
The Other Jimmy 36:96847d42f010 167 """
The Other Jimmy 36:96847d42f010 168 keys = ['s_sources', 'c_sources', 'cpp_sources', 'hex_files',
The Other Jimmy 36:96847d42f010 169 'objects', 'libraries', 'inc_dirs', 'headers', 'linker_script',
The Other Jimmy 36:96847d42f010 170 'lib_dirs']
The Other Jimmy 36:96847d42f010 171 for key in keys:
The Other Jimmy 36:96847d42f010 172 vals = getattr(resources, key)
The Other Jimmy 36:96847d42f010 173 if isinstance(vals, set):
The Other Jimmy 36:96847d42f010 174 vals = list(vals)
The Other Jimmy 36:96847d42f010 175 if isinstance(vals, list):
The Other Jimmy 36:96847d42f010 176 new_vals = []
The Other Jimmy 36:96847d42f010 177 for val in vals:
The Other Jimmy 36:96847d42f010 178 new_vals.append(rewrite_basepath(val, resources, export_path,
The Other Jimmy 36:96847d42f010 179 loc))
The Other Jimmy 36:96847d42f010 180 if isinstance(getattr(resources, key), set):
The Other Jimmy 36:96847d42f010 181 setattr(resources, key, set(new_vals))
The Other Jimmy 36:96847d42f010 182 else:
The Other Jimmy 36:96847d42f010 183 setattr(resources, key, new_vals)
The Other Jimmy 36:96847d42f010 184 elif vals:
The Other Jimmy 36:96847d42f010 185 setattr(resources, key, rewrite_basepath(vals, resources,
The Other Jimmy 36:96847d42f010 186 export_path, loc))
The Other Jimmy 36:96847d42f010 187
The Other Jimmy 36:96847d42f010 188
The Other Jimmy 36:96847d42f010 189 def generate_project_files(resources, export_path, target, name, toolchain, ide,
The Other Jimmy 36:96847d42f010 190 macros=None):
The Other Jimmy 36:96847d42f010 191 """Generate the project files for a project
The Other Jimmy 36:96847d42f010 192
The Other Jimmy 36:96847d42f010 193 Positional arguments:
The Other Jimmy 36:96847d42f010 194 resources - a Resources object containing all of the files needed to build
The Other Jimmy 36:96847d42f010 195 this project
The Other Jimmy 36:96847d42f010 196 export_path - location to place project files
The Other Jimmy 36:96847d42f010 197 name - name of the project
The Other Jimmy 36:96847d42f010 198 toolchain - a toolchain class that corresponds to the toolchain used by the
The Other Jimmy 36:96847d42f010 199 IDE or makefile
The Other Jimmy 36:96847d42f010 200 ide - IDE name to export to
The Other Jimmy 36:96847d42f010 201
The Other Jimmy 36:96847d42f010 202 Optional arguments:
The Other Jimmy 36:96847d42f010 203 macros - additional macros that should be defined within the exported
The Other Jimmy 36:96847d42f010 204 project
The Other Jimmy 36:96847d42f010 205 """
The Other Jimmy 36:96847d42f010 206 exporter_cls, _ = get_exporter_toolchain(ide)
The Other Jimmy 36:96847d42f010 207 exporter = exporter_cls(target, export_path, name, toolchain,
The Other Jimmy 36:96847d42f010 208 extra_symbols=macros, resources=resources)
The Other Jimmy 36:96847d42f010 209 exporter.generate()
The Other Jimmy 36:96847d42f010 210 files = exporter.generated_files
The Other Jimmy 36:96847d42f010 211 return files, exporter
The Other Jimmy 36:96847d42f010 212
The Other Jimmy 36:96847d42f010 213
The Other Jimmy 36:96847d42f010 214 def zip_export(file_name, prefix, resources, project_files, inc_repos):
The Other Jimmy 36:96847d42f010 215 """Create a zip file from an exported project.
The Other Jimmy 36:96847d42f010 216
The Other Jimmy 36:96847d42f010 217 Positional Parameters:
The Other Jimmy 36:96847d42f010 218 file_name - the file name of the resulting zip file
The Other Jimmy 36:96847d42f010 219 prefix - a directory name that will prefix the entire zip file's contents
The Other Jimmy 36:96847d42f010 220 resources - a resources object with files that must be included in the zip
The Other Jimmy 36:96847d42f010 221 project_files - a list of extra files to be added to the root of the prefix
The Other Jimmy 36:96847d42f010 222 directory
The Other Jimmy 36:96847d42f010 223 """
The Other Jimmy 36:96847d42f010 224 with zipfile.ZipFile(file_name, "w") as zip_file:
The Other Jimmy 36:96847d42f010 225 for prj_file in project_files:
The Other Jimmy 36:96847d42f010 226 zip_file.write(prj_file, join(prefix, basename(prj_file)))
The Other Jimmy 36:96847d42f010 227 for loc, res in resources.iteritems():
The Other Jimmy 36:96847d42f010 228 to_zip = (
The Other Jimmy 36:96847d42f010 229 res.headers + res.s_sources + res.c_sources +\
The Other Jimmy 36:96847d42f010 230 res.cpp_sources + res.libraries + res.hex_files + \
The Other Jimmy 36:96847d42f010 231 [res.linker_script] + res.bin_files + res.objects + \
The Other Jimmy 36:96847d42f010 232 res.json_files + res.lib_refs + res.lib_builds)
The Other Jimmy 36:96847d42f010 233 if inc_repos:
The Other Jimmy 36:96847d42f010 234 for directory in res.repo_dirs:
The Other Jimmy 36:96847d42f010 235 for root, _, files in walk(directory):
The Other Jimmy 36:96847d42f010 236 for repo_file in files:
The Other Jimmy 36:96847d42f010 237 source = join(root, repo_file)
The Other Jimmy 36:96847d42f010 238 to_zip.append(source)
The Other Jimmy 36:96847d42f010 239 res.file_basepath[source] = res.base_path
The Other Jimmy 36:96847d42f010 240 to_zip += res.repo_files
The Other Jimmy 36:96847d42f010 241 for source in to_zip:
The Other Jimmy 36:96847d42f010 242 if source:
The Other Jimmy 36:96847d42f010 243 zip_file.write(
The Other Jimmy 36:96847d42f010 244 source,
The Other Jimmy 36:96847d42f010 245 join(prefix, loc,
The Other Jimmy 36:96847d42f010 246 relpath(source, res.file_basepath[source])))
The Other Jimmy 36:96847d42f010 247 for source in res.lib_builds:
The Other Jimmy 36:96847d42f010 248 target_dir, _ = splitext(source)
The Other Jimmy 36:96847d42f010 249 dest = join(prefix, loc,
The Other Jimmy 36:96847d42f010 250 relpath(target_dir, res.file_basepath[source]),
The Other Jimmy 36:96847d42f010 251 ".bld", "bldrc")
The Other Jimmy 36:96847d42f010 252 zip_file.write(source, dest)
The Other Jimmy 36:96847d42f010 253
The Other Jimmy 36:96847d42f010 254
The Other Jimmy 36:96847d42f010 255
The Other Jimmy 36:96847d42f010 256 def export_project(src_paths, export_path, target, ide, libraries_paths=None,
The Other Jimmy 36:96847d42f010 257 linker_script=None, notify=None, verbose=False, name=None,
The Other Jimmy 36:96847d42f010 258 inc_dirs=None, jobs=1, silent=False, extra_verbose=False,
The Other Jimmy 36:96847d42f010 259 config=None, macros=None, zip_proj=None, inc_repos=False,
The Other Jimmy 36:96847d42f010 260 build_profile=None, app_config=None):
The Other Jimmy 36:96847d42f010 261 """Generates a project file and creates a zip archive if specified
The Other Jimmy 36:96847d42f010 262
The Other Jimmy 36:96847d42f010 263 Positional Arguments:
The Other Jimmy 36:96847d42f010 264 src_paths - a list of paths from which to find source files
The Other Jimmy 36:96847d42f010 265 export_path - a path specifying the location of generated project files
The Other Jimmy 36:96847d42f010 266 target - the mbed board/mcu for which to generate the executable
The Other Jimmy 36:96847d42f010 267 ide - the ide for which to generate the project fields
The Other Jimmy 36:96847d42f010 268
The Other Jimmy 36:96847d42f010 269 Keyword Arguments:
The Other Jimmy 36:96847d42f010 270 libraries_paths - paths to additional libraries
The Other Jimmy 36:96847d42f010 271 linker_script - path to the linker script for the specified target
The Other Jimmy 36:96847d42f010 272 notify - function is passed all events, and expected to handle notification
The Other Jimmy 36:96847d42f010 273 of the user, emit the events to a log, etc.
The Other Jimmy 36:96847d42f010 274 verbose - assigns the notify function to toolchains print_notify_verbose
The Other Jimmy 36:96847d42f010 275 name - project name
The Other Jimmy 36:96847d42f010 276 inc_dirs - additional include directories
The Other Jimmy 36:96847d42f010 277 jobs - number of threads
The Other Jimmy 36:96847d42f010 278 silent - silent build - no output
The Other Jimmy 36:96847d42f010 279 extra_verbose - assigns the notify function to toolchains
The Other Jimmy 36:96847d42f010 280 print_notify_verbose
The Other Jimmy 36:96847d42f010 281 config - toolchain's config object
The Other Jimmy 36:96847d42f010 282 macros - User-defined macros
The Other Jimmy 36:96847d42f010 283 zip_proj - string name of the zip archive you wish to creat (exclude arg
The Other Jimmy 36:96847d42f010 284 if you do not wish to create an archive
The Other Jimmy 36:96847d42f010 285 """
The Other Jimmy 36:96847d42f010 286
The Other Jimmy 36:96847d42f010 287 # Convert src_path to a list if needed
The Other Jimmy 36:96847d42f010 288 if isinstance(src_paths, dict):
The Other Jimmy 36:96847d42f010 289 paths = sum(src_paths.values(), [])
The Other Jimmy 36:96847d42f010 290 elif isinstance(src_paths, list):
The Other Jimmy 36:96847d42f010 291 paths = src_paths[:]
The Other Jimmy 36:96847d42f010 292 else:
The Other Jimmy 36:96847d42f010 293 paths = [src_paths]
The Other Jimmy 36:96847d42f010 294
The Other Jimmy 36:96847d42f010 295 # Extend src_paths wit libraries_paths
The Other Jimmy 36:96847d42f010 296 if libraries_paths is not None:
The Other Jimmy 36:96847d42f010 297 paths.extend(libraries_paths)
The Other Jimmy 36:96847d42f010 298
The Other Jimmy 36:96847d42f010 299 if not isinstance(src_paths, dict):
The Other Jimmy 36:96847d42f010 300 src_paths = {"": paths}
The Other Jimmy 36:96847d42f010 301
The Other Jimmy 36:96847d42f010 302 # Export Directory
The Other Jimmy 36:96847d42f010 303 if not exists(export_path):
The Other Jimmy 36:96847d42f010 304 makedirs(export_path)
The Other Jimmy 36:96847d42f010 305
The Other Jimmy 36:96847d42f010 306 _, toolchain_name = get_exporter_toolchain(ide)
The Other Jimmy 36:96847d42f010 307
The Other Jimmy 36:96847d42f010 308 ###################################
The Other Jimmy 36:96847d42f010 309 # mbed Classic/2.0/libary support #
The Other Jimmy 36:96847d42f010 310
The Other Jimmy 36:96847d42f010 311 # Find build system profile
The Other Jimmy 36:96847d42f010 312 profile = None
The Other Jimmy 36:96847d42f010 313 targets_json = None
The Other Jimmy 36:96847d42f010 314 for path in paths:
The Other Jimmy 36:96847d42f010 315 profile = find_build_profile(path) or profile
The Other Jimmy 36:96847d42f010 316 if profile:
The Other Jimmy 36:96847d42f010 317 targets_json = join(dirname(dirname(abspath(__file__))), 'legacy_targets.json')
The Other Jimmy 36:96847d42f010 318 else:
The Other Jimmy 36:96847d42f010 319 targets_json = find_targets_json(path) or targets_json
The Other Jimmy 36:96847d42f010 320
The Other Jimmy 36:96847d42f010 321 # Apply targets.json to active targets
The Other Jimmy 36:96847d42f010 322 if targets_json:
The Other Jimmy 36:96847d42f010 323 if not silent:
The Other Jimmy 36:96847d42f010 324 print("Using targets from %s" % targets_json)
The Other Jimmy 36:96847d42f010 325 set_targets_json_location(targets_json)
The Other Jimmy 36:96847d42f010 326
The Other Jimmy 36:96847d42f010 327 # Apply profile to toolchains
The Other Jimmy 36:96847d42f010 328 if profile:
The Other Jimmy 36:96847d42f010 329 def init_hook(self):
The Other Jimmy 36:96847d42f010 330 profile_data = get_toolchain_profile(self.name, profile)
The Other Jimmy 36:96847d42f010 331 if not profile_data:
The Other Jimmy 36:96847d42f010 332 return
The Other Jimmy 36:96847d42f010 333 if not silent:
The Other Jimmy 36:96847d42f010 334 self.info("Using toolchain %s profile %s" % (self.name, profile))
The Other Jimmy 36:96847d42f010 335
The Other Jimmy 36:96847d42f010 336 for k,v in profile_data.items():
The Other Jimmy 36:96847d42f010 337 if self.flags.has_key(k):
The Other Jimmy 36:96847d42f010 338 self.flags[k] = v
The Other Jimmy 36:96847d42f010 339 else:
The Other Jimmy 36:96847d42f010 340 setattr(self, k, v)
The Other Jimmy 36:96847d42f010 341
The Other Jimmy 36:96847d42f010 342 mbedToolchain.init = init_hook
The Other Jimmy 36:96847d42f010 343
The Other Jimmy 36:96847d42f010 344 # mbed Classic/2.0/libary support #
The Other Jimmy 36:96847d42f010 345 ###################################
The Other Jimmy 36:96847d42f010 346
The Other Jimmy 36:96847d42f010 347 # Pass all params to the unified prepare_resources()
The Other Jimmy 36:96847d42f010 348 toolchain = prepare_toolchain(
The Other Jimmy 36:96847d42f010 349 paths, "", target, toolchain_name, macros=macros, jobs=jobs,
The Other Jimmy 36:96847d42f010 350 notify=notify, silent=silent, verbose=verbose,
The Other Jimmy 36:96847d42f010 351 extra_verbose=extra_verbose, config=config, build_profile=build_profile,
The Other Jimmy 36:96847d42f010 352 app_config=app_config)
The Other Jimmy 36:96847d42f010 353 # The first path will give the name to the library
The Other Jimmy 36:96847d42f010 354 if name is None:
The Other Jimmy 36:96847d42f010 355 name = basename(normpath(abspath(src_paths[0])))
The Other Jimmy 36:96847d42f010 356
The Other Jimmy 36:96847d42f010 357 # Call unified scan_resources
The Other Jimmy 36:96847d42f010 358 resource_dict = {loc: scan_resources(path, toolchain, inc_dirs=inc_dirs)
The Other Jimmy 36:96847d42f010 359 for loc, path in src_paths.iteritems()}
The Other Jimmy 36:96847d42f010 360 resources = Resources()
The Other Jimmy 36:96847d42f010 361 toolchain.build_dir = export_path
The Other Jimmy 36:96847d42f010 362 config_header = toolchain.get_config_header()
The Other Jimmy 36:96847d42f010 363 resources.headers.append(config_header)
The Other Jimmy 36:96847d42f010 364 resources.file_basepath[config_header] = dirname(config_header)
The Other Jimmy 36:96847d42f010 365
The Other Jimmy 36:96847d42f010 366 if zip_proj:
The Other Jimmy 36:96847d42f010 367 subtract_basepath(resources, ".")
The Other Jimmy 36:96847d42f010 368 for loc, res in resource_dict.iteritems():
The Other Jimmy 36:96847d42f010 369 temp = copy.deepcopy(res)
The Other Jimmy 36:96847d42f010 370 subtract_basepath(temp, ".", loc)
The Other Jimmy 36:96847d42f010 371 resources.add(temp)
The Other Jimmy 36:96847d42f010 372 else:
The Other Jimmy 36:96847d42f010 373 for _, res in resource_dict.iteritems():
The Other Jimmy 36:96847d42f010 374 resources.add(res)
The Other Jimmy 36:96847d42f010 375
The Other Jimmy 36:96847d42f010 376 # Change linker script if specified
The Other Jimmy 36:96847d42f010 377 if linker_script is not None:
The Other Jimmy 36:96847d42f010 378 resources.linker_script = linker_script
The Other Jimmy 36:96847d42f010 379
The Other Jimmy 36:96847d42f010 380 files, exporter = generate_project_files(resources, export_path,
The Other Jimmy 36:96847d42f010 381 target, name, toolchain, ide,
The Other Jimmy 36:96847d42f010 382 macros=macros)
The Other Jimmy 36:96847d42f010 383 files.append(config_header)
The Other Jimmy 36:96847d42f010 384 if zip_proj:
The Other Jimmy 36:96847d42f010 385 for resource in resource_dict.values():
The Other Jimmy 36:96847d42f010 386 for label, res in resource.features.iteritems():
The Other Jimmy 36:96847d42f010 387 if label not in toolchain.target.features:
The Other Jimmy 36:96847d42f010 388 resource.add(res)
The Other Jimmy 36:96847d42f010 389 if isinstance(zip_proj, basestring):
The Other Jimmy 36:96847d42f010 390 zip_export(join(export_path, zip_proj), name, resource_dict, files,
The Other Jimmy 36:96847d42f010 391 inc_repos)
The Other Jimmy 36:96847d42f010 392 else:
The Other Jimmy 36:96847d42f010 393 zip_export(zip_proj, name, resource_dict, files, inc_repos)
The Other Jimmy 36:96847d42f010 394 else:
The Other Jimmy 36:96847d42f010 395 for exported in files:
The Other Jimmy 36:96847d42f010 396 if not exists(join(export_path, basename(exported))):
The Other Jimmy 36:96847d42f010 397 copyfile(exported, join(export_path, basename(exported)))
The Other Jimmy 36:96847d42f010 398
The Other Jimmy 36:96847d42f010 399 return exporter