Commit graph

3341 commits

Author SHA1 Message Date
Oliver Smith
4bf3f11b78
pmb.helpers.apk: support PMB_APK_NO_CACHE
Add a new environment variable that disables apk's caching feature for
space constrained environments such as the bpo image build jobs.

Currently we have a workaround in place in bpo: the apk cache is moved
to a tmpfs. But this is fragile and just disabling the apk cache is a
more elegant solution.

I've decided to make this an env var instead of a full pmbootstrap
option since this option is not relevant for normal users, only for CI
jobs in space constrained environments. Also we already have another
`PMB_APK_` env var.

Related: bpo issue 136
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2553
2025-03-17 07:09:10 +01:00
Caleb Connolly
dcc4137ee8
FIXUP: build: abstract CrossCompile type logic
* Make CrossCompile a proper enum type rather than a string literal,
* Introduce methods to get the correct host/build chroots depending on the
  cross compile type and target architecture.
* Remove autodetect.chroot() since it doesn't do what we expect, adjust
  all users to use cross.build_chroot() instead.
* Refactor package building to correctly use cross.host_chroot() and
  cross.build_chroot().

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2568
2025-03-16 16:30:04 +01:00
Oliver Smith
0eaedba632
CI: test different cross compilation methods
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2568
2025-03-16 16:30:04 +01:00
Oliver Smith
215a0de035
pmb.build.package: log the cross compile type
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2568
2025-03-16 16:30:04 +01:00
Oliver Smith
bef3b43343
pmb.types.CrossCompileType: split up None
Replace None with the three things it is actually used for to make the
code easier to follow:
* "autodetect"
* "unnecessary"
* "qemu-only"

I've used the term "unnecessary" instead of "native", because "native"
was previously used for "cross-native", then "cross-native2" and it
still sounds similar to these.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2568
2025-03-16 16:30:04 +01:00
Oliver Smith
0625ece550
pmb.build.backend.run_abuild: remove cross default
This function doesn't handle the case of being called without a value
set for cross (it does not autodetect it) and callers don't expect that.
So unset the default value.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2568
2025-03-16 16:30:04 +01:00
Oliver Smith
b2eb812254
pmb/build/autodetect: remove deprecated comment
As discussed with Caleb, it makes sense to keep using "cross-native" for
packages where we don't need to set up a foreign chroot because it is
faster.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2568
2025-03-16 16:30:04 +01:00
Oliver Smith
9e0c4a8393
pmb.build: fix internal cross compiling names
Use the same names as in the documentation for:
"cross-native" (not "kernel")
"cross-native2" (not "native")

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2568
2025-03-16 16:30:04 +01:00
Oliver Smith
53d705194f
build: print !tracedeps warning for cross-native 1
Building without !tracedeps is a problem with cross-native version 1 but
not version 2. Fix the warning.

Fixes: 2ee916f5 ("build: add pmb:cross-native2 (MR 2474)")

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2568
2025-03-16 16:29:59 +01:00
Oliver Smith
58119697fd
docs/cross_compiling: fix makedeps host/build desc
* makedepends_build is for the native chroot
* makedepends_host is for the foreign chroot

I had it the other way around in the documentation. The variables are so
far not documented here yet:
* https://gitlab.alpinelinux.org/alpine/abuild/-/blob/master/APKBUILD.5.scd
* https://wiki.alpinelinux.org/wiki/APKBUILD_Reference

But it now matches the comments Caleb had written for the cross-native2
implementation, and also what can be found in e.g. the abuild APKBUILD
in aports.git:

  makedepends_build="pkgconfig scdoc"
  makedepends_host="openssl-dev>3 zlib-dev"

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2566
[ci:skip-build]: already built successfully in CI
2025-03-14 21:28:37 +00:00
Clayton Craft
7f886967d1
docs/env_variables: document PMB_FDE_PASSWORD
Co-authored-by: Oliver Smith <ollieparanoid@postmarketos.org>
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2538
2025-03-14 09:45:04 -07:00
Clayton Craft
561ff0dc4c
pmb.install.format: add support for setting FDE passphrase
This adds support for using an environment variable to set the FDE
passphrase, allowing us to automate image creation when using FDE.
The method used here was borrowed from how we set the password with when
using the --password arg: write to a temp file, call something in the
chroot to read/use it, then remove it.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2538
2025-03-14 09:45:04 -07:00
Frieder Hannenheim
6465a6aa87
sideload: get channel from package not from global pmaports (MR 2569)
Currently packages that are not in the systemd channel cannot be
sideloaded when using the systemd channel. This is because apk sideload
uses the global aports channel and not the channel of the package. Fix
it with this patch.
2025-03-10 22:22:50 +01:00
Newbyte
3770641430
pmb.qemu.run: Use NonBugError for nonexistent rootfs code path (MR 2540)
We fully expect to reach this code path within normal use of
pmbootstrap. It's not a bug if we get here. As such, use NonBugError to
indicate that and clean up the output.
2025-03-10 22:15:52 +01:00
Newbyte
8c55680b03
pmb.flasher.frontend: Use NonBugError for nonexistent rootfs code path (MR 2540)
We fully expect to reach this code path within normal use of
pmbootstrap. It's not a bug if we get here. As such, use NonBugError to
indicate that and clean up the output.
2025-03-10 22:15:52 +01:00
Newbyte
3ef25e1467
pmb.netboot: Use NonBugError for nonexistent rootfs code path (MR 2540)
We fully expect to reach this code path within normal use of
pmbootstrap. It's not a bug if we get here. As such, use NonBugError to
indicate that and clean up the output.
2025-03-10 22:15:52 +01:00
Newbyte
d01f6b9079
pmb.netboot: Only attempt to install nbd after rootfs existance check (MR 2540)
The install action will initialise the native chroot, so this way we
don't have to initialise the chroot in this code path. It also gives
users feedback quicker if they haven't already initialised the rootfs
since this way they don't have to wait around for nbd to be installed
before being told that they need to generate the rootfs first.

Closes https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/issues/2549
2025-03-10 22:15:47 +01:00
Oliver Smith
06bd8d98a1
cross-native2: set CGO_CFLAGS, CGO_LDFLAGS (MR 2565)
Cross compiling go programs with cross-native2 fails for armv7, riscv64
and armhf unless we use CGO_ENABLED=1 in the APKBUILD (see related
aports issue).

Add --sysroot to CGO_CFLAGS, so cgo can find the includes and doesn't
fail with:

  go build -buildmode=pie -modcacherw -trimpath -buildvcs=false -ldflags "-s -w -X main.Version=2.6.1" -o mkinitfs ./cmd/mkinitfs
  # runtime/cgo
  _cgo_export.c:3:10: fatal error: stdlib.h: No such file or directory

Add it to LDFLAGS too for linking against libraries from the sysroot.

Related: https://gitlab.alpinelinux.org/alpine/aports/-/issues/15809
Related: https://stackoverflow.com/a/38835938
2025-03-09 15:27:27 +01:00
Stefan Hansson
32389415e3
pmb.config: Add pmb:cross-native2 to custom valid options (MR 2564)
This is needed for the linter to know about this option.

Fixes 2ee916f5d6
2025-03-08 04:03:35 +01:00
Clayton Craft
a5f7d6087a
pmb.build: install checkdepends when building (MR 2563)
Fixes a bug where checkdepends are not being installed, and packages
that run tests that depend on something in checkdepends fail because
it's missing. For example, the `plasma-workspace` forked pkg in pmaports
tells abuild to run `xwfb-run` in `check()`, this binary comes from
`xwayland-run`, which is listed in the `checkdepends`. However this
isn't being installed and so `pmb build` ultimately fails to build the
package.
2025-03-06 14:15:23 -08:00
Oliver Smith
7510e80b7b
docs/cross_compiling: new page (MR 2562)
Add the cross compiling documentation to the pmbootstrap docs.

This is based on the following wiki pages, but updated to reflect new
changes with cross-native2 and to make it more readable:
* https://wiki.postmarketos.org/wiki/Pmbootstrap/Cross_Compiling
* https://wiki.postmarketos.org/wiki/Build_internals#Cross-compile_types

