mbed-os
Dependents: cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more
tools/make.py@0:b74591d5ab33, 2017-12-11 (annotated)
- Committer:
- be_bryan
- Date:
- Mon Dec 11 17:54:04 2017 +0000
- Revision:
- 0:b74591d5ab33
motor ++
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
be_bryan | 0:b74591d5ab33 | 1 | #! /usr/bin/env python2 |
be_bryan | 0:b74591d5ab33 | 2 | """ |
be_bryan | 0:b74591d5ab33 | 3 | mbed SDK |
be_bryan | 0:b74591d5ab33 | 4 | Copyright (c) 2011-2013 ARM Limited |
be_bryan | 0:b74591d5ab33 | 5 | |
be_bryan | 0:b74591d5ab33 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
be_bryan | 0:b74591d5ab33 | 7 | you may not use this file except in compliance with the License. |
be_bryan | 0:b74591d5ab33 | 8 | You may obtain a copy of the License at |
be_bryan | 0:b74591d5ab33 | 9 | |
be_bryan | 0:b74591d5ab33 | 10 | http://www.apache.org/licenses/LICENSE-2.0 |
be_bryan | 0:b74591d5ab33 | 11 | |
be_bryan | 0:b74591d5ab33 | 12 | Unless required by applicable law or agreed to in writing, software |
be_bryan | 0:b74591d5ab33 | 13 | distributed under the License is distributed on an "AS IS" BASIS, |
be_bryan | 0:b74591d5ab33 | 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
be_bryan | 0:b74591d5ab33 | 15 | See the License for the specific language governing permissions and |
be_bryan | 0:b74591d5ab33 | 16 | limitations under the License. |
be_bryan | 0:b74591d5ab33 | 17 | |
be_bryan | 0:b74591d5ab33 | 18 | |
be_bryan | 0:b74591d5ab33 | 19 | TEST BUILD & RUN |
be_bryan | 0:b74591d5ab33 | 20 | """ |
be_bryan | 0:b74591d5ab33 | 21 | import sys |
be_bryan | 0:b74591d5ab33 | 22 | import json |
be_bryan | 0:b74591d5ab33 | 23 | from time import sleep |
be_bryan | 0:b74591d5ab33 | 24 | from shutil import copy |
be_bryan | 0:b74591d5ab33 | 25 | from os.path import join, abspath, dirname |
be_bryan | 0:b74591d5ab33 | 26 | from json import load, dump |
be_bryan | 0:b74591d5ab33 | 27 | |
be_bryan | 0:b74591d5ab33 | 28 | # Be sure that the tools directory is in the search path |
be_bryan | 0:b74591d5ab33 | 29 | ROOT = abspath(join(dirname(__file__), "..")) |
be_bryan | 0:b74591d5ab33 | 30 | sys.path.insert(0, ROOT) |
be_bryan | 0:b74591d5ab33 | 31 | |
be_bryan | 0:b74591d5ab33 | 32 | from tools.utils import args_error |
be_bryan | 0:b74591d5ab33 | 33 | from tools.utils import NotSupportedException |
be_bryan | 0:b74591d5ab33 | 34 | from tools.paths import BUILD_DIR |
be_bryan | 0:b74591d5ab33 | 35 | from tools.paths import MBED_LIBRARIES |
be_bryan | 0:b74591d5ab33 | 36 | from tools.paths import RPC_LIBRARY |
be_bryan | 0:b74591d5ab33 | 37 | from tools.paths import USB_LIBRARIES |
be_bryan | 0:b74591d5ab33 | 38 | from tools.paths import DSP_LIBRARIES |
be_bryan | 0:b74591d5ab33 | 39 | from tools.tests import TESTS, Test, TEST_MAP |
be_bryan | 0:b74591d5ab33 | 40 | from tools.tests import TEST_MBED_LIB |
be_bryan | 0:b74591d5ab33 | 41 | from tools.tests import test_known, test_name_known |
be_bryan | 0:b74591d5ab33 | 42 | from tools.targets import TARGET_MAP |
be_bryan | 0:b74591d5ab33 | 43 | from tools.options import get_default_options_parser |
be_bryan | 0:b74591d5ab33 | 44 | from tools.options import extract_profile |
be_bryan | 0:b74591d5ab33 | 45 | from tools.options import extract_mcus |
be_bryan | 0:b74591d5ab33 | 46 | from tools.build_api import build_project |
be_bryan | 0:b74591d5ab33 | 47 | from tools.build_api import mcu_toolchain_matrix |
be_bryan | 0:b74591d5ab33 | 48 | from tools.build_api import mcu_toolchain_list |
be_bryan | 0:b74591d5ab33 | 49 | from tools.build_api import mcu_target_list |
be_bryan | 0:b74591d5ab33 | 50 | from tools.build_api import merge_build_data |
be_bryan | 0:b74591d5ab33 | 51 | from utils import argparse_filestring_type |
be_bryan | 0:b74591d5ab33 | 52 | from utils import argparse_many |
be_bryan | 0:b74591d5ab33 | 53 | from utils import argparse_dir_not_parent |
be_bryan | 0:b74591d5ab33 | 54 | from tools.toolchains import mbedToolchain, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS |
be_bryan | 0:b74591d5ab33 | 55 | from tools.settings import CLI_COLOR_MAP |
be_bryan | 0:b74591d5ab33 | 56 | |
be_bryan | 0:b74591d5ab33 | 57 | if __name__ == '__main__': |
be_bryan | 0:b74591d5ab33 | 58 | # Parse Options |
be_bryan | 0:b74591d5ab33 | 59 | parser = get_default_options_parser(add_app_config=True) |
be_bryan | 0:b74591d5ab33 | 60 | group = parser.add_mutually_exclusive_group(required=False) |
be_bryan | 0:b74591d5ab33 | 61 | group.add_argument( |
be_bryan | 0:b74591d5ab33 | 62 | "-p", |
be_bryan | 0:b74591d5ab33 | 63 | type=argparse_many(test_known), |
be_bryan | 0:b74591d5ab33 | 64 | dest="program", |
be_bryan | 0:b74591d5ab33 | 65 | help="The index of the desired test program: [0-%d]" % (len(TESTS)-1)) |
be_bryan | 0:b74591d5ab33 | 66 | |
be_bryan | 0:b74591d5ab33 | 67 | group.add_argument( |
be_bryan | 0:b74591d5ab33 | 68 | "-n", |
be_bryan | 0:b74591d5ab33 | 69 | type=argparse_many(test_name_known), |
be_bryan | 0:b74591d5ab33 | 70 | dest="program", |
be_bryan | 0:b74591d5ab33 | 71 | help="The name of the desired test program") |
be_bryan | 0:b74591d5ab33 | 72 | |
be_bryan | 0:b74591d5ab33 | 73 | parser.add_argument( |
be_bryan | 0:b74591d5ab33 | 74 | "-j", "--jobs", |
be_bryan | 0:b74591d5ab33 | 75 | type=int, |
be_bryan | 0:b74591d5ab33 | 76 | dest="jobs", |
be_bryan | 0:b74591d5ab33 | 77 | default=0, |
be_bryan | 0:b74591d5ab33 | 78 | help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)") |
be_bryan | 0:b74591d5ab33 | 79 | |
be_bryan | 0:b74591d5ab33 | 80 | parser.add_argument( |
be_bryan | 0:b74591d5ab33 | 81 | "-v", "--verbose", |
be_bryan | 0:b74591d5ab33 | 82 | action="store_true", |
be_bryan | 0:b74591d5ab33 | 83 | dest="verbose", |
be_bryan | 0:b74591d5ab33 | 84 | default=False, |
be_bryan | 0:b74591d5ab33 | 85 | help="Verbose diagnostic output") |
be_bryan | 0:b74591d5ab33 | 86 | |
be_bryan | 0:b74591d5ab33 | 87 | parser.add_argument( |
be_bryan | 0:b74591d5ab33 | 88 | "--silent", |
be_bryan | 0:b74591d5ab33 | 89 | action="store_true", |
be_bryan | 0:b74591d5ab33 | 90 | dest="silent", |
be_bryan | 0:b74591d5ab33 | 91 | default=False, |
be_bryan | 0:b74591d5ab33 | 92 | help="Silent diagnostic output (no copy, compile notification)") |
be_bryan | 0:b74591d5ab33 | 93 | |
be_bryan | 0:b74591d5ab33 | 94 | parser.add_argument( |
be_bryan | 0:b74591d5ab33 | 95 | "-D", |
be_bryan | 0:b74591d5ab33 | 96 | action="append", |
be_bryan | 0:b74591d5ab33 | 97 | dest="macros", |
be_bryan | 0:b74591d5ab33 | 98 | help="Add a macro definition") |
be_bryan | 0:b74591d5ab33 | 99 | |
be_bryan | 0:b74591d5ab33 | 100 | group.add_argument( |
be_bryan | 0:b74591d5ab33 | 101 | "-S", "--supported-toolchains", |
be_bryan | 0:b74591d5ab33 | 102 | dest="supported_toolchains", |
be_bryan | 0:b74591d5ab33 | 103 | default=False, |
be_bryan | 0:b74591d5ab33 | 104 | const="matrix", |
be_bryan | 0:b74591d5ab33 | 105 | choices=["matrix", "toolchains", "targets"], |
be_bryan | 0:b74591d5ab33 | 106 | nargs="?", |
be_bryan | 0:b74591d5ab33 | 107 | help="Displays supported matrix of MCUs and toolchains") |
be_bryan | 0:b74591d5ab33 | 108 | |
be_bryan | 0:b74591d5ab33 | 109 | parser.add_argument( |
be_bryan | 0:b74591d5ab33 | 110 | '-f', '--filter', |
be_bryan | 0:b74591d5ab33 | 111 | dest='general_filter_regex', |
be_bryan | 0:b74591d5ab33 | 112 | default=None, |
be_bryan | 0:b74591d5ab33 | 113 | help='For some commands you can use filter to filter out results') |
be_bryan | 0:b74591d5ab33 | 114 | |
be_bryan | 0:b74591d5ab33 | 115 | parser.add_argument( |
be_bryan | 0:b74591d5ab33 | 116 | "--stats-depth", |
be_bryan | 0:b74591d5ab33 | 117 | type=int, |
be_bryan | 0:b74591d5ab33 | 118 | dest="stats_depth", |
be_bryan | 0:b74591d5ab33 | 119 | default=2, |
be_bryan | 0:b74591d5ab33 | 120 | help="Depth level for static memory report") |
be_bryan | 0:b74591d5ab33 | 121 | |
be_bryan | 0:b74591d5ab33 | 122 | # Local run |
be_bryan | 0:b74591d5ab33 | 123 | parser.add_argument("--automated", action="store_true", dest="automated", |
be_bryan | 0:b74591d5ab33 | 124 | default=False, help="Automated test") |
be_bryan | 0:b74591d5ab33 | 125 | parser.add_argument("--host", dest="host_test", |
be_bryan | 0:b74591d5ab33 | 126 | default=None, help="Host test") |
be_bryan | 0:b74591d5ab33 | 127 | parser.add_argument("--extra", dest="extra", |
be_bryan | 0:b74591d5ab33 | 128 | default=None, help="Extra files") |
be_bryan | 0:b74591d5ab33 | 129 | parser.add_argument("--peripherals", dest="peripherals", |
be_bryan | 0:b74591d5ab33 | 130 | default=None, help="Required peripherals") |
be_bryan | 0:b74591d5ab33 | 131 | parser.add_argument("--dep", dest="dependencies", |
be_bryan | 0:b74591d5ab33 | 132 | default=None, help="Dependencies") |
be_bryan | 0:b74591d5ab33 | 133 | parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type, |
be_bryan | 0:b74591d5ab33 | 134 | default=None, help="The source (input) directory", action="append") |
be_bryan | 0:b74591d5ab33 | 135 | parser.add_argument("--duration", type=int, dest="duration", |
be_bryan | 0:b74591d5ab33 | 136 | default=None, help="Duration of the test") |
be_bryan | 0:b74591d5ab33 | 137 | parser.add_argument("--build", dest="build_dir", type=argparse_dir_not_parent(ROOT), |
be_bryan | 0:b74591d5ab33 | 138 | default=None, help="The build (output) directory") |
be_bryan | 0:b74591d5ab33 | 139 | parser.add_argument("-N", "--artifact-name", dest="artifact_name", |
be_bryan | 0:b74591d5ab33 | 140 | default=None, help="The built project's name") |
be_bryan | 0:b74591d5ab33 | 141 | parser.add_argument("-d", "--disk", dest="disk", |
be_bryan | 0:b74591d5ab33 | 142 | default=None, help="The mbed disk") |
be_bryan | 0:b74591d5ab33 | 143 | parser.add_argument("-s", "--serial", dest="serial", |
be_bryan | 0:b74591d5ab33 | 144 | default=None, help="The mbed serial port") |
be_bryan | 0:b74591d5ab33 | 145 | parser.add_argument("-b", "--baud", type=int, dest="baud", |
be_bryan | 0:b74591d5ab33 | 146 | default=None, help="The mbed serial baud rate") |
be_bryan | 0:b74591d5ab33 | 147 | group.add_argument("-L", "--list-tests", action="store_true", dest="list_tests", |
be_bryan | 0:b74591d5ab33 | 148 | default=False, help="List available tests in order and exit") |
be_bryan | 0:b74591d5ab33 | 149 | |
be_bryan | 0:b74591d5ab33 | 150 | # Ideally, all the tests with a single "main" thread can be run with, or |
be_bryan | 0:b74591d5ab33 | 151 | # without the usb, dsp |
be_bryan | 0:b74591d5ab33 | 152 | parser.add_argument("--rpc", |
be_bryan | 0:b74591d5ab33 | 153 | action="store_true", dest="rpc", |
be_bryan | 0:b74591d5ab33 | 154 | default=False, help="Link with RPC library") |
be_bryan | 0:b74591d5ab33 | 155 | |
be_bryan | 0:b74591d5ab33 | 156 | parser.add_argument("--usb", |
be_bryan | 0:b74591d5ab33 | 157 | action="store_true", |
be_bryan | 0:b74591d5ab33 | 158 | dest="usb", |
be_bryan | 0:b74591d5ab33 | 159 | default=False, |
be_bryan | 0:b74591d5ab33 | 160 | help="Link with USB Device library") |
be_bryan | 0:b74591d5ab33 | 161 | |
be_bryan | 0:b74591d5ab33 | 162 | parser.add_argument("--dsp", |
be_bryan | 0:b74591d5ab33 | 163 | action="store_true", |
be_bryan | 0:b74591d5ab33 | 164 | dest="dsp", |
be_bryan | 0:b74591d5ab33 | 165 | default=False, |
be_bryan | 0:b74591d5ab33 | 166 | help="Link with DSP library") |
be_bryan | 0:b74591d5ab33 | 167 | |
be_bryan | 0:b74591d5ab33 | 168 | parser.add_argument("--testlib", |
be_bryan | 0:b74591d5ab33 | 169 | action="store_true", |
be_bryan | 0:b74591d5ab33 | 170 | dest="testlib", |
be_bryan | 0:b74591d5ab33 | 171 | default=False, |
be_bryan | 0:b74591d5ab33 | 172 | help="Link with mbed test library") |
be_bryan | 0:b74591d5ab33 | 173 | |
be_bryan | 0:b74591d5ab33 | 174 | parser.add_argument("--build-data", |
be_bryan | 0:b74591d5ab33 | 175 | dest="build_data", |
be_bryan | 0:b74591d5ab33 | 176 | default=None, |
be_bryan | 0:b74591d5ab33 | 177 | help="Dump build_data to this file") |
be_bryan | 0:b74591d5ab33 | 178 | |
be_bryan | 0:b74591d5ab33 | 179 | # Specify a different linker script |
be_bryan | 0:b74591d5ab33 | 180 | parser.add_argument("-l", "--linker", dest="linker_script", |
be_bryan | 0:b74591d5ab33 | 181 | type=argparse_filestring_type, |
be_bryan | 0:b74591d5ab33 | 182 | default=None, help="use the specified linker script") |
be_bryan | 0:b74591d5ab33 | 183 | |
be_bryan | 0:b74591d5ab33 | 184 | options = parser.parse_args() |
be_bryan | 0:b74591d5ab33 | 185 | |
be_bryan | 0:b74591d5ab33 | 186 | # Only prints matrix of supported toolchains |
be_bryan | 0:b74591d5ab33 | 187 | if options.supported_toolchains: |
be_bryan | 0:b74591d5ab33 | 188 | if options.supported_toolchains == "matrix": |
be_bryan | 0:b74591d5ab33 | 189 | print mcu_toolchain_matrix(platform_filter=options.general_filter_regex) |
be_bryan | 0:b74591d5ab33 | 190 | elif options.supported_toolchains == "toolchains": |
be_bryan | 0:b74591d5ab33 | 191 | toolchain_list = mcu_toolchain_list() |
be_bryan | 0:b74591d5ab33 | 192 | # Only print the lines that matter |
be_bryan | 0:b74591d5ab33 | 193 | for line in toolchain_list.split("\n"): |
be_bryan | 0:b74591d5ab33 | 194 | if not "mbed" in line: |
be_bryan | 0:b74591d5ab33 | 195 | print line |
be_bryan | 0:b74591d5ab33 | 196 | elif options.supported_toolchains == "targets": |
be_bryan | 0:b74591d5ab33 | 197 | print mcu_target_list() |
be_bryan | 0:b74591d5ab33 | 198 | exit(0) |
be_bryan | 0:b74591d5ab33 | 199 | |
be_bryan | 0:b74591d5ab33 | 200 | # Print available tests in order and exit |
be_bryan | 0:b74591d5ab33 | 201 | if options.list_tests is True: |
be_bryan | 0:b74591d5ab33 | 202 | print '\n'.join(map(str, sorted(TEST_MAP.values()))) |
be_bryan | 0:b74591d5ab33 | 203 | sys.exit() |
be_bryan | 0:b74591d5ab33 | 204 | |
be_bryan | 0:b74591d5ab33 | 205 | # force program to "0" if a source dir is specified |
be_bryan | 0:b74591d5ab33 | 206 | if options.source_dir is not None: |
be_bryan | 0:b74591d5ab33 | 207 | p = 0 |
be_bryan | 0:b74591d5ab33 | 208 | else: |
be_bryan | 0:b74591d5ab33 | 209 | # Program Number or name |
be_bryan | 0:b74591d5ab33 | 210 | p = options.program |
be_bryan | 0:b74591d5ab33 | 211 | |
be_bryan | 0:b74591d5ab33 | 212 | # If 'p' was set via -n to list of numbers make this a single element integer list |
be_bryan | 0:b74591d5ab33 | 213 | if type(p) != type([]): |
be_bryan | 0:b74591d5ab33 | 214 | p = [p] |
be_bryan | 0:b74591d5ab33 | 215 | |
be_bryan | 0:b74591d5ab33 | 216 | # Target |
be_bryan | 0:b74591d5ab33 | 217 | if options.mcu is None : |
be_bryan | 0:b74591d5ab33 | 218 | args_error(parser, "argument -m/--mcu is required") |
be_bryan | 0:b74591d5ab33 | 219 | mcu = extract_mcus(parser, options)[0] |
be_bryan | 0:b74591d5ab33 | 220 | |
be_bryan | 0:b74591d5ab33 | 221 | # Toolchain |
be_bryan | 0:b74591d5ab33 | 222 | if options.tool is None: |
be_bryan | 0:b74591d5ab33 | 223 | args_error(parser, "argument -t/--tool is required") |
be_bryan | 0:b74591d5ab33 | 224 | toolchain = options.tool[0] |
be_bryan | 0:b74591d5ab33 | 225 | |
be_bryan | 0:b74591d5ab33 | 226 | if (options.program is None) and (not options.source_dir): |
be_bryan | 0:b74591d5ab33 | 227 | args_error(parser, "one of -p, -n, or --source is required") |
be_bryan | 0:b74591d5ab33 | 228 | |
be_bryan | 0:b74591d5ab33 | 229 | if options.source_dir and not options.build_dir: |
be_bryan | 0:b74591d5ab33 | 230 | args_error(parser, "argument --build is required when argument --source is provided") |
be_bryan | 0:b74591d5ab33 | 231 | |
be_bryan | 0:b74591d5ab33 | 232 | |
be_bryan | 0:b74591d5ab33 | 233 | if options.color: |
be_bryan | 0:b74591d5ab33 | 234 | # This import happens late to prevent initializing colorization when we don't need it |
be_bryan | 0:b74591d5ab33 | 235 | import colorize |
be_bryan | 0:b74591d5ab33 | 236 | if options.verbose: |
be_bryan | 0:b74591d5ab33 | 237 | notify = mbedToolchain.print_notify_verbose |
be_bryan | 0:b74591d5ab33 | 238 | else: |
be_bryan | 0:b74591d5ab33 | 239 | notify = mbedToolchain.print_notify |
be_bryan | 0:b74591d5ab33 | 240 | notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify) |
be_bryan | 0:b74591d5ab33 | 241 | else: |
be_bryan | 0:b74591d5ab33 | 242 | notify = None |
be_bryan | 0:b74591d5ab33 | 243 | |
be_bryan | 0:b74591d5ab33 | 244 | if not TOOLCHAIN_CLASSES[toolchain].check_executable(): |
be_bryan | 0:b74591d5ab33 | 245 | search_path = TOOLCHAIN_PATHS[toolchain] or "No path set" |
be_bryan | 0:b74591d5ab33 | 246 | args_error(parser, "Could not find executable for %s.\n" |
be_bryan | 0:b74591d5ab33 | 247 | "Currently set search path: %s" |
be_bryan | 0:b74591d5ab33 | 248 | %(toolchain,search_path)) |
be_bryan | 0:b74591d5ab33 | 249 | |
be_bryan | 0:b74591d5ab33 | 250 | # Test |
be_bryan | 0:b74591d5ab33 | 251 | build_data_blob = {} if options.build_data else None |
be_bryan | 0:b74591d5ab33 | 252 | for test_no in p: |
be_bryan | 0:b74591d5ab33 | 253 | test = Test(test_no) |
be_bryan | 0:b74591d5ab33 | 254 | if options.automated is not None: test.automated = options.automated |
be_bryan | 0:b74591d5ab33 | 255 | if options.dependencies is not None: test.dependencies = options.dependencies |
be_bryan | 0:b74591d5ab33 | 256 | if options.host_test is not None: test.host_test = options.host_test; |
be_bryan | 0:b74591d5ab33 | 257 | if options.peripherals is not None: test.peripherals = options.peripherals; |
be_bryan | 0:b74591d5ab33 | 258 | if options.duration is not None: test.duration = options.duration; |
be_bryan | 0:b74591d5ab33 | 259 | if options.extra is not None: test.extra_files = options.extra |
be_bryan | 0:b74591d5ab33 | 260 | |
be_bryan | 0:b74591d5ab33 | 261 | if not test.is_supported(mcu, toolchain): |
be_bryan | 0:b74591d5ab33 | 262 | print 'The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain) |
be_bryan | 0:b74591d5ab33 | 263 | sys.exit() |
be_bryan | 0:b74591d5ab33 | 264 | |
be_bryan | 0:b74591d5ab33 | 265 | # Linking with extra libraries |
be_bryan | 0:b74591d5ab33 | 266 | if options.rpc: test.dependencies.append(RPC_LIBRARY) |
be_bryan | 0:b74591d5ab33 | 267 | if options.usb: test.dependencies.append(USB_LIBRARIES) |
be_bryan | 0:b74591d5ab33 | 268 | if options.dsp: test.dependencies.append(DSP_LIBRARIES) |
be_bryan | 0:b74591d5ab33 | 269 | if options.testlib: test.dependencies.append(TEST_MBED_LIB) |
be_bryan | 0:b74591d5ab33 | 270 | |
be_bryan | 0:b74591d5ab33 | 271 | build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id) |
be_bryan | 0:b74591d5ab33 | 272 | if options.source_dir is not None: |
be_bryan | 0:b74591d5ab33 | 273 | test.source_dir = options.source_dir |
be_bryan | 0:b74591d5ab33 | 274 | build_dir = options.source_dir |
be_bryan | 0:b74591d5ab33 | 275 | |
be_bryan | 0:b74591d5ab33 | 276 | if options.build_dir is not None: |
be_bryan | 0:b74591d5ab33 | 277 | build_dir = options.build_dir |
be_bryan | 0:b74591d5ab33 | 278 | |
be_bryan | 0:b74591d5ab33 | 279 | try: |
be_bryan | 0:b74591d5ab33 | 280 | bin_file = build_project(test.source_dir, build_dir, mcu, toolchain, |
be_bryan | 0:b74591d5ab33 | 281 | set(test.dependencies), |
be_bryan | 0:b74591d5ab33 | 282 | linker_script=options.linker_script, |
be_bryan | 0:b74591d5ab33 | 283 | clean=options.clean, |
be_bryan | 0:b74591d5ab33 | 284 | verbose=options.verbose, |
be_bryan | 0:b74591d5ab33 | 285 | notify=notify, |
be_bryan | 0:b74591d5ab33 | 286 | report=build_data_blob, |
be_bryan | 0:b74591d5ab33 | 287 | silent=options.silent, |
be_bryan | 0:b74591d5ab33 | 288 | macros=options.macros, |
be_bryan | 0:b74591d5ab33 | 289 | jobs=options.jobs, |
be_bryan | 0:b74591d5ab33 | 290 | name=options.artifact_name, |
be_bryan | 0:b74591d5ab33 | 291 | app_config=options.app_config, |
be_bryan | 0:b74591d5ab33 | 292 | inc_dirs=[dirname(MBED_LIBRARIES)], |
be_bryan | 0:b74591d5ab33 | 293 | build_profile=extract_profile(parser, |
be_bryan | 0:b74591d5ab33 | 294 | options, |
be_bryan | 0:b74591d5ab33 | 295 | toolchain), |
be_bryan | 0:b74591d5ab33 | 296 | stats_depth=options.stats_depth) |
be_bryan | 0:b74591d5ab33 | 297 | print 'Image: %s'% bin_file |
be_bryan | 0:b74591d5ab33 | 298 | |
be_bryan | 0:b74591d5ab33 | 299 | if options.disk: |
be_bryan | 0:b74591d5ab33 | 300 | # Simple copy to the mbed disk |
be_bryan | 0:b74591d5ab33 | 301 | copy(bin_file, options.disk) |
be_bryan | 0:b74591d5ab33 | 302 | |
be_bryan | 0:b74591d5ab33 | 303 | if options.serial: |
be_bryan | 0:b74591d5ab33 | 304 | # Import pyserial: https://pypi.python.org/pypi/pyserial |
be_bryan | 0:b74591d5ab33 | 305 | from serial import Serial |
be_bryan | 0:b74591d5ab33 | 306 | |
be_bryan | 0:b74591d5ab33 | 307 | sleep(TARGET_MAP[mcu].program_cycle_s) |
be_bryan | 0:b74591d5ab33 | 308 | |
be_bryan | 0:b74591d5ab33 | 309 | serial = Serial(options.serial, timeout = 1) |
be_bryan | 0:b74591d5ab33 | 310 | if options.baud: |
be_bryan | 0:b74591d5ab33 | 311 | serial.setBaudrate(options.baud) |
be_bryan | 0:b74591d5ab33 | 312 | |
be_bryan | 0:b74591d5ab33 | 313 | serial.flushInput() |
be_bryan | 0:b74591d5ab33 | 314 | serial.flushOutput() |
be_bryan | 0:b74591d5ab33 | 315 | |
be_bryan | 0:b74591d5ab33 | 316 | try: |
be_bryan | 0:b74591d5ab33 | 317 | serial.sendBreak() |
be_bryan | 0:b74591d5ab33 | 318 | except: |
be_bryan | 0:b74591d5ab33 | 319 | # In linux a termios.error is raised in sendBreak and in setBreak. |
be_bryan | 0:b74591d5ab33 | 320 | # The following setBreak() is needed to release the reset signal on the target mcu. |
be_bryan | 0:b74591d5ab33 | 321 | try: |
be_bryan | 0:b74591d5ab33 | 322 | serial.setBreak(False) |
be_bryan | 0:b74591d5ab33 | 323 | except: |
be_bryan | 0:b74591d5ab33 | 324 | pass |
be_bryan | 0:b74591d5ab33 | 325 | |
be_bryan | 0:b74591d5ab33 | 326 | while True: |
be_bryan | 0:b74591d5ab33 | 327 | c = serial.read(512) |
be_bryan | 0:b74591d5ab33 | 328 | sys.stdout.write(c) |
be_bryan | 0:b74591d5ab33 | 329 | sys.stdout.flush() |
be_bryan | 0:b74591d5ab33 | 330 | |
be_bryan | 0:b74591d5ab33 | 331 | except KeyboardInterrupt, e: |
be_bryan | 0:b74591d5ab33 | 332 | print "\n[CTRL+c] exit" |
be_bryan | 0:b74591d5ab33 | 333 | except NotSupportedException as e: |
be_bryan | 0:b74591d5ab33 | 334 | print "\nCould not compile for %s: %s" % (mcu, str(e)) |
be_bryan | 0:b74591d5ab33 | 335 | except Exception,e: |
be_bryan | 0:b74591d5ab33 | 336 | if options.verbose: |
be_bryan | 0:b74591d5ab33 | 337 | import traceback |
be_bryan | 0:b74591d5ab33 | 338 | traceback.print_exc(file=sys.stdout) |
be_bryan | 0:b74591d5ab33 | 339 | else: |
be_bryan | 0:b74591d5ab33 | 340 | print "[ERROR] %s" % str(e) |
be_bryan | 0:b74591d5ab33 | 341 | |
be_bryan | 0:b74591d5ab33 | 342 | sys.exit(1) |
be_bryan | 0:b74591d5ab33 | 343 | if options.build_data: |
be_bryan | 0:b74591d5ab33 | 344 | merge_build_data(options.build_data, build_data_blob, "application") |