Commit graph

562 commits

Author SHA1 Message Date
Newbyte
b21c545956
pmb.helpers.devices: Use get_device_category_by_directory_path()
Simplifies the code slightly.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2616
2025-07-06 19:15:21 +02:00
Newbyte
89a80265de
pmb: Only disable metadata_csum for ext4 on downstream ports
No need to worsen filesystem reliability for mainline devices that don't
need this workaround.

Closes https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/issues/2557

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2616
2025-07-06 19:15:21 +02:00
Newbyte
7035c0239d
test: Move test_devices to where it should be
Consequence of tests being moved back and forth over time.

Fixes cd672222c4

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2616
2025-07-06 19:15:13 +02:00
Oliver Smith
3d764546c1
Revert "pmb.helpers.repo: Always update APKINDEX if it doesn't exist"
This patch made the assumption that if the Alpine APKINDEX for the
"main" repository exist, all other Alpine indexes ("community",
"testing") as well as the postmarketOS indexes (normal one, systemd)
exist as well.

This is not always the case, e.g. when the internet connection dropped
while downloading indexes and so only "main" was downloaded. While this
is unlikely to happen, it is currently also breaking BPO where the
postmarketOS repository does not get set during "pmbootstrap init" on
purpose as it causes problems when bringing up new releases.

This reverts commit 752a3a98f5.

I'll make a different fix in the next patch for the problem that this
patch was made for, having a broken "pmbootstrap zap -a" with apkv3.

Related: BPO issue 160
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2636
2025-07-03 21:52:06 +02:00
Newbyte
3f09e87346
pmb.helpers.apk_static: Update "malicious server" message
While this hypothetically could be triggered by a malicious server,
more likely is that this would be caused by a bug in pmbootstrap. As
such, soften the message a bit and also remove references to the removed
-m flag.

Fixes ebfda16d6d

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2635
[ci:skip-build]: already built successfully in CI
2025-07-02 17:25:34 +02:00
Newbyte
752a3a98f5
pmb.helpers.repo: Always update APKINDEX if it doesn't exist
When using `pmb zap --pkgs-online-mismatch`, the local index is
downloaded if missing and `update()` is cached, however pmb zap removes
the index and subsequent calls to `update()` don't actually do anything
(i.e. redownload the index) so later things that expect the indext to
exist (like finding providers) blow up.

Wrap update() with a new update() method that checks if the APKINDEX
exists, and always do a "real" update if it doesn't. Also rename
update() to _update().

Co-Developed-by: Clayton Craft <clayton@craftyguy.net>
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2635
2025-07-02 17:25:33 +02:00
Clayton Craft
f9add1b6d2
pmb.helpers.apk: fix crash computing progress from apk3
Fixes:

tot = float(cur_tot[1])
      ^^^^^^^^^^^^^^^^^
ValueError: could not convert string to float: '5383561 download'

Because this line now includes " download" at the end:

  ipdb> p line
  '10727/5383561 download\n'

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2635
2025-07-02 17:25:33 +02:00
Clayton Craft
a8988872b6
pmb.helpers.apk_static: fix version check for apk3
ipdb> p version_bin
'3.0.0_rc5_git20250613-r0'
ipdb> p version
'3.0.0_rc5_git20250613-r0'

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2635
2025-07-02 17:25:32 +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
Oliver Smith
f6b0ebd78c
pmb/helpers/other: fix typo found by codespell
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2588
2025-06-03 17:25:41 +02:00
Newbyte
cd672222c4
pmb: Split devices by category during codename selection
This also reworks list_codenames() somewhat. The option to show archived
devices is removed as it never actually was used. It should be easy to
restore if someone is interested.

Closes https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/issues/2558

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2549
2025-05-25 19:26:57 +02:00
Newbyte
a9c3628297
pmb.helpers.logging: Fix type for args
This is supposed to be `object` rather than `str` according to typeshed:
57cb510fd2/stdlib/logging/__init__.pyi (L129-L212)

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2549
2025-05-25 19:26:57 +02:00
Newbyte
c426c14f47
pmb.helpers.pmaports: Clean up some strings
Use f-strings to make them easier to read and combine some not-so-long
ones into one line for easier grepping.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2549
2025-05-25 19:26:52 +02:00
Stefan Hansson
da3fa09ca2
pmb.helpers.apk: Avoid concatenation
Appeases Ruff.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2600
2025-05-25 11:39:14 +02:00
Newbyte
15007e17d2
pmb.helpers.pmaports: Add must_exist to cache signature for find()
As must_exist affects the return value of this function by changing it
from returning None to raising an exception, we need to include it in
the cache key. Otherwise, the must_exist value effectively gets "stuck"
on whatever value it was set to when the given cache key was created.

