Commit graph

503 commits

Author SHA1 Message Date
Newbyte
0ade6cab4d
pmb: Use inspect.get_annotations()
On Python 3.10 and newer, this is the recommended way of accessing
annotations[1]. It also works with Mypyc, unlike directly accessing
__annotations__.

 [1]: https://docs.python.org/3/howto/annotations.html

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2634
2025-07-10 21:09:41 +02:00
Henrik Grimler
2872ec6be8
bootimg: exynos: extract platform and subtype from dt.img header
dtbtool-exynos has two options --platform and --subtype that are
embedded in dt.img header and need to match the values that the
bootloader expects. For most devices these values are 0x50a6 and
0x217584da, respectively, but for some they have other values.

Add functionality to parse the dt.img header and extract these values,
and add them to the deviceinfo as
bootimg_qcdt_exynos_{platform,subtype} if they are not equal to the
default values.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2638
2025-07-10 21:03:01 +02:00
Newbyte
3c15b993b5
pmb.parse._apkbuild: Use NonBugError for all errors
While it is possible for these code paths to be triggered by genuine
pmbootstrap bugs, in general these should be caused by APKBUILD. As
such, use NonBugError to reduce noise.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2622
2025-07-06 21:15:31 +02:00
Henrik Grimler
f25a8bf374
treewide: switch back to bootimg_qcdt{,_type}
In some refactoring work deviceinfo_bootimg_qcdt and
deviceinfo_bootimg_qcdt_type were accidentally renamed to just
deviceinfo_qcdt{,_type}. Change back to original name everywhere.

Among the notable changes is that we modify the bootimg header_v2 test
so that bootimg_qcdt="false" is acceptable in the deviceinfo. I am not
sure why it was added to the !expected substrings, we have plenty of
header_v2 devices with the property set.

Part-of: https://gitlab.postmarketos.org/postmarketos/pmbootstrap/-/merge_requests/2628
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2628
2025-07-03 17:01:33 +02:00
Oliver Smith
47be020c7a
Remove "pmbootstrap repo_bootstrap"
The repo bootstrap logic has worked well enough in the initial systemd
bringup. But we have decided to replace the approach of building
packages multiple times during the repo_bootstrap with building each
package only once and adding -stage0 packages where necessary (currently
only a systemd-stage0 package).

Advantages:
* Replace the often breaking repo_bootstrap logic with something less
  fragile (repo_bootstrap is currently broken again).
* Can get rid of the whole bootstrap logic in pmaports.cfg, pmbootstrap,
  build.postmarketos.org. This will make pmbootstrap and bpo easier to
  maintain.
* Fix problems we have seen when upgrading two or more of (systemd,
  dbus, linux-pam-pmos) at once: it doesn't pass in CI and it doesn't
  pass in BPO
* You don't need to do a whole bootstrap at once, it is again broken
  down by package. This means if building one package fails (locally or
  in bpo), we don't need to do the whole thing again, just start at the
  package that failed. This also means it is much easier to optimize
  e.g. the stage0 packages to build faster.
* Fixes some specific bugs we currently have (abuild twice in pmaports,
  bpo tests disabled because of that, ...)

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2588
2025-06-03 17:25:41 +02:00
Pablo Correa Gómez
ba6bb4272d
pmb.parse.apkindex: account for provider_priority when locating packages
This fixes an issue where the local apk index has two packages in it
that provide the same thing, but this function was returning only the
one with the shortest name... which could be very bad :)

https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/6475#note_480167

In the process, add tests for pmb.parse.apkindex.package function. Some of
the tests would fail without this patch, surfacing a bug where priorities
are not considered, but should, and that we are now fixing.

Co-authored-by: Clayton Craft <craftyguy@postmarketos.org>
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2594
2025-05-13 19:19:00 +02:00
Anri Dellal
d7b12d98e6
pmb: Rename pmb:gpu-accel and deviceinfo_gpu_accelerated
pmb:gpu-accel -> pmb:drm
deviceinfo_gpu_accelerated -> deviceinfo_drm

Allow deviceinfo_gpu_accelerated as deprecated property

Keep pmb:gpu-accel as valid option to avoid failures for older branches
of pmaports.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2591
2025-05-08 17:33:11 +02:00
Stephan Gerhold
e9038e50d6
pmb/install: Add option to create single combined boot/root partition
With recent rework in postmarketos-initramfs, we no longer need to mount
the /boot partition in the initramfs (assuming initramfs-extra is not
used). On devices that boot without accessing the boot file system (e.g.
Android boot images, fastboot, ...), that makes it possible to install
postmarketOS on a single (potentially encrypted) partition that contains
both root (/) and /boot files.

This avoids the extra complexity of the subpartition setup we usually use
on such devices, and also avoids having to flash two partitions (when using
--split to avoid the subpartitions).

Add a --single-partition option to pmbootstrap install that allows
installing postmarketOS in this mode. For now this is just an option that
must be selected explicitly, in the future we could choose to make this the
default for Android-based devices with a large enough boot partition.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2512
2025-04-11 17:35:20 +02: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
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
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
Hugo Osvaldo Barrera
5a152aebae
test: move all tests into separate module (MR 2551)
When installing pmboostrap, all tests are installed alongside it. There
doesn't seem to be any way to selectively exclude some files inside
python modules, so move all test into a separate module instead.

This is the typical convention in python projects.

See: https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/79862
Fixes: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/issues/2541
2025-02-13 01:28:20 +01:00
Newbyte
a01578d897
pmb.parse.bootimg: Initialise chroot before installing packages in bootimg() (MR 2526)
Closes https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/issues/2535
2025-01-19 13:54:31 +01:00
Newbyte
3061e702ab
pmb: Reformat with Ruff 0.9 (MR 2525)
See https://astral.sh/blog/ruff-v0.9.0
2025-01-15 22:35:02 +01:00
Newbyte
c2787aa76f
pmb: Replace list(...)[0] with next(iter(...)) (MR 2525)
See https://docs.astral.sh/ruff/rules/unnecessary-iterable-allocation-for-first-element
2025-01-15 22:35:02 +01:00
Oliver Smith
8d446c2aeb
Rewrite repo_missing for bpo + systemd split repo (MR 2410)
The "pmbootstrap repo_missing" action is used exclusively by bpo. It
calls it only with these arguments:

  pmbootstrap repo_missing --built --arch "$ARCH"

A blocker for merging systemd into pmaports master is, that the
current repo_missing code cannot display packages that are both in
extra-repos/systemd and in another path. I have considered just not
supporting this and discussed doing that with Caleb and Clayton, but we
figured it would be a major obstacle in the future to not be able to
easily override packages with systemd specific versions (currently we
need this for 3 packages).

Integrating this into the existing repo_missing code would be hacks upon
hacks. Also the scope of the current repo_missing code has many extra
features that are not used and would be extra effort to carry along:
* Allow specifying a pkgname
* Running without --built
* --overview

So I decided to replace the repo_missing code with a much simpler, more
modern implementation, that does exactly what is needed:
* Duplicate packages in systemd and non-systemd dirs are displayed
* The output always include all packages, no matter if they are already
  built or not (same behavior as with --built)
* Removed --overview and selecting specific packages too
* The code for filling "repo" (either "systemd" or None) is more
  resilient now, as it can use proper relative paths to the root of
  pmaports. Unlike the previous implementation, it will not fail if
  subdirs are added to the systemd dir.

I have made sure that the output is exactly the same as before on
current pmaports master.

Related: bpo issue 144
Related: bpo issue 140
2025-01-10 13:04:48 +01:00
Newbyte
871a3128d8
docs, pmb: Add missing copyright headers (MR 2516)
I tried my best to get the right author based on git commit history, but
in the case of code being moved from one file to make another I might
have gotten something wrong.
2025-01-02 16:45:03 +01:00
Newbyte
7f7af62697
pmb.parse.version: Use _ for "value" variable in validate() (MR 2516)
This variable is unused, mark it as such to appease Ruff.
2025-01-02 16:45:01 +01:00
Newbyte
415893fb74
pmb.parse.version: Replace token_value() with Token enum (MR 2518)
Hopefully makes for easier to read code, and potentially also faster
once we have mypyc and the enum can get compiled into plain integers
instead of the strings we previously were working with.
2025-01-02 15:42:22 +01:00
Newbyte
01264bd39f
pmb: Add more types and fix type errors (MR 2514) 2024-12-20 16:29:33 +01:00
Newbyte
3ee75e61a5
pmb.parse.arguments: Type hint and remove unused arguments from add_kernel_arg() (MR 2514)
Presumably, args and kwargs are just here to retain compatibility with
add_argument() from argparse.ArgumentParser, but they aren't actually
used and consequently only give the illusion of compatibility. Just
remove them to simplify the function signature.
2024-12-20 15:37:28 +01:00
Newbyte
7bca381dea
pmb.parse.arguments: Ignore attr-defined on arg.completer (MR 2514)
Currently, I don't think mypy can understand monkeypatched code like
this. So, just ignore it.
2024-12-20 15:29:18 +01:00
Newbyte
fec23070bc
pmb.parse.test_version: Add unit tests for version.py (MR 2514) 2024-12-20 14:41:33 +01:00
Newbyte
a6025ed42a
pmb.parse.version: Convert rest[0] to integer before storing it in value (MR 2514)
Previously, value would sometimes be a string despite the docstring
clearly stating that it should be an integer. This seems to have been a
consequence of literally copying the original C code without considering
that strings work differently between the languages, where the
original assigning a character in a string to an integer results in the
integer having the ASCII value of that character, in Python you just get
the string value of that character. As such, match the original
implementation by explicitly converting from a string to an integer
using ord(), which gives the Unicode code of the provided character.

It is not clear to me why this disparity didn't cause any issues beyond
type errors found by mypy.

See 5d796b5678/src/version.c (L101)
2024-12-20 14:39:46 +01:00
Newbyte
c38933f2e6
pmb.parse.version: Link to older apk-tools (MR 2514)
The file version.c in modern apk-tools does not at all resemble this
file. Link to one from around the time when this code was written to
make cross-referencing easier.

Also, switch from cgit to GitLab because I couldn't be bothered to
figure out how to go through file revisions on cgit.
2024-12-20 14:02:21 +01:00
Newbyte
0925b3e425
pmb: Add more type hints (MR 2513)
And fix some consequential type errors.

[ci:skip-build]: already built successfully in CI
2024-12-19 18:52:25 +01:00
Newbyte
5ed5817e80
pmb: Add more type hints (MR 2490) 2024-12-19 10:09:22 +00:00
Newbyte
df2593400d
pmb.parse.kconfig: Rename options to arch_options in check_config_options_set (MR 2490)
Otherwise mypy gets confused by the type later in the code, and I also
think it might be confusing behaviour in general that <options> gets
overwritten in this loop.
2024-12-19 10:09:22 +00:00
Newbyte
b2d32a85e9
pmb.parse.kconfig.check_config_options_set: Update docstring (MR 2490)
The mentioned variable no longer exists, so update it to reflect how
things work now.
2024-12-19 10:09:22 +00:00
Anri Dellal
3204577530
Fix apkbuild parsing in edge cases (MR 2503)
This commit removes separator in split function arguments, so arrays
where items are separates by tabulation don't fail to parse properly.
2024-11-30 11:53:17 +03:00
Caleb Connolly
f090e86126
test: parse: add tests for bootimg parsing (MR 2477) (MR 2483)
Add some unit tests to ensure that the parser correctly detects boot
images with header v0, 2, and 3.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-29 16:50:04 +01:00
Newbyte
472726a9dc
pmb: Add more type hints (MR 2489) 2024-11-14 23:16:29 +01:00
Oliver Smith
1b4c38a01d
Revert "test: parse: add tests for bootimg parsing (MR 2477)" (MR 2482)
This caused a regression in CI tests.
This reverts commit ae35603197.

Related: issue 2497
2024-11-10 17:23:00 +01:00
Caleb Connolly
ae35603197
test: parse: add tests for bootimg parsing (MR 2477)
Add some unit tests to ensure that the parser correctly detects boot
images with header v0, 2, and 3.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-08 01:57:26 +01:00
Caleb Connolly
953f84a79a
parse: bootimg: make it work again (MR 2477)
Commit 826bb4f2dd (pmb: Properly type Bootimg (MR 2464)) broke the
bootimg_analyze command since some assumptions in whether the bootimg
dictionary had empty keys or non-existent keys were changed without
their usage being updated.

Fix this and apply a trivial cleanup to aportgen.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-08 01:57:26 +01:00
Caleb Connolly
d57b9e31e1
config: init: support --aports too (MR 2470)
We shouldn't overwrite config.aports if the user specified a custom
--aports directory. We only want to do this to update the default if
they're using a custom workdir.

