summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/build.py
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-06-23 22:59:05 +1200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-07-08 09:57:26 +0100
commitac5e720575dd3c8f86514a7a646de82c8cc28e17 (patch)
tree9c0cec5d764f1b9fb8f33d5f094d87a8fbc89ab5 /bitbake/lib/bb/build.py
parent1cf6e14a6c5ddb4daec1c1e0cce113eea8570545 (diff)
downloadpoky-ac5e720575dd3c8f86514a7a646de82c8cc28e17.tar.gz
bitbake: lib: implement basic task progress support
For long-running tasks where we have some output from the task that gives us some idea of the progress of the task (such as a percentage complete), provide the means to scrape the output for that progress information and show it to the user in the default knotty terminal output in the form of a progress bar. This is implemented using a new TaskProgress event as well as some code we can insert to do output scanning/filtering. Any task can fire TaskProgress events; however, if you have a shell task whose output you wish to scan for progress information, you just need to set the "progress" varflag on the task. This can be set to: * "percent" to just look for a number followed by a % sign * "percent:<regex>" to specify your own regex matching a percentage value (must have a single group which matches the percentage number) * "outof:<regex>" to look for the specified regex matching x out of y items completed (must have two groups - first group needs to be x, second y). We can potentially extend this in future but this should be a good start. Part of the implementation for [YOCTO #5383]. (Bitbake rev: 0d275fc5b6531957a6189069b04074065bb718a0) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/build.py')
-rw-r--r--bitbake/lib/bb/build.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py
index 2ebe67306f..4fb2a77cfd 100644
--- a/bitbake/lib/bb/build.py
+++ b/bitbake/lib/bb/build.py
@@ -35,6 +35,7 @@ import stat
35import bb 35import bb
36import bb.msg 36import bb.msg
37import bb.process 37import bb.process
38import bb.progress
38from bb import data, event, utils 39from bb import data, event, utils
39 40
40bblogger = logging.getLogger('BitBake') 41bblogger = logging.getLogger('BitBake')
@@ -137,6 +138,25 @@ class TaskInvalid(TaskBase):
137 super(TaskInvalid, self).__init__(task, None, metadata) 138 super(TaskInvalid, self).__init__(task, None, metadata)
138 self._message = "No such task '%s'" % task 139 self._message = "No such task '%s'" % task
139 140
141class TaskProgress(event.Event):
142 """
143 Task made some progress that could be reported to the user, usually in
144 the form of a progress bar or similar.
145 NOTE: this class does not inherit from TaskBase since it doesn't need
146 to - it's fired within the task context itself, so we don't have any of
147 the context information that you do in the case of the other events.
148 The event PID can be used to determine which task it came from.
149 The progress value is normally 0-100, but can also be negative
150 indicating that progress has been made but we aren't able to determine
151 how much.
152 The rate is optional, this is simply an extra string to display to the
153 user if specified.
154 """
155 def __init__(self, progress, rate=None):
156 self.progress = progress
157 self.rate = rate
158 event.Event.__init__(self)
159
140 160
141class LogTee(object): 161class LogTee(object):
142 def __init__(self, logger, outfile): 162 def __init__(self, logger, outfile):
@@ -340,6 +360,20 @@ exit $ret
340 else: 360 else:
341 logfile = sys.stdout 361 logfile = sys.stdout
342 362
363 progress = d.getVarFlag(func, 'progress', True)
364 if progress:
365 if progress == 'percent':
366 # Use default regex
367 logfile = bb.progress.BasicProgressHandler(d, outfile=logfile)
368 elif progress.startswith('percent:'):
369 # Use specified regex
370 logfile = bb.progress.BasicProgressHandler(d, regex=progress.split(':', 1)[1], outfile=logfile)
371 elif progress.startswith('outof:'):
372 # Use specified regex
373 logfile = bb.progress.OutOfProgressHandler(d, regex=progress.split(':', 1)[1], outfile=logfile)
374 else:
375 bb.warn('%s: invalid task progress varflag value "%s", ignoring' % (func, progress))
376
343 def readfifo(data): 377 def readfifo(data):
344 lines = data.split(b'\0') 378 lines = data.split(b'\0')
345 for line in lines: 379 for line in lines: