1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-14 03:49:48 +03:00
Commit graph

267 commits

Author SHA1 Message Date
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
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
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
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
016dbe42fe
pmb.chroot.binfmt: Initialise chroot before installing packages in register() (MR 2526)
Closes https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/issues/2453
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
077efe3623
pmb.chroot.apk: Use unpacking operator to create command in install_run_apk() (MR 2525)
The unpacking operator can unpack any iterable of any type, unlike the +
operator which only works on some sequences and requires them to be of
the same type usually. Using it allows us to get rid of the line that
disables the "operator" error code for this function.
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
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
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
472726a9dc
pmb: Add more type hints (MR 2489) 2024-11-14 23:16:29 +01:00
Caleb Connolly
765ba770dd
chroot: merge executibles_absolute_path() logic into require_programs() (MR 2475)
Remove this chroot-specific helper and merge it in with the existing
require_programs() logic. Now we have one unified way to discover and
use programs from the host and where we can put any additional special
handling we might need.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-06 23:53:33 +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
c4a92c37a8
chroot: apk_static: remove dead run() function (MR 2463)
Since all apk invocations withing pmbootstrap now use apk.static by
default, apk_static.run() isn't called anymore, so let's remove it.

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
Newbyte
225d8b30a0
pmb: Add lots of type hints (MR 2464) 2024-10-30 12:39:45 +01:00
Newbyte
6f79967fde
pmb.chroot.initfs: Assert that flavor is not None in build() (MR 2464)
If flavor is None here, something has gone wrong and the line after will
fail. Explicitly assert that it has the right value to appease mypy.
2024-10-29 14:49:36 +01:00
Caleb Connolly
b151871976
test: chroot: apk: fix missing return in _apkindex_package() (MR 2448)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-10-23 23:16:28 +02:00
jane400
afb036da0d
pmb.kconfig: refactor to remove args (MR 2346)
Co-authored-by: Stefan Hansson <newbyte@postmarketos.org>

Closes https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/issues/2402
2024-10-22 00:04:32 +02:00
Stefan Hansson
3ae2bf5e6a
pmb.chroot.apk: Import annotations from __future__ (MR 2425)
Works around circular import.
2024-10-13 20:12:39 +02:00
Stefan Hansson
8aa3b034b0
pmb.chroot.apk: Type hint package list in packages_get_locally_built_apks (MR 2425) 2024-10-13 20:12:39 +02:00
Stefan Hansson
71772b9b6b
pmb.parse.apkindex: Introduce proper typing (MR 2425)
And adjust other code.

Closes https://gitlab.postmarketos.org/postmarketOS/pmbootstrap/-/issues/2455
2024-10-13 20:12:34 +02:00
Caleb Connolly
0b4fb9119f
chroot: always run apk static v2 (MR 2423)
Now that we don't need weird apk-tools hacks for systemd, we can
re-implement this optimisation and always run apk static rather than
running apk through the chroot.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-10-08 16:54:29 +02:00
Clayton Craft
7a299b3fc4
pmb.chroot.apk_static: use sha256 sig for verification (MR 2417)
Fixes #2456
Depends on https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/72741
2024-09-30 18:07:59 +02:00
Caleb Connolly
4998e27cc7
chroot: force disable /usr merge (MR 2418)
We plan to ship systemd with split /usr until the /usr merge is complete
in Alpine. Let's not drop all our code yet but just forcefully disable
it.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-09-30 14:49:06 +02:00
Oliver Smith
f38d525538
pmb.chroot.apk: better error for mising apk-tools (MR 2388)
Currently the usr-merge script fails, and this leads to a very confusing
error when running pmbootstrap the next time:

  (stack trace)
  KeyError: 'apk-tools'

Show a more helpful error instead.
2024-09-17 02:27:44 +02:00
JustSoup321
375814b9d2
pmb.{chroot, install}: modify for bsdutils (MR 2315)
Tweaked-By: Oliver Smith <ollieparanoid@postmarketos.org>
2024-09-01 15:45:06 +02:00
Hugo Osvaldo Barrera
84c512ea6a
Add some missing type hints (MR 2338)
Functions with no explicit return type are considered to return `Any`.
2024-08-21 15:47:26 +02:00
Caleb Connolly
f07ceca9c6
chroot: apk: pass in both repos (MR 2377)
Pass in --repository for all channels not just the default.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-19 16:53:46 +02:00
Caleb Connolly
7544823265
chroot: apk: add quiet option (MR 2363)
Let us install packages without announcing. Useful if there is some more
contextual message display already.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-12 00:37:12 +02:00
Caleb Connolly
de268b1b82
chroot: init: use local repos (MR 2363)
Ensure we get our fork of apk straight away without having to run `apk
upgrade -a` immediately afterwards.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-12 00:37:11 +02:00
Oliver Smith
319d9681f3
TEMP: pmb.chroot.apk: fix installing local packages
As we don't call apk from outside of the chroot, the paths need to be
adjusted to be /mnt/pmbootstrap instead of the outside paths.