Make the code here less aggressive, and correctly use the last entry in
config.aports as "pmaports" instead of the first.

Fixes: #2386
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-03 12:26:32 +01:00
Newbyte
b524d6daa2
pmb.parse.bootimg: Fall back to empty string if mtk properties don't exist (MR 2466)
This should match the previous behaviour and fix crashes when these
properties don't exist.

Tested with a htc-primou bootimg.

Fixes 826bb4f2dd
[ci:skip-build]: already built successfully in CI
2024-10-31 11:09:13 +01:00
Caleb Connolly
b9354d3ccd
test: parse: add test_deviceinfo (MR 2453)
Write some basic parser tests for deviceinfo. The parser is quite basic
so there isn't much to test yet. Expecting this to gain features as we
look at e.g. making the parser the "source of truth" for the deviceinfo
format.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-10-30 23:14:01 +01:00
Newbyte
225d8b30a0
pmb: Add lots of type hints (MR 2464) 2024-10-30 12:39:45 +01:00
Newbyte
826bb4f2dd
pmb: Properly type Bootimg (MR 2464)
This could be done better with a real class instead of a TypedDict, but
it's better than a regular dict.
2024-10-29 23:08:36 +01:00
Newbyte
613f50b834
pmb.parse.depends: Remove unused functions (MR 2464)
This is no longer used as of 1299c2ef6d,
so just remove this dead code.
2024-10-29 15:42:46 +01:00
Caleb Connolly
d4d7ba0368
test: parse: apkindex: check that cache works (MR 2455)
Add a basic test to ensure that the cache does get hit as we expect.
This doesn't test for cache conflicts.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-10-27 16:42:54 +01:00
Caleb Connolly
12f9e43a08
parse: apkindex: don't require python 3.12 (MR 2455)
Use a different way of keying the apkindex path cache.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-10-27 16:42:49 +01:00
Caleb Connolly
8627ee7e73
test: parse: add test_apkindex (MR 2448)
Add a test to parse some APKINDEX data.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-10-23 23:22:04 +02:00
Caleb Connolly
a874025bbe
parse: apkindex: fix provider_priority type (MR 2448)
should be an int, but was always a string...

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-10-23 23:17:03 +02:00
Clayton Craft
2305cc5db6
pmb.parse.apkindex: fix crash when origin or timestamp are unset (MR 2449)
Sometimes these fields are not set, e.g.:

pdb> p ret
{'depends': ['build-base', 'bash', 'bison', 'findutils', 'flex', 'musl-dev', 'openssl-dev', 'perl', 'python3'], 'arch': 'noarch', 'version': '20241022.022230', 'pkgname': '.makedepends-linux-lenovo-21bx', 'provides': []}

I hit this crash when I installed the build deps for the
linux-lenovo-21bx package in the native chroot, and then ran
`pmbootstrap stats`
[ci:skip-build]: already built successfully in CI
2024-10-22 11:11:28 +02:00
Newbyte
11c7d23575
pmb.parse.arguments: Make -x and -n mutually exclusive in kconfig edit (MR 2346)
It doesn't make sense to both request the nconfig UI and the xconfig UI
at the same time. Make them mutually exclusive.
2024-10-22 00:04:33 +02:00
Luca Weiss
35cd64086f
Improvements to documentation (MR 2440)
* Make sure all Python modules are documented by adding a bit of shell
  to .ci/docs.sh
* Remove non-existing module references from .rst
* Fix various warnings from sphinx by adjusting Python docstrings
* Add class member docs to ApkindexBlock
2024-10-21 21:46:26 +02:00
Luca Weiss
327010cff1
pmb.parse.apkindex: Add missing type hints in package() (MR 2438)
Make sure to annotate the parameters.
2024-10-21 21:05:18 +02:00
Clayton Craft
47dc493701
pmb.parse.depends.package_provider: add type hinting and fix references (MR 2439)
pmb.parse.apkindex.providers now returns a dict of string:ApkindexBlock,
probably from 71772b9b6

This adds type hinting to package_provider to reflect this, and fixes
code that calls it to properly deal with the possible return types.
Without this, building FDE images is broken.
2024-10-18 13:45:57 +02:00