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 export PSTAGING_DISABLED = "0"
25 DEPLOY_DIR_PSTAGE = "${DEPLOY_DIR}/pstage"
27 PSTAGE_BUILD_CMD = "${IPKGBUILDCMD}"
28 PSTAGE_INSTALL_CMD = "ipkg-cl install -force-depends -f ${DEPLOY_DIR_PSTAGE}/ipkg-${MACHINE}.conf -o ${TMPDIR}"
29 PSTAGE_UPDATE_CMD = "ipkg-cl update -f ${DEPLOY_DIR_PSTAGE}/ipkg-${MACHINE}.conf -o ${TMPDIR}"
30 PSTAGE_REMOVE_CMD = "ipkg-cl remove -force-depends -f ${DEPLOY_DIR_PSTAGE}/ipkg-${MACHINE}.conf -o ${TMPDIR}"
31 PSTAGE_LIST_CMD = "ipkg-cl list_installed -f ${DEPLOY_DIR_PSTAGE}/ipkg-${MACHINE}.conf -o ${TMPDIR}"
32 PSTAGE_PKGNAME = "staging-${PN}_${PV}-${PR}_${MULTIMACH_ARCH}.ipk"
34 PSTAGE_TMPDIR_STAGE = "${WORKDIR}/staging-pkg"
38 Clear the build and temp directories
40 bb.note("Uninstalling package from staging...")
41 path = bb.data.getVar("PATH", d, 1)
42 removecmd = bb.data.getVar("PSTAGE_REMOVE_CMD", d, 1)
43 removepkg = bb.data.expand("staging-${PN}", d)
44 ret = os.system("PATH=\"%s\" %s %s" % (path, removecmd, removepkg))
46 bb.note("Failure removing staging package")
48 stagepkg = bb.data.expand("${DEPLOY_DIR_PSTAGE}/${PSTAGE_PKGNAME}", d)
49 bb.note("Removing staging package %s" % stagepkg)
50 #os.system('rm -rf ' + stagepkg)
54 #assemble appropriate ipkg.conf
55 conffile=${DEPLOY_DIR_PSTAGE}/ipkg-${MACHINE}.conf
56 mkdir -p ${DEPLOY_DIR_PSTAGE}/pstaging_lists
57 if [ ! -e $conffile ]; then
58 ipkgarchs="${BUILD_ARCH} all any noarch ${TARGET_ARCH} ${PACKAGE_ARCHS} ${PACKAGE_EXTRA_ARCHS} ${MACHINE}"
60 for arch in $ipkgarchs; do
61 echo "arch $arch $priority" >> $conffile
62 priority=$(expr $priority + 5)
64 echo "src oe-staging file:${DEPLOY_DIR_PSTAGE}" >> $conffile
67 cd ${DEPLOY_DIR_PSTAGE}
68 ipkg-make-index -p Packages .
75 python do_prepackaged_stage () {
78 if bb.data.getVar("PSTAGING_DISABLED", d, 1) == "1":
79 bb.build.make_stamp("do_prepackaged_stage", d)
82 bb.note("Uninstalling any existing package from staging...")
83 path = bb.data.getVar("PATH", d, 1)
84 removecmd = bb.data.getVar("PSTAGE_REMOVE_CMD", d, 1)
85 removepkg = bb.data.expand("staging-${PN}", d)
86 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
87 ret = os.system("PATH=\"%s\" %s %s" % (path, removecmd, removepkg))
88 bb.utils.unlockfile(lf)
90 bb.note("Failure attempting to remove staging package")
92 stagepkg = bb.data.expand("${DEPLOY_DIR_PSTAGE}/${PSTAGE_PKGNAME}", d)
94 if os.path.exists(stagepkg):
95 bb.note("Following speedup\n")
96 path = bb.data.getVar("PATH", d, 1)
97 installcmd = bb.data.getVar("PSTAGE_INSTALL_CMD", d, 1)
99 bb.build.exec_func("staging_helper", d)
101 bb.debug(1, "Staging stuff already packaged, using that instead")
102 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
103 ret = os.system("PATH=\"%s\" %s %s" % (path, installcmd, stagepkg))
104 bb.utils.unlockfile(lf)
106 bb.note("Failure installing prestage package")
108 bb.build.make_stamp("do_prepackaged_stage", d)
109 bb.build.make_stamp("do_fetch", d)
110 bb.build.make_stamp("do_unpack", d)
111 bb.build.make_stamp("do_munge", d)
112 bb.build.make_stamp("do_patch", d)
113 bb.build.make_stamp("do_configure", d)
114 bb.build.make_stamp("do_qa_configure", d)
115 bb.build.make_stamp("do_rig_locales", d)
116 bb.build.make_stamp("do_compile", d)
117 bb.build.make_stamp("do_install", d)
118 bb.build.make_stamp("do_deploy", d)
119 bb.build.make_stamp("do_package", d)
120 bb.build.make_stamp("do_populate_staging", d)
121 bb.build.make_stamp("do_package_write_deb", d)
122 bb.build.make_stamp("do_package_write_ipk", d)
123 bb.build.make_stamp("do_package_write", d)
124 bb.build.make_stamp("do_package_stage", d)
125 bb.build.make_stamp("do_qa_staging", d)
128 bb.build.make_stamp("do_prepackaged_stage", d)
130 do_prepackaged_stage[cleandirs] = "${PSTAGE_TMPDIR_STAGE}"
131 do_prepackaged_stage[selfstamp] = "1"
132 addtask prepackaged_stage before do_fetch
134 populate_staging_preamble () {
135 if [ "$PSTAGING_DISABLED" != "1" ]; then
136 #mkdir -p ${DEPLOY_DIR_PSTAGE}
138 stage-manager -p ${STAGING_DIR} -c ${DEPLOY_DIR_PSTAGE}/stamp-cache-staging -u
139 stage-manager -p ${CROSS_DIR} -c ${DEPLOY_DIR_PSTAGE}/stamp-cache-cross -u
143 populate_staging_postamble () {
144 if [ "$PSTAGING_DISABLED" != "1" ]; then
145 # list the packages currently installed in staging
146 ${PSTAGE_LIST_CMD} | awk '{print $1}' > ${DEPLOY_DIR_PSTAGE}/installed-list
149 stage-manager -p ${STAGING_DIR} -c ${DEPLOY_DIR_PSTAGE}/stamp-cache-staging -u -d ${PSTAGE_TMPDIR_STAGE}/staging
150 stage-manager -p ${CROSS_DIR} -c ${DEPLOY_DIR_PSTAGE}/stamp-cache-cross -u -d ${PSTAGE_TMPDIR_STAGE}/cross
155 do_populate_staging[lockfiles] = "${STAGING_DIR}/staging.lock"
156 do_populate_staging[dirs] =+ "${DEPLOY_DIR_PSTAGE}"
157 python do_populate_staging_prepend() {
158 bb.build.exec_func("populate_staging_preamble", d)
161 python do_populate_staging_append() {
162 bb.build.exec_func("populate_staging_postamble", d)
166 staging_packager () {
168 mkdir -p ${PSTAGE_TMPDIR_STAGE}/CONTROL
170 echo "Package: staging-${PN}" > ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
171 echo "Version: ${PV}-${PR}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
172 echo "Description: ${DESCRIPTION}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
173 echo "Section: ${SECTION}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
174 echo "Priority: Optional" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
175 echo "Maintainer: ${MAINTAINER}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
176 echo "Architecture: ${MULTIMACH_ARCH}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
177 echo "Source: ${SRC_URI}" >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
179 ${PSTAGE_BUILD_CMD} ${PSTAGE_TMPDIR_STAGE} ${DEPLOY_DIR_PSTAGE}
180 ${PSTAGE_INSTALL_CMD} ${DEPLOY_DIR_PSTAGE}/${PSTAGE_PKGNAME}
183 python do_package_stage () {
184 if bb.data.getVar("PSTAGING_DISABLED", d, 1) == "1":
187 bb.build.exec_func("read_subpackage_metadata", d)
188 packages = (bb.data.getVar('PACKAGES', d, 1) or "").split()
189 if len(packages) > 0:
190 stagepath = bb.data.getVar("PSTAGE_TMPDIR_STAGE", d, 1)
191 if bb.data.inherits_class('package_ipk', d):
192 ipkpath = os.path.join(stagepath, "deploy", "ipk")
193 bb.mkdirhier(ipkpath)
194 if bb.data.inherits_class('package_deb', d):
195 debpath = os.path.join(stagepath, "deploy", "deb")
196 bb.mkdirhier(debpath)
199 pkgname = bb.data.getVar('PKG_%s' % pkg, d, 1)
202 arch = bb.data.getVar('PACKAGE_ARCH_%s' % pkg, d, 1)
204 arch = bb.data.getVar('PACKAGE_ARCH', d, 1)
205 if not packaged(pkg, d):
207 if bb.data.inherits_class('package_ipk', d):
208 srcname = bb.data.expand(pkgname + "_${PV}-${PR}_" + arch + ".ipk", d)
209 srcfile = bb.data.expand("${DEPLOY_DIR_IPK}/" + arch + "/" + srcname, d)
210 if not os.path.exists(srcfile):
211 bb.fatal("Package %s does not exist yet it should" % srcfile)
212 bb.copyfile(srcfile, ipkpath + "/" + srcname)
213 if bb.data.inherits_class('package_deb', d):
215 srcname = bb.data.expand(pkgname + "_${PV}-${PR}_all.deb", d)
217 srcname = bb.data.expand(pkgname + "_${PV}-${PR}_${DPKG_ARCH}.deb", d)
218 srcfile = bb.data.expand("${DEPLOY_DIR_DEB}/" + arch + "/" + srcname, d)
219 if not os.path.exists(srcfile):
220 bb.fatal("Package %s does not exist yet it should" % srcfile)
221 bb.copyfile(srcfile, debpath + "/" + srcname)
222 bb.build.exec_func("staging_helper", d)
223 lf = bb.utils.lockfile(bb.data.expand("${STAGING_DIR}/staging.lock", d))
224 bb.build.exec_func("staging_packager", d)
225 bb.utils.unlockfile(lf)
228 addtask package_stage after do_package_write do_populate_staging before do_build