cacao-native: add mercurial recipe
[openembedded.git] / classes / packaged-staging.bbclass
blob68c973a9c7ab811fa00f9007588188df477e009d
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  ?= "/${OELAYOUT_ABI}/${DISTRO_PR}/"
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        = "${PSTAGE_DIR}/${PSTAGE_PKGPATH}/${PSTAGE_PKGNAME}"
21 PSTAGE_WORKDIR   = "${TMPDIR}/pstage"
22 PSTAGE_SCAN_CMD ?= "find ${PSTAGE_TMPDIR_STAGE} \( -name "*.la" -o -name "*-config" \) -type f"
24 PSTAGE_NATIVEDEPENDS = "\
25     shasum-native \
26     stagemanager-native \
27     "
29 BB_STAMP_WHITELIST = "${PSTAGE_NATIVEDEPENDS}"
31 def _package_unlink (f):
32     import os, errno
33     try:
34         os.unlink(f)
35         return True
36     except OSError, e:
37         if e.errno == errno.ENOENT:
38             return False
39         raise
41 python () {
42     pstage_allowed = True
44     # These classes encode staging paths into the binary data so can only be
45     # reused if the path doesn't change/
46     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):
47         path = bb.data.getVar('PSTAGE_PKGPATH', d, 1)
48         path = path + bb.data.getVar('TMPDIR', d, 1).replace('/', '-')
49         bb.data.setVar('PSTAGE_PKGPATH', path, d)
50         scan_cmd = "grep -Irl ${STAGING_DIR} ${PSTAGE_TMDPDIR_STAGE}"
51         bb.data.setVar('PSTAGE_SCAN_CMD', scan_cmd, d)
53     # PSTAGE_NATIVEDEPENDS lists the packages we need before we can use packaged 
54     # staging. There will always be some packages we depend on.
55     if bb.data.inherits_class('native', d):
56         pn = bb.data.getVar('PN', d, True)
57         nativedeps = bb.data.getVar('PSTAGE_NATIVEDEPENDS', d, True).split()
58         if pn in nativedeps:
59             pstage_allowed = False
61     # Images aren't of interest to us
62     if bb.data.inherits_class('image', d):
63         pstage_allowed = False
65     if bb.data.getVar('PSTAGING_DISABLED', d, True) == "1":
66         pstage_allowed = False
68     # Add task dependencies if we're active, otherwise mark packaged staging
69     # as inactive.
70     if pstage_allowed:
71         deps = bb.data.getVarFlag('do_setscene', 'depends', d) or ""
72         deps += " stagemanager-native:do_populate_sysroot"
73         bb.data.setVarFlag('do_setscene', 'depends', deps, d)
75         policy = bb.data.getVar("BB_STAMP_POLICY", d, True)
76         if policy == "whitelist" or policy == "full":
77            deps = bb.data.getVarFlag('do_setscene', 'recrdeptask', d) or ""
78            deps += " do_setscene"
79            bb.data.setVarFlag('do_setscene', 'recrdeptask', deps, d)
81         bb.data.setVar("PSTAGING_ACTIVE", "1", d)
82     else:
83         bb.data.setVar("PSTAGING_ACTIVE", "0", d)
86 PSTAGE_MACHCONFIG   = "${PSTAGE_WORKDIR}/opkg.conf"
88 PSTAGE_PKGMANAGER = "stage-manager-ipkg"
90 PSTAGE_BUILD_CMD        = "stage-manager-ipkg-build -o 0 -g 0"
91 PSTAGE_INSTALL_CMD      = "${PSTAGE_PKGMANAGER} -f ${PSTAGE_MACHCONFIG} -force-depends -o ${TMPDIR} install"
92 PSTAGE_UPDATE_CMD       = "${PSTAGE_PKGMANAGER} -f ${PSTAGE_MACHCONFIG} -o ${TMPDIR} update"
93 PSTAGE_REMOVE_CMD       = "${PSTAGE_PKGMANAGER} -f ${PSTAGE_MACHCONFIG} -force-depends -o ${TMPDIR} remove"
94 PSTAGE_LIST_CMD         = "${PSTAGE_PKGMANAGER} -f ${PSTAGE_MACHCONFIG} -o ${TMPDIR} list_installed"
96 PSTAGE_TMPDIR_STAGE     = "${WORKDIR}/staging-pkg"
98 def pstage_manualclean(srcname, destvarname, d):
99         src = os.path.join(bb.data.getVar('PSTAGE_TMPDIR_STAGE', d, True), srcname)
100         dest = bb.data.getVar(destvarname, d, True)
102         for walkroot, dirs, files in os.walk(src):
103                 bb.debug("rm %s" % walkroot)
104                 for file in files:
105                         # Avoid breaking the held lock
106                         if (file == "staging.lock"):
107                                 continue
108                         filepath = os.path.join(walkroot, file).replace(src, dest)
109                         _package_unlink(filepath)
111 def pstage_set_pkgmanager(d):
112     path = bb.data.getVar("PATH", d, 1)
113     pkgmanager = bb.which(path, 'opkg-cl')
114     if pkgmanager == "":
115         pkgmanager = bb.which(path, 'ipkg-cl')
116     if pkgmanager != "":
117         bb.data.setVar("PSTAGE_PKGMANAGER", pkgmanager, d)
120 def pstage_cleanpackage(pkgname, d):
121         path = bb.data.getVar("PATH", d, 1)
122         pstage_set_pkgmanager(d)
123         list_cmd = bb.data.getVar("PSTAGE_LIST_CMD", d, True)
125         bb.debug(2, "Checking if staging package installed")
126         lf = bb.utils.lockfile(bb.data.expand("${SYSROOT_LOCK}", d))
127         ret = os.system("PATH=\"%s\" %s | grep %s" % (path, list_cmd, pkgname))
128         if ret == 0:
129                 bb.debug(1, "Uninstalling package from staging...")
130                 removecmd = bb.data.getVar("PSTAGE_REMOVE_CMD", d, 1)
131                 ret = os.system("PATH=\"%s\" %s %s" % (path, removecmd, pkgname))
132                 if ret != 0:
133                         bb.note("Failure removing staging package")
134         else:
135                 bb.debug(1, "Manually removing any installed files from staging...")
136                 pstage_manualclean("sysroots", "STAGING_DIR", d)
137                 pstage_manualclean("cross", "CROSS_DIR", d)
138                 pstage_manualclean("deploy", "DEPLOY_DIR", d)
140         bb.utils.unlockfile(lf)
142 do_clean_prepend() {
143         """
144         Clear the build and temp directories
145         """
147         removepkg = bb.data.expand("${PSTAGE_PKGPN}", d)
148         pstage_cleanpackage(removepkg, d)
150         stagepkg = bb.data.expand("${PSTAGE_PKG}", d)
151         bb.note("Removing staging package %s" % base_path_out(stagepkg, d))
152         # Add a wildcard to the end of stagepkg to also get its md5
153     # if it's a fetched package
154         os.system('rm -rf ' + stagepkg + '*')
157 staging_helper () {
158         # Assemble appropriate opkg.conf
159         conffile=${PSTAGE_MACHCONFIG}
160         mkdir -p ${PSTAGE_WORKDIR}/pstaging_lists
161         if [ ! -e $conffile ]; then
162                 ipkgarchs="${BUILD_SYS}"
163                 priority=1
164                 for arch in $ipkgarchs; do
165                         echo "arch $arch $priority" >> $conffile
166                         priority=$(expr $priority + 5)
167                 done
168                 echo "dest root /" >> $conffile
169         fi
170         if [ ! -e ${TMPDIR}${libdir_native}/opkg/info/ ]; then
171                 mkdir -p ${TMPDIR}${libdir_native}/opkg/info/
172         fi
173         if [ ! -e ${TMPDIR}${libdir_native}/ipkg/ ]; then
174                 ln -sf opkg/ ${TMPDIR}${libdir_native}/ipkg || true
175         fi
178 def staging_fetch(stagepkg, d):
179     import bb.fetch
181     # only try and fetch if the user has configured a mirror
182     if bb.data.getVar('PSTAGE_MIRROR', d) != "":
183         # Copy the data object and override DL_DIR and SRC_URI
184         pd = d.createCopy()
185         dldir = bb.data.expand("${PSTAGE_DIR}/${PSTAGE_PKGPATH}", pd)
186         mirror = bb.data.expand("${PSTAGE_MIRROR}/${PSTAGE_PKGPATH}/", pd)
187         srcuri = mirror + os.path.basename(stagepkg)
188         bb.data.setVar('DL_DIR', dldir, pd)
189         bb.data.setVar('SRC_URI', srcuri, pd)
191         # Try a fetch from the pstage mirror, if it fails just return and
192         # we will build the package
193         try:
194             bb.fetch.init([srcuri], pd)
195             bb.fetch.go(pd, [srcuri])
196         except:
197             return
199 PSTAGE_TASKS_COVERED = "fetch unpack munge patch configure qa_configure rig_locales compile sizecheck install deploy package populate_sysroot package_write_deb package_write_ipk package_write package_stage qa_staging"
201 SCENEFUNCS += "packagestage_scenefunc"
203 python packagestage_scenefunc () {
204     import glob
205     if bb.data.getVar("PSTAGING_ACTIVE", d, 1) == "0":
206         return
208     bb.build.exec_func("staging_helper", d)
210     removepkg = bb.data.expand("${PSTAGE_PKGPN}", d)
212     pstage_cleanpackage(removepkg, d)
214     stagepkg = bb.data.expand("${PSTAGE_PKG}", d)
215     if not os.path.exists(stagepkg):
216         staging_fetch(stagepkg, d)
218     if os.path.exists(stagepkg):
219         path = bb.data.getVar("PATH", d, 1)
220         pstage_set_pkgmanager(d)
221         file = bb.data.getVar("FILE", d, True)
222         bb.debug(2, "Packaged staging active for %s\n" % file)
224         #
225         # Install the staging package somewhere temporarily so we can extract the stamp files
226         #
227         bb.mkdirhier(bb.data.expand("${WORKDIR}/tstage/${libdir_native}/opkg/info/ ", d))
228         cmd = bb.data.expand("${PSTAGE_PKGMANAGER} -f ${PSTAGE_MACHCONFIG} -force-depends -o ${WORKDIR}/tstage install", d)
229         ret = os.system("PATH=\"%s\" %s %s" % (path, cmd, stagepkg))
230         if ret != 0:
231             bb.fatal("Couldn't install the staging package to a temp directory")
233         #
234         # Grab the staging lock now so that we don't have other threads try and
235         # validate or install based on these stamps being valid.  This is a
236         # potential issue for certain BB_STAMP_POLICY values and enough
237         # concurrent threads.
238         #
239         lf = bb.utils.lockfile(bb.data.expand("${SYSROOT_LOCK}", d))
241         #
242         # Copy the stamp files into the main stamps directoy
243         #
244         cmd = bb.data.expand("cp -dpR ${WORKDIR}/tstage/stamps/* ${TMPDIR}/stamps/", d)
245         ret = os.system(cmd)
246         if ret != 0:
247             bb.utils.unlockfile(lf)
248             bb.fatal("Couldn't copy the staging package stamp files")
250         #
251         # Iterate over the stamps seeing if they're valid. If we find any that
252         # are invalid or the task wasn't in the taskgraph, assume caution and 
253         # do a rebuild.
254         #
255         # FIXME - some tasks are safe to ignore in the task graph. e.g. package_write_*
256         stageok = True
257         taskscovered = bb.data.getVar("PSTAGE_TASKS_COVERED", d, True).split()
258         stamp = bb.data.getVar("STAMP", d, True)
259         for task in taskscovered:
260             task = 'do_' + task
261             stampfn = "%s.%s" % (stamp, task)
262             bb.debug(1, "Checking %s" % (stampfn))
263             if os.path.exists(stampfn):
264                 stageok = bb.runqueue.check_stamp_fn(file, task, d)
265                 bb.debug(1, "Result %s" % (stageok))
266                 if not stageok:
267                     bb.utils.unlockfile(lf)
268                     break
270         # Remove the stamps and files we added above
271         # FIXME - we should really only remove the stamps we added
272         for fname in glob.glob(stamp + '.*'):
273             _package_unlink(fname)
275         os.system(bb.data.expand("rm -rf ${WORKDIR}/tstage", d))
277         if stageok:
278             bb.note("Staging package found, using it for %s." % file)
279             installcmd = bb.data.getVar("PSTAGE_INSTALL_CMD", d, 1)
280             ret = os.system("PATH=\"%s\" %s %s" % (path, installcmd, stagepkg))
281             bb.utils.unlockfile(lf)
282             if ret != 0:
283                 bb.note("Failure installing prestage package")
285             bb.build.exec_func("staging_package_libtoolhack", d)
287             bb.build.make_stamp("do_stage_package_populated", d)
288         else:
289             bb.note("Staging package found but invalid for %s" % file)
292 packagestage_scenefunc[cleandirs] = "${PSTAGE_TMPDIR_STAGE}"
293 packagestage_scenefunc[dirs] = "${STAGING_DIR}"
295 addhandler packagedstage_stampfixing_eventhandler
296 python packagedstage_stampfixing_eventhandler() {
297     if bb.event.getName(e) == "StampUpdate":
298         taskscovered = bb.data.getVar("PSTAGE_TASKS_COVERED", e.data, 1).split()
299         for (fn, task) in e.targets:
300             # strip off 'do_'
301             task = task[3:]
302             if task in taskscovered:
303                 stamp = "%s.do_stage_package_populated" % e.stampPrefix[fn]
304                 if os.path.exists(stamp):
305                     # We're targetting a task which was skipped with packaged staging
306                     # so we need to remove the autogenerated stamps.
307                     for task in taskscovered:
308                         dir = "%s.do_%s" % (e.stampPrefix[fn], task)
309                         _package_unlink(dir)
310                     _package_unlink(stamp)
313 populate_sysroot_preamble () {
314         if [ "$PSTAGING_ACTIVE" = "1" ]; then
315                 stage-manager -p ${STAGING_DIR} -c ${PSTAGE_WORKDIR}/stamp-cache-staging -u || true
316                 stage-manager -p ${CROSS_DIR} -c ${PSTAGE_WORKDIR}/stamp-cache-cross -u || true
317         fi
320 populate_sysroot_postamble () {
321         if [ "$PSTAGING_ACTIVE" = "1" ]; then
322                 # list the packages currently installed in staging
323                 # ${PSTAGE_LIST_CMD} | awk '{print $1}' > ${PSTAGE_WORKDIR}/installed-list
325                 # exitcode == 5 is ok, it means the files change
326                 set +e
327                 stage-manager -p ${STAGING_DIR} -c ${PSTAGE_WORKDIR}/stamp-cache-staging -u -d ${PSTAGE_TMPDIR_STAGE}/sysroots
328                 exitcode=$?
329                 if [ "$exitcode" != "5" -a "$exitcode" != "0" ]; then
330                         exit $exitcode
331                 fi
332                 stage-manager -p ${CROSS_DIR} -c ${PSTAGE_WORKDIR}/stamp-cache-cross -u -d ${PSTAGE_TMPDIR_STAGE}/cross/${BASE_PACKAGE_ARCH}
333                 if [ "$exitcode" != "5" -a "$exitcode" != "0" ]; then
334                         exit $exitcode
335                 fi
336                 set -e
337         fi
340 packagedstaging_fastpath () {
341         if [ "$PSTAGING_ACTIVE" = "1" ]; then
342                 mkdir -p ${PSTAGE_TMPDIR_STAGE}/sysroots/
343                 mkdir -p ${PSTAGE_TMPDIR_STAGE}/cross/${BASE_PACKAGE_ARCH}/
344                 cp -fpPR ${SYSROOT_DESTDIR}/${STAGING_DIR}/* ${PSTAGE_TMPDIR_STAGE}/sysroots/ || /bin/true
345                 cp -fpPR ${SYSROOT_DESTDIR}/${CROSS_DIR}/* ${PSTAGE_TMPDIR_STAGE}/cross/${BASE_PACKAGE_ARCH}/ || /bin/true
346         fi
349 do_populate_sysroot[dirs] =+ "${PSTAGE_DIR}"
350 python populate_sysroot_prehook() {
351     bb.build.exec_func("populate_sysroot_preamble", d)
354 python populate_sysroot_posthook() {
355     bb.build.exec_func("populate_sysroot_postamble", d)
359 staging_packager () {
361         mkdir -p ${PSTAGE_TMPDIR_STAGE}/CONTROL
362         mkdir -p ${PSTAGE_DIR}/${PSTAGE_PKGPATH}
364         echo "Package: ${PSTAGE_PKGPN}"         >  ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
365         echo "Version: ${PSTAGE_PKGVERSION}"    >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
366         echo "Description: ${DESCRIPTION}"      >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
367         echo "Section: ${SECTION}"              >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
368         echo "Priority: Optional"               >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
369         echo "Maintainer: ${MAINTAINER}"        >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
370         echo "Architecture: ${PSTAGE_PKGARCH}"  >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
371         
372         # Protect against empty SRC_URI
373         srcuri="${SRC_URI}"
374         if [ "$srcuri" == "" ]; then
375                 srcuri="OpenEmbedded"
376         fi
377         echo "Source: $srcuri"               >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
379         # Deal with libtool not supporting sysroots
380         # Need to remove hardcoded paths and fix these when we install the
381         # staging packages.
382         # Could someone please add sysroot support to libtool!
383         for i in `${PSTAGE_SCAN_CMD}` ; do \
384                 sed -i -e s:${STAGING_DIR}:FIXMESTAGINGDIR:g $i
385                 echo $i | sed -e 's:${PSTAGE_TMPDIR_STAGE}/::' >> ${PSTAGE_TMPDIR_STAGE}/sysroots/fixmepath
386         done
387         
388         ${PSTAGE_BUILD_CMD} ${PSTAGE_TMPDIR_STAGE} ${PSTAGE_DIR}/${PSTAGE_PKGPATH}
391 staging_package_installer () {
392         #${PSTAGE_INSTALL_CMD} ${PSTAGE_PKG}
394         STATUSFILE=${TMPDIR}${libdir_native}/opkg/status
395         echo "Package: ${PSTAGE_PKGPN}"        >> $STATUSFILE
396         echo "Version: ${PSTAGE_PKGVERSION}"   >> $STATUSFILE
397         echo "Status: install user installed"  >> $STATUSFILE
398         echo "Architecture: ${PSTAGE_PKGARCH}" >> $STATUSFILE
399         echo "" >> $STATUSFILE
401         CTRLFILE=${TMPDIR}${libdir_native}/opkg/info/${PSTAGE_PKGPN}.control
402         echo "Package: ${PSTAGE_PKGPN}"        > $CTRLFILE
403         echo "Version: ${PSTAGE_PKGVERSION}"   >> $CTRLFILE
404         echo "Architecture: ${PSTAGE_PKGARCH}" >> $CTRLFILE
406         cd ${PSTAGE_TMPDIR_STAGE}
407         find -type f | grep -v ./CONTROL | sed -e 's/^\.//' > ${TMPDIR}${libdir_native}/opkg/info/${PSTAGE_PKGPN}.list
410 python staging_package_libtoolhack () {
411         # Deal with libtool not supporting sysroots and add our new
412         # staging location
413         tmpdir = bb.data.getVar('TMPDIR', d, True)
414         staging = bb.data.getVar('STAGING_DIR', d, True)
415         fixmefn =  staging + "/fixmepath"
416         try:
417             fixmefd = open(fixmefn,"r")
418             fixmefiles = fixmefd.readlines()
419             fixmefd.close()
420             os.system('rm -f ' + fixmefn)
421             for file in fixmefiles:
422                 os.system("sed -i -e s:FIXMESTAGINGDIR:%s:g %s" % (staging, tmpdir + '/' + file))
423         except IOError:
424             pass
427 python do_package_stage () {
428     if bb.data.getVar("PSTAGING_ACTIVE", d, 1) != "1":
429         return
431     #
432     # Handle deploy/ packages
433     #
434     bb.build.exec_func("read_subpackage_metadata", d)
435     stagepath = bb.data.getVar("PSTAGE_TMPDIR_STAGE", d, 1)
436     tmpdir = bb.data.getVar("TMPDIR", d, True)
437     packages = (bb.data.getVar('PACKAGES', d, 1) or "").split()
438     if len(packages) > 0:
439         if bb.data.inherits_class('package_ipk', d):
440             ipkpath = bb.data.getVar('DEPLOY_DIR_IPK', d, True).replace(tmpdir, stagepath)
441         if bb.data.inherits_class('package_deb', d):
442             debpath = bb.data.getVar('DEPLOY_DIR_DEB', d, True).replace(tmpdir, stagepath)
443         if bb.data.inherits_class('package_rpm', d):
444             rpmpath = bb.data.getVar('DEPLOY_DIR_RPM', d, True).replace(tmpdir, stagepath)
446         for pkg in packages:
447             pkgname = bb.data.getVar('PKG_%s' % pkg, d, 1)
448             if not pkgname:
449                 pkgname = pkg
450             arch = bb.data.getVar('PACKAGE_ARCH_%s' % pkg, d, 1)
451             if not arch:
452                 arch = bb.data.getVar('PACKAGE_ARCH', d, 1)
453             pr = bb.data.getVar('PR_%s' % pkg, d, 1)
454             if not pr:
455                 pr = bb.data.getVar('PR', d, 1)
456             if not packaged(pkg, d):
457                 continue
458             if bb.data.inherits_class('package_ipk', d):
459                 srcname = bb.data.expand(pkgname + "_${PV}-" + pr + "${DISTRO_PR}" + "_" + arch + ".ipk", d)
460                 srcfile = bb.data.expand("${DEPLOY_DIR_IPK}/" + arch + "/" + srcname, d)
461                 if os.path.exists(srcfile):
462                     destpath = ipkpath + "/" + arch + "/"
463                     bb.mkdirhier(destpath)
464                     print destpath
465                     bb.copyfile(srcfile, destpath + srcname)
467             if bb.data.inherits_class('package_deb', d):
468                 if arch == 'all':
469                     srcname = bb.data.expand(pkgname + "_${PV}-" + pr + "${DISTRO_PR}" + "_all.deb", d)
470                 else:
471                     srcname = bb.data.expand(pkgname + "_${PV}-" + pr + "${DISTRO_PR}" + "_${DPKG_ARCH}.deb", d)
472                 srcfile = bb.data.expand("${DEPLOY_DIR_DEB}/" + arch + "/" + srcname, d)
473                 if os.path.exists(srcfile):
474                     destpath = debpath + "/" + arch + "/" 
475                     bb.mkdirhier(destpath)
476                     bb.copyfile(srcfile, destpath + srcname)
478             if bb.data.inherits_class('package_rpm', d):
479                 version = bb.data.getVar('PV', d, 1)
480                 version = version.replace('-', '+')
481                 bb.data.setVar('RPMPV', version, d)
482                 srcname = bb.data.expand(pkgname + "-${RPMPV}-" + pr + "${DISTRO_PR}" + ".${TARGET_ARCH}.rpm", d)
483                 srcfile = bb.data.expand("${DEPLOY_DIR_RPM}/" + arch + "/" + srcname, d)
484                 if os.path.exists(srcfile):
485                     destpath = rpmpath + "/" + arch + "/" 
486                     bb.mkdirhier(destpath)
487                     bb.copyfile(srcfile, destpath + srcname)
490     #
491     # Handle stamps/ files
492     #
493     stampfn = bb.data.getVar("STAMP", d, True)
494     destdir = os.path.dirname(stampfn.replace(tmpdir, stagepath))
495     bb.mkdirhier(destdir)
496     # We need to include the package_stage stamp in the staging package so create one
497     bb.build.make_stamp("do_package_stage", d)
498     os.system("cp -dpR %s.do_* %s/" % (stampfn, destdir))
500     pstage_set_pkgmanager(d)
501     bb.build.exec_func("staging_helper", d)
502     bb.build.exec_func("staging_packager", d)
503     lf = bb.utils.lockfile(bb.data.expand("${SYSROOT_LOCK}", d))
504     bb.build.exec_func("staging_package_installer", d)
505     bb.utils.unlockfile(lf)
509 # Note an assumption here is that do_deploy runs before do_package_write/do_populate_sysroot
511 addtask package_stage after do_package_write do_populate_sysroot before do_build
513 do_package_stage_all () {
514         :
516 do_package_stage_all[recrdeptask] = "do_package_stage"
517 addtask package_stage_all after do_package_stage before do_build