You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/02/04 07:48:59 UTC
[buildstream] branch tlater/message-helpers created (now 957d3ac)
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a change to branch tlater/message-helpers
in repository https://gitbox.apache.org/repos/asf/buildstream.git.
at 957d3ac job.py: Add new message helpers
This branch includes the following new commits:
new 28b4ad8 _context.py: Add simpler message handlers
new 4cda070 Use new message handlers in favor of old helpers
new 957d3ac job.py: Add new message helpers
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[buildstream] 02/03: Use new message handlers in favor of old
helpers
Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch tlater/message-helpers
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 4cda0705622faa053833f04991e2fa062be55457
Author: Tristan Maat <tr...@codethink.co.uk>
AuthorDate: Tue Jul 3 16:49:06 2018 +0100
Use new message handlers in favor of old helpers
---
buildstream/_artifactcache/artifactcache.py | 11 +--------
buildstream/_context.py | 10 ++++----
buildstream/_frontend/app.py | 18 ++++-----------
buildstream/_pipeline.py | 15 +++---------
buildstream/_platform/linux.py | 10 ++++----
buildstream/_scheduler/job.py | 36 +++++++++++++++--------------
buildstream/_scheduler/queue.py | 8 ++++---
buildstream/_stream.py | 26 ++++++++-------------
buildstream/plugin.py | 15 ++++++------
9 files changed, 58 insertions(+), 91 deletions(-)
diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py
index 2d745f8..e057451 100644
--- a/buildstream/_artifactcache/artifactcache.py
+++ b/buildstream/_artifactcache/artifactcache.py
@@ -324,15 +324,6 @@ class ArtifactCache():
# Local Private Methods #
################################################
- # _message()
- #
- # Local message propagator
- #
- def _message(self, message_type, message, **kwargs):
- args = dict(kwargs)
- self.context.message(
- Message(None, message_type, message, **args))
-
# _set_remotes():
#
# Set the list of remote caches. If project is None, the global list of
@@ -356,7 +347,7 @@ class ArtifactCache():
#
def _initialize_remotes(self):
def remote_failed(url, error):
- self._message(MessageType.WARN, "Failed to fetch remote refs from {}: {}".format(url, error))
+ self.context.warn("Failed to fetch remote refs from {}: {}".format(url, error))
with self.context.timed_activity("Initializing remote caches", silent_nested=True):
self.initialize_remotes(on_failure=remote_failed)
diff --git a/buildstream/_context.py b/buildstream/_context.py
index 52dd655..72a1fd8 100644
--- a/buildstream/_context.py
+++ b/buildstream/_context.py
@@ -425,8 +425,7 @@ class Context():
with _signals.suspendable(stop_time, resume_time):
try:
# Push activity depth for status messages
- message = Message(unique_id, MessageType.START, activity_name, detail=detail)
- self.message(message)
+ self.start(activity_name, detail=detail, plugin=unique_id)
self._push_message_depth(silent_nested)
yield
@@ -434,15 +433,14 @@ class Context():
# Note the failure in status messages and reraise, the scheduler
# expects an error when there is an error.
elapsed = datetime.datetime.now() - starttime
- message = Message(unique_id, MessageType.FAIL, activity_name, elapsed=elapsed)
self._pop_message_depth()
- self.message(message)
+ self.failure(activity_name, detail=detail, elapsed=elapsed, plugin=unique_id)
raise
elapsed = datetime.datetime.now() - starttime
- message = Message(unique_id, MessageType.SUCCESS, activity_name, elapsed=elapsed)
self._pop_message_depth()
- self.message(message)
+ self.success(activity_name, detail=detail,
+ elapsed=elapsed, plugin=unique_id)
# _push_message_depth() / _pop_message_depth()
#
diff --git a/buildstream/_frontend/app.py b/buildstream/_frontend/app.py
index 4675b0e..c8fb977 100644
--- a/buildstream/_frontend/app.py
+++ b/buildstream/_frontend/app.py
@@ -249,7 +249,7 @@ class App():
# Mark the beginning of the session
if session_name:
- self._message(MessageType.START, session_name)
+ self.context.start(session_name)
# Run the body of the session here, once everything is loaded
try:
@@ -261,9 +261,9 @@ class App():
elapsed = self.stream.elapsed_time
if isinstance(e, StreamError) and e.terminated: # pylint: disable=no-member
- self._message(MessageType.WARN, session_name + ' Terminated', elapsed=elapsed)
+ self.context.warn(session_name + ' Terminated', elapsed=elapsed)
else:
- self._message(MessageType.FAIL, session_name, elapsed=elapsed)
+ self.context.failure(session_name, elapsed=elapsed)
if self._started:
self._print_summary()
@@ -274,7 +274,7 @@ class App():
else:
# No exceptions occurred, print session time and summary
if session_name:
- self._message(MessageType.SUCCESS, session_name, elapsed=self.stream.elapsed_time)
+ self.context.success(session_name, elapsed=self.stream.elapsed_time)
if self._started:
self._print_summary()
@@ -411,21 +411,13 @@ class App():
# Local Functions #
############################################################
- # Local message propagator
- #
- def _message(self, message_type, message, **kwargs):
- args = dict(kwargs)
- self.context.message(
- Message(None, message_type, message, **args))
-
# Exception handler
#
def _global_exception_handler(self, etype, value, tb):
# Print the regular BUG message
formatted = "".join(traceback.format_exception(etype, value, tb))
- self._message(MessageType.BUG, str(value),
- detail=formatted)
+ self.context.bug(str(value), detail=formatted)
# If the scheduler has started, try to terminate all jobs gracefully,
# otherwise exit immediately.
diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py
index 9f4504d..35ba560 100644
--- a/buildstream/_pipeline.py
+++ b/buildstream/_pipeline.py
@@ -129,7 +129,7 @@ class Pipeline():
for source, ref in redundant_refs
]
detail += "\n".join(lines)
- self._message(MessageType.WARN, "Ignoring redundant source references", detail=detail)
+ self._context.warn("Ignoring redundant source references", detail=detail)
# Now create element groups to match the input target groups
elt_iter = iter(elements)
@@ -220,8 +220,8 @@ class Pipeline():
for t in targets:
new_elm = t._get_source_element()
if new_elm != t and not silent:
- self._message(MessageType.INFO, "Element '{}' redirected to '{}'"
- .format(t.name, new_elm.name))
+ self._context.info("Element '{}' redirected to '{}'"
+ .format(t.name, new_elm.name))
if new_elm not in elements:
elements.append(new_elm)
elif mode == PipelineSelection.PLAN:
@@ -444,15 +444,6 @@ class Pipeline():
raise PipelineError("Untrackable sources", detail=detail, reason="untrackable-sources")
- # _message()
- #
- # Local message propagator
- #
- def _message(self, message_type, message, **kwargs):
- args = dict(kwargs)
- self._context.message(
- Message(None, message_type, message, **args))
-
# _Planner()
#
diff --git a/buildstream/_platform/linux.py b/buildstream/_platform/linux.py
index fec512b..6f51266 100644
--- a/buildstream/_platform/linux.py
+++ b/buildstream/_platform/linux.py
@@ -75,9 +75,9 @@ class Linux(Platform):
return True
else:
- context.message(
- Message(None, MessageType.WARN,
- "Unable to create user namespaces with bubblewrap, resorting to fallback",
- detail="Some builds may not function due to lack of uid / gid 0, " +
- "artifacts created will not be trusted for push purposes."))
+ context.warn(
+ "Unable to create user namespaces with bubblewrap, resorting to fallback",
+ detail="Some builds may not function due to lack of uid / gid 0, " +
+ "artifacts created will not be trusted for push purposes."
+ )
return False
diff --git a/buildstream/_scheduler/job.py b/buildstream/_scheduler/job.py
index cc35064..c501eb0 100644
--- a/buildstream/_scheduler/job.py
+++ b/buildstream/_scheduler/job.py
@@ -173,8 +173,8 @@ class Job():
# First resume the job if it's suspended
self.resume(silent=True)
- self._message(self.element, MessageType.STATUS,
- "{} terminating".format(self.action_name))
+ self._message("{} terminating".format(self.action_name),
+ MessageType.STATUS, self.element)
# Make sure there is no garbage on the queue
self._parent_stop_listening()
@@ -205,8 +205,9 @@ class Job():
def kill(self):
# Force kill
- self._message(self.element, MessageType.WARN,
- "{} did not terminate gracefully, killing".format(self.action_name))
+ self._message("{} did not terminate gracefully, killing"
+ .format(self.action_name), self.element,
+ MessageType.WARN)
utils._kill_process_tree(self._process.pid)
# suspend()
@@ -215,8 +216,8 @@ class Job():
#
def suspend(self):
if not self._suspended:
- self._message(self.element, MessageType.STATUS,
- "{} suspending".format(self.action_name))
+ self._message("{} suspending".format(self.action_name),
+ self.element, MessageType.STATUS)
try:
# Use SIGTSTP so that child processes may handle and propagate
@@ -240,8 +241,8 @@ class Job():
def resume(self, silent=False):
if self._suspended:
if not silent:
- self._message(self.element, MessageType.STATUS,
- "{} resuming".format(self.action_name))
+ self._message("{} resuming".format(self.action_name),
+ self.element, MessageType.STATUS)
os.kill(self._process.pid, signal.SIGCONT)
self._suspended = False
@@ -268,14 +269,15 @@ class Job():
# message (str): The message
# kwargs: Remaining Message() constructor arguments
#
- def _message(self, plugin, message_type, message, **kwargs):
+ def _message(self, message, message_type, plugin, **kwargs):
args = dict(kwargs)
args['scheduler'] = True
- self._scheduler.context.message(
- Message(plugin._get_unique_id(),
- message_type,
- message,
- **args))
+ self._scheduler.context.msg(
+ message,
+ plugin=plugin._get_unique_id(),
+ msg_type=message_type,
+ **args
+ )
# _child_action()
#
@@ -324,15 +326,15 @@ class Job():
with _signals.suspendable(stop_time, resume_time), \
element._logging_enabled(self.action_name) as filename:
- self._message(element, MessageType.START, self.action_name, logfile=filename)
+ self._message(self.action_name, MessageType.START, element, logfile=filename)
# Print the element's environment at the beginning of any element's log file.
#
# This should probably be omitted for non-build tasks but it's harmless here
elt_env = element.get_environment()
env_dump = yaml.round_trip_dump(elt_env, default_flow_style=False, allow_unicode=True)
- self._message(element, MessageType.LOG,
- "Build environment for element {}".format(element.name),
+ self._message("Build environment for element {}".format(element.name),
+ MessageType.LOG, element,
detail=env_dump, logfile=filename)
try:
diff --git a/buildstream/_scheduler/queue.py b/buildstream/_scheduler/queue.py
index 15caf83..2225b0a 100644
--- a/buildstream/_scheduler/queue.py
+++ b/buildstream/_scheduler/queue.py
@@ -274,7 +274,9 @@ class Queue():
try:
workspaces.save_config()
except BstError as e:
- self._message(element, MessageType.ERROR, "Error saving workspaces", detail=str(e))
+ element._get_context().error("Error saving workspaces",
+ detail=str(e),
+ plugin=element._get_unique_id())
except Exception as e: # pylint: disable=broad-except
self._message(element, MessageType.BUG,
"Unhandled exception while saving workspaces",
@@ -351,5 +353,5 @@ class Queue():
# a message for the element they are processing
def _message(self, element, message_type, brief, **kwargs):
context = element._get_context()
- message = Message(element._get_unique_id(), message_type, brief, **kwargs)
- context.message(message)
+ context._message(brief, plugin=element._get_unique_id(),
+ msg_type=message_type, **kwargs)
diff --git a/buildstream/_stream.py b/buildstream/_stream.py
index 5013daf..b2b1b51 100644
--- a/buildstream/_stream.py
+++ b/buildstream/_stream.py
@@ -468,7 +468,7 @@ class Stream():
target._open_workspace()
workspaces.save_config()
- self._message(MessageType.INFO, "Saved workspace configuration")
+ self._context.info("Saved workspace configuration")
# workspace_close
#
@@ -495,7 +495,7 @@ class Stream():
# Delete the workspace and save the configuration
workspaces.delete_workspace(element_name)
workspaces.save_config()
- self._message(MessageType.INFO, "Closed workspace for {}".format(element_name))
+ self._context.info("Closed workspace for {}".format(element_name))
# workspace_reset
#
@@ -534,8 +534,8 @@ class Stream():
if soft:
workspace.prepared = False
- self._message(MessageType.INFO, "Reset workspace state for {} at: {}"
- .format(element.name, workspace.path))
+ self._context.info("Reset workspace state for {} at: {}"
+ .format(element.name, workspace.path))
continue
with element.timed_activity("Removing workspace directory {}"
@@ -552,7 +552,8 @@ class Stream():
with element.timed_activity("Staging sources to {}".format(workspace.path)):
element._open_workspace()
- self._message(MessageType.INFO, "Reset workspace for {} at: {}".format(element.name, workspace.path))
+ self._context.info("Reset workspace for {} at: {}"
+ .format(element.name, workspace.path))
workspaces.save_config()
@@ -626,7 +627,7 @@ class Stream():
# source-bundle only supports one target
target = self.targets[0]
- self._message(MessageType.INFO, "Bundling sources for target {}".format(target.name))
+ self._context.info("Bundling sources for target {}".format(target.name))
# Find the correct filename for the compression algorithm
tar_location = os.path.join(directory, target.normal_name + ".tar")
@@ -881,15 +882,6 @@ class Stream():
return selected, track_selected
- # _message()
- #
- # Local message propagator
- #
- def _message(self, message_type, message, **kwargs):
- args = dict(kwargs)
- self._context.message(
- Message(None, message_type, message, **args))
-
# _add_queue()
#
# Adds a queue to the stream
@@ -940,10 +932,10 @@ class Stream():
for element in self.total_elements:
element._update_state()
except BstError as e:
- self._message(MessageType.ERROR, "Error resolving final state", detail=str(e))
+ self._context.error("Error resolving final state", detail=str(e))
set_last_task_error(e.domain, e.reason)
except Exception as e: # pylint: disable=broad-except
- self._message(MessageType.BUG, "Unhandled exception while resolving final state", detail=str(e))
+ self._context.bug("Unhandled exception while resolving final state", detail=str(e))
if status == SchedStatus.ERROR:
raise StreamError()
diff --git a/buildstream/plugin.py b/buildstream/plugin.py
index 29fe2cb..3f27207 100644
--- a/buildstream/plugin.py
+++ b/buildstream/plugin.py
@@ -100,7 +100,6 @@ from weakref import WeakValueDictionary
from . import _yaml
from . import utils
from ._exceptions import PluginError, ImplError
-from ._message import Message, MessageType
class Plugin():
@@ -404,7 +403,7 @@ class Plugin():
detail (str): An optional detailed message, can be multiline output
"""
if self.__context.log_debug:
- self.__message(MessageType.DEBUG, brief, detail=detail)
+ self.__context.debug(brief, detail=detail)
def status(self, brief, *, detail=None):
"""Print a status message
@@ -415,7 +414,7 @@ class Plugin():
Note: Status messages tell about what a plugin is currently doing
"""
- self.__message(MessageType.STATUS, brief, detail=detail)
+ self.__context.status(brief, detail=detail)
def info(self, brief, *, detail=None):
"""Print an informative message
@@ -427,7 +426,7 @@ class Plugin():
Note: Informative messages tell the user something they might want
to know, like if refreshing an element caused it to change.
"""
- self.__message(MessageType.INFO, brief, detail=detail)
+ self.__context.info(brief, detail=detail)
def warn(self, brief, *, detail=None):
"""Print a warning message
@@ -436,7 +435,7 @@ class Plugin():
brief (str): The brief message
detail (str): An optional detailed message, can be multiline output
"""
- self.__message(MessageType.WARN, brief, detail=detail)
+ self.__context.warn(brief, detail=detail)
def log(self, brief, *, detail=None):
"""Log a message into the plugin's log file
@@ -448,7 +447,7 @@ class Plugin():
brief (str): The brief message
detail (str): An optional detailed message, can be multiline output
"""
- self.__message(MessageType.LOG, brief, detail=detail)
+ self.log(brief, detail=detail)
@contextmanager
def timed_activity(self, activity_name, *, detail=None, silent_nested=False):
@@ -648,8 +647,8 @@ class Plugin():
return (exit_code, output)
def __message(self, message_type, brief, **kwargs):
- message = Message(self.__unique_id, message_type, brief, **kwargs)
- self.__context.message(message)
+ self.__context._message(brief, plugin=self.__unique_id,
+ msg_type=message_type, **kwargs)
def __note_command(self, output, *popenargs, **kwargs):
workdir = os.getcwd()
[buildstream] 03/03: job.py: Add new message helpers
Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch tlater/message-helpers
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 957d3acb9c4ecc73aa4a9b154c0e87138d3b3d7e
Author: Tristan Maat <tr...@codethink.co.uk>
AuthorDate: Mon Jul 23 18:36:41 2018 +0100
job.py: Add new message helpers
---
buildstream/_scheduler/job.py | 85 +++++++++++++++++++++++++++----------------
1 file changed, 54 insertions(+), 31 deletions(-)
diff --git a/buildstream/_scheduler/job.py b/buildstream/_scheduler/job.py
index c501eb0..266dd1f 100644
--- a/buildstream/_scheduler/job.py
+++ b/buildstream/_scheduler/job.py
@@ -173,8 +173,7 @@ class Job():
# First resume the job if it's suspended
self.resume(silent=True)
- self._message("{} terminating".format(self.action_name),
- MessageType.STATUS, self.element)
+ self._status("{} terminating".format(self.action_name), self.element)
# Make sure there is no garbage on the queue
self._parent_stop_listening()
@@ -205,9 +204,8 @@ class Job():
def kill(self):
# Force kill
- self._message("{} did not terminate gracefully, killing"
- .format(self.action_name), self.element,
- MessageType.WARN)
+ self._warn("{} did not terminate gracefully, killing"
+ .format(self.action_name), self.element)
utils._kill_process_tree(self._process.pid)
# suspend()
@@ -216,8 +214,7 @@ class Job():
#
def suspend(self):
if not self._suspended:
- self._message("{} suspending".format(self.action_name),
- self.element, MessageType.STATUS)
+ self._status("{} suspending".format(self.action_name), self.element)
try:
# Use SIGTSTP so that child processes may handle and propagate
@@ -241,8 +238,7 @@ class Job():
def resume(self, silent=False):
if self._suspended:
if not silent:
- self._message("{} resuming".format(self.action_name),
- self.element, MessageType.STATUS)
+ self._status("{} resuming".format(self.action_name), self.element)
os.kill(self._process.pid, signal.SIGCONT)
self._suspended = False
@@ -269,16 +265,45 @@ class Job():
# message (str): The message
# kwargs: Remaining Message() constructor arguments
#
- def _message(self, message, message_type, plugin, **kwargs):
- args = dict(kwargs)
- args['scheduler'] = True
- self._scheduler.context.msg(
- message,
+ def _message(self, text, plugin, *, msg_type=None, **kwargs):
+ self._scheduler.context._message(
+ text,
plugin=plugin._get_unique_id(),
- msg_type=message_type,
- **args
+ msg_type=msg_type,
+ scheduler=True,
+ **kwargs
)
+ def _start(self, *args, **kwargs):
+ self._message(*args, msg_type=MessageType.START, **kwargs)
+
+ def _success(self, *args, **kwargs):
+ self._message(*args, msg_type=MessageType.SUCCESS, **kwargs)
+
+ def _failure(self, *args, **kwargs):
+ self._message(*args, msg_type=MessageType.FAIL, **kwargs)
+
+ def _debug(self, *args, **kwargs):
+ self._message(*args, msg_type=MessageType.DEBUG, **kwargs)
+
+ def _status(self, *args, **kwargs):
+ self._message(*args, msg_type=MessageType.STATUS, **kwargs)
+
+ def _info(self, *args, **kwargs):
+ self._message(*args, msg_type=MessageType.INFO, **kwargs)
+
+ def _warn(self, *args, **kwargs):
+ self._message(*args, msg_type=MessageType.WARN, **kwargs)
+
+ def _error(self, *args, **kwargs):
+ self._message(*args, msg_type=MessageType.ERROR, **kwargs)
+
+ def _bug(self, *args, **kwargs):
+ self._message(*args, msg_type=MessageType.BUG, **kwargs)
+
+ def _log(self, *args, **kwargs):
+ self._message(*args, msg_type=MessageType.LOG, **kwargs)
+
# _child_action()
#
# Perform the action in the child process, this calls the action_cb.
@@ -326,16 +351,15 @@ class Job():
with _signals.suspendable(stop_time, resume_time), \
element._logging_enabled(self.action_name) as filename:
- self._message(self.action_name, MessageType.START, element, logfile=filename)
+ self._start(self.action_name, element, logfile=filename)
# Print the element's environment at the beginning of any element's log file.
#
# This should probably be omitted for non-build tasks but it's harmless here
elt_env = element.get_environment()
env_dump = yaml.round_trip_dump(elt_env, default_flow_style=False, allow_unicode=True)
- self._message("Build environment for element {}".format(element.name),
- MessageType.LOG, element,
- detail=env_dump, logfile=filename)
+ self._log("Build environment for element {}".format(element.name),
+ element, detail=env_dump, logfile=filename)
try:
# Try the task action
@@ -344,12 +368,12 @@ class Job():
elapsed = datetime.datetime.now() - starttime
if self._tries <= self._max_retries:
- self._message(element, MessageType.FAIL, "Try #{} failed, retrying".format(self._tries),
- elapsed=elapsed)
+ self._failure("Try #{} failed, retrying".format(self._tries),
+ element, elapsed=elapsed)
else:
- self._message(element, MessageType.FAIL, str(e),
- elapsed=elapsed, detail=e.detail,
- logfile=filename, sandbox=e.sandbox)
+ self._failure(str(e), element, elapsed=elapsed,
+ detail=e.detail, logfile=filename,
+ sandbox=e.sandbox)
# Report changes in the workspace, even if there was a handled failure
self._child_send_workspace()
@@ -366,9 +390,8 @@ class Job():
#
elapsed = datetime.datetime.now() - starttime
detail = "An unhandled exception occured:\n\n{}".format(traceback.format_exc())
- self._message(element, MessageType.BUG, self.action_name,
- elapsed=elapsed, detail=detail,
- logfile=filename)
+ self._bug(self.action_name, element, elapsed=elapsed,
+ detail=detail, logfile=filename)
self._child_shutdown(1)
else:
@@ -377,8 +400,8 @@ class Job():
self._child_send_result(result)
elapsed = datetime.datetime.now() - starttime
- self._message(element, MessageType.SUCCESS, self.action_name, elapsed=elapsed,
- logfile=filename)
+ self._success(self.action_name, element,
+ elapsed=elapsed, logfile=filename)
# Shutdown needs to stay outside of the above context manager,
# make sure we dont try to handle SIGTERM while the process
@@ -562,7 +585,7 @@ class Job():
if envelope.message_type == 'message':
# Propagate received messages from children
# back through the context.
- self._scheduler.context.message(envelope.message)
+ self._scheduler.context._send_message(envelope.message)
elif envelope.message_type == 'error':
# For regression tests only, save the last error domain / reason
# reported from a child task in the main process, this global state
[buildstream] 01/03: _context.py: Add simpler message handlers
Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
tvb pushed a commit to branch tlater/message-helpers
in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 28b4ad8d3314af3926a91a07bf6c1fb723baf1b4
Author: Tristan Maat <tr...@codethink.co.uk>
AuthorDate: Tue Jul 3 16:43:47 2018 +0100
_context.py: Add simpler message handlers
---
buildstream/_context.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 46 insertions(+), 3 deletions(-)
diff --git a/buildstream/_context.py b/buildstream/_context.py
index 1a59af2..52dd655 100644
--- a/buildstream/_context.py
+++ b/buildstream/_context.py
@@ -25,6 +25,7 @@ from . import _cachekey
from . import _signals
from . import _site
from . import _yaml
+from .plugin import Plugin
from ._exceptions import LoadError, LoadErrorReason, BstError
from ._message import Message, MessageType
from ._profile import Topics, profile_start, profile_end
@@ -324,8 +325,7 @@ class Context():
# Args:
# message: A Message object
#
- def message(self, message):
-
+ def _send_message(self, message):
# Tag message only once
if message.depth is None:
message.depth = len(list(self._message_depth))
@@ -336,7 +336,50 @@ class Context():
assert self._message_handler
self._message_handler(message, context=self)
- return
+
+ # _message():
+ #
+ # The global message API. Any message-sending functions should go
+ # through here. This will call `_send_message` to deliver the
+ # final message.
+ #
+ def _message(self, text, *, plugin=None, msg_type=None, **kwargs):
+ if isinstance(plugin, Plugin):
+ plugin_id = plugin._get_unique_id()
+ else:
+ plugin_id = plugin
+
+ self._send_message(Message(plugin, msg_type, str(text), **kwargs))
+
+ def start(self, text, *, plugin=None, **kwargs):
+ self._message(text, plugin=plugin, msg_type=MessageType.START, **kwargs)
+
+ def success(self, text, *, plugin=None, **kwargs):
+ self._message(text, plugin=plugin, msg_type=MessageType.SUCCESS, **kwargs)
+
+ def failure(self, text, *, plugin=None, **kwargs):
+ self._message(text, plugin=plugin, msg_type=MessageType.FAIL, **kwargs)
+
+ def debug(self, text, *, plugin=None, **kwargs):
+ self._message(text, plugin=plugin, msg_type=MessageType.DEBUG, **kwargs)
+
+ def status(self, text, *, plugin=None, **kwargs):
+ self._message(text, plugin=plugin, msg_type=MessageType.STATUS, **kwargs)
+
+ def info(self, text, *, plugin=None, **kwargs):
+ self._message(text, plugin=plugin, msg_type=MessageType.INFO, **kwargs)
+
+ def warn(self, text, *, plugin=None, **kwargs):
+ self._message(text, plugin=plugin, msg_type=MessageType.WARN, **kwargs)
+
+ def error(self, text, *, plugin=None, **kwargs):
+ self._message(text, plugin=plugin, msg_type=MessageType.ERROR, **kwargs)
+
+ def bug(self, text, *, plugin=None, **kwargs):
+ self._message(text, plugin=plugin, msg_type=MessageType.BUG, **kwargs)
+
+ def log(self, text, *, plugin=None, **kwargs):
+ self._message(text, plugin=plugin, msg_type=MessageType.LOG, **kwargs)
# silence()
#