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

3230 commits

Author SHA1 Message Date
Dominik Bayerl
87515529cf
pmbootstrap: run partprobe after repartitioning (MR 2473)
On some kernels (notably, WSL2) parted fails to inform the kernel
about the new partition layout, leading to errors when trying to
create the new filesystems.

This change runs an additional `partprobe` after updating the
partition table, informing the kernel about the new layout.

Fixes: #2422
Signed-off-by: Dominik Bayerl <dominik.bayerl@carissma.eu>
[caleb: move call so it runs after partition_cgpt() as well]
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-04 08:09:37 +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
Oliver Smith
3b4b9cd061
gitlab-ci: install py3-tomli for py 3.10 tests (MR 2471)
pmbootstrap requires "tomli" if running with python < 3.11, so install
it.
2024-11-03 13:52:21 +01:00
Caleb Connolly
7e7057042f
core: chroot: make ChrootType membership check work on python 3.10 (MR 2471)
You can't check enum membership with __contains__() on Python 3.10, poke
inside the enum instead.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-03 13:52:21 +01:00
Caleb Connolly
3592f9a285
CI: run pytest and install test against Python 3.10 (MR 2471)
Use Alpine 3.17 to test pmbootstrap with older versions of Python

Fixes: #2477
Suggested-by: Oliver Smith <ollieparanoid@postmarketos.org>
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-03 13:52:16 +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
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
70dc855281
config: init: dont clobber config (MR 2470)
When pmbootstrap starts up, it loads the config file (or uses the
defaults) and then merged some arguments (e.g. --work) into it. However
in config.init.frontend() we were creating yet another new Config, but
it's too late to merge args in at this point...

Rework this slightly to fix that major oversight and remove the totally
unnecessary hack of calling pmb.config.load() again.

This fixes calling pmbootstrap init with --work

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-03 12:26:26 +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
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
Caleb Connolly
af1bf53867
helpers: logging: reduce the risk of a cyclical import (MR 2463)
Lazy load pmb.config.styles and move the pmb.__version__ print elsewhere
so the logging module is (closer to) a standalone entity. This is
necessary to be able to import it in pmb/helpers/apk.py otherwise we get
a cyclical dependency.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:38 +01:00
Caleb Connolly
2f39edd584
commands: repo_bootstrap: type hint (MR 2463)
make mypy happy

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 18:15:38 +01:00
Caleb Connolly
8b880b7198
config: export workdir modules (MR 2463)
Make intellisense happy

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-11-02 17:49:41 +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
a1ff3a69f3
CI: expand integration tests (MR 2453)
Refactor the integration test script to support running a variety of
tests, and add CI jobs for them.

Additionally, move the integration tests to their own stage so we don't
potentially waste a bunch of CI time running them on broken branches.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-10-30 23:14:01 +01:00
Caleb Connolly
3dfe906871
CI: drop log.txt from integration job artifacts (MR 2453)
We run pmbootstrap with --details-to-stdout now, so this isn't needed.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-10-30 23:14:01 +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
511d490015
pyproject.toml: Set disallow_untyped_decorators = true (MR 2464)
We pass this too, so might as well ensure we don't regress.
2024-10-30 12:39:45 +01:00
Newbyte
f24b6e7c9b
pyproject.toml: Set disallow_incomplete_defs = true (MR 2464)
We pass this check now.
2024-10-30 12:39:45 +01:00
Newbyte
225d8b30a0
pmb: Add lots of type hints (MR 2464) 2024-10-30 12:39:45 +01:00
Newbyte
d05d57b37e
pmb.install.recovery: Assert that partitions are not None (MR 2464)
They should definitely not be None here, thus assert it so we don't need
to keep checking for None later.
2024-10-29 23:08:37 +01:00
Newbyte
b49da9ad82
pmb.install.recovery: Check for None before going through blacklist (MR 2464)
It doesn't really make sense to check the blacklist against None, so
just skip the value if it's None. Appeases mypy.
2024-10-29 23:08:37 +01:00
Newbyte
8bc848fa77
pmb.install._install: Use bool(...) when figuring out whether to use cgpt (MR 2464)
Otherwise, if pmb.parse.deviceinfo().cgpt_kpart is an empty string, for
example, we end up passing an empty string to get_partition_layout()
instead of False.
2024-10-29 23:08:37 +01:00
Newbyte
fc44b64233
pmb.flasher.init: Assert that depends is a list (MR 2464)
pmaports_cfg.get() can return other types, too. As such, we need to
assert that it's a list to appease mypy.
2024-10-29 23:08:37 +01:00
Newbyte
d5586979aa
pmb.sideload: Separate distinct uses of add_cmd into different variables (MR 2464)
Helps mypy understand the code better and also makes it easier to read
as a human in my opinion.
2024-10-29 23:08:36 +01:00
Newbyte
d4ea780752
pmb.helpers.run_core: Properly type pipe_read() (MR 2464)
I think the "these types make no sense" comment were about
output_return_buffer, which defaulted to False but was to be set to
list[bytes] if used. I changed it so that it defaults to None, which
probably is more conventional. Other than that I didn't notice anything
weird about the types here.

