merge of 'ebb880278ddb813fb7b527d822caeb57adc81179'
[openembedded.git] / classes / packaged-staging.bbclass
blob4b4ebb58bff4548c4f954768621f5142cbf8546e
2 # Populated ${STAGING} using packages
4 # To use it add that line to conf/local.conf:
6 # INHERIT += "packaged-staging"
8 # You also need ipkg-cl and ipkg-make-index installed on your host
9 # put ipkg-build from org.openembedded.packaged-staging/contrib/ in your $PATH
11 # BUGS:
12 # * does not distinguish between -native, -cross and other packages
14 # TODO:
15 # * also build a feed for native and cross packages 
16 # * make package detection a bit smarter (search for compatible archs)
17 # * make do_clean clean staging as well
19 # Summary:
20 # This class will have two modes of operation:
21 # PSTAGE_MODE = 'repopulate': repopulated staging from scratch for each packages
22 # PSTAGE_MODE = 'append': append each package to staging (current behaviour)
24 inherit package
26 DEPENDS = "stagemanager-native"
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.conf -o "
32 PSTAGE_UPDATE_CMD       = "ipkg-cl update -f ${DEPLOY_DIR_PSTAGE}/ipkg.conf -o "
33 PSTAGE_LIST_CMD         = "ipkg-cl list_installed -f ${DEPLOY_DIR_PSTAGE}/ipkg.conf -o "
34 PSTAGE_PKGNAME          = "staging-${PN}_${PV}-${PR}_${PACKAGE_ARCH}.ipk"
35 PCROSS_PKGNAME          = "cross-${PN}_${PV}-${PR}_${BUILD_ARCH}.ipk"
37 SPAWNFILE               = "${STAGING_DIR}/pkgmaps/${P}-${PR}.spawn"
38 SPAWNIPK                = "${spawn}"
40 PSTAGE_TMPDIR_STAGE     = "${TMPDIR}/tmp-staging"
41 PSTAGE_TMPDIR_CROSS     = "${TMPDIR}/tmp-cross"
43 STAGING_BASEDIR         = "${STAGING_LIBDIR}/.."
45 PACKAGEFUNCS += "do_write_ipk_list"
47 python do_write_ipk_list () {
48         import os, sys
49         ipkdir = bb.data.getVar('DEPLOY_DIR_IPK', d, 1)
50         stagingdir = bb.data.getVar('STAGING_DIR', d, 1)
51         tmpdir = bb.data.getVar('TMPDIR', d, 1)
52         p = bb.data.getVar('P', d, 1)
53         pr = bb.data.getVar('PR', d, 1)
55         packages = bb.data.getVar('PACKAGES', d, 1)
56         if not packages:
57                 bb.debug(1, "PACKAGES not defined, nothing to package")
58                 return
60         if packages == []:
61                 bb.debug(1, "No packages; nothing to do")
62                 return
64         # Generate ipk.conf if it or the stamp doesnt exist
65         listfile = os.path.join(stagingdir,"pkgmaps","%s-%s.spawn" %  ( p , pr ))
66         os.system('mkdir -p ' + stagingdir + '/pkgmaps')
67         if not os.access(listfile, os.R_OK):
68                 os.system('rm -f ' + listfile)
69                 f = open(listfile,"w")
70                 for spawn in packages.split():
71                         #check if the packagename has changed due to debian shlib renaming
72                         localdata = bb.data.createCopy(d)
73                         pkgname = bb.data.getVar('PKG_%s' % spawn, localdata, 1)
74                         if not pkgname:
75                                 pkgname = spawn
76                         f.write("%s\n" % pkgname)
77                 f.close()
81 do_clean_append() {
82         """clear the build and temp directories"""
83         stagepkg = bb.data.expand("${DEPLOY_DIR_PSTAGE}/${PSTAGE_PKGNAME}", d)
84         if stagepkg == '//': raise bb.build.FuncFailed("wrong DATADIR")
85         bb.note("removing " + stagepkg)
86         os.system('rm -rf ' + stagepkg)
90 do_stage_prepend() {
92         stage-manager -p ${STAGING_DIR} -c ${DEPLOY_DIR_PSTAGE}/staging-stamp-cache -u
94         stage-manager -p ${CROSS_DIR} -c ${DEPLOY_DIR_PSTAGE}/cross-stamp-cache -u
96         if [ ! -e ${STAGING_BASEDIR} ]; then
97                 mkdir -p ${STAGING_BASEDIR}
98         fi
100         if [ ! -e ${DEPLOY_DIR_PSTAGE} ]; then
101                 mkdir -p ${DEPLOY_DIR_PSTAGE}
102         fi
104         if [ -e ${STAGING_BASEDIR}/usr ]; then
105                 oenote "${STAGING_BASEDIR}/usr already present, leaving it alone"
106         else
107                 oenote "${STAGING_BASEDIR}/usr not present, symlinking it"
108                 ln -s ${STAGING_BASEDIR}/ ${STAGING_BASEDIR}/usr
109         fi
111         #assemble appropriate ipkg.conf
112         if [ -e ${DEPLOY_DIR_PSTAGE}/ipkg.conf ]; then
113                 rm ${DEPLOY_DIR_PSTAGE}/ipkg.conf
114         fi
116         ipkgarchs="${BUILD_ARCH} all any noarch ${TARGET_ARCH} ${PACKAGE_ARCHS} ${PACKAGE_EXTRA_ARCHS} ${MACHINE}"
117         priority=1
118         for arch in $ipkgarchs; do
119                 echo "arch $arch $priority" >> ${DEPLOY_DIR_PSTAGE}/ipkg.conf
120                 priority=$(expr $priority + 5)
121         done
122         echo "src oe file:${DEPLOY_DIR_IPK}" >> ${DEPLOY_DIR_PSTAGE}/ipkg.conf 
123         export OLD_PWD=`pwd`
124         cd ${DEPLOY_DIR_IPK} && rm *${BUILD_ARCH}.ipk -f ; ipkg-make-index -p Packages . ; cd ${OLD_PWD}
125         ${PSTAGE_UPDATE_CMD} ${STAGING_BASEDIR}
127         #check for generated packages
128         if [ -e ${SPAWNFILE} ]; then
129                 oenote "List of spawned packages found: ${P}.spawn"
130                 for spawn in `cat ${SPAWNFILE} | grep -v locale | grep -v dbg | grep -v gconv | grep -v charmap` ; do \
131                         if [ -e ${DEPLOY_DIR_IPK}/${spawn}_* ]; then
132                                 ${PSTAGE_INSTALL_CMD} ${STAGING_BASEDIR} ${spawn}          
133                                 # clean up .la files to avoid having references to the builddirs in the binaries
134                                 for lafile in ${STAGING_LIBDIR}/*.la ; do \
135                                         sed -i s:installed=yes:installed=no:g ${lafile} || true
136                                 done
138                                 #fix up linker script to poin to staging
139                                 if [ -e ${STAGING_LIBDIR}/libc.so ]; then
140                                         sed -i s:\ /lib:\ ${STAGING_LIBDIR}:g ${STAGING_LIBDIR}/libc.so
141                                         sed -i s:\ /usr/lib:\ ${STAGING_LIBDIR}:g ${STAGING_LIBDIR}/libc.so
142                                 fi
143                         else
144                                 oenote "${spawn} not found, probably empty package"
145                         fi
146                 done
147                 exit 0
148         else
149                 oenote "Spawn file not found!"
150         fi
152         if [ -e ${DEPLOY_DIR_PSTAGE}/${PCROSS_PKGNAME} ]; then
153                 oenote "Cross stuff already packaged, using that instead"
154                 ${PSTAGE_INSTALL_CMD} ${CROSS_DIR}  ${DEPLOY_DIR_PSTAGE}/${PCROSS_PKGNAME}
155         fi
157         if [ -e ${DEPLOY_DIR_PSTAGE}/${PSTAGE_PKGNAME} ]; then
158                 oenote "Staging stuff already packaged, using that instead"
159                 ${PSTAGE_INSTALL_CMD} ${STAGING_DIR}  ${DEPLOY_DIR_PSTAGE}/${PSTAGE_PKGNAME}
160                 exit 0      
161         fi
164         mkdir -p ${STAGING_BINDIR}
165         mkdir -p ${STAGING_LIBDIR}
166         mkdir -p ${STAGING_INCDIR}
167         mkdir -p ${STAGING_DATADIR}/aclocal
170 do_stage_append() {
172         mkdir -p ${DEPLOY_DIR_PSTAGE}
174         # list the packages currently installed in staging
175         ${PSTAGE_LIST_CMD} ${STAGING_DIR} | awk '{print $1}' > ${DEPLOY_DIR_PSTAGE}/installed-staging_list         
176         ${PSTAGE_LIST_CMD} ${CROSS_DIR} | awk '{print $1}' > ${DEPLOY_DIR_PSTAGE}/installed-cross_list
178         set +e
179         rm -rf ${PSTAGE_TMPDIR_STAGE}
180         stage-manager -p ${STAGING_DIR} -c ${DEPLOY_DIR_PSTAGE}/staging-stamp-cache -u -d ${PSTAGE_TMPDIR_STAGE}
181         rc=$?
182         set -e
184         if [ $rc == 5 ]; then
186                 #make a package for staging
187                 mkdir -p ${PSTAGE_TMPDIR_STAGE}/CONTROL
189                 echo "Package: staging-${PN}"           >  ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
190                 echo "Version: ${PV}-${PR}"             >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
191                 echo "Description: ${DESCRIPTION}"      >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
192                 echo "Section: ${SECTION}"              >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
193                 echo "Priority: Optional"               >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
194                 echo "Maintainer: ${MAINTAINER}"        >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
195                 echo "Architecture: ${PACKAGE_ARCH}"    >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
196                 echo "Source: ${SRC_URI}"               >> ${PSTAGE_TMPDIR_STAGE}/CONTROL/control
198                 ${PSTAGE_BUILD_CMD} ${PSTAGE_TMPDIR_STAGE} ${DEPLOY_DIR_PSTAGE}
200                 ${PSTAGE_INSTALL_CMD} ${STAGING_DIR} ${DEPLOY_DIR_PSTAGE}/${PSTAGE_PKGNAME}
201         fi
203         set +e
204         rm -rf ${PSTAGE_TMPDIR_CROSS}
205         stage-manager -p ${CROSS_DIR} -c ${DEPLOY_DIR_PSTAGE}/cross-stamp-cache -u -d ${PSTAGE_TMPDIR_CROSS}
206         rc=$?
207         set -e
209         if [ $rc == 5 ]; then
211                 #make a package for cross
212                 mkdir -p ${PSTAGE_TMPDIR_CROSS}/CONTROL
214                 echo "Package: cross-${PN}"             >  ${PSTAGE_TMPDIR_CROSS}/CONTROL/control
215                 echo "Version: ${PV}-${PR}"             >> ${PSTAGE_TMPDIR_CROSS}/CONTROL/control
216                 echo "Description: ${DESCRIPTION}"      >> ${PSTAGE_TMPDIR_CROSS}/CONTROL/control
217                 echo "Section: ${SECTION}"              >> ${PSTAGE_TMPDIR_CROSS}/CONTROL/control
218                 echo "Priority: Optional"               >> ${PSTAGE_TMPDIR_CROSS}/CONTROL/control
219                 echo "Maintainer: ${MAINTAINER}"        >> ${PSTAGE_TMPDIR_CROSS}/CONTROL/control
220                 echo "Architecture: ${BUILD_ARCH}"      >> ${PSTAGE_TMPDIR_CROSS}/CONTROL/control
221                 echo "Source: ${SRC_URI}"               >> ${PSTAGE_TMPDIR_CROSS}/CONTROL/control
222         
223                 ${PSTAGE_BUILD_CMD} ${PSTAGE_TMPDIR_CROSS} ${DEPLOY_DIR_PSTAGE}
225                 ${PSTAGE_INSTALL_CMD} ${CROSS_DIR} ${DEPLOY_DIR_PSTAGE}/${PCROSS_PKGNAME}
226         fi