packaged-staging.bbclass: Only need to run after do_package_write, no need to list...
[vuplus_openembedded] / classes / packaged-staging.bbclass
1 #
2 # Populate builds using prebuilt packages where possible to speed up builds
3 # and allow staging to be reconstructed.
4 #
5 # To use it add that line to conf/local.conf:
6 #
7 # INHERIT = "packaged-staging"
8
9 python () {
10     import bb
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)
15
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)
19     else:
20         bb.data.setVar("PSTAGING_DISABLED", "1", d)
21 }
22
23 export PSTAGING_DISABLED = "0"
24
25 DEPLOY_DIR_PSTAGE       = "${DEPLOY_DIR}/pstage" 
26
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"
33
34 PSTAGE_TMPDIR_STAGE     = "${WORKDIR}/staging-pkg"
35
36 do_clean_append() {
37         """
38         Clear the build and temp directories
39         """
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))
45         if ret != 0:
46             bb.note("Failure removing staging package")
47
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)
51 }
52
53 staging_helper () {
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}"
59                 priority=1
60                 for arch in $ipkgarchs; do
61                         echo "arch $arch $priority" >> $conffile
62                         priority=$(expr $priority + 5)
63                 done
64                 echo "src oe-staging file:${DEPLOY_DIR_PSTAGE}" >> $conffile
65
66                 OLD_PWD=`pwd`
67                 cd ${DEPLOY_DIR_PSTAGE}
68                 ipkg-make-index -p Packages . 
69                 cd ${OLD_PWD}
70
71                 ${PSTAGE_UPDATE_CMD}
72         fi
73 }
74
75 python do_prepackaged_stage () {
76     import os
77
78     if bb.data.getVar("PSTAGING_DISABLED", d, 1) == "1":
79         bb.build.make_stamp("do_prepackaged_stage", d)
80         return
81
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)
89     if ret != 0:
90         bb.note("Failure attempting to remove staging package")
91
92     stagepkg = bb.data.expand("${DEPLOY_DIR_PSTAGE}/${PSTAGE_PKGNAME}", d)
93
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)
98
99         bb.build.exec_func("staging_helper", d)
100
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)
105         if ret != 0:
106             bb.note("Failure installing prestage package")
107
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)
126
127     else:
128         bb.build.make_stamp("do_prepackaged_stage", d)
129 }
130 do_prepackaged_stage[cleandirs] = "${PSTAGE_TMPDIR_STAGE}"
131 do_prepackaged_stage[selfstamp] = "1"
132 addtask prepackaged_stage before do_fetch
133
134 populate_staging_preamble () {
135         if [ "$PSTAGING_DISABLED" != "1" ]; then
136                 #mkdir -p ${DEPLOY_DIR_PSTAGE}
137
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
140         fi
141 }
142
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         
147
148                 set +e
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
151                 set -e
152         fi
153 }
154
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)
159 }
160
161 python do_populate_staging_append() {
162     bb.build.exec_func("populate_staging_postamble", d)
163 }
164
165
166 staging_packager () {
167
168         mkdir -p ${PSTAGE_TMPDIR_STAGE}/CONTROL
169
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
178
179         ${PSTAGE_BUILD_CMD} ${PSTAGE_TMPDIR_STAGE} ${DEPLOY_DIR_PSTAGE}
180         ${PSTAGE_INSTALL_CMD} ${DEPLOY_DIR_PSTAGE}/${PSTAGE_PKGNAME}
181 }
182
183 python do_package_stage () {
184     if bb.data.getVar("PSTAGING_DISABLED", d, 1) == "1":
185         return
186
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)
197
198         for pkg in packages:
199             pkgname = bb.data.getVar('PKG_%s' % pkg, d, 1)
200             if not pkgname:
201                 pkgname = pkg
202             arch = bb.data.getVar('PACKAGE_ARCH_%s' % pkg, d, 1)
203             if not arch:
204                 arch = bb.data.getVar('PACKAGE_ARCH', d, 1)
205             if not packaged(pkg, d):
206                 continue
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):
214                 if arch == 'all':
215                     srcname = bb.data.expand(pkgname + "_${PV}-${PR}_all.deb", d)
216                 else:
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)
226 }
227
228 addtask package_stage after do_package_write do_populate_staging before do_build
229