This causes weird issues, see [1] and [2]. As such, include it in the
cache signature to fix this.

 [1]: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2601
 [2]: https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/6507#note_481093

Supersedes https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2601
Closes https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/issues/2610

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2604
2025-05-25 11:18:01 +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
Oliver Smith
9e8c4b2810
lint: adjust comment for empty apkbuild_paths
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2584
2025-04-15 15:57:55 +02:00
Clayton Craft
7ab40a4336
pmb.lint: Don't try to lint apkbuild paths that are empty
This fixes an issue where pmb lint tries to lint an apkbuild using a repo path that the apkbuild doesn't exist in.
For example, it fixes this:

```
[22:13:26] (native) linting postmarketos-ui-cosmic with apkbuild-lint
[22:13:26] *** apkbuild-lint output ***
Error: File APKBUILD does not exist
[22:13:26] *** apkbuild-lint output ***
[22:13:26] ERROR: Linter failed!
Traceback (most recent call last):
  File "/builds/postmarketOS/pmaports/.ci/lib/apkbuild_linting.py", line 26, in <module>
    common.run_pmbootstrap(["-q", "lint"] + packages)
  File "/builds/postmarketOS/pmaports/.ci/lib/common.py", line 52, in run_pmbootstrap
    subprocess.run(cmd, universal_newlines=True, check=True)
  File "/usr/lib/python3.12/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['pmbootstrap', '--aports', '/builds/postmarketOS/pmaports', '-q', 'lint', 'postmarketos-ui-cosmic']' returned non-zero exit status 2.
```

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2584
2025-04-15 11:51:29 +02:00
Jens Reidel
ec0163ce63
Add option to auto-select the best mirror
Signed-off-by: Jens Reidel <adrian@travitia.xyz>
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2559
2025-04-11 17:27:33 +02:00
Alexey Minnekhanov
d5e4d76118
Log only if config was really changed
Print to stdout only if config option has been really changed.
If the new setting is equal to old one, be silent.

Signed-off-by: Alexey Minnekhanov <alexeymin@postmarketos.org>
Part-of: https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/merge_requests/2539
2025-04-08 20:59:12 +03:00
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
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
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
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
1965818fae
pmb.helpers.logging: Use PEP 8-compliant naming (MR 2537)
See https://docs.astral.sh/ruff/rules/invalid-class-name
2025-02-02 22:48:51 +01:00
Newbyte
6415aea8af
pmb: Remove unnecessary pass statements (MR 2537)
See https://docs.astral.sh/ruff/rules/unnecessary-placeholder
2025-02-02 22:48:50 +01:00
Newbyte
5a2eafd3af
pmb.helpers.ui: Add must_exist argument to check_option() (MR 2530)
Will be used in the next commit.
2025-01-16 12:22:28 +01:00
Newbyte
01faedcf37
pmb.types: Fix type for PmbArgs.output (MR 2522)
And remove hack needed to accomodate this wrong type.
2025-01-15 23:25:57 +01:00
Oliver Smith
6a776fc67c
helpers.run.core.add_proxy_env_vars: fix variables (MR 2525)
Looks like there was a missing comma when this was added initially.
Caught this while reviewing the formatting patch.
2025-01-15 22:55:27 +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
7037d9ab46
pmb.helpers.aportupgrade: Remove unnecessary regex (MR 2525)
See https://docs.astral.sh/ruff/rules/unnecessary-regular-expression
2025-01-15 22:35:02 +01:00
Newbyte
c797b30dfe
pmb: Use unpacking operator to concatenate collections (MR 2525)
See https://docs.astral.sh/ruff/rules/collection-literal-concatenation

