Refactor notification logic into it's own class

pull/6781/head
Jimmy Brisson 2018-04-25 14:21:25 -05:00
parent b033a6e42e
commit 72beee7e90
5 changed files with 241 additions and 206 deletions

View File

@ -292,9 +292,8 @@ def get_mbed_official_release(version):
def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
macros=None, clean=False, jobs=1,
notify=None, silent=False, verbose=False,
extra_verbose=False, config=None,
app_config=None, build_profile=None):
notify=None, config=None, app_config=None,
build_profile=None):
""" Prepares resource related objects - toolchain, target, config
Positional arguments:
@ -307,9 +306,6 @@ def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
clean - Rebuild everything if True
jobs - how many compilers we can run at once
notify - Notify function for logs
silent - suppress printing of progress indicators
verbose - Write the actual tools command lines used if True
extra_verbose - even more output!
config - a Config object to use instead of creating one
app_config - location of a chosen mbed_app.json file
build_profile - a list of mergeable build profiles
@ -332,13 +328,12 @@ def prepare_toolchain(src_paths, build_dir, target, toolchain_name,
for key in profile:
profile[key].extend(contents[toolchain_name].get(key, []))
toolchain = cur_tc(target, notify, macros, silent, build_dir=build_dir,
extra_verbose=extra_verbose, build_profile=profile)
toolchain = cur_tc(
target, notify, macros, build_dir=build_dir, build_profile=profile)
toolchain.config = config
toolchain.jobs = jobs
toolchain.build_all = clean
toolchain.VERBOSE = verbose
return toolchain
@ -489,11 +484,10 @@ def scan_resources(src_paths, toolchain, dependencies_paths=None,
return resources
def build_project(src_paths, build_path, target, toolchain_name,
libraries_paths=None, linker_script=None,
clean=False, notify=None, verbose=False, name=None,
macros=None, inc_dirs=None, jobs=1, silent=False,
libraries_paths=None, linker_script=None, clean=False, silent=False,
notify=None, name=None, macros=None, inc_dirs=None, jobs=1,
report=None, properties=None, project_id=None,
project_description=None, extra_verbose=False, config=None,
project_description=None, config=None,
app_config=None, build_profile=None, stats_depth=None):
""" Build a project. A project may be a test or a user program.
@ -509,17 +503,14 @@ def build_project(src_paths, build_path, target, toolchain_name,
linker_script - the file that drives the linker to do it's job
clean - Rebuild everything if True
notify - Notify function for logs
verbose - Write the actual tools command lines used if True
name - the name of the project
macros - additional macros
inc_dirs - additional directories where include files may be found
jobs - how many compilers we can run at once
silent - suppress printing of progress indicators
report - a dict where a result may be appended
properties - UUUUHHHHH beats me
project_id - the name put in the report
project_description - the human-readable version of what this thing does
extra_verbose - even more output!
config - a Config object to use instead of creating one
app_config - location of a chosen mbed_app.json file
build_profile - a dict of flags that will be passed to the compiler
@ -540,15 +531,14 @@ def build_project(src_paths, build_path, target, toolchain_name,
toolchain = prepare_toolchain(
src_paths, build_path, target, toolchain_name, macros=macros,
clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose,
extra_verbose=extra_verbose, config=config, app_config=app_config,
build_profile=build_profile)
clean=clean, jobs=jobs, notify=notify, config=config,
app_config=app_config, build_profile=build_profile)
# The first path will give the name to the library
name = (name or toolchain.config.name or
basename(normpath(abspath(src_paths[0]))))
toolchain.info("Building project %s (%s, %s)" %
(name, toolchain.target.name, toolchain_name))
notify.info("Building project %s (%s, %s)" %
(name, toolchain.target.name, toolchain_name))
# Initialize reporting
if report != None:
@ -610,7 +600,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
if report != None:
end = time()
cur_result["elapsed_time"] = end - start
cur_result["output"] = toolchain.get_output() + memap_table
cur_result["output"] = notify.get_output() + memap_table
cur_result["result"] = "OK"
cur_result["memory_usage"] = (memap_instance.mem_report
if memap_instance is not None else None)
@ -633,7 +623,7 @@ def build_project(src_paths, build_path, target, toolchain_name,
cur_result["elapsed_time"] = end - start
toolchain_output = toolchain.get_output()
toolchain_output = notify.get_output()
if toolchain_output:
cur_result["output"] += toolchain_output
@ -644,9 +634,8 @@ def build_project(src_paths, build_path, target, toolchain_name,
def build_library(src_paths, build_path, target, toolchain_name,
dependencies_paths=None, name=None, clean=False,
archive=True, notify=None, verbose=False, macros=None,
inc_dirs=None, jobs=1, silent=False, report=None,
properties=None, extra_verbose=False, project_id=None,
archive=True, notify=None, macros=None, inc_dirs=None, jobs=1,
report=None, properties=None, project_id=None,
remove_config_header_file=False, app_config=None,
build_profile=None):
""" Build a library
@ -664,14 +653,11 @@ def build_library(src_paths, build_path, target, toolchain_name,
clean - Rebuild everything if True
archive - whether the library will create an archive file
notify - Notify function for logs
verbose - Write the actual tools command lines used if True
macros - additional macros
inc_dirs - additional directories where include files may be found
jobs - how many compilers we can run at once
silent - suppress printing of progress indicators
report - a dict where a result may be appended
properties - UUUUHHHHH beats me
extra_verbose - even more output!
project_id - the name that goes in the report
remove_config_header_file - delete config header file when done building
app_config - location of a chosen mbed_app.json file
@ -698,14 +684,13 @@ def build_library(src_paths, build_path, target, toolchain_name,
# Pass all params to the unified prepare_toolchain()
toolchain = prepare_toolchain(
src_paths, build_path, target, toolchain_name, macros=macros,
clean=clean, jobs=jobs, notify=notify, silent=silent,
verbose=verbose, extra_verbose=extra_verbose, app_config=app_config,
clean=clean, jobs=jobs, notify=notify, app_config=app_config,
build_profile=build_profile)
# The first path will give the name to the library
if name is None:
name = basename(normpath(abspath(src_paths[0])))
toolchain.info("Building library %s (%s, %s)" %
notify.info("Building library %s (%s, %s)" %
(name, toolchain.target.name, toolchain_name))
# Initialize reporting
@ -770,7 +755,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
if report != None:
end = time()
cur_result["elapsed_time"] = end - start
cur_result["output"] = toolchain.get_output()
cur_result["output"] = notify.get_output()
cur_result["result"] = "OK"
@ -788,7 +773,7 @@ def build_library(src_paths, build_path, target, toolchain_name,
cur_result["elapsed_time"] = end - start
toolchain_output = toolchain.get_output()
toolchain_output = notify.get_output()
if toolchain_output:
cur_result["output"] += toolchain_output
@ -805,9 +790,8 @@ def mbed2_obj_path(target_name, toolchain_name):
real_tc_name = TOOLCHAIN_CLASSES[toolchain_name].__name__
return join("TARGET_" + target_name, "TOOLCHAIN_" + real_tc_name)
def build_lib(lib_id, target, toolchain_name, verbose=False,
clean=False, macros=None, notify=None, jobs=1, silent=False,
report=None, properties=None, extra_verbose=False,
def build_lib(lib_id, target, toolchain_name, clean=False, macros=None,
notify=None, jobs=1, report=None, properties=None,
build_profile=None):
""" Legacy method for building mbed libraries
@ -818,14 +802,11 @@ def build_lib(lib_id, target, toolchain_name, verbose=False,
Keyword arguments:
clean - Rebuild everything if True
verbose - Write the actual tools command lines used if True
macros - additional macros
notify - Notify function for logs
jobs - how many compilers we can run at once
silent - suppress printing of progress indicators
report - a dict where a result may be appended
properties - UUUUHHHHH beats me
extra_verbose - even more output!
build_profile - a dict of flags that will be passed to the compiler
"""
lib = Library(lib_id)
@ -890,10 +871,9 @@ def build_lib(lib_id, target, toolchain_name, verbose=False,
toolchain = prepare_toolchain(
src_paths, tmp_path, target, toolchain_name, macros=macros,
notify=notify, silent=silent, extra_verbose=extra_verbose,
build_profile=build_profile, jobs=jobs, clean=clean)
notify=notify, build_profile=build_profile, jobs=jobs, clean=clean)
toolchain.info("Building library %s (%s, %s)" %
notify.info("Building library %s (%s, %s)" %
(name.upper(), target.name, toolchain_name))
# Take into account the library configuration (MBED_CONFIG_FILE)
@ -947,7 +927,7 @@ def build_lib(lib_id, target, toolchain_name, verbose=False,
if report != None and needed_update:
end = time()
cur_result["elapsed_time"] = end - start
cur_result["output"] = toolchain.get_output()
cur_result["output"] = notify.get_output()
cur_result["result"] = "OK"
add_result_to_report(report, cur_result)
@ -959,7 +939,7 @@ def build_lib(lib_id, target, toolchain_name, verbose=False,
cur_result["result"] = "FAIL"
cur_result["elapsed_time"] = end - start
toolchain_output = toolchain.get_output()
toolchain_output = notify.get_output()
if toolchain_output:
cur_result["output"] += toolchain_output
@ -970,9 +950,8 @@ def build_lib(lib_id, target, toolchain_name, verbose=False,
# We do have unique legacy conventions about how we build and package the mbed
# library
def build_mbed_libs(target, toolchain_name, verbose=False,
clean=False, macros=None, notify=None, jobs=1, silent=False,
report=None, properties=None, extra_verbose=False,
def build_mbed_libs(target, toolchain_name, clean=False, macros=None,
notify=None, jobs=1, report=None, properties=None,
build_profile=None):
""" Function returns True is library was built and false if building was
skipped
@ -982,15 +961,12 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
toolchain_name - the name of the build tools
Keyword arguments:
verbose - Write the actual tools command lines used if True
clean - Rebuild everything if True
macros - additional macros
notify - Notify function for logs
jobs - how many compilers we can run at once
silent - suppress printing of progress indicators
report - a dict where a result may be appended
properties - UUUUHHHHH beats me
extra_verbose - even more output!
build_profile - a dict of flags that will be passed to the compiler
"""
@ -1034,8 +1010,7 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
mkdir(tmp_path)
toolchain = prepare_toolchain(
[""], tmp_path, target, toolchain_name, macros=macros,verbose=verbose,
notify=notify, silent=silent, extra_verbose=extra_verbose,
[""], tmp_path, target, toolchain_name, macros=macros, notify=notify,
build_profile=build_profile, jobs=jobs, clean=clean)
# Take into account the library configuration (MBED_CONFIG_FILE)
@ -1044,7 +1019,7 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
toolchain.set_config_data(toolchain.config.get_config_data())
# mbed
toolchain.info("Building library %s (%s, %s)" %
notify.info("Building library %s (%s, %s)" %
('MBED', target.name, toolchain_name))
# Common Headers
@ -1111,7 +1086,7 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
if report != None:
end = time()
cur_result["elapsed_time"] = end - start
cur_result["output"] = toolchain.get_output()
cur_result["output"] = notify.get_output()
cur_result["result"] = "OK"
add_result_to_report(report, cur_result)
@ -1124,7 +1099,7 @@ def build_mbed_libs(target, toolchain_name, verbose=False,
cur_result["result"] = "FAIL"
cur_result["elapsed_time"] = end - start
toolchain_output = toolchain.get_output()
toolchain_output = notify.get_output()
if toolchain_output:
cur_result["output"] += toolchain_output

View File

@ -45,6 +45,7 @@ from tools.targets import TARGET_MAP
from tools.options import get_default_options_parser
from tools.options import extract_profile
from tools.options import extract_mcus
from tools.notifier import TerminalNotifier
from tools.build_api import build_project
from tools.build_api import mcu_toolchain_matrix
from tools.build_api import mcu_toolchain_list
@ -232,16 +233,7 @@ if __name__ == '__main__':
args_error(parser, "argument --build is required when argument --source is provided")
if options.color:
# This import happens late to prevent initializing colorization when we don't need it
import colorize
if options.verbose:
notify = mbedToolchain.print_notify_verbose
else:
notify = mbedToolchain.print_notify
notify = colorize.print_in_color_notifier(CLI_COLOR_MAP, notify)
else:
notify = None
notify = TerminalNotifier(options.verbose, options.silent)
if not TOOLCHAIN_CLASSES[toolchain].check_executable():
search_path = TOOLCHAIN_PATHS[toolchain] or "No path set"
@ -283,10 +275,9 @@ if __name__ == '__main__':
set(test.dependencies),
linker_script=options.linker_script,
clean=options.clean,
verbose=options.verbose,
notify=notify,
report=build_data_blob,
silent=options.silent,
report=build_data_blob,
macros=options.macros,
jobs=options.jobs,
name=options.artifact_name,

174
tools/notifier/__init__.py Normal file
View File

@ -0,0 +1,174 @@
# mbed SDK
# Copyright (c) 2011-2013 ARM Limited
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function, division, absolute_import
from abc import ABCMeta, abstractmethod
from os.path import basename
from ..settings import PRINT_COMPILER_OUTPUT_AS_LINK
class Notifier(object):
"""
Notifiers send build system events to a front end or may implement a front
end themselves, displaying warnings and errors for a user.
This is different from a logger in a few ways:
* The structure of the events are defined by this interface.
* A "progress" level is included allowing signaling completion status to
users.
* It's tailored to providing events from a build system.
The structure of a message is a dict with a 'type' key. The type key
determines the remaining keys as follows:
type | description and remaining keys
---------- | ------------------------------
info | A simple message. The 'message' key contains the message
debug | Another simple message; this one is less useful when compiles
| are working. Again, the 'message' key contains the message
progress | A progress indicator, which may include progress as a
| percentage. The action key includes what action was taken to
| make this progress, the file key what file was used to make
| this progress, and the percent key, when present, indicates
| how far along the build is.
tool_error | When a compile fails, this contains the entire output of the
| compiler.
var | Provides a key, in the 'key' key, and a value, in the 'value'
| key, for use in a UI. At the time of writing it's used to
| communicate the binary location to the online IDE.
"""
__metaclass__ = ABCMeta
@abstractmethod
def notify(self, event):
"""
Send the user a notification specified in the event.
"""
raise NotImplemented
def info(self, message):
"""
Send the user a simple message.
"""
self.notify({'type': 'info', 'message': message})
def debug(self, message):
"""
Send a debug message to the user.
"""
if isinstance(message, list):
message = ' '.join(message)
message = "[DEBUG] " + message
self.notify({'type': 'debug', 'message': message})
def cc_info(self, info=None):
if info is not None:
info['type'] = 'cc'
self.notify(info)
def cc_verbose(self, message, file=""):
self.debug(message)
def progress(self, action, file, percent=None):
"""
Indicate compilation progress to a user.
"""
msg = {'type': 'progress', 'action': action, 'file': file}
if percent:
msg['percent'] = percent
self.notify(msg)
def tool_error(self, message):
"""
Communicate a full fatal error to a user.
"""
self.notify({'type': 'tool_error', 'message': message})
def var(self, key, value):
"""
Update a UI with a key, value pair
"""
self.notify({'type': 'var', 'key': key, 'val': value})
class TerminalNotifier(Notifier):
"""
Writes notifications to a terminal based on a silent and verbose flag.
"""
def __init__(self, verbose=False, silent=False):
self.verbose = verbose
self.silent = silent
self.output = ""
def get_output(self):
return self.output
def notify(self, event):
if self.verbose:
msg = self.print_notify_verbose(event)
else:
msg = self.print_notify(event)
if msg:
if not self.silent:
print(msg)
self.output += msg + "\n"
def print_notify(self, event):
""" Default command line notification
"""
if not self.verbose and event['type'] == 'tool_error':
return event['message']
elif event['type'] in ['info']:
return event['message']
elif event['type'] == 'cc':
event['severity'] = event['severity'].title()
if PRINT_COMPILER_OUTPUT_AS_LINK:
event['file'] = getcwd() + event['file'].strip('.')
return '[%(severity)s] %(file)s:%(line)s:%(col)s: %(message)s' % event
else:
event['file'] = basename(event['file'])
return '[%(severity)s] %(file)s@%(line)s,%(col)s: %(message)s' % event
elif event['type'] == 'progress':
if 'percent' in event:
return '{} [{:>5.1f}%]: {}'.format(event['action'].title(),
event['percent'],
basename(event['file']))
else:
return '{}: {}'.format(event['action'].title(),
basename(event['file']))
def print_notify_verbose(self, event):
""" Default command line notification with more verbose mode
"""
if event['type'] in ['info', 'debug']:
return event['message']
elif event['type'] == 'cc':
event['severity'] = event['severity'].title()
event['file'] = basename(event['file'])
event['mcu_name'] = "None"
event['target_name'] = event['target_name'].upper() if event['target_name'] else "Unknown"
event['toolchain_name'] = event['toolchain_name'].upper() if event['toolchain_name'] else "Unknown"
return '[%(severity)s] %(target_name)s::%(toolchain_name)s::%(file)s@%(line)s: %(message)s' % event
elif event['type'] == 'progress':
return self.print_notify(event) # standard handle

View File

@ -37,6 +37,7 @@ from ..utils import (run_cmd, mkdir, rel_path, ToolException,
NotSupportedException, split_path, compile_worker)
from ..settings import MBED_ORG_USER, PRINT_COMPILER_OUTPUT_AS_LINK
from .. import hooks
from ..notifier import TerminalNotifier
from ..memap import MemapParser
@ -351,8 +352,8 @@ class mbedToolchain:
profile_template = {'common':[], 'c':[], 'cxx':[], 'asm':[], 'ld':[]}
def __init__(self, target, notify=None, macros=None, silent=False,
extra_verbose=False, build_profile=None, build_dir=None):
def __init__(self, target, notify=None, macros=None, build_profile=None,
build_dir=None):
self.target = target
self.name = self.__class__.__name__
@ -414,17 +415,9 @@ class mbedToolchain:
# or an application was linked
# *Silent* is a boolean
if notify:
self.notify_fun = notify
elif extra_verbose:
self.notify_fun = self.print_notify_verbose
self.notify = notify
else:
self.notify_fun = self.print_notify
# Silent builds (no output)
self.silent = silent
# Print output buffer
self.output = str()
self.notify = TerminalNotifier()
# uVisor spepcific rules
if 'UVISOR' in self.target.features and 'UVISOR_SUPPORTED' in self.target.extra_labels:
@ -447,70 +440,7 @@ class mbedToolchain:
return True
def get_output(self):
return self.output
def print_notify(self, event, silent=False):
""" Default command line notification
"""
msg = None
if not self.VERBOSE and event['type'] == 'tool_error':
msg = event['message']
elif event['type'] in ['info', 'debug']:
msg = event['message']
elif event['type'] == 'cc':
event['severity'] = event['severity'].title()
if PRINT_COMPILER_OUTPUT_AS_LINK:
event['file'] = getcwd() + event['file'].strip('.')
msg = '[%(severity)s] %(file)s:%(line)s:%(col)s: %(message)s' % event
else:
event['file'] = basename(event['file'])
msg = '[%(severity)s] %(file)s@%(line)s,%(col)s: %(message)s' % event
elif event['type'] == 'progress':
if 'percent' in event:
msg = '{} [{:>5.1f}%]: {}'.format(event['action'].title(),
event['percent'],
basename(event['file']))
else:
msg = '{}: {}'.format(event['action'].title(),
basename(event['file']))
if msg:
if not silent:
print(msg)
self.output += msg + "\n"
def print_notify_verbose(self, event, silent=False):
""" Default command line notification with more verbose mode
"""
if event['type'] in ['info', 'debug']:
self.print_notify(event, silent=silent) # standard handle
elif event['type'] == 'cc':
event['severity'] = event['severity'].title()
event['file'] = basename(event['file'])
event['mcu_name'] = "None"
event['target_name'] = event['target_name'].upper() if event['target_name'] else "Unknown"
event['toolchain_name'] = event['toolchain_name'].upper() if event['toolchain_name'] else "Unknown"
msg = '[%(severity)s] %(target_name)s::%(toolchain_name)s::%(file)s@%(line)s: %(message)s' % event
if not silent:
print(msg)
self.output += msg + "\n"
elif event['type'] == 'progress':
self.print_notify(event) # standard handle
# THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
def notify(self, event):
""" Little closure for notify functions
"""
event['toolchain'] = self
return self.notify_fun(event, self.silent)
return self.notifier.get_output()
def get_symbols(self, for_asm=False):
if for_asm:
@ -890,7 +820,7 @@ class mbedToolchain:
self.to_be_compiled = len(files_to_compile)
self.compiled = 0
self.cc_verbose("Macros: "+' '.join(['-D%s' % s for s in self.get_symbols()]))
self.notify.cc_verbose("Macros: "+' '.join(['-D%s' % s for s in self.get_symbols()]))
inc_paths = resources.inc_dirs
if inc_dirs is not None:
@ -949,7 +879,7 @@ class mbedToolchain:
self.compiled += 1
self.progress("compile", item['source'], build_update=True)
for res in result['results']:
self.cc_verbose("Compile: %s" % ' '.join(res['command']), result['source'])
self.notify.cc_verbose("Compile: %s" % ' '.join(res['command']), result['source'])
self.compile_output([
res['code'],
res['output'],
@ -987,7 +917,7 @@ class mbedToolchain:
self.compiled += 1
self.progress("compile", result['source'], build_update=True)
for res in result['results']:
self.cc_verbose("Compile: %s" % ' '.join(res['command']), result['source'])
self.notify.cc_verbose("Compile: %s" % ' '.join(res['command']), result['source'])
self.compile_output([
res['code'],
res['output'],
@ -1098,9 +1028,9 @@ class mbedToolchain:
# Parse output for Warnings and Errors
self.parse_output(_stderr)
self.debug("Return: %s"% _rc)
self.notify.debug("Return: %s"% _rc)
for error_line in _stderr.splitlines():
self.debug("Output: %s"% error_line)
self.notify.debug("Output: %s"% error_line)
# Check return code
if _rc != 0:
@ -1127,7 +1057,7 @@ class mbedToolchain:
ext = self.target.OUTPUT_EXT
if hasattr(self.target, 'OUTPUT_NAMING'):
self.var("binary_naming", self.target.OUTPUT_NAMING)
self.notify.var("binary_naming", self.target.OUTPUT_NAMING)
if self.target.OUTPUT_NAMING == "8.3":
name = name[0:8]
ext = ext[0:3]
@ -1162,8 +1092,8 @@ class mbedToolchain:
# Initialize memap and process map file. This doesn't generate output.
self.mem_stats(map)
self.var("compile_succeded", True)
self.var("binary", filename)
self.notify.var("compile_succeded", True)
self.notify.var("binary", filename)
return full_path, needed_update
@ -1171,54 +1101,24 @@ class mbedToolchain:
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
def default_cmd(self, command):
_stdout, _stderr, _rc = run_cmd(command, work_dir=getcwd(), chroot=self.CHROOT)
self.debug("Return: %s"% _rc)
self.notify.debug("Return: %s"% _rc)
for output_line in _stdout.splitlines():
self.debug("Output: %s"% output_line)
self.notify.debug("Output: %s"% output_line)
for error_line in _stderr.splitlines():
self.debug("Errors: %s"% error_line)
self.notify.debug("Errors: %s"% error_line)
if _rc != 0:
for line in _stderr.splitlines():
self.tool_error(line)
raise ToolException(_stderr)
### NOTIFICATIONS ###
def info(self, message):
self.notify({'type': 'info', 'message': message})
# THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
def debug(self, message):
if self.VERBOSE:
if isinstance(message, list):
message = ' '.join(message)
message = "[DEBUG] " + message
self.notify({'type': 'debug', 'message': message})
# THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
def cc_info(self, info=None):
if info is not None:
info['type'] = 'cc'
self.notify(info)
# THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY
def cc_verbose(self, message, file=""):
self.debug(message)
def progress(self, action, file, build_update=False):
msg = {'type': 'progress', 'action': action, 'file': file}
if build_update:
msg['percent'] = 100. * float(self.compiled) / float(self.to_be_compiled)
self.notify(msg)
def tool_error(self, message):
self.notify({'type': 'tool_error', 'message': message})
def var(self, key, value):
self.notify({'type': 'var', 'key': key, 'val': value})
percent = 100. * float(self.compiled) / float(self.to_be_compiled)
else:
percent = None
self.notify.progress(action, file, percent)
# THIS METHOD IS BEING OVERRIDDEN BY THE MBED ONLINE BUILD SYSTEM
# ANY CHANGE OF PARAMETERS OR RETURN VALUES WILL BREAK COMPATIBILITY

View File

@ -48,12 +48,10 @@ class ARM(mbedToolchain):
return mbedToolchain.generic_check_executable("ARM", 'armcc', 2, 'bin')
def __init__(self, target, notify=None, macros=None,
silent=False, extra_verbose=False, build_profile=None,
build_dir=None):
mbedToolchain.__init__(self, target, notify, macros, silent,
build_dir=build_dir,
extra_verbose=extra_verbose,
build_profile=build_profile)
build_profile=None, build_dir=None):
mbedToolchain.__init__(
self, target, notify, macros, build_dir=build_dir,
build_profile=build_profile)
if target.core not in self.SUPPORTED_CORES:
raise NotSupportedException(
"this compiler does not support the core %s" % target.core)
@ -102,7 +100,7 @@ class ARM(mbedToolchain):
match = ARM.DIAGNOSTIC_PATTERN.match(line)
if match is not None:
if msg is not None:
self.cc_info(msg)
self.notify.cc_info(msg)
msg = None
msg = {
'severity': match.group('severity').lower(),
@ -119,13 +117,13 @@ class ARM(mbedToolchain):
match = ARM.INDEX_PATTERN.match(line)
if match is not None:
msg['col'] = len(match.group('col'))
self.cc_info(msg)
self.notify.cc_info(msg)
msg = None
else:
msg['text'] += line+"\n"
if msg is not None:
self.cc_info(msg)
self.notify.cc_info(msg)
def get_dep_option(self, object):
base, _ = splitext(object)
@ -238,7 +236,7 @@ class ARM(mbedToolchain):
link_files = self.get_link_file(cmd[1:])
cmd = [cmd_linker, '--via', link_files]
self.cc_verbose("Link: %s" % ' '.join(cmd))
self.notify.cc_verbose("Link: %s" % ' '.join(cmd))
self.default_cmd(cmd)
@hook_tool
@ -263,7 +261,7 @@ class ARM(mbedToolchain):
else:
rmtree(bin)
self.cc_verbose("FromELF: %s" % ' '.join(cmd))
self.notify.cc_verbose("FromELF: %s" % ' '.join(cmd))
self.default_cmd(cmd)
@staticmethod
@ -285,10 +283,8 @@ class ARM(mbedToolchain):
class ARM_STD(ARM):
def __init__(self, target, notify=None, macros=None,
silent=False, extra_verbose=False, build_profile=None,
build_dir=None):
ARM.__init__(self, target, notify, macros, silent,
build_dir=build_dir, extra_verbose=extra_verbose,
build_profile=None, build_dir=None):
ARM.__init__(self, target, notify, macros, build_dir=build_dir,
build_profile=build_profile)
if "ARM" not in target.supported_toolchains:
raise NotSupportedException("ARM compiler support is required for ARM build")
@ -299,8 +295,7 @@ class ARM_MICRO(ARM):
def __init__(self, target, notify=None, macros=None,
silent=False, extra_verbose=False, build_profile=None,
build_dir=None):
ARM.__init__(self, target, notify, macros, silent,
build_dir=build_dir, extra_verbose=extra_verbose,
ARM.__init__(self, target, notify, macros, build_dir=build_dir,
build_profile=build_profile)
if not set(("ARM", "uARM")).intersection(set(target.supported_toolchains)):
raise NotSupportedException("ARM/uARM compiler support is required for ARM build")