Clone of official tools

Committer:
Anders Blomdell
Date:
Thu Feb 04 17:17:13 2021 +0100
Revision:
47:21ae3e5a7128
Parent:
43:2a7da56ebd24
Add a few normpath calls

Who changed what in which revision?

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