Import Mbed OS hard-float snapshot

This commit is contained in:
Beslan
2026-06-01 20:15:04 +03:00
commit d3738e2f89
16278 changed files with 10628036 additions and 0 deletions

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

@@ -0,0 +1,105 @@
# 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 future.utils import with_metaclass
class Notifier(with_metaclass(ABCMeta, 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.
"""
@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)
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.notify({
'type': 'cc',
'severity': 'verbose',
'file': file,
'message': 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})

27
tools/notifier/mock.py Normal file
View File

@@ -0,0 +1,27 @@
# 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 . import Notifier
class MockNotifier(Notifier):
"""Collect notifications
"""
def __init__(self):
self.messages = []
def notify(self, message):
self.messages.append(message)

146
tools/notifier/term.py Normal file
View File

@@ -0,0 +1,146 @@
# 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 past.builtins import basestring
import re
import sys
from os import getcwd
from os.path import (basename, abspath)
from . import Notifier
from ..settings import (PRINT_COMPILER_OUTPUT_AS_LINK,
CLI_COLOR_MAP, COLOR)
class TerminalNotifier(Notifier):
"""
Writes notifications to a terminal based on silent, verbose and color flags.
"""
def __init__(self, verbose=False, silent=False, color=False):
self.verbose = verbose
self.silent = silent
self.output = ""
self.color = color or COLOR
if self.color:
from colorama import init, Fore, Back, Style
init()
self.COLORS = {
'none' : "",
'default' : Style.RESET_ALL,
'black' : Fore.BLACK,
'red' : Fore.RED,
'green' : Fore.GREEN,
'yellow' : Fore.YELLOW,
'blue' : Fore.BLUE,
'magenta' : Fore.MAGENTA,
'cyan' : Fore.CYAN,
'white' : Fore.WHITE,
'on_black' : Back.BLACK,
'on_red' : Back.RED,
'on_green' : Back.GREEN,
'on_yellow' : Back.YELLOW,
'on_blue' : Back.BLUE,
'on_magenta' : Back.MAGENTA,
'on_cyan' : Back.CYAN,
'on_white' : Back.WHITE,
}
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:
if self.color:
self.print_in_color(event, msg)
else:
print(msg)
self.output += msg + "\n"
def print_notify(self, event):
""" Command line notification
"""
if event['type'] in ('tool_error', 'info'):
return event['message']
elif event['type'] == 'cc' and event['severity'] != 'verbose':
event['severity'] = event['severity'].title()
if PRINT_COMPILER_OUTPUT_AS_LINK:
event['file'] = abspath(event['file'])
return '[{severity}] {file}:{line}:{col}: {message}'.format(
**event)
else:
event['file'] = basename(event['file'])
return '[{severity}] {file}@{line},{col}: {message}'.format(
**event)
elif event['type'] == 'progress':
event['action'] = event['action'].title()
event['file'] = basename(event['file'])
if 'percent' in event:
format_string = '{action} [{percent:>5.1f}%]: {file}'
else:
format_string = '{action}: {file}'
return format_string.format(**event)
def print_notify_verbose(self, event):
""" Command line notification with more verbose mode
"""
if event['type'] == 'info' or (event['type'] == 'cc' and
event['severity'] == 'verbose'):
return event['message']
elif event['type'] == 'debug':
return "[DEBUG] {message}".format(**event)
elif event['type'] in ('progress', 'cc'):
return self.print_notify(event)
COLOR_MATCHER = re.compile(r"(\w+)(\W+on\W+\w+)?")
def colorstring_to_escapecode(self, color_string):
""" Convert a color string from a string into an ascii escape code that
will print that color on the terminal.
Positional arguments:
color_string - the string to parse
"""
match = re.match(self.COLOR_MATCHER, color_string)
if match:
return self.COLORS[match.group(1)] + \
(self.COLORS[match.group(2).strip().replace(" ", "_")]
if match.group(2) else "")
else:
return self.COLORS['default']
def print_in_color(self, event, msg):
""" Wrap a toolchain notifier in a colorizer. This colorizer will wrap
notifications in a color if the severity matches a color in the
CLI_COLOR_MAP.
"""
"""The notification function inself"""
if sys.stdout.isatty() and event.get('severity', None) in CLI_COLOR_MAP:
sys.stdout.write(self.colorstring_to_escapecode(
CLI_COLOR_MAP[event['severity']]))
print(msg)
sys.stdout.write(self.colorstring_to_escapecode('default'))
else:
print(msg)