public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Uladzimir Bely <ubely@ilbers.de>
To: isar-users@googlegroups.com
Subject: [RFC 2/4] isar-apt: PoC of reusing isar-apt repo
Date: Thu,  2 Sep 2021 11:58:15 +0200	[thread overview]
Message-ID: <20210902095817.32165-3-ubely@ilbers.de> (raw)
In-Reply-To: <20210902095817.32165-1-ubely@ilbers.de>

The idea of reusing isar-apt repo at second build is to early
exit from build-related tasks if the package with the same
version already exists in current isar-apt.

Also, redefining default values of REPO_ISAR_DIR and REPO_ISAR_DB_DIR
maybe useful to share isar-apt between different builds

REPO_ISAR_DIR = "/path/to/isar-apt/${DISTRO}-${DISTRO_ARCH}/apt"
REPO_ISAR_DB_DIR = "/path/to/isar-apt/${DISTRO}-${DISTRO_ARCH}/db"

The variable ISAR_APT_ALWAYS_REBUILD_ON_CHANGE in local.conf
allow to control the behvaiour:

0: Use the cache, rebuilt only if needed
1: Don't use cache, rebuilt packages always (old behaviour)

Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
 meta-isar/conf/local.conf.sample    |  4 ++
 meta/classes/dpkg-base.bbclass      |  1 +
 meta/classes/isar-apt-cache.bbclass | 72 +++++++++++++++++++++++++++++
 3 files changed, 77 insertions(+)
 create mode 100644 meta/classes/isar-apt-cache.bbclass

diff --git a/meta-isar/conf/local.conf.sample b/meta-isar/conf/local.conf.sample
index 96a8beb..ae1ba45 100644
--- a/meta-isar/conf/local.conf.sample
+++ b/meta-isar/conf/local.conf.sample
@@ -201,6 +201,10 @@ ISAR_CROSS_COMPILE ?= "0"
 # does not access the network
 #BB_NO_NETWORK ?= "1"
 
+#
+# Comment or set to 0 to use previously built isar_apt repo if package version hasn't changed
+ISAR_APT_ALWAYS_REBUILD_ON_CHANGE ?= "1"
+
 # Set root password to 'root'
 # Password was encrypted using following command:
 #   mkpasswd -m sha512crypt -R 10000
diff --git a/meta/classes/dpkg-base.bbclass b/meta/classes/dpkg-base.bbclass
index aa529ca..59113b3 100644
--- a/meta/classes/dpkg-base.bbclass
+++ b/meta/classes/dpkg-base.bbclass
@@ -9,6 +9,7 @@ inherit debianize
 inherit terminal
 inherit repository
 inherit deb-dl-dir
+inherit isar-apt-cache
 
 DEPENDS ?= ""
 
diff --git a/meta/classes/isar-apt-cache.bbclass b/meta/classes/isar-apt-cache.bbclass
new file mode 100644
index 0000000..c9533f0
--- /dev/null
+++ b/meta/classes/isar-apt-cache.bbclass
@@ -0,0 +1,72 @@
+# This software is a part of ISAR.
+# Copyright (C) 2017-2019 Siemens AG
+# Copyright (C) 2019 ilbers GmbH
+#
+# SPDX-License-Identifier: MIT
+
+iac_check_package_in_repo() {
+    DISTS_ISAR="${REPO_ISAR_DIR}/${DISTRO}/dists/${DEBDISTRONAME}"
+    PACKAGES="${DISTS_ISAR}/main/binary-${DISTRO_ARCH}/Packages"
+
+    if [ ! -f "${PACKAGES}" ]; then
+        return 1
+    fi
+
+    if ! grep -q "^Package: ${PN}$" "${PACKAGES}"; then
+        return 2
+    fi
+
+    local repo_version=$(sed -n -e '/^Package: ${PN}$/,/Version/p' ${PACKAGES} | grep '^Version' | sed -e 's/.* //')
+    local new_version=$(head -n1 ${S}/debian/changelog | sed -e 's/.* (\(.*\)) .*/\1/')
+
+    if [ "${repo_version}" != "${new_version}" ]; then
+        return 3
+    fi
+
+    bbnote "Package ${PN}-${PV} is already in isar-apt repo, reuse it"
+    return 0
+}
+
+iac_check_need_rebuild() {
+    if [ "${ISAR_APT_ALWAYS_REBUILD_ON_CHANGE}" = "1" ]; then
+       return 1
+    fi
+
+    iac_check_package_in_repo
+}
+
+def iac_check_task_early_exit():
+    try:
+        bb.build.exec_func("iac_check_need_rebuild", d)
+        return True
+    except:
+        return False
+
+
+python do_apt_fetch_prepend() {
+    if iac_check_task_early_exit():
+        return 0
+}
+
+python do_apt_unpack_prepend() {
+    if iac_check_task_early_exit():
+        return 0
+}
+
+do_prepare_build_prepend() {
+    iac_check_need_rebuild && return
+}
+
+do_deploy_deb_prepend() {
+    iac_check_need_rebuild && return
+}
+
+python do_install_builddeps_prepend() {
+    if iac_check_task_early_exit():
+        return 0
+}
+
+python do_dpkg_build_prepend() {
+    if iac_check_task_early_exit():
+        return 0
+}
-- 
2.20.1


  parent reply	other threads:[~2021-09-02  9:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-02  9:58 [RFC 0/4] PoC for isar-apt repo reusing Uladzimir Bely
2021-09-02  9:58 ` [RFC 1/4] meta-isar: Fix do_dpkg_build override for prebuild-deb recipe Uladzimir Bely
2021-09-02  9:58 ` Uladzimir Bely [this message]
2021-09-02  9:58 ` [RFC 3/4] ci: Test for isar-apt reuse Uladzimir Bely
2021-09-02  9:58 ` [RFC 4/4] doc: Add section for isar-apt reuse functionality Uladzimir Bely
2021-09-02 11:11 ` [RFC 0/4] PoC for isar-apt repo reusing Henning Schild
2021-09-03  8:43   ` Baurzhan Ismagulov
2021-09-03  5:52 ` Jan Kiszka
2021-09-03  8:18   ` Uladzimir Bely

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=20210902095817.32165-3-ubely@ilbers.de \
    --to=ubely@ilbers.de \
    --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