Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:380207fcb5c1 1 #! /usr/bin/env python2
borlanic 0:380207fcb5c1 2 """
borlanic 0:380207fcb5c1 3 mbed SDK
borlanic 0:380207fcb5c1 4 Copyright (c) 2011-2013 ARM Limited
borlanic 0:380207fcb5c1 5
borlanic 0:380207fcb5c1 6 Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:380207fcb5c1 7 you may not use this file except in compliance with the License.
borlanic 0:380207fcb5c1 8 You may obtain a copy of the License at
borlanic 0:380207fcb5c1 9
borlanic 0:380207fcb5c1 10 http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:380207fcb5c1 11
borlanic 0:380207fcb5c1 12 Unless required by applicable law or agreed to in writing, software
borlanic 0:380207fcb5c1 13 distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:380207fcb5c1 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:380207fcb5c1 15 See the License for the specific language governing permissions and
borlanic 0:380207fcb5c1 16 limitations under the License.
borlanic 0:380207fcb5c1 17
borlanic 0:380207fcb5c1 18 LIBRARIES BUILD
borlanic 0:380207fcb5c1 19 """
borlanic 0:380207fcb5c1 20 from __future__ import print_function, division, absolute_import
borlanic 0:380207fcb5c1 21
borlanic 0:380207fcb5c1 22 import sys
borlanic 0:380207fcb5c1 23 from time import time
borlanic 0:380207fcb5c1 24 from os.path import join, abspath, dirname
borlanic 0:380207fcb5c1 25
borlanic 0:380207fcb5c1 26
borlanic 0:380207fcb5c1 27 # Be sure that the tools directory is in the search path
borlanic 0:380207fcb5c1 28 ROOT = abspath(join(dirname(__file__), ".."))
borlanic 0:380207fcb5c1 29 sys.path.insert(0, ROOT)
borlanic 0:380207fcb5c1 30
borlanic 0:380207fcb5c1 31
borlanic 0:380207fcb5c1 32 from tools.toolchains import TOOLCHAINS, TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS
borlanic 0:380207fcb5c1 33 from tools.toolchains import mbedToolchain
borlanic 0:380207fcb5c1 34 from tools.targets import TARGET_NAMES, TARGET_MAP
borlanic 0:380207fcb5c1 35 from tools.options import get_default_options_parser
borlanic 0:380207fcb5c1 36 from tools.options import extract_profile
borlanic 0:380207fcb5c1 37 from tools.options import extract_mcus
borlanic 0:380207fcb5c1 38 from tools.build_api import build_library, build_mbed_libs, build_lib
borlanic 0:380207fcb5c1 39 from tools.build_api import mcu_toolchain_matrix
borlanic 0:380207fcb5c1 40 from tools.build_api import print_build_results
borlanic 0:380207fcb5c1 41 from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT
borlanic 0:380207fcb5c1 42 from utils import argparse_filestring_type, args_error
borlanic 0:380207fcb5c1 43 from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, CLI_COLOR_MAP
borlanic 0:380207fcb5c1 44 from utils import argparse_filestring_type, argparse_dir_not_parent
borlanic 0:380207fcb5c1 45
borlanic 0:380207fcb5c1 46 if __name__ == '__main__':
borlanic 0:380207fcb5c1 47 start = time()
borlanic 0:380207fcb5c1 48
borlanic 0:380207fcb5c1 49 # Parse Options
borlanic 0:380207fcb5c1 50 parser = get_default_options_parser()
borlanic 0:380207fcb5c1 51
borlanic 0:380207fcb5c1 52 parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type,
borlanic 0:380207fcb5c1 53 default=None, help="The source (input) directory", action="append")
borlanic 0:380207fcb5c1 54
borlanic 0:380207fcb5c1 55 parser.add_argument("--build", dest="build_dir", type=argparse_dir_not_parent(ROOT),
borlanic 0:380207fcb5c1 56 default=None, help="The build (output) directory")
borlanic 0:380207fcb5c1 57
borlanic 0:380207fcb5c1 58 parser.add_argument("--no-archive", dest="no_archive", action="store_true",
borlanic 0:380207fcb5c1 59 default=False, help="Do not produce archive (.ar) file, but rather .o")
borlanic 0:380207fcb5c1 60
borlanic 0:380207fcb5c1 61 # Extra libraries
borlanic 0:380207fcb5c1 62 parser.add_argument("-r", "--rtos",
borlanic 0:380207fcb5c1 63 action="store_true",
borlanic 0:380207fcb5c1 64 dest="rtos",
borlanic 0:380207fcb5c1 65 default=False,
borlanic 0:380207fcb5c1 66 help="Compile the rtos")
borlanic 0:380207fcb5c1 67
borlanic 0:380207fcb5c1 68 parser.add_argument("--rpc",
borlanic 0:380207fcb5c1 69 action="store_true",
borlanic 0:380207fcb5c1 70 dest="rpc",
borlanic 0:380207fcb5c1 71 default=False,
borlanic 0:380207fcb5c1 72 help="Compile the rpc library")
borlanic 0:380207fcb5c1 73
borlanic 0:380207fcb5c1 74 parser.add_argument("-u", "--usb",
borlanic 0:380207fcb5c1 75 action="store_true",
borlanic 0:380207fcb5c1 76 dest="usb",
borlanic 0:380207fcb5c1 77 default=False,
borlanic 0:380207fcb5c1 78 help="Compile the USB Device library")
borlanic 0:380207fcb5c1 79
borlanic 0:380207fcb5c1 80 parser.add_argument("-d", "--dsp",
borlanic 0:380207fcb5c1 81 action="store_true",
borlanic 0:380207fcb5c1 82 dest="dsp",
borlanic 0:380207fcb5c1 83 default=False,
borlanic 0:380207fcb5c1 84 help="Compile the DSP library")
borlanic 0:380207fcb5c1 85
borlanic 0:380207fcb5c1 86 parser.add_argument( "--cpputest",
borlanic 0:380207fcb5c1 87 action="store_true",
borlanic 0:380207fcb5c1 88 dest="cpputest_lib",
borlanic 0:380207fcb5c1 89 default=False,
borlanic 0:380207fcb5c1 90 help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)")
borlanic 0:380207fcb5c1 91
borlanic 0:380207fcb5c1 92 parser.add_argument("-D",
borlanic 0:380207fcb5c1 93 action="append",
borlanic 0:380207fcb5c1 94 dest="macros",
borlanic 0:380207fcb5c1 95 help="Add a macro definition")
borlanic 0:380207fcb5c1 96
borlanic 0:380207fcb5c1 97 parser.add_argument("-S", "--supported-toolchains",
borlanic 0:380207fcb5c1 98 action="store_true",
borlanic 0:380207fcb5c1 99 dest="supported_toolchains",
borlanic 0:380207fcb5c1 100 default=False,
borlanic 0:380207fcb5c1 101 help="Displays supported matrix of MCUs and toolchains")
borlanic 0:380207fcb5c1 102
borlanic 0:380207fcb5c1 103 parser.add_argument('-f', '--filter',
borlanic 0:380207fcb5c1 104 dest='general_filter_regex',
borlanic 0:380207fcb5c1 105 default=None,
borlanic 0:380207fcb5c1 106 help='For some commands you can use filter to filter out results')
borlanic 0:380207fcb5c1 107
borlanic 0:380207fcb5c1 108 parser.add_argument("-j", "--jobs", type=int, dest="jobs",
borlanic 0:380207fcb5c1 109 default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)")
borlanic 0:380207fcb5c1 110 parser.add_argument("-N", "--artifact-name", dest="artifact_name",
borlanic 0:380207fcb5c1 111 default=None, help="The built project's name")
borlanic 0:380207fcb5c1 112
borlanic 0:380207fcb5c1 113 parser.add_argument("-v", "--verbose",
borlanic 0:380207fcb5c1 114 action="store_true",
borlanic 0:380207fcb5c1 115 dest="verbose",
borlanic 0:380207fcb5c1 116 default=False,
borlanic 0:380207fcb5c1 117 help="Verbose diagnostic output")
borlanic 0:380207fcb5c1 118
borlanic 0:380207fcb5c1 119 parser.add_argument("--silent",
borlanic 0:380207fcb5c1 120 action="store_true",
borlanic 0:380207fcb5c1 121 dest="silent",
borlanic 0:380207fcb5c1 122 default=False,
borlanic 0:380207fcb5c1 123 help="Silent diagnostic output (no copy, compile notification)")
borlanic 0:380207fcb5c1 124
borlanic 0:380207fcb5c1 125 parser.add_argument("-x", "--extra-verbose-notifications",
borlanic 0:380207fcb5c1 126 action="store_true",
borlanic 0:380207fcb5c1 127 dest="extra_verbose_notify",
borlanic 0:380207fcb5c1 128 default=False,
borlanic 0:380207fcb5c1 129 help="Makes compiler more verbose, CI friendly.")
borlanic 0:380207fcb5c1 130
borlanic 0:380207fcb5c1 131 options = parser.parse_args()
borlanic 0:380207fcb5c1 132
borlanic 0:380207fcb5c1 133 # Only prints matrix of supported toolchains
borlanic 0:380207fcb5c1 134 if options.supported_toolchains:
borlanic 0:380207fcb5c1 135 print(mcu_toolchain_matrix(platform_filter=options.general_filter_regex))
borlanic 0:380207fcb5c1 136 exit(0)
borlanic 0:380207fcb5c1 137
borlanic 0:380207fcb5c1 138
borlanic 0:380207fcb5c1 139 # Get target list
borlanic 0:380207fcb5c1 140 targets = extract_mcus(parser, options) if options.mcu else TARGET_NAMES
borlanic 0:380207fcb5c1 141
borlanic 0:380207fcb5c1 142 # Get toolchains list
borlanic 0:380207fcb5c1 143 toolchains = options.tool if options.tool else TOOLCHAINS
borlanic 0:380207fcb5c1 144
borlanic 0:380207fcb5c1 145 if options.source_dir and not options.build_dir:
borlanic 0:380207fcb5c1 146 args_error(parser, "argument --build is required by argument --source")
borlanic 0:380207fcb5c1 147
borlanic 0:380207fcb5c1 148 if options.color:
borlanic 0:380207fcb5c1 149 # This import happens late to prevent initializing colorization when we don't need it
borlanic 0:380207fcb5c1 150 import colorize
borlanic 0:380207fcb5c1 151 if options.verbose:
borlanic 0:380207fcb5c1 152 notify = mbedToolchain.print_notify_verbose
borlanic 0:380207fcb5c1 153 else:
borlanic 0:380207fcb5c1 154 notify = mbedToolchain.print_notify
borlanic 0:380207fcb5c1 155 notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify)
borlanic 0:380207fcb5c1 156 else:
borlanic 0:380207fcb5c1 157 notify = None
borlanic 0:380207fcb5c1 158
borlanic 0:380207fcb5c1 159 # Get libraries list
borlanic 0:380207fcb5c1 160 libraries = []
borlanic 0:380207fcb5c1 161
borlanic 0:380207fcb5c1 162 # Additional Libraries
borlanic 0:380207fcb5c1 163 if options.rpc:
borlanic 0:380207fcb5c1 164 libraries.extend(["rpc"])
borlanic 0:380207fcb5c1 165 if options.usb:
borlanic 0:380207fcb5c1 166 libraries.append("usb")
borlanic 0:380207fcb5c1 167 if options.dsp:
borlanic 0:380207fcb5c1 168 libraries.extend(["dsp"])
borlanic 0:380207fcb5c1 169 if options.cpputest_lib:
borlanic 0:380207fcb5c1 170 libraries.extend(["cpputest"])
borlanic 0:380207fcb5c1 171
borlanic 0:380207fcb5c1 172 # Build results
borlanic 0:380207fcb5c1 173 failures = []
borlanic 0:380207fcb5c1 174 successes = []
borlanic 0:380207fcb5c1 175 skipped = []
borlanic 0:380207fcb5c1 176
borlanic 0:380207fcb5c1 177 for toolchain in toolchains:
borlanic 0:380207fcb5c1 178 if not TOOLCHAIN_CLASSES[toolchain].check_executable():
borlanic 0:380207fcb5c1 179 search_path = TOOLCHAIN_PATHS[toolchain] or "No path set"
borlanic 0:380207fcb5c1 180 args_error(parser, "Could not find executable for %s.\n"
borlanic 0:380207fcb5c1 181 "Currently set search path: %s"
borlanic 0:380207fcb5c1 182 % (toolchain, search_path))
borlanic 0:380207fcb5c1 183
borlanic 0:380207fcb5c1 184 for toolchain in toolchains:
borlanic 0:380207fcb5c1 185 for target in targets:
borlanic 0:380207fcb5c1 186 tt_id = "%s::%s" % (toolchain, target)
borlanic 0:380207fcb5c1 187 if toolchain not in TARGET_MAP[target].supported_toolchains:
borlanic 0:380207fcb5c1 188 # Log this later
borlanic 0:380207fcb5c1 189 print("%s skipped: toolchain not supported" % tt_id)
borlanic 0:380207fcb5c1 190 skipped.append(tt_id)
borlanic 0:380207fcb5c1 191 else:
borlanic 0:380207fcb5c1 192 try:
borlanic 0:380207fcb5c1 193 mcu = TARGET_MAP[target]
borlanic 0:380207fcb5c1 194 profile = extract_profile(parser, options, toolchain)
borlanic 0:380207fcb5c1 195 if options.source_dir:
borlanic 0:380207fcb5c1 196 lib_build_res = build_library(options.source_dir, options.build_dir, mcu, toolchain,
borlanic 0:380207fcb5c1 197 extra_verbose=options.extra_verbose_notify,
borlanic 0:380207fcb5c1 198 verbose=options.verbose,
borlanic 0:380207fcb5c1 199 silent=options.silent,
borlanic 0:380207fcb5c1 200 jobs=options.jobs,
borlanic 0:380207fcb5c1 201 clean=options.clean,
borlanic 0:380207fcb5c1 202 archive=(not options.no_archive),
borlanic 0:380207fcb5c1 203 macros=options.macros,
borlanic 0:380207fcb5c1 204 name=options.artifact_name,
borlanic 0:380207fcb5c1 205 build_profile=profile)
borlanic 0:380207fcb5c1 206 else:
borlanic 0:380207fcb5c1 207 lib_build_res = build_mbed_libs(mcu, toolchain,
borlanic 0:380207fcb5c1 208 extra_verbose=options.extra_verbose_notify,
borlanic 0:380207fcb5c1 209 verbose=options.verbose,
borlanic 0:380207fcb5c1 210 silent=options.silent,
borlanic 0:380207fcb5c1 211 jobs=options.jobs,
borlanic 0:380207fcb5c1 212 clean=options.clean,
borlanic 0:380207fcb5c1 213 macros=options.macros,
borlanic 0:380207fcb5c1 214 build_profile=profile)
borlanic 0:380207fcb5c1 215
borlanic 0:380207fcb5c1 216 for lib_id in libraries:
borlanic 0:380207fcb5c1 217 build_lib(lib_id, mcu, toolchain,
borlanic 0:380207fcb5c1 218 extra_verbose=options.extra_verbose_notify,
borlanic 0:380207fcb5c1 219 verbose=options.verbose,
borlanic 0:380207fcb5c1 220 silent=options.silent,
borlanic 0:380207fcb5c1 221 clean=options.clean,
borlanic 0:380207fcb5c1 222 macros=options.macros,
borlanic 0:380207fcb5c1 223 jobs=options.jobs,
borlanic 0:380207fcb5c1 224 build_profile=profile)
borlanic 0:380207fcb5c1 225 if lib_build_res:
borlanic 0:380207fcb5c1 226 successes.append(tt_id)
borlanic 0:380207fcb5c1 227 else:
borlanic 0:380207fcb5c1 228 skipped.append(tt_id)
borlanic 0:380207fcb5c1 229 except Exception as e:
borlanic 0:380207fcb5c1 230 if options.verbose:
borlanic 0:380207fcb5c1 231 import traceback
borlanic 0:380207fcb5c1 232 traceback.print_exc(file=sys.stdout)
borlanic 0:380207fcb5c1 233 sys.exit(1)
borlanic 0:380207fcb5c1 234 failures.append(tt_id)
borlanic 0:380207fcb5c1 235 print(e)
borlanic 0:380207fcb5c1 236
borlanic 0:380207fcb5c1 237
borlanic 0:380207fcb5c1 238 # Write summary of the builds
borlanic 0:380207fcb5c1 239 print("\nCompleted in: (%.2f)s\n" % (time() - start))
borlanic 0:380207fcb5c1 240
borlanic 0:380207fcb5c1 241 for report, report_name in [(successes, "Build successes:"),
borlanic 0:380207fcb5c1 242 (skipped, "Build skipped:"),
borlanic 0:380207fcb5c1 243 (failures, "Build failures:"),
borlanic 0:380207fcb5c1 244 ]:
borlanic 0:380207fcb5c1 245 if report:
borlanic 0:380207fcb5c1 246 print(print_build_results(report, report_name))
borlanic 0:380207fcb5c1 247
borlanic 0:380207fcb5c1 248 if failures:
borlanic 0:380207fcb5c1 249 sys.exit(1)