Co-authored-by: Caleb Connolly <caleb@postmarketos.org>
2025-03-02 17:07:41 +01:00
Caleb Connolly
92fca6614b
config: add pigz to build_packages (MR 2561)
Speed up compressing packages after build by using pigz which does
parallelised compression!

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2025-03-01 13:21:25 +00:00
Caleb Connolly
09053af572
build: backend: remove trailing spaces (MR 2474)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2025-02-27 01:29:35 +01:00
Caleb Connolly
2ee916f5d6
build: add pmb:cross-native2 (MR 2474)
Set things up so that we can run abuild on the native chroot and use
it's cross compilation features rather than running it and the build
system through QEMU. This massively speeds up building when it works.

cross-native used to be quite limited in functionality and didn't
integrate into abuild itself, this commit fixes that.

Packages can opt-in to this by adding pmb:cross-native2 to their options
and configuring makedepends_host and makedepends_build.

This also speeds up building packages like postmarketos-initramfs since
it entirely avoids running commands through QEMU (usually abuild itself
would be run through QEMU).

Lastly, we preserve the old pmb:cross-kernel options, this can be used to
enable the old cross compiler behaviour which is used for cross
compiling kernels in pmaports. This allows them to keep being supporting
while we adapt them to the new cross-native2.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2025-02-27 01:29:35 +01:00
Caleb Connolly
5a00964943
core: Arch: define supported arches as a set (MR 2474)
Rather than a list which we later convert to a set.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2025-02-27 01:29:35 +01:00
Caleb Connolly
8f0971eb92
core: Arch: add method to map to Go arch (MR 2474)
Map architectures to the strings used for GOARCH for cross compiling Go
applications.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2025-02-27 01:29:35 +01:00
Caleb Connolly
801437e681
core: Arch: add .supported_binary() (MR 2474)
The .supported() method errs on the side of exposing too many
architectures to make porting for new or less-common platforms easier.

It therefore isn't suitable for using as a list of supported
architectures we can probe the binary repository for.

Introduce a .supported_binary() method to export only the architectures
where we have a binary repository.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2025-02-27 01:29:30 +01:00
Oliver Smith
c74735ea7a
Prepare 3.3.1 release 2025-02-27 01:09:19 +01:00
Oliver Smith
3eff3ff39e
pyproject.toml: fix tests getting installed
Instead of automatic python package discovery that for some reason still
picks up the test module even though it should be excluded, specify the
"pmb" module manually to be installed.

Follow-up to MR 2551.

Fixes: issue 2541
2025-02-27 01:07:19 +01:00
Oliver Smith
60a4ed7f84
Prepare 3.3.0 release 2025-02-27 00:39:06 +01:00
Newbyte
39966f03c0
pmb.parse.apkindex: Improve parse_add_block() type hint (MR 2515)
I didn't really understand mypy's overloading well when I wrote this. It
makes sense to have a third overload here with bool as type for
multiple_providers used in circumstances where a literal isn't provided
for that parameter.
2025-02-27 00:28:16 +01:00
Newbyte
978e6cf7d3
pmb.chroot.run: Add another overload for root() (MR 2515)
Having a more generic overload like this fixes the issue where mypy
complains about no matching overloads at the call site in userm().
2025-02-27 00:28:16 +01:00
Anri Dellal
6411aa4791
helpers.cli: Fix regex validation (MR 2557)
According to Python documentation, p.match checks
if characters at the beginning of string match the regex

This commit changes validation to full length of string
2025-02-27 00:24:08 +01:00
Anri Dellal
f85899ef3d
pmbootstrap chroot: fix --image bugs (MR 2556)
- Properly run commands at host to mount rootfs
- Always refuse to zap chroot_image, since it is never added to workdir.cfg

Co-authored-by: Newbyte <newbyte@postmarketos.org>
2025-02-27 00:06:45 +01:00
Oliver Smith
d90a037fd6
pmb.install.format: set bytes-per-inode to 16384 (MR 2558)
After setting "-T big", we still saw some images failing with "out of
space" errors in bpo, such as "v24.12:samsung-espresso10:xfce4".

