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
theotherjimmy 43:2a7da56ebd24 1 # mbed SDK
theotherjimmy 43:2a7da56ebd24 2 # Copyright (c) 2011-2013 ARM Limited
theotherjimmy 43:2a7da56ebd24 3 #
theotherjimmy 43:2a7da56ebd24 4 # Licensed under the Apache License, Version 2.0 (the "License");
theotherjimmy 43:2a7da56ebd24 5 # you may not use this file except in compliance with the License.
theotherjimmy 43:2a7da56ebd24 6 # You may obtain a copy of the License at
theotherjimmy 43:2a7da56ebd24 7 #
theotherjimmy 43:2a7da56ebd24 8 # http://www.apache.org/licenses/LICENSE-2.0
theotherjimmy 43:2a7da56ebd24 9 #
theotherjimmy 43:2a7da56ebd24 10 # Unless required by applicable law or agreed to in writing, software
theotherjimmy 43:2a7da56ebd24 11 # distributed under the License is distributed on an "AS IS" BASIS,
theotherjimmy 43:2a7da56ebd24 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
theotherjimmy 43:2a7da56ebd24 13 # See the License for the specific language governing permissions and
theotherjimmy 43:2a7da56ebd24 14 # limitations under the License.
theotherjimmy 43:2a7da56ebd24 15
theotherjimmy 43:2a7da56ebd24 16 from __future__ import print_function, division, absolute_import
theotherjimmy 43:2a7da56ebd24 17
theotherjimmy 43:2a7da56ebd24 18 from abc import ABCMeta, abstractmethod
theotherjimmy 43:2a7da56ebd24 19
theotherjimmy 43:2a7da56ebd24 20
theotherjimmy 43:2a7da56ebd24 21 class Notifier(object):
theotherjimmy 43:2a7da56ebd24 22 """
theotherjimmy 43:2a7da56ebd24 23 Notifiers send build system events to a front end or may implement a front
theotherjimmy 43:2a7da56ebd24 24 end themselves, displaying warnings and errors for a user.
theotherjimmy 43:2a7da56ebd24 25
theotherjimmy 43:2a7da56ebd24 26 This is different from a logger in a few ways:
theotherjimmy 43:2a7da56ebd24 27 * The structure of the events are defined by this interface.
theotherjimmy 43:2a7da56ebd24 28 * A "progress" level is included allowing signaling completion status to
theotherjimmy 43:2a7da56ebd24 29 users.
theotherjimmy 43:2a7da56ebd24 30 * It's tailored to providing events from a build system.
theotherjimmy 43:2a7da56ebd24 31
theotherjimmy 43:2a7da56ebd24 32 The structure of a message is a dict with a 'type' key. The type key
theotherjimmy 43:2a7da56ebd24 33 determines the remaining keys as follows:
theotherjimmy 43:2a7da56ebd24 34 type | description and remaining keys
theotherjimmy 43:2a7da56ebd24 35 ---------- | ------------------------------
theotherjimmy 43:2a7da56ebd24 36 info | A simple message. The 'message' key contains the message
theotherjimmy 43:2a7da56ebd24 37 debug | Another simple message; this one is less useful when compiles
theotherjimmy 43:2a7da56ebd24 38 | are working. Again, the 'message' key contains the message
theotherjimmy 43:2a7da56ebd24 39 progress | A progress indicator, which may include progress as a
theotherjimmy 43:2a7da56ebd24 40 | percentage. The action key includes what action was taken to
theotherjimmy 43:2a7da56ebd24 41 | make this progress, the file key what file was used to make
theotherjimmy 43:2a7da56ebd24 42 | this progress, and the percent key, when present, indicates
theotherjimmy 43:2a7da56ebd24 43 | how far along the build is.
theotherjimmy 43:2a7da56ebd24 44 tool_error | When a compile fails, this contains the entire output of the
theotherjimmy 43:2a7da56ebd24 45 | compiler.
theotherjimmy 43:2a7da56ebd24 46 var | Provides a key, in the 'key' key, and a value, in the 'value'
theotherjimmy 43:2a7da56ebd24 47 | key, for use in a UI. At the time of writing it's used to
theotherjimmy 43:2a7da56ebd24 48 | communicate the binary location to the online IDE.
theotherjimmy 43:2a7da56ebd24 49 """
theotherjimmy 43:2a7da56ebd24 50
theotherjimmy 43:2a7da56ebd24 51 __metaclass__ = ABCMeta
theotherjimmy 43:2a7da56ebd24 52
theotherjimmy 43:2a7da56ebd24 53 @abstractmethod
theotherjimmy 43:2a7da56ebd24 54 def notify(self, event):
theotherjimmy 43:2a7da56ebd24 55 """
theotherjimmy 43:2a7da56ebd24 56 Send the user a notification specified in the event.
theotherjimmy 43:2a7da56ebd24 57 """
theotherjimmy 43:2a7da56ebd24 58 raise NotImplemented
theotherjimmy 43:2a7da56ebd24 59
theotherjimmy 43:2a7da56ebd24 60 def info(self, message):
theotherjimmy 43:2a7da56ebd24 61 """
theotherjimmy 43:2a7da56ebd24 62 Send the user a simple message.
theotherjimmy 43:2a7da56ebd24 63 """
theotherjimmy 43:2a7da56ebd24 64 self.notify({'type': 'info', 'message': message})
theotherjimmy 43:2a7da56ebd24 65
theotherjimmy 43:2a7da56ebd24 66 def debug(self, message):
theotherjimmy 43:2a7da56ebd24 67 """
theotherjimmy 43:2a7da56ebd24 68 Send a debug message to the user.
theotherjimmy 43:2a7da56ebd24 69 """
theotherjimmy 43:2a7da56ebd24 70 if isinstance(message, list):
theotherjimmy 43:2a7da56ebd24 71 message = ' '.join(message)
theotherjimmy 43:2a7da56ebd24 72 self.notify({'type': 'debug', 'message': message})
theotherjimmy 43:2a7da56ebd24 73
theotherjimmy 43:2a7da56ebd24 74 def cc_info(self, info=None):
theotherjimmy 43:2a7da56ebd24 75 if info is not None:
theotherjimmy 43:2a7da56ebd24 76 info['type'] = 'cc'
theotherjimmy 43:2a7da56ebd24 77 self.notify(info)
theotherjimmy 43:2a7da56ebd24 78
theotherjimmy 43:2a7da56ebd24 79 def cc_verbose(self, message, file=""):
theotherjimmy 43:2a7da56ebd24 80 self.notify({
theotherjimmy 43:2a7da56ebd24 81 'type': 'cc',
theotherjimmy 43:2a7da56ebd24 82 'severity': 'verbose',
theotherjimmy 43:2a7da56ebd24 83 'file': file,
theotherjimmy 43:2a7da56ebd24 84 'message': message
theotherjimmy 43:2a7da56ebd24 85 })
theotherjimmy 43:2a7da56ebd24 86
theotherjimmy 43:2a7da56ebd24 87 def progress(self, action, file, percent=None):
theotherjimmy 43:2a7da56ebd24 88 """
theotherjimmy 43:2a7da56ebd24 89 Indicate compilation progress to a user.
theotherjimmy 43:2a7da56ebd24 90 """
theotherjimmy 43:2a7da56ebd24 91 msg = {'type': 'progress', 'action': action, 'file': file}
theotherjimmy 43:2a7da56ebd24 92 if percent:
theotherjimmy 43:2a7da56ebd24 93 msg['percent'] = percent
theotherjimmy 43:2a7da56ebd24 94 self.notify(msg)
theotherjimmy 43:2a7da56ebd24 95
theotherjimmy 43:2a7da56ebd24 96 def tool_error(self, message):
theotherjimmy 43:2a7da56ebd24 97 """
theotherjimmy 43:2a7da56ebd24 98 Communicate a full fatal error to a user.
theotherjimmy 43:2a7da56ebd24 99 """
theotherjimmy 43:2a7da56ebd24 100 self.notify({'type': 'tool_error', 'message': message})
theotherjimmy 43:2a7da56ebd24 101
theotherjimmy 43:2a7da56ebd24 102 def var(self, key, value):
theotherjimmy 43:2a7da56ebd24 103 """
theotherjimmy 43:2a7da56ebd24 104 Update a UI with a key, value pair
theotherjimmy 43:2a7da56ebd24 105 """
theotherjimmy 43:2a7da56ebd24 106 self.notify({'type': 'var', 'key': key, 'val': value})