2 # Populate builds using prebuilt packages where possible to speed up builds
3 # and allow staging to be reconstructed.
5 # To use it add that line to conf/local.conf:
7 # INHERIT += "packaged-staging"
12 # bitbake.conf set PSTAGING_ACTIVE = "0", this class sets to "1" if we're active
14 PSTAGE_PKGVERSION = "${PV}-${PR}"
15 PSTAGE_PKGARCH = "${BUILD_SYS}"
16 PSTAGE_EXTRAPATH ?= ""
17 PSTAGE_PKGPATH = "${DISTRO}${PSTAGE_EXTRAPATH}"
18 PSTAGE_PKGPN = "${@bb.data.expand('staging-${PN}-${MULTIMACH_ARCH}${TARGET_VENDOR}-${TARGET_OS}', d).replace('_', '-')}"
19 PSTAGE_PKGNAME = "${PSTAGE_PKGPN}_${PSTAGE_PKGVERSION}_${PSTAGE_PKGARCH}.ipk"
20 PSTAGE_PKG = "${DEPLOY_DIR_PSTAGE}/${PSTAGE_PKGPATH}/${PSTAGE_PKGNAME}"
22 # multimachine.bbclass will override this but add a default in case we're not using it
23 MULTIMACH_ARCH ?= "${PACKAGE_ARCH}"
25 PSTAGE_NATIVEDEPENDS = "\
36 update-alternatives-cworth-native \
48 # These classes encode staging paths into the binary data so can only be
49 # reused if the path doesn't change/
50 if bb.data.inherits_class('native', d) or bb.data.inherits_class('cross', d) or bb.data.inherits_class('sdk', d):
51 path = bb.data.getVar('PSTAGE_PKGPATH', d, 1)
52 path = path + bb.data.getVar('TMPDIR', d, 1).replace('/', '-')
53 bb.data.setVar('PSTAGE_PKGPATH', path, d)
55 # PSTAGE_NATIVEDEPENDS lists the packages we need before we can use packaged
56 # staging. There will always be some packages we depend on.
57 if bb.data.inherits_class('native', d):
58 pn = bb.data.getVar('PN', d, True)
59 nativedeps = bb.data.getVar('PSTAGE_NATIVEDEPENDS', d, True).split()
61 pstage_allowed = False
63 # Images aren't of interest to us
64 if bb.data.inherits_class('image', d):
65 pstage_allowed = False
67 # Add task dependencies if we're active, otherwise mark packaged staging
70 deps = bb.data.getVarFlag('do_populate_staging', 'depends', d) or ""
71 deps += " stagemanager-native:do_populate_staging"
72 bb.data.setVarFlag('do_populate_staging', 'depends', deps, d)
74 deps = bb.data.getVarFlag('do_prepackaged_stage', 'depends', d) or ""
75 deps += " opkg-native:do_populate_staging ipkg-utils-native:do_populate_staging"
76 bb.data.setVarFlag('do_prepackaged_stage', 'depends', deps, d)
77 bb.data.setVar("PSTAGING_ACTIVE", "1", d)
79 bb.data.setVar("PSTAGING_ACTIVE", "0", d)
82 DEPLOY_DIR_PSTAGE = "${DEPLOY_DIR}/pstage"
83 PSTAGE_MACHCONFIG = "${DEPLOY_DIR_PSTAGE}/opkg.conf"
85 PSTAGE_BUILD_CMD = "${IPKGBUILDCMD}"
86 PSTAGE_INSTALL_CMD = "opkg-cl install -force-depends -f ${PSTAGE_MACHCONFIG} -o ${TMPDIR}"
87 PSTAGE_UPDATE_CMD = "opkg-cl update -f ${PSTAGE_MACHCONFIG} -o ${TMPDIR}"
88 PSTAGE_REMOVE_CMD = "opkg-cl remove -force-depends -f ${PSTAGE_MACHCONFIG} -o ${TMPDIR}"
89 PSTAGE_LIST_CMD = "opkg-cl list_installed -f ${PSTAGE_MACHCONFIG} -o ${TMPDIR}"
91 PSTAGE_TMPDIR_STAGE = "${WORKDIR}/staging-pkg"
95 Clear the build and temp directories
97 bb.note("Uninstalling package from staging...")
98 path = bb.data.getVar("PATH", d, 1)
99 removecmd = bb.data.getVar("PSTAGE_REMOVE_CMD", d, 1)
100 removepkg = bb.data.expand("${PSTAGE_PKGPN}", d)
101 ret = os.system("PATH=\"%s\" %s %s" % (path, removecmd, removepkg))
103 bb.note("Failure removing staging package")
105 stagepkg = bb.data.expand("${PSTAGE_PKG}", d)
106 bb.note("Removing staging package %s" % stagepkg)
107 os.system('rm -rf ' + stagepkg)
111 # Assemble appropriate opkg.conf
112 conffile=${PSTAGE_MACHCONFIG}
113 mkdir -p ${DEPLOY_DIR_PSTAGE}/pstaging_lists
114 if [ ! -e $conffile ]; then
115 ipkgarchs="${BUILD_SYS}"
117 for arch in $ipkgarchs; do
118 echo "arch $arch $priority" >> $conffile
119 priority=$(expr $priority + 5)
124 PSTAGE_TASKS_COVERED = "fetch unpack munge patch configure qa_configure rig_locales compile sizecheck install deploy package populate_staging package_write_deb package_write_ipk package_write package_stage qa_staging"
126 python do_prepackaged_stage () {
129 if bb.data.getVar("PSTAGING_ACTIVE", d, 1) == "0":
130 bb.build.make_stamp("do_prepackaged_stage", d)
133 bb.note("Uninstalling any existing package from staging...")
134 path = bb.data.getVar("PATH", d, 1)
135 removecmd = bb.data.getVar("PSTAGE_REMOVE_CMD", d, 1)
136 removepkg = bb.data.expand("${PSTAGE_PKGPN}", d)
137 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
138 ret = os.system("PATH=\"%s\" %s %s" % (path, removecmd, removepkg))
139 bb.utils.unlockfile(lf)
141 bb.note("Failure attempting to remove staging package")
143 stagepkg = bb.data.expand("${PSTAGE_PKG}", d)
145 if os.path.exists(stagepkg):
146 bb.note("Following speedup\n")
147 path = bb.data.getVar("PATH", d, 1)
148 installcmd = bb.data.getVar("PSTAGE_INSTALL_CMD", d, 1)
150 bb.build.exec_func("staging_helper", d)
152 bb.debug(1, "Staging stuff already packaged, using that instead")
153 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
154 ret = os.system("PATH=\"%s\" %s %s" % (path, installcmd, stagepkg))
155 bb.utils.unlockfile(lf)
157 bb.note("Failure installing prestage package")
159 #bb.build.make_stamp("do_prepackaged_stage", d)
160 #for task in bb.data.getVar("PSTAGE_TASKS_COVERED", d, 1).split():
161 # bb.build.make_stamp("do_" + task, d)
162 bb.build.make_stamp("do_stage_package_populated", d)
165 bb.build.make_stamp("do_prepackaged_stage", d)
167 do_prepackaged_stage[cleandirs] = "${PSTAGE_TMPDIR_STAGE}"
168 do_prepackaged_stage[selfstamp] = "1"
169 addtask prepackaged_stage before do_fetch
171 addhandler packagedstage_stampfixing_eventhandler
172 python packagedstage_stampfixing_eventhandler() {
173 from bb.event import getName
176 if getName(e) == "StampUpdate":
177 taskscovered = bb.data.getVar("PSTAGE_TASKS_COVERED", e.data, 1).split()
178 for (fn, task) in e.targets:
181 if task in taskscovered:
182 stamp = "%s.do_stage_package_populated" % e.stampPrefix[fn]
183 if os.path.exists(stamp):
184 # We're targetting a task which was skipped with packaged staging
185 # so we need to remove the autogenerated stamps.
186 for task in taskscovered:
187 dir = "%s.do_%s" % (e.stampPrefix[fn], task)
188 os.system('rm -f ' + dir)
189 os.system('rm -f ' + stamp)
194 populate_staging_preamble () {
195 if [ "$PSTAGING_ACTIVE" = "1" ]; then
196 stage-manager -p ${STAGING_DIR} -c ${DEPLOY_DIR_PSTAGE}/stamp-cache-staging -u || true
197 stage-manager -p ${CROSS_DIR} -c ${DEPLOY_DIR_PSTAGE}/stamp-cache-cross -u || true
201 populate_staging_postamble () {
202 if [ "$PSTAGING_ACTIVE" = "1" ]; then
203 # list the packages currently installed in staging
204 ${PSTAGE_LIST_CMD} | awk '{print $1}' > ${DEPLOY_DIR_PSTAGE}/installed-list
207 stage-manager -p ${STAGING_DIR} -c ${DEPLOY_DIR_PSTAGE}/stamp-cache-staging -u -d ${PSTAGE_TMPDIR_STAGE}/staging
208 stage-manager -p ${CROSS_DIR} -c ${DEPLOY_DIR_PSTAGE}/stamp-cache-cross -u -d ${PSTAGE_TMPDIR_STAGE}/cross
213 do_populate_staging[lockfiles] = "${STAGING_DIR}/staging.lock"
214 do_populate_staging[dirs] =+ "${DEPLOY_DIR_PSTAGE}"
215 python do_populate_staging_prepend() {
216 bb.build.exec_func("populate_staging_preamble", d)
219 python do_populate_staging_append() {
220 bb.build.exec_func("populate_staging_postamble", d)
224 staging_packager () {
226 mkdir -p ${PSTAGE_TMPDIR_STAGE}/CONTROL
227 mkdir -p ${DEPLOY_DIR_PSTAGE}/${PSTAGE_PKGPATH}
229 echo "Package: ${PSTAGE_PKGPN}" > ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
230 echo "Version: ${PSTAGE_PKGVERSION}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
231 echo "Description: ${DESCRIPTION}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
232 echo "Section: ${SECTION}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
233 echo "Priority: Optional" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
234 echo "Maintainer: ${MAINTAINER}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
235 echo "Architecture: ${PSTAGE_PKGARCH}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
236 echo "Source: ${SRC_URI}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
238 ${PSTAGE_BUILD_CMD} ${PSTAGE_TMPDIR_STAGE} ${DEPLOY_DIR_PSTAGE}/${PSTAGE_PKGPATH}
239 ${PSTAGE_INSTALL_CMD} ${PSTAGE_PKG}
242 staging_package_installer () {
243 ${PSTAGE_INSTALL_CMD} ${PSTAGE_PKG}
246 python do_package_stage () {
247 if bb.data.getVar("PSTAGING_ACTIVE", d, 1) != "1":
251 # Handle deploy/ packages
253 bb.build.exec_func("read_subpackage_metadata", d)
254 stagepath = bb.data.getVar("PSTAGE_TMPDIR_STAGE", d, 1)
255 tmpdir = bb.data.getVar("TMPDIR", d, True)
256 packages = (bb.data.getVar('PACKAGES', d, 1) or "").split()
257 if len(packages) > 0:
258 if bb.data.inherits_class('package_ipk', d):
259 ipkpath = bb.data.getVar('DEPLOY_DIR_IPK', d, True).replace(tmpdir, stagepath)
260 bb.mkdirhier(ipkpath)
261 if bb.data.inherits_class('package_deb', d):
262 debpath = bb.data.getVar('DEPLOY_DIR_DEB', d, True).replace(tmpdir, stagepath)
263 bb.mkdirhier(debpath)
266 pkgname = bb.data.getVar('PKG_%s' % pkg, d, 1)
269 arch = bb.data.getVar('PACKAGE_ARCH_%s' % pkg, d, 1)
271 arch = bb.data.getVar('PACKAGE_ARCH', d, 1)
272 pr = bb.data.getVar('PR_%s' % pkg, d, 1)
274 pr = bb.data.getVar('PR', d, 1)
275 if not packaged(pkg, d):
277 if bb.data.inherits_class('package_ipk', d):
278 srcname = bb.data.expand(pkgname + "_${PV}-" + pr + "_" + arch + ".ipk", d)
279 srcfile = bb.data.expand("${DEPLOY_DIR_IPK}/" + arch + "/" + srcname, d)
280 if not os.path.exists(srcfile):
281 bb.fatal("Package %s does not exist yet it should" % srcfile)
282 bb.copyfile(srcfile, ipkpath + "/" + srcname)
283 if bb.data.inherits_class('package_deb', d):
285 srcname = bb.data.expand(pkgname + "_${PV}-" + pr + "_all.deb", d)
287 srcname = bb.data.expand(pkgname + "_${PV}-" + pr + "_${DPKG_ARCH}.deb", d)
288 srcfile = bb.data.expand("${DEPLOY_DIR_DEB}/" + arch + "/" + srcname, d)
289 if not os.path.exists(srcfile):
290 bb.fatal("Package %s does not exist yet it should" % srcfile)
291 bb.copyfile(srcfile, debpath + "/" + srcname)
294 # Handle stamps/ files
296 stampfn = bb.data.getVar("STAMP", d, True)
297 destdir = os.path.dirname(stampfn.replace(tmpdir, stagepath))
298 bb.mkdirhier(destdir)
299 # We need to include the package_stage stamp in the staging package so create one
300 bb.build.make_stamp("do_package_stage", d)
301 os.system("cp %s.do_* %s/" % (stampfn, destdir))
303 bb.build.exec_func("staging_helper", d)
304 bb.build.exec_func("staging_packager", d)
305 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
306 bb.build.exec_func("staging_package_installer", d)
307 bb.utils.unlockfile(lf)
311 # Note an assumption here is that do_deploy runs before do_package_write/do_populate_staging
313 addtask package_stage after do_package_write do_populate_staging before do_build