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"
11 if not bb.data.inherits_class('native', d) and not bb.data.inherits_class('image', d) and not bb.data.inherits_class('cross', d) and not bb.data.inherits_class('sdk', d):
12 deps = bb.data.getVarFlag('do_populate_staging', 'depends', d) or ""
13 deps += " stagemanager-native:do_populate_staging"
14 bb.data.setVarFlag('do_populate_staging', 'depends', deps, d)
16 deps = bb.data.getVarFlag('do_prepackaged_stage', 'depends', d) or ""
17 deps += " ipkg-native:do_populate_staging ipkg-utils-native:do_populate_staging"
18 bb.data.setVarFlag('do_prepackaged_stage', 'depends', deps, d)
20 bb.data.setVar("PSTAGING_DISABLED", "1", d)
23 # multimachine.bbclass will override this
24 MULTIMACH_ARCH ?= "${PACKAGE_ARCH}"
26 export PSTAGING_DISABLED = "0"
28 DEPLOY_DIR_PSTAGE = "${DEPLOY_DIR}/pstage"
30 PSTAGE_BUILD_CMD = "${IPKGBUILDCMD}"
31 PSTAGE_INSTALL_CMD = "ipkg-cl install -force-depends -f ${DEPLOY_DIR_PSTAGE}/ipkg-${MACHINE}.conf -o ${TMPDIR}"
32 PSTAGE_UPDATE_CMD = "ipkg-cl update -f ${DEPLOY_DIR_PSTAGE}/ipkg-${MACHINE}.conf -o ${TMPDIR}"
33 PSTAGE_REMOVE_CMD = "ipkg-cl remove -force-depends -f ${DEPLOY_DIR_PSTAGE}/ipkg-${MACHINE}.conf -o ${TMPDIR}"
34 PSTAGE_LIST_CMD = "ipkg-cl list_installed -f ${DEPLOY_DIR_PSTAGE}/ipkg-${MACHINE}.conf -o ${TMPDIR}"
35 PSTAGE_PKGNAME = "staging-${PN}_${PV}-${PR}_${MULTIMACH_ARCH}.ipk"
37 PSTAGE_TMPDIR_STAGE = "${WORKDIR}/staging-pkg"
41 Clear the build and temp directories
43 bb.note("Uninstalling package from staging...")
44 path = bb.data.getVar("PATH", d, 1)
45 removecmd = bb.data.getVar("PSTAGE_REMOVE_CMD", d, 1)
46 removepkg = bb.data.expand("staging-${PN}", d)
47 ret = os.system("PATH=\"%s\" %s %s" % (path, removecmd, removepkg))
49 bb.note("Failure removing staging package")
51 stagepkg = bb.data.expand("${DEPLOY_DIR_PSTAGE}/${PSTAGE_PKGNAME}", d)
52 bb.note("Removing staging package %s" % stagepkg)
53 #os.system('rm -rf ' + stagepkg)
57 #assemble appropriate ipkg.conf
58 conffile=${DEPLOY_DIR_PSTAGE}/ipkg-${MACHINE}.conf
59 mkdir -p ${DEPLOY_DIR_PSTAGE}/pstaging_lists
60 if [ ! -e $conffile ]; then
61 ipkgarchs="${BUILD_ARCH} all any noarch ${TARGET_ARCH} ${PACKAGE_ARCHS} ${PACKAGE_EXTRA_ARCHS} ${MACHINE}"
63 for arch in $ipkgarchs; do
64 echo "arch $arch $priority" >> $conffile
65 priority=$(expr $priority + 5)
67 echo "src oe-staging file:${DEPLOY_DIR_PSTAGE}" >> $conffile
70 cd ${DEPLOY_DIR_PSTAGE}
71 ipkg-make-index -p Packages .
78 python do_prepackaged_stage () {
81 if bb.data.getVar("PSTAGING_DISABLED", d, 1) == "1":
82 bb.build.make_stamp("do_prepackaged_stage", d)
85 bb.note("Uninstalling any existing package from staging...")
86 path = bb.data.getVar("PATH", d, 1)
87 removecmd = bb.data.getVar("PSTAGE_REMOVE_CMD", d, 1)
88 removepkg = bb.data.expand("staging-${PN}", d)
89 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
90 ret = os.system("PATH=\"%s\" %s %s" % (path, removecmd, removepkg))
91 bb.utils.unlockfile(lf)
93 bb.note("Failure attempting to remove staging package")
95 stagepkg = bb.data.expand("${DEPLOY_DIR_PSTAGE}/${PSTAGE_PKGNAME}", d)
97 if os.path.exists(stagepkg):
98 bb.note("Following speedup\n")
99 path = bb.data.getVar("PATH", d, 1)
100 installcmd = bb.data.getVar("PSTAGE_INSTALL_CMD", d, 1)
102 bb.build.exec_func("staging_helper", d)
104 bb.debug(1, "Staging stuff already packaged, using that instead")
105 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
106 ret = os.system("PATH=\"%s\" %s %s" % (path, installcmd, stagepkg))
107 bb.utils.unlockfile(lf)
109 bb.note("Failure installing prestage package")
111 bb.build.make_stamp("do_prepackaged_stage", d)
112 bb.build.make_stamp("do_fetch", d)
113 bb.build.make_stamp("do_unpack", d)
114 bb.build.make_stamp("do_munge", d)
115 bb.build.make_stamp("do_patch", d)
116 bb.build.make_stamp("do_configure", d)
117 bb.build.make_stamp("do_qa_configure", d)
118 bb.build.make_stamp("do_rig_locales", d)
119 bb.build.make_stamp("do_compile", d)
120 bb.build.make_stamp("do_install", d)
121 bb.build.make_stamp("do_deploy", d)
122 bb.build.make_stamp("do_package", d)
123 bb.build.make_stamp("do_populate_staging", d)
124 bb.build.make_stamp("do_package_write_deb", d)
125 bb.build.make_stamp("do_package_write_ipk", d)
126 bb.build.make_stamp("do_package_write", d)
127 bb.build.make_stamp("do_package_stage", d)
128 bb.build.make_stamp("do_qa_staging", d)
131 bb.build.make_stamp("do_prepackaged_stage", d)
133 do_prepackaged_stage[cleandirs] = "${PSTAGE_TMPDIR_STAGE}"
134 do_prepackaged_stage[selfstamp] = "1"
135 addtask prepackaged_stage before do_fetch
137 populate_staging_preamble () {
138 if [ "$PSTAGING_DISABLED" != "1" ]; then
139 #mkdir -p ${DEPLOY_DIR_PSTAGE}
141 stage-manager -p ${STAGING_DIR} -c ${DEPLOY_DIR_PSTAGE}/stamp-cache-staging -u
142 stage-manager -p ${CROSS_DIR} -c ${DEPLOY_DIR_PSTAGE}/stamp-cache-cross -u
146 populate_staging_postamble () {
147 if [ "$PSTAGING_DISABLED" != "1" ]; then
148 # list the packages currently installed in staging
149 ${PSTAGE_LIST_CMD} | awk '{print $1}' > ${DEPLOY_DIR_PSTAGE}/installed-list
152 stage-manager -p ${STAGING_DIR} -c ${DEPLOY_DIR_PSTAGE}/stamp-cache-staging -u -d ${PSTAGE_TMPDIR_STAGE}/staging
153 stage-manager -p ${CROSS_DIR} -c ${DEPLOY_DIR_PSTAGE}/stamp-cache-cross -u -d ${PSTAGE_TMPDIR_STAGE}/cross
158 do_populate_staging[lockfiles] = "${STAGING_DIR}/staging.lock"
159 do_populate_staging[dirs] =+ "${DEPLOY_DIR_PSTAGE}"
160 python do_populate_staging_prepend() {
161 bb.build.exec_func("populate_staging_preamble", d)
164 python do_populate_staging_append() {
165 bb.build.exec_func("populate_staging_postamble", d)
169 staging_packager () {
171 mkdir -p ${PSTAGE_TMPDIR_STAGE}/CONTROL
173 echo "Package: staging-${PN}" > ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
174 echo "Version: ${PV}-${PR}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
175 echo "Description: ${DESCRIPTION}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
176 echo "Section: ${SECTION}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
177 echo "Priority: Optional" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
178 echo "Maintainer: ${MAINTAINER}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
179 echo "Architecture: ${MULTIMACH_ARCH}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
180 echo "Source: ${SRC_URI}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
182 ${PSTAGE_BUILD_CMD} ${PSTAGE_TMPDIR_STAGE} ${DEPLOY_DIR_PSTAGE}
183 ${PSTAGE_INSTALL_CMD} ${DEPLOY_DIR_PSTAGE}/${PSTAGE_PKGNAME}
186 python do_package_stage () {
187 if bb.data.getVar("PSTAGING_DISABLED", d, 1) == "1":
190 bb.build.exec_func("read_subpackage_metadata", d)
191 packages = (bb.data.getVar('PACKAGES', d, 1) or "").split()
192 if len(packages) > 0:
193 stagepath = bb.data.getVar("PSTAGE_TMPDIR_STAGE", d, 1)
194 if bb.data.inherits_class('package_ipk', d):
195 ipkpath = os.path.join(stagepath, "deploy", "ipk")
196 bb.mkdirhier(ipkpath)
197 if bb.data.inherits_class('package_deb', d):
198 debpath = os.path.join(stagepath, "deploy", "deb")
199 bb.mkdirhier(debpath)
202 pkgname = bb.data.getVar('PKG_%s' % pkg, d, 1)
205 arch = bb.data.getVar('PACKAGE_ARCH_%s' % pkg, d, 1)
207 arch = bb.data.getVar('PACKAGE_ARCH', d, 1)
208 if not packaged(pkg, d):
210 if bb.data.inherits_class('package_ipk', d):
211 srcname = bb.data.expand(pkgname + "_${PV}-${PR}_" + arch + ".ipk", d)
212 srcfile = bb.data.expand("${DEPLOY_DIR_IPK}/" + arch + "/" + srcname, d)
213 if not os.path.exists(srcfile):
214 bb.fatal("Package %s does not exist yet it should" % srcfile)
215 bb.copyfile(srcfile, ipkpath + "/" + srcname)
216 if bb.data.inherits_class('package_deb', d):
218 srcname = bb.data.expand(pkgname + "_${PV}-${PR}_all.deb", d)
220 srcname = bb.data.expand(pkgname + "_${PV}-${PR}_${DPKG_ARCH}.deb", d)
221 srcfile = bb.data.expand("${DEPLOY_DIR_DEB}/" + arch + "/" + srcname, d)
222 if not os.path.exists(srcfile):
223 bb.fatal("Package %s does not exist yet it should" % srcfile)
224 bb.copyfile(srcfile, debpath + "/" + srcname)
225 bb.build.exec_func("staging_helper", d)
226 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
227 bb.build.exec_func("staging_packager", d)
228 bb.utils.unlockfile(lf)
231 addtask package_stage after do_package_write do_populate_staging before do_build