2010-09-29 10:19:22 +00:00
SSTATE_VERSION = "1"
2010-08-04 10:34:18 +00:00
2010-09-29 10:19:22 +00:00
SSTATE_MANIFESTS = "${TMPDIR}/sstate-control"
SSTATE_MANFILEPREFIX = "${SSTATE_MANIFESTS}/manifest-${SSTATE_PKGARCH}-${PN}"
2010-08-04 10:34:18 +00:00
2010-09-29 09:57:16 +00:00
SSTATE_PKGARCH = "${BASE_PACKAGE_ARCH}"
2010-09-29 11:11:51 +00:00
SSTATE_PKGNAME = "sstate-${PN}-${MULTIMACH_ARCH}${TARGET_VENDOR}-${TARGET_OS}-${PV}-${PR}-${SSTATE_PKGARCH}-${SSTATE_VERSION}-${BB_TASKHASH}"
2010-09-29 10:19:22 +00:00
SSTATE_PKG = "${SSTATE_DIR}/${SSTATE_PKGNAME}"
2010-08-04 10:34:18 +00:00
2010-09-29 09:57:16 +00:00
SSTATE_SCAN_CMD ?= "find ${SSTATE_BUILDDIR} \( -name "*.la" -o -name "*-config" \) -type f"
2010-08-04 10:34:18 +00:00
python () {
if bb.data.inherits_class('native', d):
2010-09-29 09:57:16 +00:00
bb.data.setVar('SSTATE_PKGARCH', bb.data.getVar('BUILD_ARCH', d), d)
2010-08-04 10:34:18 +00:00
elif bb.data.inherits_class('cross', d) or bb.data.inherits_class('crosssdk', d):
2010-09-29 09:57:16 +00:00
bb.data.setVar('SSTATE_PKGARCH', bb.data.expand("${BUILD_ARCH}_${BASE_PACKAGE_ARCH}", d), d)
2010-08-04 10:34:18 +00:00
elif bb.data.inherits_class('nativesdk', d):
2010-09-29 09:57:16 +00:00
bb.data.setVar('SSTATE_PKGARCH', bb.data.expand("${SDK_ARCH}", d), d)
2010-08-04 10:34:18 +00:00
elif bb.data.inherits_class('cross-canadian', d):
2010-09-29 09:57:16 +00:00
bb.data.setVar('SSTATE_PKGARCH', bb.data.expand("${SDK_ARCH}_${BASE_PACKAGE_ARCH}", d), d)
2010-08-04 10:34:18 +00:00
# These classes encode staging paths into their scripts data so can only be
# reused if we manipulate the paths
if bb.data.inherits_class('native', d) or bb.data.inherits_class('cross', d) or bb.data.inherits_class('sdk', d) or bb.data.inherits_class('crosssdk', d):
2010-09-29 09:57:16 +00:00
scan_cmd = "grep -Irl ${STAGING_DIR} ${SSTATE_BUILDDIR}"
bb.data.setVar('SSTATE_SCAN_CMD', scan_cmd, d)
2010-08-04 10:34:18 +00:00
for task in (bb.data.getVar('SSTATETASKS', d, True) or "").split():
funcs = bb.data.getVarFlag(task, 'prefuncs', d) or ""
funcs = "sstate_task_prefunc " + funcs
bb.data.setVarFlag(task, 'prefuncs', funcs, d)
funcs = bb.data.getVarFlag(task, 'postfuncs', d) or ""
2010-09-07 14:13:02 +00:00
funcs = funcs + " sstate_task_postfunc"
2010-08-04 10:34:18 +00:00
bb.data.setVarFlag(task, 'postfuncs', funcs, d)
}
def sstate_init(name, d):
ss = {}
ss['name'] = name
ss['dirs'] = []
ss['plaindirs'] = []
ss['lockfiles'] = []
return ss
def sstate_state_fromvars(d):
task = bb.data.getVar('BB_CURRENTTASK', d, True)
if not task:
bb.fatal("sstate code running without task context?!")
task = task.replace("_setscene", "")
name = bb.data.expand(bb.data.getVarFlag("do_" + task, 'sstate-name', d), d)
inputs = (bb.data.expand(bb.data.getVarFlag("do_" + task, 'sstate-inputdirs', d) or "", d)).split()
outputs = (bb.data.expand(bb.data.getVarFlag("do_" + task, 'sstate-outputdirs', d) or "", d)).split()
plaindirs = (bb.data.expand(bb.data.getVarFlag("do_" + task, 'sstate-plaindirs', d) or "", d)).split()
lockfiles = (bb.data.expand(bb.data.getVarFlag("do_" + task, 'sstate-lockfile', d) or "", d)).split()
2010-09-03 17:22:20 +00:00
interceptfuncs = (bb.data.expand(bb.data.getVarFlag("do_" + task, 'sstate-interceptfuncs', d) or "", d)).split()
2010-08-04 10:34:18 +00:00
if not name or len(inputs) != len(outputs):
bb.fatal("sstate variables not setup correctly?!")
ss = sstate_init(name, d)
for i in range(len(inputs)):
sstate_add(ss, inputs[i], outputs[i], d)
ss['lockfiles'] = lockfiles
ss['plaindirs'] = plaindirs
2010-09-03 17:22:20 +00:00
ss['interceptfuncs'] = interceptfuncs
2010-08-04 10:34:18 +00:00
return ss
def sstate_add(ss, source, dest, d):
srcbase = os.path.basename(source)
ss['dirs'].append([srcbase, source, dest])
return ss
def sstate_install(ss, d):
import oe.path
sharedfiles = []
shareddirs = []
2010-09-29 09:57:16 +00:00
bb.mkdirhier(bb.data.expand("${SSTATE_MANIFESTS}", d))
manifest = bb.data.expand("${SSTATE_MANFILEPREFIX}.%s" % ss['name'], d)
2010-08-04 10:34:18 +00:00
if os.access(manifest, os.R_OK):
bb.fatal("Package already staged (%s)?!" % manifest)
locks = []
for lock in ss['lockfiles']:
locks.append(bb.utils.lockfile(lock))
for state in ss['dirs']:
oe.path.copytree(state[1], state[2])
for walkroot, dirs, files in os.walk(state[1]):
for file in files:
srcpath = os.path.join(walkroot, file)
dstpath = srcpath.replace(state[1], state[2])
bb.debug(2, "Staging %s to %s" % (srcpath, dstpath))
sharedfiles.append(dstpath)
for dir in dirs:
2010-08-30 08:13:49 +00:00
srcdir = os.path.join(walkroot, dir)
dstdir = srcdir.replace(state[1], state[2])
bb.debug(2, "Staging %s to %s" % (srcdir, dstdir))
if not dstdir.endswith("/"):
dstdir = dstdir + "/"
shareddirs.append(dstdir)
2010-08-04 10:34:18 +00:00
f = open(manifest, "w")
for file in sharedfiles:
f.write(file + "\n")
# We want to ensure that directories appear at the end of the manifest
# so that when we test to see if they should be deleted any contents
# added by the task will have been removed first.
2010-09-29 11:10:57 +00:00
dirs = sorted(shareddirs, key=len)
# Must remove children first, which will have a longer path than the parent
for di in reversed(dirs):
f.write(di + "\n")
2010-08-04 10:34:18 +00:00
f.close()
for lock in locks:
bb.utils.unlockfile(lock)
def sstate_installpkg(ss, d):
import oe.path
2010-09-29 10:02:07 +00:00
sstateinst = bb.data.expand("${WORKDIR}/sstate-install-%s/" % ss['name'], d)
sstatepkg = bb.data.getVar('SSTATE_PKG', d, True) + '_' + ss['name'] + ".tgz"
2010-08-04 10:34:18 +00:00
2010-09-29 10:02:07 +00:00
if not os.path.exists(sstatepkg):
pstaging_fetch(sstatepkg, d)
2010-08-04 10:34:18 +00:00
2010-09-29 10:02:07 +00:00
if not os.path.isfile(sstatepkg):
bb.note("Staging package %s does not exist" % sstatepkg)
2010-08-04 10:34:18 +00:00
return False
sstate_clean(ss, d)
2010-09-29 10:02:07 +00:00
bb.data.setVar('SSTATE_INSTDIR', sstateinst, d)
bb.data.setVar('SSTATE_PKG', sstatepkg, d)
2010-08-04 10:34:18 +00:00
bb.build.exec_func('sstate_unpack_package', d)
# Fixup hardcoded paths
2010-09-29 10:02:07 +00:00
fixmefn = sstateinst + "fixmepath"
2010-08-04 10:34:18 +00:00
if os.path.isfile(fixmefn):
staging = bb.data.getVar('STAGING_DIR', d, True)
fixmefd = open(fixmefn, "r")
fixmefiles = fixmefd.readlines()
fixmefd.close()
for file in fixmefiles:
2010-09-29 10:02:07 +00:00
os.system("sed -i -e s:FIXMESTAGINGDIR:%s:g %s" % (staging, sstateinst + file))
2010-08-04 10:34:18 +00:00
for state in ss['dirs']:
if os.path.exists(state[1]):
oe.path.remove(state[1])
2010-09-29 10:02:07 +00:00
oe.path.copytree(sstateinst + state[0], state[1])
2010-08-04 10:34:18 +00:00
sstate_install(ss, d)
for plain in ss['plaindirs']:
2010-09-29 10:02:07 +00:00
bb.mkdirhier(sstateinst + plain)
oe.path.copytree(sstateinst + plain, bb.data.getVar('WORKDIR', d, True) + plain)
2010-08-04 10:34:18 +00:00
return True
def sstate_clean_manifest(manifest, d):
import oe.path
if not os.path.exists(manifest):
return
mfile = open(manifest)
entries = mfile.readlines()
mfile.close()
for entry in entries:
entry = entry.strip()
2010-08-30 08:13:49 +00:00
bb.debug(2, "Removing manifest: %s" % entry)
2010-08-04 10:34:18 +00:00
if entry.endswith("/"):
2010-09-03 14:28:11 +00:00
if os.path.islink(entry[:-1]):
os.remove(entry[:-1])
elif os.path.exists(entry) and len(os.listdir(entry)) == 0:
os.rmdir(entry[:-1])
2010-08-04 10:34:18 +00:00
else:
oe.path.remove(entry)
oe.path.remove(manifest)
def sstate_clean(ss, d):
2010-09-29 09:57:16 +00:00
manifest = bb.data.expand("${SSTATE_MANFILEPREFIX}.%s" % ss['name'], d)
2010-08-04 10:34:18 +00:00
locks = []
for lock in ss['lockfiles']:
locks.append(bb.utils.lockfile(lock))
sstate_clean_manifest(manifest, d)
for lock in locks:
bb.utils.unlockfile(lock)
2010-08-27 11:29:01 +00:00
SCENEFUNCS += "sstate_cleanall"
2010-08-27 11:33:58 +00:00
CLEANFUNCS += "sstate_cleanall"
2010-08-27 11:29:01 +00:00
2010-08-04 10:34:18 +00:00
python sstate_cleanall() {
import fnmatch
2010-08-27 11:33:58 +00:00
bb.note("Removing shared state for package %s" % bb.data.getVar('PN', d, True))
2010-08-04 10:34:18 +00:00
2010-09-29 09:57:16 +00:00
manifest_dir = bb.data.getVar('SSTATE_MANIFESTS', d, True)
manifest_prefix = bb.data.getVar("SSTATE_MANFILEPREFIX", d, True)
2010-08-30 06:27:24 +00:00
manifest_pattern = os.path.basename(manifest_prefix) + ".*"
2010-08-04 10:34:18 +00:00
2010-08-27 11:33:58 +00:00
if not os.path.exists(manifest_dir):
return
2010-08-04 10:34:18 +00:00
for manifest in (os.listdir(manifest_dir)):
if fnmatch.fnmatch(manifest, manifest_pattern):
sstate_clean_manifest(manifest_dir + "/" + manifest, d)
}
def sstate_package(ss, d):
import oe.path
2010-09-29 10:02:07 +00:00
sstatebuild = bb.data.expand("${WORKDIR}/sstate-build-%s/" % ss['name'], d)
sstatepkg = bb.data.getVar('SSTATE_PKG', d, True) + '_'+ ss['name'] + ".tgz"
bb.mkdirhier(sstatebuild)
bb.mkdirhier(os.path.dirname(sstatepkg))
2010-08-04 10:34:18 +00:00
for state in ss['dirs']:
srcbase = state[0].rstrip("/").rsplit('/', 1)[0]
2010-09-29 10:02:07 +00:00
oe.path.copytree(state[1], sstatebuild + state[0])
2010-08-04 10:34:18 +00:00
for walkroot, dirs, files in os.walk(state[1]):
for file in files:
srcpath = os.path.join(walkroot, file)
2010-09-29 10:02:07 +00:00
dstpath = srcpath.replace(state[1], sstatebuild + state[0])
2010-08-04 10:34:18 +00:00
bb.debug(2, "Preparing %s for packaging at %s" % (srcpath, dstpath))
workdir = bb.data.getVar('WORKDIR', d, True)
for plain in ss['plaindirs']:
2010-09-29 10:02:07 +00:00
pdir = plain.replace(workdir, sstatebuild)
2010-08-04 10:34:18 +00:00
bb.mkdirhier(plain)
bb.mkdirhier(pdir)
oe.path.copytree(plain, pdir)
2010-09-29 10:02:07 +00:00
bb.data.setVar('SSTATE_BUILDDIR', sstatebuild, d)
bb.data.setVar('SSTATE_PKG', sstatepkg, d)
2010-08-04 10:34:18 +00:00
bb.build.exec_func('sstate_create_package', d)
2010-09-13 14:41:07 +00:00
2010-09-29 10:02:07 +00:00
bb.siggen.dump_this_task(sstatepkg + ".siginfo", d)
2010-08-04 10:34:18 +00:00
return
2010-09-29 10:02:07 +00:00
def pstaging_fetch(sstatepkg, d):
2010-08-04 10:34:18 +00:00
import bb.fetch
# only try and fetch if the user has configured a mirror
2010-09-29 10:19:22 +00:00
if bb.data.getVar('SSTATE_MIRROR', d) != "":
2010-08-04 10:34:18 +00:00
# Copy the data object and override DL_DIR and SRC_URI
pd = d.createCopy()
2010-09-29 10:19:22 +00:00
dldir = bb.data.expand("${SSTATE_DIR}", pd)
mirror = bb.data.expand("${SSTATE_MIRROR}/", pd)
2010-09-29 10:02:07 +00:00
srcuri = mirror + os.path.basename(sstatepkg)
2010-08-04 10:34:18 +00:00
bb.data.setVar('DL_DIR', dldir, pd)
bb.data.setVar('SRC_URI', srcuri, pd)
2010-09-29 10:02:07 +00:00
# Try a fetch from the sstate mirror, if it fails just return and
2010-08-04 10:34:18 +00:00
# we will build the package
try:
bb.fetch.init([srcuri], pd)
bb.fetch.go(pd, [srcuri])
except:
return
def sstate_setscene(d):
shared_state = sstate_state_fromvars(d)
accelerate = sstate_installpkg(shared_state, d)
if not accelerate:
raise bb.build.FuncFailed("No suitable staging package found")
python sstate_task_prefunc () {
shared_state = sstate_state_fromvars(d)
sstate_clean(shared_state, d)
}
python sstate_task_postfunc () {
shared_state = sstate_state_fromvars(d)
sstate_install(shared_state, d)
2010-09-03 17:22:20 +00:00
for intercept in shared_state['interceptfuncs']:
bb.build.exec_func(intercept, d)
2010-08-04 10:34:18 +00:00
sstate_package(shared_state, d)
}
#
2010-09-29 10:02:07 +00:00
# Shell function to generate a sstate package from a directory
2010-09-29 09:57:16 +00:00
# set as SSTATE_BUILDDIR
2010-08-04 10:34:18 +00:00
#
sstate_create_package () {
# Need to remove hardcoded paths and fix these when we install the
# staging packages.
2010-09-29 09:57:16 +00:00
for i in `${SSTATE_SCAN_CMD}` ; do \
2010-08-04 10:34:18 +00:00
sed -i -e s:${STAGING_DIR}:FIXMESTAGINGDIR:g $i
2010-09-29 09:57:16 +00:00
echo $i | sed -e 's:${SSTATE_BUILDDIR}::' >> ${SSTATE_BUILDDIR}fixmepath
2010-08-04 10:34:18 +00:00
done
2010-09-29 09:57:16 +00:00
cd ${SSTATE_BUILDDIR}
tar -cvzf ${SSTATE_PKG} *
2010-08-04 10:34:18 +00:00
}
#
# Shell function to decompress and prepare a package for installation
#
sstate_unpack_package () {
2010-09-29 09:57:16 +00:00
mkdir -p ${SSTATE_INSTDIR}
cd ${SSTATE_INSTDIR}
tar -xvzf ${SSTATE_PKG}
2010-08-04 10:34:18 +00:00
}