Also check for None as necessary to appease mypy.
2024-10-29 23:08:36 +01:00
Newbyte
47c8492577
pmb.qemu.run: Use f-string for img_path_2nd argument building (MR 2464)
img_path_2nd is a Path, not a str, so we can't just rely on string
concatenation here.

img_path_2nd is a Path as that's what create_second_storage() returns
since 198f302a36.
2024-10-29 23:08:36 +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
f2c7fa1107
pmb.types: Add Apkbuild type (MR 2464)
Useful for annotating places where a parsed APKBUILD is expected.
2024-10-29 23:08:36 +01:00
Newbyte
b0526128fe
pmb.install._install: Round root size to nearest int in get_subpartitions_size() (MR 2464)
This makes the behaviour match the docstring which specifies that this
function returns integers.
2024-10-29 23:08:36 +01:00
Newbyte
c1527ba95d
pmb.types: Simplify CrossCompileType definition (MR 2464)
This is equivalent to the previous definition, but more concise.
2024-10-29 23:08:36 +01:00
Newbyte
6b55ce7b53
pmb.build.envkernel: Convert Arch.native() to str (MR 2464)
We don't want an actual Arch object in the environment object.
2024-10-29 23:08:36 +01:00
Newbyte
98f1491426
pmb.build.envkernel: Properly construct path to remove (MR 2464)
Can't construct a path by using the / operator on strings, so use the
Path constructor instead.
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
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
Newbyte
1aa0b05014
pmb.install.blockdevice: Avoid reusing size_mb variable in create_and_mount_image() (MR 2464)
Reusing this variable might lead to confusing bugs later if this code is
changed in the future, and also leads to mypy being confused about the
type of size_mb as it then gets assigned both str and int values.
2024-10-29 14:21:01 +01:00
Newbyte
f507aed9aa
pmb.build.autodetect: Fix return type and docstring for arch() (MR 2464)
At some point, this function was updated to use the Arch type instead of
plain strings, but the return type was left omitted and the docstring
outdated.
2024-10-29 13:49:37 +01:00
Newbyte
a89ecb11d2
pmb.build._package: Remove reference to nonexistent parameter (MR 2464)
No parameter called "now" exists for this function, so don't document
it.
2024-10-29 13:08:07 +01:00
Newbyte
44f28be2b1
CI: Don't set colour output for mypy (MR 2464)
This is already the default: https://mypy.readthedocs.io/en/stable/config_file.html#confval-color_output
2024-10-29 12:55:14 +01:00
Newbyte
f65eb27453
pyproject.toml: Add tool.mypy section (MR 2464)
And remove --check-untyped-defs from mypy.sh script to avoid
duplication.
2024-10-29 12:53:00 +01:00
Oliver Smith
7269d05b20
pmb.helpers.repo.download: proper error for 404 (MR 2462)
Flush the progress bar displayed by the function before logging a
warning message for 404 not found responses from the server. Without
flushing, this message gets lost.

In addition to the warning, display a NOTE and ERROR at the end to
explain what went wrong:

  [20:16:50] Update package index for x86_64 (4 file(s))
  [20:16:51] WARNING: file not found: http://mirror.postmarketos.org/postmarketos_get_404_test/edge/main/x86_64/APKINDEX.tar.gz
  [20:16:51] NOTE: check the [mirrors] section in 'pmbootstrap config'
  [20:16:51] ERROR: getting APKINDEX from binary package mirror failed!

Without handling this properly, pmbootstrap would fail slightly later
with a much less useful error:

  [15:14:28] ERROR: expected str, bytes or os.PathLike object, not NoneType

Fixes: pmbootstrap issue 2424
2024-10-27 20:52:13 +01:00
Oliver Smith
3ead8f8859
migrate_work_folder: print suffix in migration msg (MR 2460) 2024-10-27 20:47:06 +01:00
Oliver Smith
60cae5811b
migrate_work_folder: 7-2.x: skip update git url 2x (MR 2460)
Don't update the git URL again when coming from 7-2.x where this step
was already done. This didn't fail, but was potentially confusing for
the user since the git URLs were already upgraded from 7 -> 7-2x.
2024-10-27 20:47:00 +01:00
Caleb Connolly
50321d41f6
build: package: skip prioritizing deps of pkg which are a subpkg of pkg (MR 2459)
Some packages in aports have their own subpackages in their
dependencies, for some reason. This causes our resolver to assume there
is a cyclical dependency.

Adjust the resolver to safely ignore these dependencies, since they'll
be built as a part of the package that depends on them.

For example, modemmanager depends on libmm-glib which is a subpackage of
modemmanager. Currently to build modemmanager in pmaports it would be
necessary to manually modify the APKBUILD after copying it from aports.
This change avoids that.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-10-27 19:36:04 +01:00
Oliver Smith
497188eb30
CI: force IPv4 for gitlab.postmarketos.org (MR 2459) 2024-10-27 19:35:59 +01:00