2005-08-31 10:47:56 +00:00
|
|
|
# ex:ts=4:sw=4:sts=4:et
|
|
|
|
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2007-01-08 23:53:01 +00:00
|
|
|
#
|
|
|
|
# BitBake 'Build' implementation
|
|
|
|
#
|
|
|
|
# Core code for function execution and task handling in the
|
|
|
|
# BitBake build tools.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2003, 2004 Chris Larson
|
|
|
|
#
|
|
|
|
# Based on Gentoo's portage.py.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
2014-08-20 12:23:27 +00:00
|
|
|
# Based on functions from the base bb module, Copyright 2003 Holger Schurig
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2010-06-10 17:35:31 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import logging
|
2011-06-08 16:23:42 +00:00
|
|
|
import shlex
|
2012-11-28 19:39:23 +00:00
|
|
|
import glob
|
2014-03-17 15:28:46 +00:00
|
|
|
import time
|
2015-04-21 15:48:49 +00:00
|
|
|
import stat
|
2010-06-10 17:35:31 +00:00
|
|
|
import bb
|
2010-12-10 04:38:35 +00:00
|
|
|
import bb.msg
|
2010-12-10 01:14:48 +00:00
|
|
|
import bb.process
|
2016-06-23 10:59:05 +00:00
|
|
|
import bb.progress
|
2016-05-12 07:30:35 +00:00
|
|
|
from bb import data, event, utils
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2010-12-10 04:38:35 +00:00
|
|
|
bblogger = logging.getLogger('BitBake')
|
|
|
|
logger = logging.getLogger('BitBake.Build')
|
2010-06-10 17:35:31 +00:00
|
|
|
|
2010-12-20 02:30:49 +00:00
|
|
|
NULL = open(os.devnull, 'r+')
|
2010-12-10 01:14:48 +00:00
|
|
|
|
2015-04-21 15:48:49 +00:00
|
|
|
__mtime_cache = {}
|
|
|
|
|
|
|
|
def cached_mtime_noerror(f):
|
|
|
|
if f not in __mtime_cache:
|
|
|
|
try:
|
|
|
|
__mtime_cache[f] = os.stat(f)[stat.ST_MTIME]
|
|
|
|
except OSError:
|
|
|
|
return 0
|
|
|
|
return __mtime_cache[f]
|
|
|
|
|
|
|
|
def reset_cache():
|
|
|
|
global __mtime_cache
|
|
|
|
__mtime_cache = {}
|
|
|
|
|
2014-08-20 12:23:27 +00:00
|
|
|
# When we execute a Python function, we'd like certain things
|
|
|
|
# in all namespaces, hence we add them to __builtins__.
|
2009-10-13 07:25:34 +00:00
|
|
|
# If we do not do this and use the exec globals, they will
|
|
|
|
# not be available to subfunctions.
|
2016-04-30 19:43:52 +00:00
|
|
|
if hasattr(__builtins__, '__setitem__'):
|
|
|
|
builtins = __builtins__
|
|
|
|
else:
|
|
|
|
builtins = __builtins__.__dict__
|
|
|
|
|
|
|
|
builtins['bb'] = bb
|
|
|
|
builtins['os'] = os
|
2009-10-13 07:25:34 +00:00
|
|
|
|
2005-08-31 10:47:56 +00:00
|
|
|
class FuncFailed(Exception):
|
2011-01-17 23:54:11 +00:00
|
|
|
def __init__(self, name = None, logfile = None):
|
2010-09-10 01:03:40 +00:00
|
|
|
self.logfile = logfile
|
2010-12-15 22:35:13 +00:00
|
|
|
self.name = name
|
2011-01-17 23:54:11 +00:00
|
|
|
if name:
|
2012-01-13 17:01:46 +00:00
|
|
|
self.msg = 'Function failed: %s' % name
|
2011-01-17 23:54:11 +00:00
|
|
|
else:
|
|
|
|
self.msg = "Function failed"
|
2010-09-10 01:03:40 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2010-09-10 20:02:04 +00:00
|
|
|
if self.logfile and os.path.exists(self.logfile):
|
2013-05-24 10:28:38 +00:00
|
|
|
msg = ("%s (log file is located at %s)" %
|
2011-01-17 15:52:06 +00:00
|
|
|
(self.msg, self.logfile))
|
2010-09-10 21:20:47 +00:00
|
|
|
else:
|
2011-01-17 15:52:06 +00:00
|
|
|
msg = self.msg
|
2010-09-10 01:03:40 +00:00
|
|
|
return msg
|
2005-08-31 10:47:56 +00:00
|
|
|
|
|
|
|
class TaskBase(event.Event):
|
|
|
|
"""Base class for task events"""
|
|
|
|
|
2013-09-14 16:54:09 +00:00
|
|
|
def __init__(self, t, logfile, d):
|
2005-08-31 10:47:56 +00:00
|
|
|
self._task = t
|
2016-11-25 15:28:08 +00:00
|
|
|
self._package = d.getVar("PF")
|
|
|
|
self.taskfile = d.getVar("FILE")
|
2013-09-18 12:15:49 +00:00
|
|
|
self.taskname = self._task
|
2013-09-14 16:54:09 +00:00
|
|
|
self.logfile = logfile
|
2014-03-17 15:28:46 +00:00
|
|
|
self.time = time.time()
|
2010-01-20 18:46:02 +00:00
|
|
|
event.Event.__init__(self)
|
2016-11-25 15:28:08 +00:00
|
|
|
self._message = "recipe %s: task %s: %s" % (d.getVar("PF"), t, self.getDisplayName())
|
2005-08-31 10:47:56 +00:00
|
|
|
|
|
|
|
def getTask(self):
|
|
|
|
return self._task
|
|
|
|
|
|
|
|
def setTask(self, task):
|
|
|
|
self._task = task
|
|
|
|
|
2012-03-01 14:57:37 +00:00
|
|
|
def getDisplayName(self):
|
|
|
|
return bb.event.getName(self)[4:]
|
|
|
|
|
2005-08-31 10:47:56 +00:00
|
|
|
task = property(getTask, setTask, None, "task property")
|
|
|
|
|
|
|
|
class TaskStarted(TaskBase):
|
|
|
|
"""Task execution started"""
|
2013-11-01 15:58:31 +00:00
|
|
|
def __init__(self, t, logfile, taskflags, d):
|
|
|
|
super(TaskStarted, self).__init__(t, logfile, d)
|
|
|
|
self.taskflags = taskflags
|
2005-08-31 10:47:56 +00:00
|
|
|
|
|
|
|
class TaskSucceeded(TaskBase):
|
|
|
|
"""Task execution completed"""
|
|
|
|
|
|
|
|
class TaskFailed(TaskBase):
|
|
|
|
"""Task execution failed"""
|
2010-09-10 01:03:40 +00:00
|
|
|
|
2012-01-13 17:01:49 +00:00
|
|
|
def __init__(self, task, logfile, metadata, errprinted = False):
|
|
|
|
self.errprinted = errprinted
|
2013-09-14 16:54:09 +00:00
|
|
|
super(TaskFailed, self).__init__(task, logfile, metadata)
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2012-02-27 18:54:11 +00:00
|
|
|
class TaskFailedSilent(TaskBase):
|
|
|
|
"""Task execution failed (silently)"""
|
2012-03-01 14:57:37 +00:00
|
|
|
def getDisplayName(self):
|
|
|
|
# Don't need to tell the user it was silent
|
|
|
|
return "Failed"
|
|
|
|
|
2010-08-16 15:37:29 +00:00
|
|
|
class TaskInvalid(TaskBase):
|
2010-09-10 01:03:40 +00:00
|
|
|
|
|
|
|
def __init__(self, task, metadata):
|
2013-09-14 16:54:09 +00:00
|
|
|
super(TaskInvalid, self).__init__(task, None, metadata)
|
2010-09-10 01:03:40 +00:00
|
|
|
self._message = "No such task '%s'" % task
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2016-06-23 10:59:05 +00:00
|
|
|
class TaskProgress(event.Event):
|
|
|
|
"""
|
|
|
|
Task made some progress that could be reported to the user, usually in
|
|
|
|
the form of a progress bar or similar.
|
|
|
|
NOTE: this class does not inherit from TaskBase since it doesn't need
|
|
|
|
to - it's fired within the task context itself, so we don't have any of
|
|
|
|
the context information that you do in the case of the other events.
|
|
|
|
The event PID can be used to determine which task it came from.
|
|
|
|
The progress value is normally 0-100, but can also be negative
|
|
|
|
indicating that progress has been made but we aren't able to determine
|
|
|
|
how much.
|
|
|
|
The rate is optional, this is simply an extra string to display to the
|
|
|
|
user if specified.
|
|
|
|
"""
|
|
|
|
def __init__(self, progress, rate=None):
|
|
|
|
self.progress = progress
|
|
|
|
self.rate = rate
|
|
|
|
event.Event.__init__(self)
|
|
|
|
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2010-12-14 16:20:33 +00:00
|
|
|
class LogTee(object):
|
2010-12-14 16:25:58 +00:00
|
|
|
def __init__(self, logger, outfile):
|
|
|
|
self.outfile = outfile
|
2010-12-14 16:20:33 +00:00
|
|
|
self.logger = logger
|
2010-12-14 16:25:58 +00:00
|
|
|
self.name = self.outfile.name
|
2010-12-14 16:20:33 +00:00
|
|
|
|
2010-12-10 01:14:48 +00:00
|
|
|
def write(self, string):
|
2010-12-14 16:20:33 +00:00
|
|
|
self.logger.plain(string)
|
2010-12-14 16:25:58 +00:00
|
|
|
self.outfile.write(string)
|
2010-12-14 16:20:33 +00:00
|
|
|
|
|
|
|
def __enter__(self):
|
2010-12-14 16:25:58 +00:00
|
|
|
self.outfile.__enter__()
|
2010-12-14 16:20:33 +00:00
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, *excinfo):
|
2010-12-14 16:25:58 +00:00
|
|
|
self.outfile.__exit__(*excinfo)
|
2010-12-10 01:14:48 +00:00
|
|
|
|
|
|
|
def __repr__(self):
|
2010-12-14 16:25:58 +00:00
|
|
|
return '<LogTee {0}>'.format(self.name)
|
2012-06-22 11:55:55 +00:00
|
|
|
def flush(self):
|
|
|
|
self.outfile.flush()
|
2010-12-10 01:14:48 +00:00
|
|
|
|
2016-03-30 19:52:56 +00:00
|
|
|
#
|
|
|
|
# pythonexception allows the python exceptions generated to be raised
|
|
|
|
# as the real exceptions (not FuncFailed) and without a backtrace at the
|
|
|
|
# origin of the failure.
|
|
|
|
#
|
|
|
|
def exec_func(func, d, dirs = None, pythonexception=False):
|
2014-08-20 12:23:27 +00:00
|
|
|
"""Execute a BB 'function'"""
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2016-07-14 18:56:22 +00:00
|
|
|
try:
|
|
|
|
oldcwd = os.getcwd()
|
|
|
|
except:
|
|
|
|
oldcwd = None
|
|
|
|
|
2013-06-20 13:00:59 +00:00
|
|
|
flags = d.getVarFlags(func)
|
2010-12-10 01:14:48 +00:00
|
|
|
cleandirs = flags.get('cleandirs')
|
2010-04-20 18:53:31 +00:00
|
|
|
if cleandirs:
|
2013-06-20 13:00:59 +00:00
|
|
|
for cdir in d.expand(cleandirs).split():
|
2010-12-10 01:14:48 +00:00
|
|
|
bb.utils.remove(cdir, True)
|
2014-01-06 09:52:35 +00:00
|
|
|
bb.utils.mkdirhier(cdir)
|
2007-09-05 08:40:25 +00:00
|
|
|
|
2010-04-20 18:53:31 +00:00
|
|
|
if dirs is None:
|
2010-12-10 01:14:48 +00:00
|
|
|
dirs = flags.get('dirs')
|
2010-04-20 18:53:31 +00:00
|
|
|
if dirs:
|
2013-06-20 13:00:59 +00:00
|
|
|
dirs = d.expand(dirs).split()
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2010-04-20 18:53:31 +00:00
|
|
|
if dirs:
|
|
|
|
for adir in dirs:
|
|
|
|
bb.utils.mkdirhier(adir)
|
2005-08-31 10:47:56 +00:00
|
|
|
adir = dirs[-1]
|
|
|
|
else:
|
2016-07-14 18:56:22 +00:00
|
|
|
adir = None
|
2016-09-14 21:29:43 +00:00
|
|
|
|
|
|
|
body = d.getVar(func, False)
|
|
|
|
if not body:
|
|
|
|
if body is None:
|
|
|
|
logger.warning("Function %s doesn't exist", func)
|
|
|
|
return
|
|
|
|
|
2010-12-10 01:14:48 +00:00
|
|
|
ispython = flags.get('python')
|
2010-09-30 20:04:18 +00:00
|
|
|
|
2010-12-10 01:29:31 +00:00
|
|
|
lockflag = flags.get('lockfiles')
|
|
|
|
if lockflag:
|
2014-02-27 15:42:07 +00:00
|
|
|
lockfiles = [f for f in d.expand(lockflag).split()]
|
2010-12-10 01:29:31 +00:00
|
|
|
else:
|
|
|
|
lockfiles = None
|
|
|
|
|
2016-11-25 15:28:08 +00:00
|
|
|
tempdir = d.getVar('T')
|
2012-05-23 15:45:12 +00:00
|
|
|
|
|
|
|
# or func allows items to be executed outside of the normal
|
|
|
|
# task set, such as buildhistory
|
2016-11-25 15:28:08 +00:00
|
|
|
task = d.getVar('BB_RUNTASK') or func
|
2012-05-23 15:45:12 +00:00
|
|
|
if task == func:
|
|
|
|
taskfunc = task
|
|
|
|
else:
|
|
|
|
taskfunc = "%s.%s" % (task, func)
|
|
|
|
|
2016-11-25 15:28:08 +00:00
|
|
|
runfmt = d.getVar('BB_RUNFMT') or "run.{func}.{pid}"
|
2012-05-23 15:45:12 +00:00
|
|
|
runfn = runfmt.format(taskfunc=taskfunc, task=task, func=func, pid=os.getpid())
|
|
|
|
runfile = os.path.join(tempdir, runfn)
|
|
|
|
bb.utils.mkdirhier(os.path.dirname(runfile))
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2013-08-16 09:20:59 +00:00
|
|
|
# Setup the courtesy link to the runfn, only for tasks
|
|
|
|
# we create the link 'just' before the run script is created
|
|
|
|
# if we create it after, and if the run script fails, then the
|
|
|
|
# link won't be created as an exception would be fired.
|
|
|
|
if task == func:
|
|
|
|
runlink = os.path.join(tempdir, 'run.{0}'.format(task))
|
|
|
|
if runlink:
|
|
|
|
bb.utils.remove(runlink)
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.symlink(runfn, runlink)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
2010-12-10 01:29:31 +00:00
|
|
|
with bb.utils.fileslocked(lockfiles):
|
2010-01-20 18:46:02 +00:00
|
|
|
if ispython:
|
2016-03-30 19:52:56 +00:00
|
|
|
exec_func_python(func, d, runfile, cwd=adir, pythonexception=pythonexception)
|
2010-01-20 18:46:02 +00:00
|
|
|
else:
|
2011-01-05 00:54:16 +00:00
|
|
|
exec_func_shell(func, d, runfile, cwd=adir)
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2016-09-26 20:53:13 +00:00
|
|
|
try:
|
|
|
|
curcwd = os.getcwd()
|
|
|
|
except:
|
|
|
|
curcwd = None
|
|
|
|
|
|
|
|
if oldcwd and curcwd != oldcwd:
|
2016-07-14 18:56:22 +00:00
|
|
|
try:
|
2016-09-26 20:53:13 +00:00
|
|
|
bb.warn("Task %s changed cwd to %s" % (func, curcwd))
|
2016-07-14 18:56:22 +00:00
|
|
|
os.chdir(oldcwd)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2010-12-10 01:14:48 +00:00
|
|
|
_functionfmt = """
|
|
|
|
{function}(d)
|
|
|
|
"""
|
2010-12-10 04:38:35 +00:00
|
|
|
logformatter = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
|
2016-03-30 19:52:56 +00:00
|
|
|
def exec_func_python(func, d, runfile, cwd=None, pythonexception=False):
|
2005-08-31 10:47:56 +00:00
|
|
|
"""Execute a python BB 'function'"""
|
|
|
|
|
bitbake: build: Improve python execution tracebacks
If something fails in a exec_func_python() the current stack trace shows
incorrect filenames and linenumbers. For example:
The stack trace of python calls that resulted in this exception/failure was:
File: '/media/build1/poky/meta/recipes-sato/images/core-image-sato.bb', lineno: 200, function: <module>
0196: chksum = bb.utils.sha256_file(fn)
0197: f.write('%s\t%s\n' % (chksum, os.path.relpath(fn, baseoutpath)))
0198:
0199:
*** 0200:copy_buildsystem(d)
0201:
File: '/media/build1/poky/meta/recipes-sato/images/core-image-sato.bb', lineno: 9, function: copy_buildsystem
0005:IMAGE_FEATURES += "splash package-management x11-base x11-sato ssh-server-dropbear hwcodecs"
0006:
0007:LICENSE = "MIT"
0008:
*** 0009:inherit core-image
0010:
0011:IMAGE_INSTALL += "packagegroup-core-x11-sato-games"
File: '/usr/lib/python2.7/subprocess.py', lineno: 535, function: check_call
0531: The arguments are the same as for the Popen constructor. Example:
0532:
0533: check_call(["ls", "-l"])
0534: """
*** 0535: retcode = call(*popenargs, **kwargs)
0536: if retcode:
0537: cmd = kwargs.get("args")
0538: if cmd is None:
0539: cmd = popenargs[0]
The problem is the use of "FILE" to obtain the current filename. Instead,
we therefore inject the function being executed into the methodpool which
allows us to correct its linenumber and filename information. We can then
clearly mark the initial piece as autogenerated and the rest of the linenumber
and filename information should be correct. Afterwards the trace starts:
The stack trace of python calls that resulted in this exception/failure was:
File: 'exec_python_func() autogenerated', lineno: 2, function: <module>
0001:
*** 0002:copy_buildsystem(d)
0003:
File: '/media/build1/poky/meta/classes/populate_sdk_ext.bbclass', lineno: 66, function: copy_buildsystem
0062: import glob
0063: import oe.copy_buildsystem
0064: import subprocess
0065:
*** 0066: subprocess.check_call("foo")
0067:
0068: oe_init_env_script = d.getVar('OE_INIT_ENV_SCRIPT', True)
0069:
0070: conf_bbpath = ''
File: '/usr/lib/python2.7/subprocess.py', lineno: 535, function: check_call
0531: The arguments are the same as for the Popen constructor. Example:
0532:
0533: check_call(["ls", "-l"])
0534: """
*** 0535: retcode = call(*popenargs, **kwargs)
0536: if retcode:
0537: cmd = kwargs.get("args")
0538: if cmd is None:
0539: cmd = popenargs[0]
We can't inject into methodpool at parsing time, since there may be
_append or other override operations against the function before its
execution.
(Bitbake rev: fae153095d23157dd7e72c29f683f86149ee33a8)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2016-02-09 15:08:42 +00:00
|
|
|
code = _functionfmt.format(function=func)
|
2010-12-10 01:14:48 +00:00
|
|
|
bb.utils.mkdirhier(os.path.dirname(runfile))
|
|
|
|
with open(runfile, 'w') as script:
|
2014-08-27 13:24:52 +00:00
|
|
|
bb.data.emit_func_python(func, script, d)
|
2010-12-10 01:14:48 +00:00
|
|
|
|
|
|
|
if cwd:
|
2011-03-25 15:58:52 +00:00
|
|
|
try:
|
|
|
|
olddir = os.getcwd()
|
2016-07-14 18:56:22 +00:00
|
|
|
except OSError as e:
|
|
|
|
bb.warn("%s: Cannot get cwd: %s" % (func, e))
|
2011-03-25 15:58:52 +00:00
|
|
|
olddir = None
|
2010-12-10 01:14:48 +00:00
|
|
|
os.chdir(cwd)
|
|
|
|
|
2012-05-23 15:45:11 +00:00
|
|
|
bb.debug(2, "Executing python function %s" % func)
|
|
|
|
|
2010-01-20 18:46:02 +00:00
|
|
|
try:
|
bitbake: build: Improve python execution tracebacks
If something fails in a exec_func_python() the current stack trace shows
incorrect filenames and linenumbers. For example:
The stack trace of python calls that resulted in this exception/failure was:
File: '/media/build1/poky/meta/recipes-sato/images/core-image-sato.bb', lineno: 200, function: <module>
0196: chksum = bb.utils.sha256_file(fn)
0197: f.write('%s\t%s\n' % (chksum, os.path.relpath(fn, baseoutpath)))
0198:
0199:
*** 0200:copy_buildsystem(d)
0201:
File: '/media/build1/poky/meta/recipes-sato/images/core-image-sato.bb', lineno: 9, function: copy_buildsystem
0005:IMAGE_FEATURES += "splash package-management x11-base x11-sato ssh-server-dropbear hwcodecs"
0006:
0007:LICENSE = "MIT"
0008:
*** 0009:inherit core-image
0010:
0011:IMAGE_INSTALL += "packagegroup-core-x11-sato-games"
File: '/usr/lib/python2.7/subprocess.py', lineno: 535, function: check_call
0531: The arguments are the same as for the Popen constructor. Example:
0532:
0533: check_call(["ls", "-l"])
0534: """
*** 0535: retcode = call(*popenargs, **kwargs)
0536: if retcode:
0537: cmd = kwargs.get("args")
0538: if cmd is None:
0539: cmd = popenargs[0]
The problem is the use of "FILE" to obtain the current filename. Instead,
we therefore inject the function being executed into the methodpool which
allows us to correct its linenumber and filename information. We can then
clearly mark the initial piece as autogenerated and the rest of the linenumber
and filename information should be correct. Afterwards the trace starts:
The stack trace of python calls that resulted in this exception/failure was:
File: 'exec_python_func() autogenerated', lineno: 2, function: <module>
0001:
*** 0002:copy_buildsystem(d)
0003:
File: '/media/build1/poky/meta/classes/populate_sdk_ext.bbclass', lineno: 66, function: copy_buildsystem
0062: import glob
0063: import oe.copy_buildsystem
0064: import subprocess
0065:
*** 0066: subprocess.check_call("foo")
0067:
0068: oe_init_env_script = d.getVar('OE_INIT_ENV_SCRIPT', True)
0069:
0070: conf_bbpath = ''
File: '/usr/lib/python2.7/subprocess.py', lineno: 535, function: check_call
0531: The arguments are the same as for the Popen constructor. Example:
0532:
0533: check_call(["ls", "-l"])
0534: """
*** 0535: retcode = call(*popenargs, **kwargs)
0536: if retcode:
0537: cmd = kwargs.get("args")
0538: if cmd is None:
0539: cmd = popenargs[0]
We can't inject into methodpool at parsing time, since there may be
_append or other override operations against the function before its
execution.
(Bitbake rev: fae153095d23157dd7e72c29f683f86149ee33a8)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2016-02-09 15:08:42 +00:00
|
|
|
text = "def %s(d):\n%s" % (func, d.getVar(func, False))
|
|
|
|
fn = d.getVarFlag(func, "filename", False)
|
|
|
|
lineno = int(d.getVarFlag(func, "lineno", False))
|
|
|
|
bb.methodpool.insert_method(func, text, fn, lineno - 1)
|
|
|
|
|
|
|
|
comp = utils.better_compile(code, func, "exec_python_func() autogenerated")
|
2016-03-30 19:52:56 +00:00
|
|
|
utils.better_exec(comp, {"d": d}, code, "exec_python_func() autogenerated", pythonexception=pythonexception)
|
2014-05-30 14:56:11 +00:00
|
|
|
except (bb.parse.SkipRecipe, bb.build.FuncFailed):
|
|
|
|
raise
|
2010-09-10 18:34:39 +00:00
|
|
|
except:
|
2016-03-30 19:52:56 +00:00
|
|
|
if pythonexception:
|
|
|
|
raise
|
2010-12-10 01:14:48 +00:00
|
|
|
raise FuncFailed(func, None)
|
|
|
|
finally:
|
2012-05-23 15:45:11 +00:00
|
|
|
bb.debug(2, "Python function %s finished" % func)
|
|
|
|
|
2011-03-25 15:58:52 +00:00
|
|
|
if cwd and olddir:
|
|
|
|
try:
|
|
|
|
os.chdir(olddir)
|
2016-07-14 18:56:22 +00:00
|
|
|
except OSError as e:
|
|
|
|
bb.warn("%s: Cannot restore cwd %s: %s" % (func, olddir, e))
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2014-02-03 11:33:07 +00:00
|
|
|
def shell_trap_code():
|
|
|
|
return '''#!/bin/sh\n
|
2012-10-10 22:11:54 +00:00
|
|
|
# Emit a useful diagnostic if something fails:
|
|
|
|
bb_exit_handler() {
|
|
|
|
ret=$?
|
|
|
|
case $ret in
|
|
|
|
0) ;;
|
|
|
|
*) case $BASH_VERSION in
|
2016-01-28 00:43:16 +00:00
|
|
|
"") echo "WARNING: exit code $ret from a shell command.";;
|
|
|
|
*) echo "WARNING: ${BASH_SOURCE[0]}:${BASH_LINENO[0]} exit $ret from '$BASH_COMMAND'";;
|
2012-10-10 22:11:54 +00:00
|
|
|
esac
|
|
|
|
exit $ret
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
trap 'bb_exit_handler' 0
|
|
|
|
set -e
|
2014-02-03 11:33:07 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
def exec_func_shell(func, d, runfile, cwd=None):
|
|
|
|
"""Execute a shell function from the metadata
|
|
|
|
|
|
|
|
Note on directory behavior. The 'dirs' varflag should contain a list
|
|
|
|
of the directories you need created prior to execution. The last
|
|
|
|
item in the list is where we will chdir/cd to.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Don't let the emitted shell script override PWD
|
|
|
|
d.delVarFlag('PWD', 'export')
|
|
|
|
|
|
|
|
with open(runfile, 'w') as script:
|
|
|
|
script.write(shell_trap_code())
|
2012-10-10 22:11:54 +00:00
|
|
|
|
2013-06-20 13:00:59 +00:00
|
|
|
bb.data.emit_func(func, script, d)
|
2011-11-28 06:32:40 +00:00
|
|
|
|
2012-02-28 13:37:41 +00:00
|
|
|
if bb.msg.loggerVerboseLogs:
|
|
|
|
script.write("set -x\n")
|
2011-02-25 22:36:15 +00:00
|
|
|
if cwd:
|
2013-11-20 00:31:39 +00:00
|
|
|
script.write("cd '%s'\n" % cwd)
|
2012-05-23 15:45:10 +00:00
|
|
|
script.write("%s\n" % func)
|
2012-10-10 22:11:54 +00:00
|
|
|
script.write('''
|
|
|
|
# cleanup
|
|
|
|
ret=$?
|
|
|
|
trap '' 0
|
2015-07-23 23:09:01 +00:00
|
|
|
exit $ret
|
2012-10-10 22:11:54 +00:00
|
|
|
''')
|
2011-03-16 15:07:29 +00:00
|
|
|
|
2016-05-12 07:30:35 +00:00
|
|
|
os.chmod(runfile, 0o775)
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2010-12-10 01:14:48 +00:00
|
|
|
cmd = runfile
|
2016-02-02 23:49:09 +00:00
|
|
|
if d.getVarFlag(func, 'fakeroot', False):
|
2016-11-25 15:28:08 +00:00
|
|
|
fakerootcmd = d.getVar('FAKEROOT')
|
2011-11-28 06:32:40 +00:00
|
|
|
if fakerootcmd:
|
|
|
|
cmd = [fakerootcmd, runfile]
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2011-09-23 16:05:00 +00:00
|
|
|
if bb.msg.loggerDefaultVerbose:
|
2011-01-05 00:54:16 +00:00
|
|
|
logfile = LogTee(logger, sys.stdout)
|
|
|
|
else:
|
2011-01-05 18:55:38 +00:00
|
|
|
logfile = sys.stdout
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2016-11-25 15:28:09 +00:00
|
|
|
progress = d.getVarFlag(func, 'progress')
|
2016-06-23 10:59:05 +00:00
|
|
|
if progress:
|
|
|
|
if progress == 'percent':
|
|
|
|
# Use default regex
|
|
|
|
logfile = bb.progress.BasicProgressHandler(d, outfile=logfile)
|
|
|
|
elif progress.startswith('percent:'):
|
|
|
|
# Use specified regex
|
|
|
|
logfile = bb.progress.BasicProgressHandler(d, regex=progress.split(':', 1)[1], outfile=logfile)
|
|
|
|
elif progress.startswith('outof:'):
|
|
|
|
# Use specified regex
|
|
|
|
logfile = bb.progress.OutOfProgressHandler(d, regex=progress.split(':', 1)[1], outfile=logfile)
|
|
|
|
else:
|
|
|
|
bb.warn('%s: invalid task progress varflag value "%s", ignoring' % (func, progress))
|
|
|
|
|
2016-07-25 22:32:26 +00:00
|
|
|
fifobuffer = bytearray()
|
2015-07-10 13:51:40 +00:00
|
|
|
def readfifo(data):
|
2016-07-25 22:32:26 +00:00
|
|
|
nonlocal fifobuffer
|
|
|
|
fifobuffer.extend(data)
|
|
|
|
while fifobuffer:
|
|
|
|
message, token, nextmsg = fifobuffer.partition(b"\00")
|
|
|
|
if token:
|
|
|
|
splitval = message.split(b' ', 1)
|
|
|
|
cmd = splitval[0].decode("utf-8")
|
|
|
|
if len(splitval) > 1:
|
|
|
|
value = splitval[1].decode("utf-8")
|
|
|
|
else:
|
|
|
|
value = ''
|
|
|
|
if cmd == 'bbplain':
|
|
|
|
bb.plain(value)
|
|
|
|
elif cmd == 'bbnote':
|
|
|
|
bb.note(value)
|
|
|
|
elif cmd == 'bbwarn':
|
|
|
|
bb.warn(value)
|
|
|
|
elif cmd == 'bberror':
|
|
|
|
bb.error(value)
|
|
|
|
elif cmd == 'bbfatal':
|
|
|
|
# The caller will call exit themselves, so bb.error() is
|
|
|
|
# what we want here rather than bb.fatal()
|
|
|
|
bb.error(value)
|
|
|
|
elif cmd == 'bbfatal_log':
|
|
|
|
bb.error(value, forcelog=True)
|
|
|
|
elif cmd == 'bbdebug':
|
|
|
|
splitval = value.split(' ', 1)
|
|
|
|
level = int(splitval[0])
|
|
|
|
value = splitval[1]
|
|
|
|
bb.debug(level, value)
|
|
|
|
else:
|
|
|
|
bb.warn("Unrecognised command '%s' on FIFO" % cmd)
|
|
|
|
fifobuffer = nextmsg
|
2015-07-10 13:51:40 +00:00
|
|
|
else:
|
2016-07-25 22:32:26 +00:00
|
|
|
break
|
|
|
|
|
2016-11-25 15:28:08 +00:00
|
|
|
tempdir = d.getVar('T')
|
2015-07-10 13:51:40 +00:00
|
|
|
fifopath = os.path.join(tempdir, 'fifo.%s' % os.getpid())
|
|
|
|
if os.path.exists(fifopath):
|
|
|
|
os.unlink(fifopath)
|
|
|
|
os.mkfifo(fifopath)
|
2016-05-12 07:30:35 +00:00
|
|
|
with open(fifopath, 'r+b', buffering=0) as fifo:
|
2015-07-10 13:51:40 +00:00
|
|
|
try:
|
|
|
|
bb.debug(2, "Executing shell function %s" % func)
|
|
|
|
|
|
|
|
try:
|
|
|
|
with open(os.devnull, 'r+') as stdin:
|
|
|
|
bb.process.run(cmd, shell=False, stdin=stdin, log=logfile, extrafiles=[(fifo,readfifo)])
|
|
|
|
except bb.process.CmdError:
|
2016-11-25 15:28:08 +00:00
|
|
|
logfn = d.getVar('BB_LOGFILE')
|
2015-07-10 13:51:40 +00:00
|
|
|
raise FuncFailed(func, logfn)
|
|
|
|
finally:
|
|
|
|
os.unlink(fifopath)
|
2010-12-10 01:14:48 +00:00
|
|
|
|
2012-05-23 15:45:11 +00:00
|
|
|
bb.debug(2, "Shell function %s finished" % func)
|
|
|
|
|
2010-12-10 01:14:48 +00:00
|
|
|
def _task_data(fn, task, d):
|
2013-06-20 13:00:59 +00:00
|
|
|
localdata = bb.data.createCopy(d)
|
2010-12-10 01:14:48 +00:00
|
|
|
localdata.setVar('BB_FILENAME', fn)
|
|
|
|
localdata.setVar('BB_CURRENTTASK', task[3:])
|
|
|
|
localdata.setVar('OVERRIDES', 'task-%s:%s' %
|
2014-02-17 14:07:41 +00:00
|
|
|
(task[3:].replace('_', '-'), d.getVar('OVERRIDES', False)))
|
2010-12-10 01:14:48 +00:00
|
|
|
localdata.finalize()
|
2013-06-20 13:00:59 +00:00
|
|
|
bb.data.expandKeys(localdata)
|
2010-12-10 01:14:48 +00:00
|
|
|
return localdata
|
|
|
|
|
|
|
|
def _exec_task(fn, task, d, quieterr):
|
|
|
|
"""Execute a BB 'task'
|
|
|
|
|
|
|
|
Execution of a task involves a bit more setup than executing a function,
|
|
|
|
running it with its own local metadata, and with some useful variables set.
|
|
|
|
"""
|
2016-02-02 23:49:09 +00:00
|
|
|
if not d.getVarFlag(task, 'task', False):
|
2010-08-16 15:37:29 +00:00
|
|
|
event.fire(TaskInvalid(task, d), d)
|
2010-06-10 17:35:31 +00:00
|
|
|
logger.error("No such task: %s" % task)
|
2010-08-16 15:37:29 +00:00
|
|
|
return 1
|
|
|
|
|
2010-12-10 01:14:48 +00:00
|
|
|
logger.debug(1, "Executing task %s", task)
|
2008-03-03 22:01:45 +00:00
|
|
|
|
2010-12-10 01:14:48 +00:00
|
|
|
localdata = _task_data(fn, task, d)
|
2016-11-25 15:28:08 +00:00
|
|
|
tempdir = localdata.getVar('T')
|
2010-12-10 01:14:48 +00:00
|
|
|
if not tempdir:
|
|
|
|
bb.fatal("T variable not set, unable to build")
|
2010-10-11 11:53:54 +00:00
|
|
|
|
2013-09-20 09:54:40 +00:00
|
|
|
# Change nice level if we're asked to
|
2016-11-25 15:28:08 +00:00
|
|
|
nice = localdata.getVar("BB_TASK_NICE_LEVEL")
|
2013-09-20 09:54:40 +00:00
|
|
|
if nice:
|
|
|
|
curnice = os.nice(0)
|
|
|
|
nice = int(nice) - curnice
|
|
|
|
newnice = os.nice(nice)
|
|
|
|
logger.debug(1, "Renice to %s " % newnice)
|
2016-11-25 15:28:08 +00:00
|
|
|
ionice = localdata.getVar("BB_TASK_IONICE_LEVEL")
|
2015-10-24 10:19:06 +00:00
|
|
|
if ionice:
|
|
|
|
try:
|
|
|
|
cls, prio = ionice.split(".", 1)
|
|
|
|
bb.utils.ioprio_set(os.getpid(), int(cls), int(prio))
|
|
|
|
except:
|
|
|
|
bb.warn("Invalid ionice level %s" % ionice)
|
2013-09-20 09:54:40 +00:00
|
|
|
|
2010-12-10 01:14:48 +00:00
|
|
|
bb.utils.mkdirhier(tempdir)
|
2012-05-23 15:45:09 +00:00
|
|
|
|
|
|
|
# Determine the logfile to generate
|
2016-11-25 15:28:08 +00:00
|
|
|
logfmt = localdata.getVar('BB_LOGFMT') or 'log.{task}.{pid}'
|
2012-05-23 15:45:12 +00:00
|
|
|
logbase = logfmt.format(task=task, pid=os.getpid())
|
2012-05-23 15:45:09 +00:00
|
|
|
|
|
|
|
# Document the order of the tasks...
|
|
|
|
logorder = os.path.join(tempdir, 'log.task_order')
|
|
|
|
try:
|
2013-05-09 21:06:45 +00:00
|
|
|
with open(logorder, 'a') as logorderfile:
|
|
|
|
logorderfile.write('{0} ({1}): {2}\n'.format(task, os.getpid(), logbase))
|
2012-05-23 15:45:09 +00:00
|
|
|
except OSError:
|
|
|
|
logger.exception("Opening log file '%s'", logorder)
|
|
|
|
pass
|
|
|
|
|
|
|
|
# Setup the courtesy link to the logfn
|
|
|
|
loglink = os.path.join(tempdir, 'log.{0}'.format(task))
|
2012-03-27 19:07:23 +00:00
|
|
|
logfn = os.path.join(tempdir, logbase)
|
2010-12-10 01:14:48 +00:00
|
|
|
if loglink:
|
|
|
|
bb.utils.remove(loglink)
|
2010-10-11 11:53:54 +00:00
|
|
|
|
2010-12-10 01:14:48 +00:00
|
|
|
try:
|
2012-03-27 19:07:23 +00:00
|
|
|
os.symlink(logbase, loglink)
|
2010-12-10 01:14:48 +00:00
|
|
|
except OSError:
|
|
|
|
pass
|
2010-10-11 11:53:54 +00:00
|
|
|
|
2010-12-10 01:14:48 +00:00
|
|
|
prefuncs = localdata.getVarFlag(task, 'prefuncs', expand=True)
|
|
|
|
postfuncs = localdata.getVarFlag(task, 'postfuncs', expand=True)
|
2010-10-11 11:53:54 +00:00
|
|
|
|
2012-01-13 17:01:49 +00:00
|
|
|
class ErrorCheckHandler(logging.Handler):
|
|
|
|
def __init__(self):
|
|
|
|
self.triggered = False
|
|
|
|
logging.Handler.__init__(self, logging.ERROR)
|
|
|
|
def emit(self, record):
|
2015-07-13 15:05:12 +00:00
|
|
|
if getattr(record, 'forcelog', False):
|
|
|
|
self.triggered = False
|
|
|
|
else:
|
|
|
|
self.triggered = True
|
2012-01-13 17:01:49 +00:00
|
|
|
|
2010-12-10 01:14:48 +00:00
|
|
|
# Handle logfiles
|
2013-05-09 21:06:45 +00:00
|
|
|
si = open('/dev/null', 'r')
|
2010-12-10 01:14:48 +00:00
|
|
|
try:
|
2012-05-23 15:45:12 +00:00
|
|
|
bb.utils.mkdirhier(os.path.dirname(logfn))
|
2013-05-09 21:06:45 +00:00
|
|
|
logfile = open(logfn, 'w')
|
2010-12-10 01:14:48 +00:00
|
|
|
except OSError:
|
|
|
|
logger.exception("Opening log file '%s'", logfn)
|
|
|
|
pass
|
2010-10-11 11:53:54 +00:00
|
|
|
|
2010-12-10 01:14:48 +00:00
|
|
|
# Dup the existing fds so we dont lose them
|
|
|
|
osi = [os.dup(sys.stdin.fileno()), sys.stdin.fileno()]
|
|
|
|
oso = [os.dup(sys.stdout.fileno()), sys.stdout.fileno()]
|
|
|
|
ose = [os.dup(sys.stderr.fileno()), sys.stderr.fileno()]
|
2010-10-11 11:53:54 +00:00
|
|
|
|
2010-12-10 01:14:48 +00:00
|
|
|
# Replace those fds with our own
|
|
|
|
os.dup2(si.fileno(), osi[1])
|
|
|
|
os.dup2(logfile.fileno(), oso[1])
|
|
|
|
os.dup2(logfile.fileno(), ose[1])
|
2010-08-16 15:37:29 +00:00
|
|
|
|
2014-08-20 12:23:27 +00:00
|
|
|
# Ensure Python logging goes to the logfile
|
2011-01-05 00:54:16 +00:00
|
|
|
handler = logging.StreamHandler(logfile)
|
|
|
|
handler.setFormatter(logformatter)
|
2011-08-12 22:24:43 +00:00
|
|
|
# Always enable full debug output into task logfiles
|
|
|
|
handler.setLevel(logging.DEBUG - 2)
|
2011-01-05 00:54:16 +00:00
|
|
|
bblogger.addHandler(handler)
|
|
|
|
|
2012-01-13 17:01:49 +00:00
|
|
|
errchk = ErrorCheckHandler()
|
|
|
|
bblogger.addHandler(errchk)
|
|
|
|
|
2011-01-05 00:54:16 +00:00
|
|
|
localdata.setVar('BB_LOGFILE', logfn)
|
2012-05-23 15:45:12 +00:00
|
|
|
localdata.setVar('BB_RUNTASK', task)
|
2011-01-05 00:54:16 +00:00
|
|
|
|
2013-11-01 15:58:31 +00:00
|
|
|
flags = localdata.getVarFlags(task)
|
|
|
|
|
2010-12-10 01:14:48 +00:00
|
|
|
try:
|
2016-10-04 16:11:23 +00:00
|
|
|
try:
|
|
|
|
event.fire(TaskStarted(task, logfn, flags, localdata), localdata)
|
|
|
|
except (bb.BBHandledException, SystemExit):
|
|
|
|
return 1
|
|
|
|
except FuncFailed as exc:
|
2010-09-10 01:03:40 +00:00
|
|
|
logger.error(str(exc))
|
2016-10-04 16:11:23 +00:00
|
|
|
return 1
|
|
|
|
|
|
|
|
try:
|
|
|
|
for func in (prefuncs or '').split():
|
|
|
|
exec_func(func, localdata)
|
|
|
|
exec_func(task, localdata)
|
|
|
|
for func in (postfuncs or '').split():
|
|
|
|
exec_func(func, localdata)
|
|
|
|
except FuncFailed as exc:
|
|
|
|
if quieterr:
|
|
|
|
event.fire(TaskFailedSilent(task, logfn, localdata), localdata)
|
|
|
|
else:
|
|
|
|
errprinted = errchk.triggered
|
|
|
|
logger.error(str(exc))
|
|
|
|
event.fire(TaskFailed(task, logfn, localdata, errprinted), localdata)
|
|
|
|
return 1
|
|
|
|
except bb.BBHandledException:
|
|
|
|
event.fire(TaskFailed(task, logfn, localdata, True), localdata)
|
|
|
|
return 1
|
2010-10-11 11:53:54 +00:00
|
|
|
finally:
|
|
|
|
sys.stdout.flush()
|
|
|
|
sys.stderr.flush()
|
|
|
|
|
2011-01-05 00:54:16 +00:00
|
|
|
bblogger.removeHandler(handler)
|
|
|
|
|
2010-10-11 11:53:54 +00:00
|
|
|
# Restore the backup fds
|
|
|
|
os.dup2(osi[0], osi[1])
|
|
|
|
os.dup2(oso[0], oso[1])
|
|
|
|
os.dup2(ose[0], ose[1])
|
|
|
|
|
|
|
|
# Close the backup fds
|
|
|
|
os.close(osi[0])
|
|
|
|
os.close(oso[0])
|
|
|
|
os.close(ose[0])
|
2010-12-10 01:14:48 +00:00
|
|
|
si.close()
|
|
|
|
|
|
|
|
logfile.close()
|
|
|
|
if os.path.exists(logfn) and os.path.getsize(logfn) == 0:
|
|
|
|
logger.debug(2, "Zero size logfn %s, removing", logfn)
|
|
|
|
bb.utils.remove(logfn)
|
|
|
|
bb.utils.remove(loglink)
|
2013-09-14 16:54:09 +00:00
|
|
|
event.fire(TaskSucceeded(task, logfn, localdata), localdata)
|
2010-12-10 01:14:48 +00:00
|
|
|
|
2016-02-02 23:49:09 +00:00
|
|
|
if not localdata.getVarFlag(task, 'nostamp', False) and not localdata.getVarFlag(task, 'selfstamp', False):
|
2011-01-06 19:40:41 +00:00
|
|
|
make_stamp(task, localdata)
|
2010-08-16 15:37:29 +00:00
|
|
|
|
|
|
|
return 0
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2011-06-10 16:22:54 +00:00
|
|
|
def exec_task(fn, task, d, profile = False):
|
2014-02-03 11:33:07 +00:00
|
|
|
try:
|
2010-12-10 01:14:48 +00:00
|
|
|
quieterr = False
|
2016-02-02 23:49:09 +00:00
|
|
|
if d.getVarFlag(task, "quieterrors", False) is not None:
|
2010-12-10 01:14:48 +00:00
|
|
|
quieterr = True
|
|
|
|
|
2014-02-03 11:33:07 +00:00
|
|
|
if profile:
|
2016-11-25 15:28:08 +00:00
|
|
|
profname = "profile-%s.log" % (d.getVar("PN") + "-" + task)
|
2011-06-10 16:22:54 +00:00
|
|
|
try:
|
|
|
|
import cProfile as profile
|
|
|
|
except:
|
|
|
|
import profile
|
|
|
|
prof = profile.Profile()
|
|
|
|
ret = profile.Profile.runcall(prof, _exec_task, fn, task, d, quieterr)
|
|
|
|
prof.dump_stats(profname)
|
|
|
|
bb.utils.process_profilelog(profname)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
else:
|
|
|
|
return _exec_task(fn, task, d, quieterr)
|
|
|
|
|
2010-12-10 01:14:48 +00:00
|
|
|
except Exception:
|
|
|
|
from traceback import format_exc
|
|
|
|
if not quieterr:
|
|
|
|
logger.error("Build of %s failed" % (task))
|
|
|
|
logger.error(format_exc())
|
2012-01-13 17:01:49 +00:00
|
|
|
failedevent = TaskFailed(task, None, d, True)
|
2010-12-10 01:14:48 +00:00
|
|
|
event.fire(failedevent, d)
|
|
|
|
return 1
|
|
|
|
|
2016-08-31 10:37:53 +00:00
|
|
|
def stamp_internal(taskname, d, file_name, baseonly=False, noextra=False):
|
2007-01-08 23:53:01 +00:00
|
|
|
"""
|
|
|
|
Internal stamp helper function
|
|
|
|
Makes sure the stamp directory exists
|
|
|
|
Returns the stamp path+filename
|
2011-01-06 15:41:39 +00:00
|
|
|
|
|
|
|
In the bitbake core, d can be a CacheData and file_name will be set.
|
|
|
|
When called in task context, d will be a data store, file_name will not be set
|
2007-01-08 23:53:01 +00:00
|
|
|
"""
|
2011-01-27 11:20:50 +00:00
|
|
|
taskflagname = taskname
|
|
|
|
if taskname.endswith("_setscene") and taskname != "do_setscene":
|
|
|
|
taskflagname = taskname.replace("_setscene", "")
|
|
|
|
|
2011-01-06 15:41:39 +00:00
|
|
|
if file_name:
|
2016-01-11 10:27:26 +00:00
|
|
|
stamp = d.stamp[file_name]
|
2011-01-27 11:20:50 +00:00
|
|
|
extrainfo = d.stamp_extrainfo[file_name].get(taskflagname) or ""
|
2011-01-06 15:41:39 +00:00
|
|
|
else:
|
2016-11-25 15:28:08 +00:00
|
|
|
stamp = d.getVar('STAMP')
|
|
|
|
file_name = d.getVar('BB_FILENAME')
|
2016-11-25 15:28:09 +00:00
|
|
|
extrainfo = d.getVarFlag(taskflagname, 'stamp-extra-info') or ""
|
2011-01-06 15:41:39 +00:00
|
|
|
|
2014-06-18 16:59:39 +00:00
|
|
|
if baseonly:
|
|
|
|
return stamp
|
2016-08-31 10:37:53 +00:00
|
|
|
if noextra:
|
|
|
|
extrainfo = ""
|
2014-06-18 16:59:39 +00:00
|
|
|
|
2005-08-31 10:47:56 +00:00
|
|
|
if not stamp:
|
|
|
|
return
|
2011-01-06 15:41:39 +00:00
|
|
|
|
2011-01-18 08:18:18 +00:00
|
|
|
stamp = bb.parse.siggen.stampfile(stamp, file_name, taskname, extrainfo)
|
2011-01-06 19:43:41 +00:00
|
|
|
|
2012-08-15 15:57:47 +00:00
|
|
|
stampdir = os.path.dirname(stamp)
|
2015-04-21 15:48:49 +00:00
|
|
|
if cached_mtime_noerror(stampdir) == 0:
|
2012-08-15 15:57:47 +00:00
|
|
|
bb.utils.mkdirhier(stampdir)
|
2011-01-06 19:43:41 +00:00
|
|
|
|
2007-01-08 23:53:01 +00:00
|
|
|
return stamp
|
|
|
|
|
2012-09-18 10:32:04 +00:00
|
|
|
def stamp_cleanmask_internal(taskname, d, file_name):
|
|
|
|
"""
|
|
|
|
Internal stamp helper function to generate stamp cleaning mask
|
|
|
|
Returns the stamp path+filename
|
|
|
|
|
|
|
|
In the bitbake core, d can be a CacheData and file_name will be set.
|
|
|
|
When called in task context, d will be a data store, file_name will not be set
|
|
|
|
"""
|
|
|
|
taskflagname = taskname
|
|
|
|
if taskname.endswith("_setscene") and taskname != "do_setscene":
|
|
|
|
taskflagname = taskname.replace("_setscene", "")
|
|
|
|
|
|
|
|
if file_name:
|
2016-01-11 10:27:26 +00:00
|
|
|
stamp = d.stampclean[file_name]
|
2012-09-18 10:32:04 +00:00
|
|
|
extrainfo = d.stamp_extrainfo[file_name].get(taskflagname) or ""
|
|
|
|
else:
|
2016-11-25 15:28:08 +00:00
|
|
|
stamp = d.getVar('STAMPCLEAN')
|
|
|
|
file_name = d.getVar('BB_FILENAME')
|
2016-11-25 15:28:09 +00:00
|
|
|
extrainfo = d.getVarFlag(taskflagname, 'stamp-extra-info') or ""
|
2012-09-18 10:32:04 +00:00
|
|
|
|
|
|
|
if not stamp:
|
2012-11-28 13:34:33 +00:00
|
|
|
return []
|
|
|
|
|
|
|
|
cleanmask = bb.parse.siggen.stampcleanmask(stamp, file_name, taskname, extrainfo)
|
2012-09-18 10:32:04 +00:00
|
|
|
|
2012-11-28 13:34:33 +00:00
|
|
|
return [cleanmask, cleanmask.replace(taskflagname, taskflagname + "_setscene")]
|
2012-09-18 10:32:04 +00:00
|
|
|
|
2007-01-08 23:53:01 +00:00
|
|
|
def make_stamp(task, d, file_name = None):
|
|
|
|
"""
|
|
|
|
Creates/updates a stamp for a given task
|
|
|
|
(d can be a data dict or dataCache)
|
|
|
|
"""
|
2012-09-18 10:32:04 +00:00
|
|
|
cleanmask = stamp_cleanmask_internal(task, d, file_name)
|
2012-11-28 13:34:33 +00:00
|
|
|
for mask in cleanmask:
|
2012-11-28 19:39:23 +00:00
|
|
|
for name in glob.glob(mask):
|
2013-02-21 15:23:35 +00:00
|
|
|
# Preserve sigdata files in the stamps directory
|
2016-11-02 15:06:00 +00:00
|
|
|
if "sigdata" in name or "sigbasedata" in name:
|
2012-11-28 19:39:23 +00:00
|
|
|
continue
|
2013-02-21 15:23:35 +00:00
|
|
|
# Preserve taint files in the stamps directory
|
|
|
|
if name.endswith('.taint'):
|
|
|
|
continue
|
2012-11-28 19:39:23 +00:00
|
|
|
os.unlink(name)
|
2014-02-03 11:33:07 +00:00
|
|
|
|
2007-01-08 23:53:01 +00:00
|
|
|
stamp = stamp_internal(task, d, file_name)
|
2011-01-06 19:43:41 +00:00
|
|
|
# Remove the file and recreate to force timestamp
|
|
|
|
# change on broken NFS filesystems
|
2007-01-08 23:53:01 +00:00
|
|
|
if stamp:
|
2011-01-10 22:05:19 +00:00
|
|
|
bb.utils.remove(stamp)
|
2013-05-09 21:06:45 +00:00
|
|
|
open(stamp, "w").close()
|
2007-01-08 23:53:01 +00:00
|
|
|
|
2011-05-25 22:19:41 +00:00
|
|
|
# If we're in task context, write out a signature file for each task
|
|
|
|
# as it completes
|
|
|
|
if not task.endswith("_setscene") and task != "do_setscene" and not file_name:
|
2014-06-18 16:59:39 +00:00
|
|
|
stampbase = stamp_internal(task, d, None, True)
|
2016-11-25 15:28:08 +00:00
|
|
|
file_name = d.getVar('BB_FILENAME')
|
2014-06-18 16:59:39 +00:00
|
|
|
bb.parse.siggen.dump_sigtask(file_name, task, stampbase, True)
|
2011-05-25 22:19:41 +00:00
|
|
|
|
2007-01-08 23:53:01 +00:00
|
|
|
def del_stamp(task, d, file_name = None):
|
|
|
|
"""
|
|
|
|
Removes a stamp for a given task
|
|
|
|
(d can be a data dict or dataCache)
|
|
|
|
"""
|
2011-01-07 14:03:27 +00:00
|
|
|
stamp = stamp_internal(task, d, file_name)
|
2011-01-10 22:05:19 +00:00
|
|
|
bb.utils.remove(stamp)
|
2011-01-06 19:43:41 +00:00
|
|
|
|
2012-06-18 15:45:35 +00:00
|
|
|
def write_taint(task, d, file_name = None):
|
|
|
|
"""
|
|
|
|
Creates a "taint" file which will force the specified task and its
|
|
|
|
dependents to be re-run the next time by influencing the value of its
|
|
|
|
taskhash.
|
|
|
|
(d can be a data dict or dataCache)
|
|
|
|
"""
|
|
|
|
import uuid
|
|
|
|
if file_name:
|
|
|
|
taintfn = d.stamp[file_name] + '.' + task + '.taint'
|
|
|
|
else:
|
2016-11-25 15:28:08 +00:00
|
|
|
taintfn = d.getVar('STAMP') + '.' + task + '.taint'
|
2012-06-18 15:45:35 +00:00
|
|
|
bb.utils.mkdirhier(os.path.dirname(taintfn))
|
|
|
|
# The specific content of the taint file is not really important,
|
|
|
|
# we just need it to be random, so a random UUID is used
|
|
|
|
with open(taintfn, 'w') as taintf:
|
|
|
|
taintf.write(str(uuid.uuid4()))
|
|
|
|
|
2016-08-31 10:37:53 +00:00
|
|
|
def stampfile(taskname, d, file_name = None, noextra=False):
|
2011-01-18 08:18:18 +00:00
|
|
|
"""
|
|
|
|
Return the stamp for a given task
|
|
|
|
(d can be a data dict or dataCache)
|
|
|
|
"""
|
2016-08-31 10:37:53 +00:00
|
|
|
return stamp_internal(taskname, d, file_name, noextra=noextra)
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2015-08-03 19:20:43 +00:00
|
|
|
def add_tasks(tasklist, d):
|
2015-06-18 14:14:19 +00:00
|
|
|
task_deps = d.getVar('_task_deps', False)
|
2006-11-16 15:02:15 +00:00
|
|
|
if not task_deps:
|
|
|
|
task_deps = {}
|
2008-03-03 22:01:45 +00:00
|
|
|
if not 'tasks' in task_deps:
|
|
|
|
task_deps['tasks'] = []
|
|
|
|
if not 'parents' in task_deps:
|
|
|
|
task_deps['parents'] = {}
|
2006-11-16 15:02:15 +00:00
|
|
|
|
2007-08-20 07:48:43 +00:00
|
|
|
for task in tasklist:
|
2013-06-20 13:00:59 +00:00
|
|
|
task = d.expand(task)
|
2013-12-18 10:44:30 +00:00
|
|
|
|
2013-06-20 13:00:59 +00:00
|
|
|
d.setVarFlag(task, 'task', 1)
|
2008-03-03 22:01:45 +00:00
|
|
|
|
|
|
|
if not task in task_deps['tasks']:
|
|
|
|
task_deps['tasks'].append(task)
|
2007-08-20 07:48:43 +00:00
|
|
|
|
2013-06-20 13:00:59 +00:00
|
|
|
flags = d.getVarFlags(task)
|
2007-08-20 07:48:43 +00:00
|
|
|
def getTask(name):
|
2008-03-03 22:01:45 +00:00
|
|
|
if not name in task_deps:
|
|
|
|
task_deps[name] = {}
|
2007-08-20 07:48:43 +00:00
|
|
|
if name in flags:
|
2013-06-20 13:00:59 +00:00
|
|
|
deptask = d.expand(flags[name])
|
2007-08-20 07:48:43 +00:00
|
|
|
task_deps[name][task] = deptask
|
|
|
|
getTask('depends')
|
2012-06-22 11:51:29 +00:00
|
|
|
getTask('rdepends')
|
2007-08-20 07:48:43 +00:00
|
|
|
getTask('deptask')
|
|
|
|
getTask('rdeptask')
|
|
|
|
getTask('recrdeptask')
|
2013-06-19 13:03:39 +00:00
|
|
|
getTask('recideptask')
|
2007-08-20 07:48:43 +00:00
|
|
|
getTask('nostamp')
|
2010-08-16 15:37:29 +00:00
|
|
|
getTask('fakeroot')
|
2010-11-06 14:33:05 +00:00
|
|
|
getTask('noexec')
|
2011-06-22 15:10:58 +00:00
|
|
|
getTask('umask')
|
2008-03-03 22:01:45 +00:00
|
|
|
task_deps['parents'][task] = []
|
2013-01-07 17:35:39 +00:00
|
|
|
if 'deps' in flags:
|
|
|
|
for dep in flags['deps']:
|
2013-06-20 13:00:59 +00:00
|
|
|
dep = d.expand(dep)
|
2013-01-07 17:35:39 +00:00
|
|
|
task_deps['parents'][task].append(dep)
|
2007-08-20 07:48:43 +00:00
|
|
|
|
|
|
|
# don't assume holding a reference
|
2013-06-20 13:00:59 +00:00
|
|
|
d.setVar('_task_deps', task_deps)
|
2005-08-31 10:47:56 +00:00
|
|
|
|
2013-12-18 10:45:02 +00:00
|
|
|
def addtask(task, before, after, d):
|
|
|
|
if task[:3] != "do_":
|
|
|
|
task = "do_" + task
|
|
|
|
|
|
|
|
d.setVarFlag(task, "task", 1)
|
2015-06-18 14:14:19 +00:00
|
|
|
bbtasks = d.getVar('__BBTASKS', False) or []
|
2015-08-03 19:20:43 +00:00
|
|
|
if task not in bbtasks:
|
2013-12-18 10:45:02 +00:00
|
|
|
bbtasks.append(task)
|
|
|
|
d.setVar('__BBTASKS', bbtasks)
|
|
|
|
|
2016-02-02 23:49:09 +00:00
|
|
|
existing = d.getVarFlag(task, "deps", False) or []
|
2013-12-18 10:45:02 +00:00
|
|
|
if after is not None:
|
|
|
|
# set up deps for function
|
|
|
|
for entry in after.split():
|
|
|
|
if entry not in existing:
|
|
|
|
existing.append(entry)
|
|
|
|
d.setVarFlag(task, "deps", existing)
|
|
|
|
if before is not None:
|
|
|
|
# set up things that depend on this func
|
|
|
|
for entry in before.split():
|
2016-02-02 23:49:09 +00:00
|
|
|
existing = d.getVarFlag(entry, "deps", False) or []
|
2013-12-18 10:45:02 +00:00
|
|
|
if task not in existing:
|
|
|
|
d.setVarFlag(entry, "deps", [task] + existing)
|
|
|
|
|
|
|
|
def deltask(task, d):
|
|
|
|
if task[:3] != "do_":
|
|
|
|
task = "do_" + task
|
|
|
|
|
2015-08-03 19:20:43 +00:00
|
|
|
bbtasks = d.getVar('__BBTASKS', False) or []
|
|
|
|
if task in bbtasks:
|
|
|
|
bbtasks.remove(task)
|
2016-06-15 02:42:10 +00:00
|
|
|
d.delVarFlag(task, 'task')
|
2015-08-03 19:20:43 +00:00
|
|
|
d.setVar('__BBTASKS', bbtasks)
|
|
|
|
|
|
|
|
d.delVarFlag(task, 'deps')
|
|
|
|
for bbtask in d.getVar('__BBTASKS', False) or []:
|
2016-02-02 23:49:09 +00:00
|
|
|
deps = d.getVarFlag(bbtask, 'deps', False) or []
|
2015-08-03 19:20:43 +00:00
|
|
|
if task in deps:
|
|
|
|
deps.remove(task)
|
|
|
|
d.setVarFlag(bbtask, 'deps', deps)
|