I've looked at /etc/mke2fs.conf to figure out what exactly gets
configured with "-T big". What I did not realize is that the inode
ratio gets bigger by going from small -> big, big -> huge, but with a
larger ratio FEWER inodes will be created (see man mkfs.ext4, -i
bytes-per-inode).

In /etc/mke2fs.conf in Alpine edge:

	[defaults]
	…
		blocksize = 4096
		inode_size = 256
		inode_ratio = 16384

	[fs_types]
	…
		small = {
			blocksize = 1024
			inode_ratio = 4096
		}
		floppy = {
			blocksize = 1024
			inode_ratio = 8192
		}
		big = {
			inode_ratio = 32768
		}
		huge = {
			inode_ratio = 65536
		}
		news = {
			inode_ratio = 4096
		}
	…

So I've tried out half the ratio value we get with "big" now, 16384.
With that we finally seem to have:

* Enough inodes for small UIs (console, none) as well as big UIs with
  lots of files (xfce4, plasma-desktop, ...)

* We don't directly specify an inode count (-N) anymore as we did
  earlier, which had problems with small images as the inode count would
  be too large for the given image size (pmb#2572).

Test builds with various images:

Filesystem              Inodes      Used Available Use% Mounted on
master:postmarketos-trailblazer:none:
/dev/installp2           35440      5111     30329  14% /mnt/install
master:postmarketos-trailblazer:console:
/dev/installp2           47232      8713     38519  18% /mnt/install
master:pine64-pinebookpro:plasma-desktop:
/dev/installp2          276352    100607    175745  36% /mnt/install
v24.12:samsung-espresso10:xfce4:
/dev/installp2           80960     51150     29810  63% /mnt/install

So the most Use% I could get is 63% with this, leaving a nice margin for
the future.
2025-02-23 13:45:36 +01:00
Oliver Smith
06957b2173
install: log space/inodes used in image (MR 2558)
Log how well we have used the space and available inodes in the
resulting images, to show how well the mkfs parameters we have decided
on are working.
2025-02-23 13:45:32 +01:00
Stefan Hansson
5f8d0141d7
pyproject.toml: Remove ignore for F401 in __init__.py files (MR 2545)
This is no longer necessary to pass checks, and it allows further unused
import analysis.
2025-02-23 11:40:44 +01:00
Stefan Hansson
ebc5ab9ecd
pmb.chroot: Rename exists() to user_exists() (MR 2545)
This name is what's used at the one call site the codebase currently
has, and it means we can have an explicit re-export which Ruff won't
complain about.
2025-02-23 11:40:44 +01:00
Stefan Hansson
bdcc188f05
pmb: Use explicit re-exports (MR 2545)
See https://docs.astral.sh/ruff/rules/unused-import
2025-02-23 11:40:44 +01:00
Stefan Hansson
0620232819
pmb: Remove unused imports (MR 2545) 2025-02-23 11:40:40 +01:00
Oliver Smith
63fce4fcb5
pmb.install.format: set ext4 usage-type to big (MR 2555)
Using "-N" to set a specific inode count caused errors:
* With 100K, we got "out of space" errors when creating images for
  bigger UIs with many small files like:
  pine64-pinebookpro:plasma-desktop
* With 1M (current value), we got "out of space" for small images like:
  postmarketos-trailblazer:console

Use "-T big" instead to set the usage-type that is closest to how we
expect the filesystem to be used, once it is flashed to the user's
device and resized. This will indirectly set the bytes-per-inode. I've
verified that building both the big
pine64-pinebookpro:plasma-desktop and small
postmarketos-trailblazer:console (and even with UI=none) works with
this change.

I've verified that building both the small image works with this.

From the mkfs.ext4 man page:

       -T usage-type[,...]
              Specify how the file system is going to be used, so that mke2fs
              can choose optimal file system parameters for that use.  The
              usage types that are supported are defined in the configuration
              file /etc/mke2fs.conf.  The user may specify one or more usage
              types using a comma separated list.

              If this option is is not specified, mke2fs will pick a single
              default usage type based on the size of the file system to be
              created.  If the file system size is less than 3 megabytes,
              mke2fs will use the file system type floppy.  If the file system
              size is greater than or equal to 3 but less than 512 megabytes,
              mke2fs(8) will use the file system type small.  If the file
              system size is greater than or equal to 4 terabytes but less
              than 16 terabytes, mke2fs(8) will use the file system type big.
              If the file system size is greater than or equal to 16
              terabytes, mke2fs(8) will use the file system type huge.
              Otherwise, mke2fs(8) will use the default file system type
              default.

Fixes: d0d7c2d4 ("pmb.install.format: set ext4 usage-type to big")
Fixes: issue 2572
2025-02-19 19:49:17 +01:00
Oliver Smith
3b5e66d289
ci/markdown: fix shellcheck errors (MR 2485)
Don't try to modify a variable in the while loop, as it runs in a
subshell because of the pipe. Fail on the first error instead, like we
have it in .ci/shellcheck.sh.

This can be optimized later on (for both scripts) if we really want to.

Fix for:

  In ./.ci/markdown.sh line 17:
  	markdownlint-cli "$file" || MDL_FAILED=1
                                      ^--------^ SC2030 (info): Modification of MDL_FAILED is local (to subshell caused by pipeline).
  In ./.ci/markdown.sh line 20:
  if [ "$MDL_FAILED" = "1" ]; then
        ^---------^ SC2031 (info): MDL_FAILED was modified in a subshell. That change might be lost.
2025-02-17 00:20:03 +01:00
Oliver Smith
22d777bd82
ci/markdown: don't run "npm install" as root (MR 2485)
Move the "npm install" command to the section that runs as regular user
instead of root. Instead of creating a /usr/bin/markdownlint-cli
symlink, run the JS file from the path where npm installs it. Try to
find a markdownlint-cli executable and use it instead if it exists, in
case users run this script outside of "pmbootstrap chroot" and have the
linter installed under that name.
2025-02-17 00:20:03 +01:00
Caleb Connolly
ebed7abe4f
add pre-commit hook for ruff (MR 2485)
Add a pre-commit hook that runs ruff.sh and tells you how to auto-fix
issues, add a section to CONTRIBUTING.md to document it.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2025-02-17 00:20:03 +01:00
Caleb Connolly
314cc81016
CONTRIBUTING: document markdown linting (MR 2485)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2025-02-17 00:20:03 +01:00
Caleb Connolly
65419c2bbe
treewide: lint markdown files (MR 2485)
lint all the markdown files so they pass markdownlint.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2025-02-17 00:20:03 +01:00
Caleb Connolly
14d9134d8b
CI: add markdown lint (MR 2485)
Add a CI job to enforce markdown linting

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2025-02-17 00:19:59 +01:00
Caleb Connolly
67773c4293
chroot: add --usb flag to make usb devices available (MR 2554)
Add a flag to bind-mount in the necessary sysfs directories for USB
devices to be accessed inside the chroot. This is the same as how we do
it for "pmbootstrap flasher" but allows running arbitrary commands in
the chroot.

This is useful to allow using pmbootstrap chroot's as a sandbox for
custom flashing procedures.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2025-02-16 22:16:11 +01:00
Anri Dellal
192a29fb1b
pmbootstrap config: Fix setting attribute value to False (MR 2546)
_type(value) in super().__setattr__(key, _type(value)) always returns
True for a valid string, even if the string is "False".

This code also didn't fail when any other value besides True or False
was passed, though it must fail.

Fix #2554
2025-02-16 20:41:18 +01:00
Oliver Smith
ffa58f402c
pmb.install.format: set ext4 inodes to 1M (MR 2552)
Make 10x the amount of inodes available for ext4 partitions when using
"pmbootstrap install" without the "--disk" argument so we won't run out
for sure. The previous value was not enough in some edge cases. We do
need to set this as the default is not enough either.

Fixes: issue 2568
2025-02-16 18:08:03 +01:00