joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers build.py Source File

build.py

00001 #! /usr/bin/env python2
00002 """
00003 mbed SDK
00004 Copyright (c) 2011-2013 ARM Limited
00005 
00006 Licensed under the Apache License, Version 2.0 (the "License");
00007 you may not use this file except in compliance with the License.
00008 You may obtain a copy of the License at
00009 
00010     http://www.apache.org/licenses/LICENSE-2.0
00011 
00012 Unless required by applicable law or agreed to in writing, software
00013 distributed under the License is distributed on an "AS IS" BASIS,
00014 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 See the License for the specific language governing permissions and
00016 limitations under the License.
00017 
00018 LIBRARIES BUILD
00019 """
00020 import sys
00021 from time import time
00022 from os.path import join, abspath, dirname
00023 
00024 
00025 # Be sure that the tools directory is in the search path
00026 ROOT = abspath(join(dirname(__file__), ".."))
00027 sys.path.insert(0, ROOT)
00028 
00029 
00030 from tools.toolchains import TOOLCHAINS
00031 from tools.toolchains import mbedToolchain
00032 from tools.targets import TARGET_NAMES, TARGET_MAP
00033 from tools.options import get_default_options_parser
00034 from tools.build_api import build_library, build_mbed_libs, build_lib
00035 from tools.build_api import mcu_toolchain_matrix
00036 from tools.build_api import static_analysis_scan, static_analysis_scan_lib, static_analysis_scan_library
00037 from tools.build_api import print_build_results
00038 from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT
00039 from utils import argparse_filestring_type, args_error
00040 from tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, CLI_COLOR_MAP
00041 from utils import argparse_filestring_type, argparse_dir_not_parent
00042 
00043 if __name__ == '__main__':
00044     start = time()
00045 
00046     # Parse Options
00047     parser = get_default_options_parser()
00048 
00049     parser.add_argument("--source", dest="source_dir", type=argparse_filestring_type,
00050                         default=None, help="The source (input) directory", action="append")
00051 
00052     parser.add_argument("--build", dest="build_dir", type=argparse_dir_not_parent(ROOT),
00053                       default=None, help="The build (output) directory")
00054 
00055     parser.add_argument("--no-archive", dest="no_archive", action="store_true",
00056                       default=False, help="Do not produce archive (.ar) file, but rather .o")
00057 
00058     # Extra libraries
00059     parser.add_argument("-r", "--rtos",
00060                       action="store_true",
00061                       dest="rtos",
00062                       default=False,
00063                       help="Compile the rtos")
00064 
00065     parser.add_argument("--rpc",
00066                       action="store_true",
00067                       dest="rpc",
00068                       default=False,
00069                       help="Compile the rpc library")
00070 
00071     parser.add_argument("-e", "--eth",
00072                       action="store_true", dest="eth",
00073                       default=False,
00074                       help="Compile the ethernet library")
00075 
00076     parser.add_argument("-U", "--usb_host",
00077                       action="store_true",
00078                       dest="usb_host",
00079                       default=False,
00080                       help="Compile the USB Host library")
00081 
00082     parser.add_argument("-u", "--usb",
00083                       action="store_true",
00084                       dest="usb",
00085                       default=False,
00086                       help="Compile the USB Device library")
00087 
00088     parser.add_argument("-d", "--dsp",
00089                       action="store_true",
00090                       dest="dsp",
00091                       default=False,
00092                       help="Compile the DSP library")
00093 
00094     parser.add_argument("-F", "--fat",
00095                       action="store_true",
00096                       dest="fat",
00097                       default=False,
00098                       help="Compile FS and SD card file system library")
00099 
00100     parser.add_argument("-b", "--ublox",
00101                       action="store_true",
00102                       dest="ublox",
00103                       default=False,
00104                       help="Compile the u-blox library")
00105 
00106     parser.add_argument( "--cpputest",
00107                       action="store_true",
00108                       dest="cpputest_lib",
00109                       default=False,
00110                       help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)")
00111 
00112     parser.add_argument("-D",
00113                       action="append",
00114                       dest="macros",
00115                       help="Add a macro definition")
00116 
00117     parser.add_argument("-S", "--supported-toolchains",
00118                       action="store_true",
00119                       dest="supported_toolchains",
00120                       default=False,
00121                       help="Displays supported matrix of MCUs and toolchains")
00122 
00123     parser.add_argument('-f', '--filter',
00124                       dest='general_filter_regex',
00125                       default=None,
00126                       help='For some commands you can use filter to filter out results')
00127 
00128     parser.add_argument("--cppcheck",
00129                       action="store_true",
00130                       dest="cppcheck_validation",
00131                       default=False,
00132                       help="Forces 'cppcheck' static code analysis")
00133 
00134     parser.add_argument("-j", "--jobs", type=int, dest="jobs",
00135                       default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)")
00136     parser.add_argument("-N", "--artifact-name", dest="artifact_name",
00137                       default=None, help="The built project's name")
00138 
00139     parser.add_argument("-v", "--verbose",
00140                       action="store_true",
00141                       dest="verbose",
00142                       default=False,
00143                       help="Verbose diagnostic output")
00144 
00145     parser.add_argument("--silent",
00146                       action="store_true",
00147                       dest="silent",
00148                       default=False,
00149                       help="Silent diagnostic output (no copy, compile notification)")
00150 
00151     parser.add_argument("-x", "--extra-verbose-notifications",
00152                       action="store_true",
00153                       dest="extra_verbose_notify",
00154                       default=False,
00155                       help="Makes compiler more verbose, CI friendly.")
00156 
00157     options = parser.parse_args()
00158 
00159     # Only prints matrix of supported toolchains
00160     if options.supported_toolchains:
00161         print mcu_toolchain_matrix(platform_filter=options.general_filter_regex)
00162         exit(0)
00163 
00164     # Get target list
00165     targets = options.mcu if options.mcu else TARGET_NAMES
00166 
00167     # Get toolchains list
00168     toolchains = options.tool if options.tool else TOOLCHAINS
00169 
00170     if options.source_dir and not options.build_dir:
00171         args_error(parser, "argument --build is required by argument --source")
00172 
00173     if options.color:
00174         # This import happens late to prevent initializing colorization when we don't need it
00175         import colorize
00176         if options.verbose:
00177             notify = mbedToolchain.print_notify_verbose
00178         else:
00179             notify = mbedToolchain.print_notify
00180         notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify)
00181     else:
00182         notify = None
00183 
00184     # Get libraries list
00185     libraries = []
00186 
00187     # Additional Libraries
00188     if options.rtos:
00189         libraries.extend(["rtx", "rtos"])
00190     if options.rpc:
00191         libraries.extend(["rpc"])
00192     if options.eth:
00193         libraries.append("eth")
00194     if options.usb:
00195         libraries.append("usb")
00196     if options.usb_host:
00197         libraries.append("usb_host")
00198     if options.dsp:
00199         libraries.extend(["dsp"])
00200     if options.fat:
00201         libraries.extend(["fat"])
00202     if options.ublox:
00203         libraries.extend(["rtx", "rtos", "usb_host", "ublox"])
00204     if options.cpputest_lib:
00205         libraries.extend(["cpputest"])
00206 
00207     # Build results
00208     failures = []
00209     successes = []
00210     skipped = []
00211 
00212     # CPPCHECK code validation
00213     if options.cppcheck_validation:
00214         for toolchain in toolchains:
00215             for target in targets:
00216                 try:
00217                     mcu = TARGET_MAP[target]
00218                     # CMSIS and MBED libs analysis
00219                     static_analysis_scan(mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, verbose=options.verbose, jobs=options.jobs)
00220                     for lib_id in libraries:
00221                         # Static check for library
00222                         static_analysis_scan_lib(lib_id, mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT,
00223                                   options=options.options,
00224                                   extra_verbose=options.extra_verbose_notify, verbose=options.verbose, jobs=options.jobs, clean=options.clean,
00225                                   macros=options.macros)
00226                         pass
00227                 except Exception, e:
00228                     if options.verbose:
00229                         import traceback
00230                         traceback.print_exc(file=sys.stdout)
00231                         sys.exit(1)
00232                     print e
00233     else:
00234         # Build
00235         for toolchain in toolchains:
00236             for target in targets:
00237                 tt_id = "%s::%s" % (toolchain, target)
00238                 if toolchain not in TARGET_MAP[target].supported_toolchains:
00239                     # Log this later
00240                     print "%s skipped: toolchain not supported" % tt_id
00241                     skipped.append(tt_id)
00242                 else:
00243                     try:
00244                         mcu = TARGET_MAP[target]
00245                         if options.source_dir:
00246                             lib_build_res = build_library(options.source_dir, options.build_dir, mcu, toolchain,
00247                                                         options=options.options,
00248                                                         extra_verbose=options.extra_verbose_notify,
00249                                                         verbose=options.verbose,
00250                                                         silent=options.silent,
00251                                                         jobs=options.jobs,
00252                                                         clean=options.clean,
00253                                                         archive=(not options.no_archive),
00254                                                         macros=options.macros,
00255                                                         name=options.artifact_name)
00256                         else:
00257                             lib_build_res = build_mbed_libs(mcu, toolchain,
00258                                                         options=options.options,
00259                                                         extra_verbose=options.extra_verbose_notify,
00260                                                         verbose=options.verbose,
00261                                                         silent=options.silent,
00262                                                         jobs=options.jobs,
00263                                                         clean=options.clean,
00264                                                         macros=options.macros)
00265 
00266                         for lib_id in libraries:
00267                             build_lib(lib_id, mcu, toolchain,
00268                                     options=options.options,
00269                                     extra_verbose=options.extra_verbose_notify,
00270                                     verbose=options.verbose,
00271                                     silent=options.silent,
00272                                     clean=options.clean,
00273                                     macros=options.macros,
00274                                     jobs=options.jobs)
00275                         if lib_build_res:
00276                             successes.append(tt_id)
00277                         else:
00278                             skipped.append(tt_id)
00279                     except Exception, e:
00280                         if options.verbose:
00281                             import traceback
00282                             traceback.print_exc(file=sys.stdout)
00283                             sys.exit(1)
00284                         failures.append(tt_id)
00285                         print e
00286 
00287     # Write summary of the builds
00288     print
00289     print "Completed in: (%.2f)s" % (time() - start)
00290     print
00291 
00292     for report, report_name in [(successes, "Build successes:"),
00293                                 (skipped, "Build skipped:"),
00294                                 (failures, "Build failures:"),
00295                                ]:
00296         if report:
00297             print print_build_results(report, report_name),
00298 
00299     if failures:
00300         sys.exit(1)