This should be reverted together with the other TEMP commit after we
upgraded apk to fix this properly (see issue 2388).

Fixes: f5122420 ("TEMP: chroot: apk: run apk through QEMU again (MR 2351)")
2024-07-08 23:33:06 +02:00
Caleb Connolly
f512242073
TEMP: chroot: apk: run apk through QEMU again (MR 2351)
This revers b82c4eb167 ("chroot: always run apk static (MR 2252)")
since the current iteration of the apk-tools /usr merge patches
don't handle --root properly and will behave differently based on your
host systems directory structure (specifially for /usr merge).

This commit can be reverted once we fix apk-tools.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-08 16:54:11 +02:00
Caleb Connolly
0e62eaac67
ruff: format (MR 2344)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-08 16:09:42 +02:00
Caleb Connolly
5881d01cce
chroot: init: build a nice log message for outdated chroots (MR 2344)
* Cache the function so we only do the check once per-run
* check all chroot's at once so the message will be printed near the
  start of output (rather than halfway through after building packages
  or something).

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-08 16:00:14 +02:00
Anri Dellal
0c932c273d
Fix bootimg_analyze error (MR 2339)
Fix error:
rm: can't remove '/tmp/bootimg_parser': No such file or directory

Fixes #2379
2024-06-30 17:40:01 +02:00
gompa
8390a093d8
Fix quotation reuse (MR 2336)
Python 3.10.12 fails without this patch:

File "/media/gompa/73d88639-a730-456c-a428-6d500b4020b7/pmbootstrap/pmb/parse/arguments.py", line 844 help="Alpine Linux mirror, default: " f"{default_config.mirrors["alpine"]}",
SyntaxError: f-string: unmatched '['

Related: https://peps.python.org/pep-0701/
(Commit message written by Oliver)
2024-06-24 21:55:53 +02:00
Oliver Smith
a8413c61a5
pmb.chroot.run.user: fix missing return (MR 2329)
Fix broken output_return=True, causing "pmbootstrap kconfig edit" to
break.
2024-06-23 19:16:26 +02:00
Oliver Smith
18fa4e58a3
Ruff: fix typing.Xxx is deprecated, use xxx instead (MR 2327) 2024-06-23 19:13:57 +02:00
Hugo Osvaldo Barrera
e421bb2d41
Auto-format codebase with ruff (MR 2325)
See: https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2324
Closes: https://gitlab.com/postmarketOS/pmbootstrap/-/merge_requests/2278
2024-06-23 15:40:13 +02:00
Caleb Connolly
b89e300c26
tests: fix tests (MR 2252)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:42 +02:00
Caleb Connolly
e6c737f342
ruff: run check --fix (MR 2252)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:42 +02:00
Caleb Connolly
cb6cd3bc4c
chroot: apk: safety net when chroot unitialized (MR 2252)
We recently changed how we manage chroots, requiring the user (of the
chroot) to initialize it before doing stuff like installing packages.

There are however still certain edgecases in pmbootstrap where this
doesn't get done (for example qemu/run.py would attempt to install the
kernel package for the device, but we don't initialize the rootfs chroot
in QEMU since that doesn't make sense to do). Check for and catch this
situation explicitly so we don't ruin someones day, but still be loud
about it so we can hopefully catch the remaining instances of this.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:42 +02:00
Caleb Connolly
8ecbf1a7de
chroot: apk: don't filter out local packages (MR 2252)
This turns out to have been wrong, since we need to give apk the package
name AND the apk file, it installs the apk and then uninstalls it but
leaves the package installed by name.
2024-06-23 12:38:42 +02:00
Caleb Connolly
099bd2f4fa
treewide: remove rogue leading slashes (MR 2252)
One flaw of pathlib is that Path("/tmp/") / "/some/relative/path"
results in Path("/some/relative/path")....

Fix the places in the codebase where we get this wrong.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:42 +02:00
Caleb Connolly
ac148da791
chroot: apk: recurse depends for locally built packages (MR 2252)
Turns out this is necessary, *sigh*. Since we could have one locally
built package depend on another locally built package.

So yeah, re-implement this, but in a slightly lazier / hopefully faster
way.

Bah

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:42 +02:00
Caleb Connolly
6f12c0c902
chroot: apk: check all channels for local package (MR 2252)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:42 +02:00