public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Vijai Kumar K <Vijaikumar_Kanagarajan@mentor.com>
To: <isar-users@googlegroups.com>, <ibr@radix50.net>
Cc: Vijai Kumar K <Vijaikumar_Kanagarajan@mentor.com>
Subject: [PATCH v9 03/14] meta: cache deb srcs as part of postprocessing
Date: Thu, 26 Nov 2020 16:49:01 +0530	[thread overview]
Message-ID: <20201126111912.3037-4-Vijaikumar_Kanagarajan@mentor.com> (raw)
In-Reply-To: <20201126111912.3037-1-Vijaikumar_Kanagarajan@mentor.com>

Collect the deb sources of the corresponding deb binaries cached
in DEBDIR as part of image postprocess.

Signed-off-by: Vijai Kumar K <Vijaikumar_Kanagarajan@mentor.com>
---
 meta/classes/deb-dl-dir.bbclass | 27 +++++++++++++++++++++++++++
 meta/classes/image.bbclass      |  2 +-
 meta/classes/rootfs.bbclass     |  8 ++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/meta/classes/deb-dl-dir.bbclass b/meta/classes/deb-dl-dir.bbclass
index 92f0259..bbc6f0a 100644
--- a/meta/classes/deb-dl-dir.bbclass
+++ b/meta/classes/deb-dl-dir.bbclass
@@ -5,6 +5,33 @@
 
 inherit repository
 
+debsrc_download() {
+    export rootfs="$1"
+    export rootfs_distro="$2"
+    mkdir -p "${DEBSRCDIR}"/"${rootfs_distro}"
+    sudo -E -s <<'EOSUDO'
+    mkdir -p "${rootfs}/deb-src"
+    mountpoint -q "${rootfs}/deb-src" || \
+    mount --bind "${DEBSRCDIR}" "${rootfs}/deb-src"
+EOSUDO
+    ( flock 9
+    set -e
+    printenv | grep -q BB_VERBOSE_LOGS && set -x
+    find "${rootfs}/var/cache/apt/archives/" -maxdepth 1 -type f -iname '*\.deb' | while read package; do
+        local src="$( dpkg-deb --show --showformat '${source:Package}' "${package}" )"
+        local version="$( dpkg-deb --show --showformat '${source:Version}' "${package}" )"
+
+        sudo -E chroot --userspec=$( id -u ):$( id -g ) ${rootfs} \
+            sh -c ' mkdir -p "/deb-src/${1}/${2}" && cd "/deb-src/${1}/${2}" && apt-get -y --download-only --only-source source "$2"="$3" ' download-src "${rootfs_distro}" "${src}" "${version}"
+    done
+    ) 9>"${DEBSRCDIR}/${rootfs_distro}.lock"
+    sudo -E -s <<'EOSUDO'
+    mountpoint -q "${rootfs}/deb-src" && \
+    umount -l "${rootfs}/deb-src"
+    rm -rf "${rootfs}/deb-src"
+EOSUDO
+}
+
 deb_dl_dir_import() {
     export pc="${DEBDIR}/${2}"
     export rootfs="${1}"
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 2391529..51cb2e1 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -63,7 +63,7 @@ image_do_mounts() {
 }
 
 ROOTFSDIR = "${IMAGE_ROOTFS}"
-ROOTFS_FEATURES += "clean-package-cache generate-manifest"
+ROOTFS_FEATURES += "clean-package-cache generate-manifest cache-deb-src"
 ROOTFS_PACKAGES += "${IMAGE_PREINSTALL} ${IMAGE_INSTALL}"
 ROOTFS_MANIFEST_DEPLOY_DIR ?= "${DEPLOY_DIR_IMAGE}"
 
diff --git a/meta/classes/rootfs.bbclass b/meta/classes/rootfs.bbclass
index fb4a3b6..f972a89 100644
--- a/meta/classes/rootfs.bbclass
+++ b/meta/classes/rootfs.bbclass
@@ -184,6 +184,14 @@ python do_rootfs_install() {
 }
 addtask rootfs_install before do_rootfs_postprocess after do_unpack
 
+ROOTFS_POSTPROCESS_COMMAND += "${@bb.utils.contains('ROOTFS_FEATURES', 'cache-deb-src', 'cache_deb_src', '', d)}"
+cache_deb_src() {
+    rootfs_install_resolvconf
+    deb_dl_dir_import ${ROOTFSDIR} ${ROOTFS_DISTRO}
+    debsrc_download ${ROOTFSDIR} ${ROOTFS_DISTRO}
+    rootfs_install_clean_files
+}
+
 ROOTFS_POSTPROCESS_COMMAND += "${@bb.utils.contains('ROOTFS_FEATURES', 'clean-package-cache', 'rootfs_postprocess_clean_package_cache', '', d)}"
 rootfs_postprocess_clean_package_cache() {
     sudo -E chroot '${ROOTFSDIR}' \
-- 
2.17.1


  parent reply	other threads:[~2020-11-26 11:19 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-26 11:18 [PATCH v9 00/14] Debsrc caching Vijai Kumar K
2020-11-26 11:18 ` [PATCH v9 01/14] rootfs: Make rootfs finalize a separate task Vijai Kumar K
2020-11-26 11:19 ` [PATCH v9 02/14] deb-dl-dir: Cache host distro debs separately Vijai Kumar K
2020-11-26 11:19 ` Vijai Kumar K [this message]
2020-11-26 11:19 ` [PATCH v9 04/14] deb-dl-dir: Make debsrc_download faster Vijai Kumar K
2020-11-26 11:19 ` [PATCH v9 05/14] deb-dl-dir: Download files only belonging to the current image Vijai Kumar K
2020-11-26 11:19 ` [PATCH v9 06/14] deb-dl-dir: Factor out the mounting part Vijai Kumar K
2020-11-26 11:19 ` [PATCH v9 07/14] deb-dl-dir: Fix skipping of removed files Vijai Kumar K
2020-11-26 11:19 ` [PATCH v9 08/14] repository: Add a sanity test to check missing sources Vijai Kumar K
2020-11-26 11:21   ` [PATCH v9 09/14] base-apt: Introduce BASE_REPO_FEATURES Vijai Kumar K
2020-11-26 11:21     ` [PATCH v9 10/14] repository: Fix failures due to missing section Vijai Kumar K
2020-11-26 11:21     ` [PATCH v9 11/14] scripts/ci_build.sh: Enable deb-src caching Vijai Kumar K
2020-11-26 11:21     ` [PATCH v9 12/14] rootfs: Fix possible overwrite of existing resolv.conf Vijai Kumar K
2020-11-26 11:21     ` [PATCH v9 13/14] rootfs: Handle failures when postprocess is rerun Vijai Kumar K
2020-11-26 11:22       ` [PATCH v9 14/14] doc/user_manual.md: Document details about deb-src caching Vijai Kumar K
2020-11-26 17:28         ` Anton Mikanovich
2020-11-26 17:56           ` vijaikumar....@gmail.com
2020-11-26 18:12             ` vijaikumar....@gmail.com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201126111912.3037-4-Vijaikumar_Kanagarajan@mentor.com \
    --to=vijaikumar_kanagarajan@mentor.com \
    --cc=ibr@radix50.net \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox