1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-13 11:29:46 +03:00
Commit graph

541 commits

Author SHA1 Message Date
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
Anri Dellal
556160b200
pmb.helpers.locale: new module (MR 2497)
Add module that provides utilities and information related to localization.

Initial implementation includes code to generate keyboard configs
for locale set by user.
2024-12-03 13:17:14 +01:00
Oliver Smith
07f04ae12a
pmb.helpers.repo.update: support PMB_APK_FORCE_MISSING_REPOSITORIES (MR 2505)
Do not abort if one or more APKINDEX files cannot be downloaded, if
PMB_APK_FORCE_MISSING_REPOSITORIES is set. This is needed when
bootstrapping new stable branches. The same environment variable is
already used in pmbootstrap code to pass --force-missing-repositories to
apk in pmb.chroot.apk.install_run_apk().
2024-12-03 06:24:03 +01:00
Jens Reidel
822e89ed13
helpers: pmaports: Always fall back to parsing all APKBUILDS (MR 2476)
Previously, it would only fall back to parsing all APKBUILDs if a main
package was guessed for this potential subpackage. We do however want to
scan all APKBUILDs in case the package is provided by one of the
packages in pmaports.

Signed-off-by: Jens Reidel <adrian@travitia.xyz>
2024-11-25 13:09:53 +01:00
Jens Reidel
e2354ec26f
helpers: pmaports: Fix package detection for cross g++ and musl-dev (MR 2476)
g++ is a subpackage of gcc, but cannot be detected as such easily by
pmbootstrap. This is because g++ is not gcc-g++ or any other variant of
such package names. Similarly, the detection for musl-dev-ppc64le and
other architectures is broken, since the -dev suffix detection does not
work if there is an architecture suffix.

To fix it, add special case handling for cross toolchain and packages
and have that fixup the -dev cases and hardcode g++ as a subpackage of
gcc.

To reproduce:
- Generate ppc64le cross packages:
  pmbootstrap aportgen gcc-ppc64le musl-ppc64le
- Build a package (to trigger building cross compilers):
  pmbootstrap build hello-world --arch=ppc64le

Signed-off-by: Jens Reidel <adrian@travitia.xyz>
2024-11-25 13:08:50 +01:00
Iuri Jikidze
215dfcc663
pmb.helpers.git: fix get_upstream_remote() (MR 2496)
Fixes bec2a4b154

[ci:skip-build]: already built successfully in CI
2024-11-18 12:16:42 +01:00
J. Pablo Navarro
bec2a4b154
helpers: git: ignore case in get_upstream_remote() 2024-11-18 04:12:38 +01:00
Newbyte
472726a9dc
pmb: Add more type hints (MR 2489) 2024-11-14 23:16:29 +01:00
Oliver Smith
cfa455cc5e
zap: cache_clean: get apk.static if missing (MR 2481)
After extending CI to always run "pmbootstrap zap -a" it revealed
another bug: we did not ensure at this point that apk.static is
available. Rung apk_static.init() to ensure it gets downloaded and
extracted at this point if it is missing.
2024-11-10 18:22:43 +01:00
Oliver Smith
506b7685c2
Fix pmb zap -a permissions error (MR 2481)
The tmp dir is owned by root, when it gets created earlier by apk
running as root to store the apk progress fifo. Use another directory to
work around this for now (getting close to the 3.0.0 release), we can
rework the apk progress fifo later on if we want.

Fixes: issue 2491
2024-11-10 18:22:38 +01:00
Oliver Smith
2a7864b080
Tweak messages for 'Could not find aport' (MR 2480)
Replace aports -> pmaports in these messages.

$ pmbootstrap build systemd
[17:37:02] NOTE: The package 'systemd' exists in extra-repos/systemd, but systemd is currently disabled
[17:37:02] ERROR: Could not find package 'systemd' in pmaports
2024-11-10 17:43:39 +01:00
Oliver Smith
67318823b5
pmaports.find: show extra-repos/systemd hint (MR 2480)
If the user tries to build a package, but it can't be found: check if
systemd is disabled and the package is in extra-repos/systemd, display a
hint about it.

$ pmbootstrap build systemd
[17:33:53] NOTE: The package 'systemd' exists in extra-repos/systemd, but systemd is currently disabled
[17:33:53] ERROR: Could not find aport for package: systemd

Fixes: issue 2398
2024-11-10 17:43:39 +01:00
Oliver Smith
0a0f6ead33
Replace skip_extra_repos -> with_extra_repos (MR 2480)
Replace the boolean skip_extra_repos with a new with_extra_repos
argument that can be default, enabled or disabled.

This will be used to explicitly enable extra repos in a package search
even if systemd is currently disabled, so we can display a hint when a
package was not found because systemd is disabled in a follow-up patch.
2024-11-10 17:43:39 +01:00
Oliver Smith
444d9e256f
pmaports._find_apkbuilds: use new cache logic (MR 2480)
Use the nice @Cache decorator that Caleb introduced earlier.
2024-11-10 17:43:39 +01:00
Caleb Connolly
39235fedfb
show the status output on failure (MR 2472)
There is a lot of context and state management needed when using
pmbootstrap, sometimes it can be a lot to keep in your head. Let's print
the output of "pmbootstrap status" when stuff goes wrong, this might
help remind people if e.g. their pmaports checkout is on the wrong
branch, or they're building for the wrong device.

Additionally, don't print the "run pmbootstrap log for details" message
if pmbootstrap was called with --details-to-stdout

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-04 10:15:59 +09:00
Caleb Connolly
a72a60f546
core: pkgrepo: support arbitrarily named pmaports directories (MR 2470)
There was an oversight when this API was originally created and it
implicitly assumed that the pmaports repository was always named
"pmaports". This unfortunately broke some peoples workflows.

Introduce a new "pkgrepo_name()" function and adjust the codebase to use
it, as well as adjusting pkgrepo internally to special case the
"pmaports" repo so that it's always named pmaports no matter what the
directory itself is named.

This is probably more complexity than we should be dealing with here, we
should probably create a new type to encode this behaviour.

Fixes: #2412
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-03 12:26:32 +01:00
Caleb Connolly
500b0908f8
helpers: run: stop handling Arch in PathString (MR 2463)
This was always a hack, and it looks like there (hopefully) aren't any
placs where we still need to handle this.

Possibly expecting regressions... But then we have something to write a
test for.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:39 +01:00
Caleb Connolly
41c8413fda
helpers: apk: sanity check final command (MR 2463)
When running "apk add" we must always have --cache-dir set! We also
expect --no-interactive to be set.

Add some asserts so we don't regress here.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:39 +01:00
Caleb Connolly
7847488058
commands: remove deviceinfo_parse (MR 2463)
Since parse.deviceinfo() returns a custom class now, it can't be
trivially serialized as JSON.

This has been broken for months now so it's clear nobody is using this.
Let's take the chance to get rid of it.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:38 +01:00
Caleb Connolly
26ec1631ca
helpers: apk_static: move from pmb.chroot (MR 2463)
Move the apk_static module from pmb/chroot to pmb/helpers which is a
more suitable location.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:38 +01:00
Caleb Connolly
42158637a7
chroot: apk: use apk.static in all cases (MR 2463)
In 0b4fb9119f (chroot: always run apk static v2 (MR 2423)) we adjusted
install_run_apk() to run apk static on the host and pass in the local
binary repo with "--repository". This function can call apk in two ways,
either with the progress bar handling or without, the second case was
never updated and still ran apk inside the chroot incorrectly and with
an incorrect --repository flag.

Let's finish the job by refactoring helpers/apk.py to support all our
usecases and pointing everything to it, removing the last few situations
where we call "pmb.chroot.root(["apk", ...]).

The apk_with_progress() function is replaced by a generic "run()"
function which takes a boolean to indicate if we should render apk
progress.

Additionally, a new cache_clean() function is added so that "pmbootstrap
zap --pkgs-online-mismatch" can FINALLY be refactored to not rely on a
chroot existing. This requires some hacks but nothing serious, see the
comments in the function for details.

The chroot.init() code is now simplified since handling the --root,
--arch, --cache-dir, and --repository flags is now all done by
apk._prepare_cmd() as and when appropriate.

Lastly, this fixes a (previously unnoticed) bug where apk.static was
actually using /var/cache/apk on your host machine for its cache... This
is definitely not good behaviour....

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:38 +01:00
Caleb Connolly
12846f3b8e
helpers: apk: move update_repository_list() from chroot.apk (MR 2463)
This function better belongs here, especially as it will be used outside
of the context of a chroot() soon.

Additionally, it's adjusted to take the rootfs path as its first
argument rather than a chroot, since it could operate on any rootfs.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:38 +01:00