From: Anton Mikanovich <amikan@ilbers.de>
To: isar-users@googlegroups.com
Cc: Anton Mikanovich <amikan@ilbers.de>
Subject: [RFC 5/5] isar: Add external builder
Date: Fri, 25 Feb 2022 10:40:40 +0300 [thread overview]
Message-ID: <20220225074040.20975-6-amikan@ilbers.de> (raw)
In-Reply-To: <20220225074040.20975-1-amikan@ilbers.de>
Build Isar with external tool to parce all Debian package dependencies.
Support only one target build for now,
mc:qemuamd64-bullseye:isar-image-base is used by default.
Usage (inside build dir):
$ ../isar_builder.py
Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
isar_builder.py | 142 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 142 insertions(+)
create mode 100755 isar_builder.py
diff --git a/isar_builder.py b/isar_builder.py
new file mode 100755
index 0000000..cf99c52
--- /dev/null
+++ b/isar_builder.py
@@ -0,0 +1,142 @@
+#!/usr/bin/env python3
+
+import os
+import sys
+import apt_pkg
+import apt.progress.base
+
+sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '/bitbake/lib')
+
+import bb.tinfoil
+
+class IsarBuilder:
+ def __init__(self):
+ self.tinfoil = bb.tinfoil.Tinfoil()
+ self.tinfoil.prepare()
+
+ def create_apt_rootfs(self, rootfs):
+ repo_isar_dir = '%s/tmp/deploy/isar-apt/%s-%s/apt' % (os.path.abspath(os.getcwd()), self.distro, self.arch)
+ mirror = 'file://%s/%s' % (repo_isar_dir, self.distro)
+ codename = 'isar'
+
+ if not os.path.exists(rootfs + '/var/lib/dpkg'):
+ os.makedirs(rootfs + '/var/lib/dpkg')
+ open(rootfs + '/var/lib/dpkg/status', 'w').close()
+
+ if not os.path.exists(rootfs + '/etc/apt/preferences.d'):
+ os.makedirs(rootfs + '/etc/apt/preferences.d')
+ with open(rootfs + '/etc/apt/sources.list', 'w') as f:
+ f.write('deb [arch=%s] %s %s main\n' % (self.arch, mirror, codename))
+ f.write('deb-src [arch=%s] %s %s main\n' % (self.arch, mirror, codename))
+
+ if not os.path.exists(rootfs + '/var/cache/apt/archives/partial'):
+ os.makedirs(rootfs + '/var/cache/apt/archives/partial')
+
+ def apt_config(self):
+ apt_pkg.init()
+
+ rootfs = os.path.abspath(os.getcwd()) + '/tmp/deps_poc_rootfs/%s-%s' % (self.distro, self.arch)
+
+ if not os.path.isdir(rootfs):
+ self.create_apt_rootfs(rootfs)
+
+ apt_pkg.config.set('APT::Architecture', self.arch)
+ apt_pkg.config.set('Dir', rootfs)
+ apt_pkg.config.set('Dir::Cache', rootfs + '/var/cache/apt')
+ apt_pkg.config.set('Dir::State::status', rootfs + '/var/lib/dpkg/status')
+
+ apt_pkg.config.set("Acquire::AllowInsecureRepositories", "1")
+
+ def isar_apt_update(self):
+ sources = apt_pkg.SourceList()
+ sources.read_main_list()
+
+ progress = apt.progress.text.AcquireProgress()
+
+ self.cache = apt_pkg.Cache()
+ self.cache.update(progress, sources)
+ self.cache = apt_pkg.Cache()
+
+ def srcpackage_lookup(self, pkg):
+ if pkg in self.cache:
+ return
+ if self.tinfoil.find_best_provider(pkg)[3] is None:
+ return
+ if pkg not in self.target_deps:
+ self.need_deb.append(pkg)
+ self.sr.restart()
+ if self.sr.lookup(pkg) is None:
+ self.need_source.append(pkg)
+ return
+ if 'Build-Depends' not in self.sr.build_depends:
+ return
+ for dep in self.sr.build_depends['Build-Depends']:
+ child = str(dep[0][0])
+ if child not in self.checkdeps:
+ self.checkdeps.append(child)
+ self.srcpackage_lookup(child)
+
+ def bitbake(self, mc, targets, task='', justbuild=[]):
+ targets = [targets] if isinstance(targets, str) else targets
+ target_str = ''
+ for pn in targets:
+ target_str += 'mc:%s:%s ' % (mc, pn if not task else ':'.join([pn, task]))
+ targets.clear()
+ for pn in justbuild:
+ target_str += 'mc:%s:%s ' % (mc, pn)
+ justbuild.clear()
+ if target_str != '':
+ print('Building %s' % target_str)
+ self.tinfoil.build_targets(target_str)
+
+ def build(self, mc, target):
+ d = self.tinfoil.parse_recipe('multiconfig:%s:%s' % (mc, target))
+ self.distro = d.getVar('DISTRO', expand=True)
+ self.arch = d.getVar('DISTRO_ARCH', expand=True)
+
+ recipecache = self.tinfoil.cooker.recipecaches[mc]
+ provider = self.tinfoil.find_best_provider('multiconfig:%s:%s' % (mc, target))
+ self.target_deps = recipecache.deps[provider[3]]
+
+ kernel_image = d.getVar('KERNEL_IMAGE_PKG', expand=True) or ''
+ if kernel_image in self.target_deps:
+ kernel = self.tinfoil.find_best_provider('multiconfig:%s:%s' % (mc, kernel_image))
+ if kernel[3].endswith('linux-distro.bb'):
+ self.target_deps.remove(kernel_image)
+ print('Remove %s from checking' % kernel_image)
+
+ self.need_source = self.target_deps.copy()
+ self.need_deb = []
+
+ self.apt_config()
+
+ maxdepth = 3
+ while maxdepth > 0:
+ maxdepth -= 1
+
+ self.bitbake(mc, self.need_source, 'do_deploy_source', self.need_deb)
+
+ self.isar_apt_update()
+ self.sr = apt_pkg.SourceRecords()
+
+ self.checkdeps = []
+ for dep in self.target_deps:
+ if dep not in self.checkdeps:
+ self.checkdeps.append(dep)
+ self.srcpackage_lookup(dep)
+
+ if not self.need_source:
+ break
+
+ if self.need_source:
+ print('Following packages still left unchecked: ' + str(self.need_source))
+
+ if self.need_deb:
+ print('Additional Debian dependencies found:' + str(self.need_deb))
+ self.bitbake(mc, self.need_deb)
+
+ # start final build
+ self.bitbake(mc, target)
+
+ib = IsarBuilder()
+ib.build('qemuamd64-bullseye', 'isar-image-base')
--
2.25.1
prev parent reply other threads:[~2022-02-25 7:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-25 7:40 [RFC 0/5] Debian dependencies investigation Anton Mikanovich
2022-02-25 7:40 ` [RFC 1/5] dpkg-base: Cover do_apt_unpack task by lock Anton Mikanovich
2022-02-25 17:30 ` Jan Kiszka
2022-02-25 7:40 ` [RFC 2/5] meta: Implement two stage build Anton Mikanovich
2022-02-25 7:40 ` [RFC 3/5] libhello: Declare provided packages Anton Mikanovich
2022-02-25 7:40 ` [RFC 4/5] hello-isar: Remove duplicated dependency Anton Mikanovich
2022-02-25 7:40 ` Anton Mikanovich [this message]
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=20220225074040.20975-6-amikan@ilbers.de \
--to=amikan@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