This is also slightly faster according to a microbenchmark that
shows it taking around 19% less time to run:
https://github.com/astral-sh/ruff/pull/1957#issue-1538092351
2025-01-15 22:35:02 +01:00
Newbyte
38b333372d
pmb.helpers.locale: Use frozenset for primary_layouts (MR 2525)
This shouldn't change at runtime, so avoid any potential issues with it
being a mutable class variable by making it immutable.
2025-01-15 22:35:02 +01:00
Newbyte
5d707e154c
pmb.helpers.run_core: Remove unnecessary str(...) (MR 2525)
Integers automatically get converted to strings when used in f-strings
like this, so just get rid of this explicit conversion.
2025-01-15 22:35:02 +01:00
Oliver Smith
35d1a7b1b3
repo_missing: ensure pkgs don't depend on themselves
For some reason, gnome-shell-mobile depends on itself with current
resolving code. Ensure this does not happen.
2025-01-10 17:56:11 +01:00
Oliver Smith
6da1b6d635
repo_missing: fix picking wrong package info
Fix that repo_missing would pick the wrong package information if a
package is in both the normal repository and the split repository.

This would lead to having the wrong version and depends:

        "pkgname": "gnome-shell-mobile",
        "repo": null,  # not in the systemd repo
        "version": "99946.1-r1",
        "depends": [

Instead of the correct version:

        "pkgname": "gnome-shell-mobile",
        "repo": null,  # not in the systemd repo
        "version": "46.1-r1",
        "depends": [

Fix this by calling pmb.parse.apkbuild() directly with the APKBUILD path
when iterating over the APKBUILDs, instead of pmb.helpers.package.get().
2025-01-10 17:48:34 +01:00
Oliver Smith
3ddb725e8a
repo_missing: ensure abuild is not twice in deps
Fix that abuild gets added twice in packages that exist in both the main
and split systemd repository:

        "pkgname": "gnome-settings-daemon-mobile",
        "repo": null,
        "version": "99946.0-r0",
        "depends": [
            "abuild",
            "abuild",
            "alsa-lib-dev",
            "colord-dev",

This fixes the following error in bpo when it tries to use the output of
"pmbootstrap repo_missing":

  UNIQUE constraint failed: package_dependency.package_id, package_dependency.dependency_id

Related: https://postmarketos.org/edge/2025/01/09/systemd-soon/
2025-01-10 16:29:17 +01:00
Oliver Smith
02591cfda2
repo_missing: if abuild is forked, add it as dep (MR 2410)
In the systemd repository, we currently have a forked version of
abuild, which needs to be used to build all other packages. Check if we
have a forked abuild, and if it is the case, add it to the dependencies
of all other packages.

Closes: issue 2401
2025-01-10 13:04:48 +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
01264bd39f
pmb: Add more types and fix type errors (MR 2514) 2024-12-20 16:29:33 +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
Robert Eckelmann
b87ae17414
docs: fix typos (MR 2510)
this fixes the typos found in #2524

Signed-off-by: Robert Eckelmann <longnoserob@postmarketos.org>
2024-12-19 16:36:21 +01:00
Newbyte
5ed5817e80
pmb: Add more type hints (MR 2490) 2024-12-19 10:09:22 +00:00
Newbyte
d5cdc3e145
pmb.helpers.repo_missing: Use f-string in get_relevant_packages() (MR 2490)
Otherwise this will crash as you cannot directly concatenate str with
Arch, but f-strings don't have this problem.
2024-12-19 10:09:22 +00:00
Newbyte
1a0827c95c
pmb/helpers/repo_missing: Remove <arch> from filter_aport_packages() docstring (MR 2490)
This argument doesn't exist. Presumably this was copied from
filter_arch_packages() without adapting the comment.
2024-12-19 10:09:22 +00:00
Newbyte
c8bd5abde1
pmb.helpers.http: Simplify retrieve_json() (MR 2490)
The parameters of this function were needlessly complicated. While I
understand the intent of trying to replicate the API of retrieve()
without duplicating the parameter list, in practice this feels like
reducing duplication to a fault to me. This is due to that the third
parameter, <allow_404>, doesn't make sense in the context of
retrieve_json() as it would raise an exception[1] if retrieve() returns
None (which is the effect of <allow_404> when a 404 occurs), thus merely
changing the exception that gets raised to a less descriptive one
instead of actually behaving like retrieve() would with that parameter
set to True.

With <allow_404> eliminated, there's just two parameters left, and I
don't think duplicating those is a big deal. So make the function easier
to read and annotate by getting rid of the args/kwargs logic.

 [1]: json.loads() raises an exception if its first argument is None
2024-12-19 10:09:22 +00:00
Oliver Smith
47984a8722
Fix spelling "infront" -> "in front"
Make codespell CI check pass again. This is trivial, so directly pushing
to master.
2024-12-10 17:20:24 +01:00
Anri Dellal
bdc4a4872e
pmb.helpers.locale: add unit tests (MR 2497) 2024-12-03 13:17:14 +01:00