2017-05-26 20:08:45 +00:00
|
|
|
"""
|
2020-01-06 01:40:27 +00:00
|
|
|
Copyright 2020 Oliver Smith
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
This file is part of pmbootstrap.
|
|
|
|
|
|
|
|
pmbootstrap is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
pmbootstrap is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import glob
|
|
|
|
import filecmp
|
|
|
|
|
|
|
|
import pmb.chroot
|
|
|
|
import pmb.chroot.apk_static
|
|
|
|
import pmb.config
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
import pmb.helpers.repo
|
2017-05-26 20:08:45 +00:00
|
|
|
import pmb.helpers.run
|
|
|
|
import pmb.parse.arch
|
|
|
|
|
|
|
|
|
|
|
|
def copy_resolv_conf(args, suffix="native"):
|
|
|
|
"""
|
|
|
|
Use pythons super fast file compare function (due to caching)
|
|
|
|
and copy the /etc/resolv.conf to the chroot, in case it is
|
|
|
|
different from the host.
|
2017-08-20 12:34:31 +00:00
|
|
|
If the file doesn't exist, create an empty file with 'touch'.
|
2017-05-26 20:08:45 +00:00
|
|
|
"""
|
|
|
|
host = "/etc/resolv.conf"
|
|
|
|
chroot = args.work + "/chroot_" + suffix + host
|
2017-08-20 12:34:31 +00:00
|
|
|
if os.path.exists(host):
|
|
|
|
if not os.path.exists(chroot) or not filecmp.cmp(host, chroot):
|
|
|
|
pmb.helpers.run.root(args, ["cp", host, chroot])
|
|
|
|
else:
|
|
|
|
pmb.helpers.run.root(args, ["touch", chroot])
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
def init(args, suffix="native"):
|
|
|
|
# When already initialized: just prepare the chroot
|
|
|
|
chroot = args.work + "/chroot_" + suffix
|
|
|
|
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
|
2017-07-26 19:01:44 +00:00
|
|
|
emulate = pmb.parse.arch.cpu_emulation_required(args, arch)
|
|
|
|
|
2017-05-26 20:08:45 +00:00
|
|
|
pmb.chroot.mount(args, suffix)
|
|
|
|
if os.path.islink(chroot + "/bin/sh"):
|
2017-07-26 19:01:44 +00:00
|
|
|
if emulate:
|
2017-05-26 20:08:45 +00:00
|
|
|
pmb.chroot.binfmt.register(args, arch)
|
|
|
|
copy_resolv_conf(args, suffix)
|
2017-07-11 17:19:39 +00:00
|
|
|
pmb.chroot.apk.update_repository_list(args, suffix)
|
2017-05-26 20:08:45 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
# Require apk-tools-static
|
|
|
|
pmb.chroot.apk_static.init(args)
|
|
|
|
|
pmb: qemu-user-static from aport, not from Debian
Overview:
In order to execute foreign arch binaries on the host system, we are
using the Linux kernel's binfmt_misc feature in combination with
static builds of QEMU. Before this patch, the statically compiled
QEMU binaries were taken from Debian (mostly because I did not realize
that Alpine ships them as well). Now we can use the ones from the aport.
Benefits:
This allows us to easily update and patch the QEMU executables, we
don't need to be in sync with Debian's versions anymore.
Alpine's package is more modular, so we can save some download,
install, zap time, as well as disk space: setting up an armhf chroot
with pmbootstrap took ~102 MB before, now it's ~18 MB.
Detailed changes:
* Remove `cross/qemu-user-static-repack` aport
* Add `data/qemu-user-binfmt.txt` with the binfmt_misc flags for ELF
binaries of various arches (extracted from Debian's packaging)
* When parsing that file, don't write verbose messages to
`pmbootstrap log` anymore, only to the verbose log (can be enabled
with `pmbootstrap -v`)
* Rename `pmb.parse.arch.alpine_to_debian()` to ...`alpine_to_qemu()`
* Rename `arch_debian` to `arch_qemu`
2018-08-01 21:38:37 +00:00
|
|
|
# Non-native chroot: set up QEMU with binfmt_misc
|
2017-07-26 19:01:44 +00:00
|
|
|
if emulate:
|
2017-05-26 20:08:45 +00:00
|
|
|
pmb.chroot.binfmt.register(args, arch)
|
|
|
|
|
|
|
|
logging.info("(" + suffix + ") install alpine-base")
|
|
|
|
|
2018-04-29 22:17:57 +00:00
|
|
|
# Initialize cache
|
2017-05-26 20:08:45 +00:00
|
|
|
apk_cache = args.work + "/cache_apk_" + arch
|
2017-11-04 02:19:23 +00:00
|
|
|
pmb.helpers.run.root(args, ["ln", "-s", "-f", "/var/cache/apk", chroot +
|
2017-05-26 20:08:45 +00:00
|
|
|
"/etc/apk/cache"])
|
|
|
|
|
2017-07-11 17:19:39 +00:00
|
|
|
# Initialize /etc/apk/keys/, resolv.conf, repositories
|
2017-05-26 20:08:45 +00:00
|
|
|
for key in glob.glob(pmb.config.apk_keys_path + "/*.pub"):
|
|
|
|
pmb.helpers.run.root(args, ["cp", key, args.work +
|
|
|
|
"/config_apk_keys/"])
|
|
|
|
copy_resolv_conf(args, suffix)
|
2017-07-11 17:19:39 +00:00
|
|
|
pmb.chroot.apk.update_repository_list(args, suffix)
|
2017-05-26 20:08:45 +00:00
|
|
|
|
2018-01-23 00:54:48 +00:00
|
|
|
# Non-native chroot: install qemu-user-binary
|
2017-07-26 19:01:44 +00:00
|
|
|
if emulate:
|
pmb: qemu-user-static from aport, not from Debian
Overview:
In order to execute foreign arch binaries on the host system, we are
using the Linux kernel's binfmt_misc feature in combination with
static builds of QEMU. Before this patch, the statically compiled
QEMU binaries were taken from Debian (mostly because I did not realize
that Alpine ships them as well). Now we can use the ones from the aport.
Benefits:
This allows us to easily update and patch the QEMU executables, we
don't need to be in sync with Debian's versions anymore.
Alpine's package is more modular, so we can save some download,
install, zap time, as well as disk space: setting up an armhf chroot
with pmbootstrap took ~102 MB before, now it's ~18 MB.
Detailed changes:
* Remove `cross/qemu-user-static-repack` aport
* Add `data/qemu-user-binfmt.txt` with the binfmt_misc flags for ELF
binaries of various arches (extracted from Debian's packaging)
* When parsing that file, don't write verbose messages to
`pmbootstrap log` anymore, only to the verbose log (can be enabled
with `pmbootstrap -v`)
* Rename `pmb.parse.arch.alpine_to_debian()` to ...`alpine_to_qemu()`
* Rename `arch_debian` to `arch_qemu`
2018-08-01 21:38:37 +00:00
|
|
|
arch_qemu = pmb.parse.arch.alpine_to_qemu(arch)
|
2018-01-23 00:54:48 +00:00
|
|
|
pmb.helpers.run.root(args, ["mkdir", "-p", chroot + "/usr/bin"])
|
2017-05-26 20:08:45 +00:00
|
|
|
pmb.helpers.run.root(args, ["cp", args.work +
|
pmb: qemu-user-static from aport, not from Debian
Overview:
In order to execute foreign arch binaries on the host system, we are
using the Linux kernel's binfmt_misc feature in combination with
static builds of QEMU. Before this patch, the statically compiled
QEMU binaries were taken from Debian (mostly because I did not realize
that Alpine ships them as well). Now we can use the ones from the aport.
Benefits:
This allows us to easily update and patch the QEMU executables, we
don't need to be in sync with Debian's versions anymore.
Alpine's package is more modular, so we can save some download,
install, zap time, as well as disk space: setting up an armhf chroot
with pmbootstrap took ~102 MB before, now it's ~18 MB.
Detailed changes:
* Remove `cross/qemu-user-static-repack` aport
* Add `data/qemu-user-binfmt.txt` with the binfmt_misc flags for ELF
binaries of various arches (extracted from Debian's packaging)
* When parsing that file, don't write verbose messages to
`pmbootstrap log` anymore, only to the verbose log (can be enabled
with `pmbootstrap -v`)
* Rename `pmb.parse.arch.alpine_to_debian()` to ...`alpine_to_qemu()`
* Rename `arch_debian` to `arch_qemu`
2018-08-01 21:38:37 +00:00
|
|
|
"/chroot_native/usr/bin/qemu-" + arch_qemu,
|
|
|
|
chroot + "/usr/bin/qemu-" + arch_qemu + "-static"])
|
2018-01-23 00:54:48 +00:00
|
|
|
|
2018-03-04 13:44:27 +00:00
|
|
|
# Install alpine-base
|
|
|
|
pmb.helpers.repo.update(args, arch)
|
2018-02-09 18:43:58 +00:00
|
|
|
pmb.chroot.apk_static.run(args, ["--no-progress", "--root", chroot,
|
2018-01-23 00:54:48 +00:00
|
|
|
"--cache-dir", apk_cache, "--initdb", "--arch", arch,
|
|
|
|
"add", "alpine-base"])
|
2017-05-26 20:08:45 +00:00
|
|
|
|
2017-10-12 20:08:10 +00:00
|
|
|
# Building chroots: create "pmos" user, add symlinks to /home/pmos
|
|
|
|
if not suffix.startswith("rootfs_"):
|
|
|
|
pmb.chroot.root(args, ["adduser", "-D", "pmos", "-u",
|
2018-06-09 06:52:24 +00:00
|
|
|
pmb.config.chroot_uid_user], suffix, auto_init=False)
|
2017-10-12 20:08:10 +00:00
|
|
|
|
|
|
|
# Create the links (with subfolders if necessary)
|
|
|
|
for target, link_name in pmb.config.chroot_home_symlinks.items():
|
|
|
|
link_dir = os.path.dirname(link_name)
|
|
|
|
if not os.path.exists(chroot + link_dir):
|
|
|
|
pmb.chroot.user(args, ["mkdir", "-p", link_dir], suffix)
|
|
|
|
pmb.chroot.user(args, ["ln", "-s", target, link_name], suffix)
|
|
|
|
pmb.chroot.root(args, ["chown", "pmos:pmos", target],
|
|
|
|
suffix)
|