[2/4] rootfs_deb.bbclass:support incremental deb image generation

Submitted by Hongxu Jia on Jan. 22, 2013, 8:19 a.m.

Details

Message ID 36709c1e79a84e4d4dc08682f8901d1733a67523.1358824498.git.hongxu.jia@windriver.com
State New
Headers show

Commit Message

Hongxu Jia Jan. 22, 2013, 8:19 a.m.
1. Let shell function "rootfs_install_packages" support incremental deb
   image generation. The following is the design:

   1) If deb incremental generation is supported:
      1) Compare solution manifest with previous installed manifest to dump
         unused package names and remove them.

      2) Compare three manifests to dump updated packages and reinstall them.

   2) Install packages as solution manifest lists.

   3) Change solution manifest to installed manifest for next image session.

   4) Back up dpkg database for next image session.

2. Add checks for the creation of symbolic link "${IMAGE_ROOTFS}${opkgli-
   bdir}/info" and "${IMAGE_ROOTFS}${opkglibdir}/status".

[YOCTO #1893]

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 meta/classes/rootfs_deb.bbclass |   58 +++++++++++++++++++++++++++++++++++----
 1 file changed, 52 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/meta/classes/rootfs_deb.bbclass b/meta/classes/rootfs_deb.bbclass
index 9997996..f61608b 100644
--- a/meta/classes/rootfs_deb.bbclass
+++ b/meta/classes/rootfs_deb.bbclass
@@ -26,6 +26,9 @@  deb_package_getflag() {
 fakeroot rootfs_deb_do_rootfs () {
 	set +e
 
+	# Dir could be changed to symbolic link by previous image session.
+	[ -L ${IMAGE_ROOTFS}/var/lib/dpkg/alternatives ] && \
+		rm ${IMAGE_ROOTFS}/var/lib/dpkg/alternatives
 	mkdir -p ${IMAGE_ROOTFS}/var/lib/dpkg/alternatives
 
 	# update index
@@ -85,9 +88,9 @@  fakeroot rootfs_deb_do_rootfs () {
 	if [ -e ${IMAGE_ROOTFS}/var/lib/dpkg/alternatives ]; then
 		rmdir ${IMAGE_ROOTFS}/var/lib/dpkg/alternatives
 	fi
-	ln -s ${opkglibdir}/alternatives ${IMAGE_ROOTFS}/var/lib/dpkg/alternatives
-	ln -s /var/lib/dpkg/info ${IMAGE_ROOTFS}${opkglibdir}/info
-	ln -s /var/lib/dpkg/status ${IMAGE_ROOTFS}${opkglibdir}/status
+	ln -sf ${opkglibdir}/alternatives ${IMAGE_ROOTFS}/var/lib/dpkg/alternatives
+	ln -sfn /var/lib/dpkg/info ${IMAGE_ROOTFS}${opkglibdir}/info
+	ln -sfn /var/lib/dpkg/status ${IMAGE_ROOTFS}${opkglibdir}/status
 
 	${ROOTFS_POSTPROCESS_COMMAND}
 
@@ -126,9 +129,52 @@  rootfs_list_installed_depends() {
 	${DPKG_QUERY_COMMAND} -W -f='Package: ${Package}\nDepends: ${Depends}\nRecommends: ${Recommends}\n\n' | opkg-query-helper.py
 }
 
+
+#
+# Install deb packages
+#
+# $1-- the list of package names that will be installed
 rootfs_install_packages() {
-	${STAGING_BINDIR_NATIVE}/apt-get install `cat $1` --force-yes --allow-unauthenticated
 
-	# Mark all packages installed
-	sed -i -e "s/Status: install ok unpacked/Status: install ok installed/;" $INSTALL_ROOTFS_DEB/var/lib/dpkg/status
+	# The pkgs_installed_manifest is used to list the package's names which
+	# are installed in the previous deb image.
+	local pkgs_installed_manifest="${T}/installed_$(basename $1)"
+
+	# The pkgs_solution_manifest is used to list the package's names which
+	# should be installed just right now.
+	local pkgs_solution_manifest="$1"
+
+	sort -u $pkgs_solution_manifest -o $pkgs_solution_manifest
+
+	# The deb incremental generation base on the previous image
+	if [ "${INC_DEB_IMAGE_GEN}" = "1" -a -e $pkgs_installed_manifest ]; then
+		# Remove unused deb packages by comparing the two manifests.
+		package_remove_unused_deb "$pkgs_solution_manifest" "$pkgs_installed_manifest"
+
+		# Reinstall updated packages by comparing the two manifests.
+		package_reinstall_updated_deb "$pkgs_solution_manifest" "$pkgs_installed_manifest"
+	fi
+
+	# Install packages by the names which pkgs_solution_manifest lists
+	local all_package_list=$(cat $pkgs_solution_manifest)
+	for i in $all_package_list; do
+		echo "NOTE: Installing $i"
+		apt-get install $i --force-yes --allow-unauthenticated
+		if [ $? -ne 0 ]; then
+			echo "ERROR: Install $i failed"
+			exit 1
+		fi
+	done
+
+	# Update installed manifest for next image session.
+	cp $pkgs_solution_manifest $pkgs_installed_manifest
+
+	# Mark all packages installed and remove Config-version
+	sed -i -e "s/Status: install ok unpacked/Status: install ok installed/;" \
+		-e "/^Config-Version:/d" $INSTALL_ROOTFS_DEB/var/lib/dpkg/status
+
+	# Back up dpkg database for the next image session.
+	local dpkg_dir="${T}/dpkg${INSTALL_ROOTFS_DEB}"
+	mkdir -p $dpkg_dir
+	cp -rf ${INSTALL_ROOTFS_DEB}/var/lib/dpkg/* $dpkg_dir
 }