Commit graph

125 commits

Author SHA1 Message Date
Oliver Smith
7c4c63f9fc
build: package: split has_cyclical_dep in function (MR 2388)
Split has_cyclical_dependency logic into an extra function, so it is
easier to read.
2024-09-17 02:27:44 +02:00
Oliver Smith
b76963ab03
pmb: build: add debug log about missing deps (MR 2388)
Have messages like the following in "pmbootstrap log" to better
understand why resolving packages fails. The bug with -dev pkgs not
being recognized will be fixed in a follow-up patch.

> systemd: missing dependency linux-pam-dev, trying to queue other packages first
> linux-pam: missing dependency systemd-dev, trying to queue other packages first
> dbus: missing dependency systemd-dev, trying to queue other packages first
2024-09-17 02:27:44 +02:00
Oliver Smith
22865fdfa7
build: package: rename do_continue -> missing_deps (MR 2388)
Make the code easier to understand with a more meaningful variable name.
2024-09-17 02:27:44 +02:00
Oliver Smith
9542ed006d
build: package: better error for remaining pkgs (MR 2388)
List each pkgname in a new line, instead of having a one line list of
dictionaries with lots of attributes.
2024-09-17 02:27:44 +02:00
Oliver Smith
de7fdf6c97
build: package: add warning for cyclical build dep (MR 2388)
Print a warning when breaking cyclical dependencies, for example with
current kde-nightly branch:

> WARNING: cyclical build dependency, building kirigami with binary package of qqc2-desktop-style
2024-09-17 02:27:44 +02:00
Oliver Smith
ed2077bfb1
build: package: move stuck var out of queue_item (MR 2388)
Set "stuck = False" in the "while disarray and not stuck" loop
directly, instead of setting it in the queue_item() function that gets
called from it. This way the loop logic can be understood without
looking at queue_item().
2024-09-17 02:27:44 +02:00
Caleb Connolly
63ef3f1305
build: package: break cyclical dependencies in build queue (MR 2388)
Most of the time when building it's reasonably safe to fall back on an
older binary package for building in order to break cyclical
dependencies (e.g. dbus and systemd depend on each other at build time,
but it's safe to build both against older versions of the other).

Implement the necessary logic to break cyclical dependencies by
detecting them and checking for the existence of a binary package.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
Tweaked-by: Oliver Smith <ollieparanoid@postmarketos.org>
2024-09-17 02:27:44 +02:00
Caleb Connolly
52b85b2605
build: package: fix logging in pkgver mismatch (MR 2388)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-09-17 02:27:44 +02:00
Caleb Connolly
d4d6292545
build: package: build packages in the right order (MR 2388)
Decide the order to build packages in by looking through the build queue
and making sure dependencies are queued before any packages that depend
on them, bailing out in the case of cyclical dependencies.

This should handle subpackages too.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-09-17 02:27:44 +02:00
Caleb Connolly
b7045702fb
build: package: include package count in msg about installing deps (MR 2388) 2024-09-17 02:27:44 +02:00
Caleb Connolly
03bccfd037
build: package: bail out if newer binary package exists (MR 2388)
When building with --src or --force, other logic to detect when to build
a package is skipped. However there are no (known) cases when someone
might want to build a package if the resulting binary package version
will be older than an existing binary package. Catch this case and fail
with recommendations for user action (update pmaports, clear local
binary repo).

This should help avoid the situation where you accidentally build an old
version of a package and it never actually gets installed.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
Tweaked-by: Oliver Smith <ollieparanoid@postmarketos.org>
2024-09-17 02:27:44 +02:00
Caleb Connolly
bdc2c07837
build: package: improve readability of is_cached_or_cache() (MR 2388)
This function is really hard to understand, try to make this a bit
better by adjusting the wording to better reflect what it does.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-09-17 02:27:44 +02:00
Caleb Connolly
b63e7fa594
build: package: don't queue build_packages as dependencies (MR 2388)
build_packages like apk-tools and alpine-base might get picked up and
queued for build as dependencies of other packages. We don't want this
since we always ensure they are queued first. Avoid queuing them in this
case.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-09-17 02:27:44 +02:00
Caleb Connolly
69fa230f3f
build: package: build outdated dependencies for packages (MR 2388)
It turns out the current behaviour was not preserving the old behaviour
at all, and was wrong. We want to build ALL outdated or new packages we
encounter via the dependency graph.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-09-17 02:27:39 +02:00
Caleb Connolly
1fe7b9931c
build: package: queue subpkg depends for base package too (MR 2380)
We handle this correctly for dependencies of the base package but not
the base package itself.... Fix this.

Should avoid duplication here ideally.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-21 17:38:04 +02:00
Caleb Connolly
e5dc22b838
build: package: queue subpkg depends for build (MR 2379)
A previous attempt inserted subpackage depends into the package depends
list returned by get_depends().

This meant that pmb would try to install subpackage depends when
building the package, which breaks for some cases like device packages
with kernel variants since the depends of different subpackages might
conflict with each other.

Let's instead just add the subpackage depends to the build queue, so
they get built like package depends, without being pulled in as build
dependencies for the package.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-21 17:25:31 +02:00
Caleb Connolly
3680a0d7de
Revert "build: package: add subpkg depends (MR 2377)" (MR 2379)
This reverts commit 6002a73329.
2024-07-21 17:08:42 +02:00
Caleb Connolly
6002a73329
build: package: add subpkg depends (MR 2377)
Recurse dependencies of subpackages too.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-19 16:58:26 +02:00
Caleb Connolly
d8e5037336
build: package: build build packages even when nothing else is queued (MR 2376)
Bail on empty build queue after checking if build_packages need
building. So if apk-tools / alpine-base / etc are outdated but nothing
else is they'll still be built.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-18 03:41:05 +02:00
Oliver Smith
36dd53f402
Run ruff check --fix (MR 2357)
Now that we have target-version = "py310" in [tool.ruff] in
pyproject.toml, ruff check complains about using typing.Optional and
typing.Union instead of newer syntax. Run the tool to fix it.
2024-07-16 00:26:35 +02:00
Caleb Connolly
2ce06e9791
build: package: properly ensure build-base packages are built first (MR 2363)
In ("build: special case building abuild (MR 2356)") we tried to ensure
that abuild would be built before anything else, however this
implementation failed miserably if the first package given didn't
actually need to be built (since we skip building deps of packages that
aren't flagged for build).

Let's take a different stab at this by actually inserting build_packages
into the build queue if they need building. They're inserted at the end
just before the queue is reversed, so they will always be built first.

This makes the order of pmb.config.build_packages important, enshrine
this with a comment.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-12 00:37:12 +02:00
Caleb Connolly
889a1e011d
build: package: fail gracefully if --src and dependencies need building (MR 2363)
If you build a package with --src but some dep is outdated, force you
to build it (or otherwise handle the situation yourself). We can't guess
what to do here.

This could be made configurable (opt-in) in the future.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-12 00:37:12 +02:00
Caleb Connolly
d2f40a9a29
build: package: update all build_packages in buildroot after building (MR 2363)
We might have just built some other package which will later be used to
build more packages. Handle all of them and don't special case abuild.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-12 00:37:12 +02:00
Caleb Connolly
234673ce03
build: special case building abuild (MR 2356)
Since abuild is an implicit dependency of everything, we need special
case handling for it. Insert it as a dependency of the first package in
the build queue so that it will be built if outdated, then after
building re-install it in the chroot so all subsequent packages will use
the freshly built abuild.

This is currently used for systemd where we use an abuild fork

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-09 00:19:57 +02:00
Caleb Connolly
c5135ac62a
build: use get_pkgver() again (MR 2353)
During rework this got lost, re-incorporate it so packages built with
--src have a relevant pkgver.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-09 00:07:53 +02:00
Arnav Singh
6915c6a17b
pmb.build._package: Fix installing cross-compile deps in native chroot (MR 2341) 2024-07-02 17:37:03 +02:00
Newbyte
b07fb4b24f
pmb.build._package: Move comment to docstring (MR 2337)
This explains a parameter, so let's put it in the right place.
2024-06-24 20:23:01 +02:00
Newbyte
ca6d0eba28
pmb.build: Properly type cross-compilation types (MR 2337) 2024-06-24 20:23:01 +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
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
ceaad5c291
build: move run_abuild and friends to a new file (MR 2252)
_package.py was getting pretty big. split the actual build steps out.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:42 +02:00
Caleb Connolly
0857f1aa4e
build: package: improve logging (MR 2252)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:42 +02:00
Caleb Connolly
4a52f46bf0
build: fail if remote checksums mismatch (MR 2252)
This is a potential security risk. Tighten things up so we only allow
local checksums to mismatch but remote ones must be correct.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:42 +02:00
Caleb Connolly
2babb61778
build: package: support incremental builds with --src (MR 2252)
Avoid deleting build artifacts when building with --src.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:42 +02:00
Caleb Connolly
91d29a1b2a
build: package: don't copy files that are in .gitignore (MR 2252)
This avoids copying local build artifacts and other things, if they're
in .gitignore then abuild shouldn't need them anyway.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:42 +02:00
Caleb Connolly
19a54ee0d6
build: package: fix --src (MR 2252)
Make sure rsync is actually installed.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:41 +02:00
Caleb Connolly
7d85bb31d5
build: ignore invalid checksums unless --strict (MR 2252)
We can fairly easily patch abuild by appending anything we want to the
APKBUILD file after copying it to the chroot.

Leverage this to override the verify() function so that it doesn't die
when checksums don't match.

Instead let's build the package anyway, but set a flag and print a
warning with instructions on how to generate the checksums.

We should continue to require APKBUILDs in pmaports to have valid
checksums.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:41 +02:00
Caleb Connolly
77f66eb43d
build: package: more dependency resolution fixes (MR 2252)
It was the case that packages were being queued in the wrong order,
since the dependency resolver queues the package before descending into
it's dependencies. This was a bit of a goof since the top level package
was always added last. If we add it first then we can just reverse the
queue and now everything is fine...

Additionally, the logic on when a dependency should be built was a bit
wonky. A case is added for when a dependency exists only in the source
repo and the requisite package isn't marked for build. The solver will
now build the dependency regardless. This is surely an edgecase but
somehow I ran into it, I suspect due to a bug elsewhere...

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:41 +02:00
Caleb Connolly
7f258516db
build: package: fix cache (MR 2252)
Big blunder lol, now it actually caches...

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:41 +02:00
Caleb Connolly
f2ca9c618e
ruff: run check --fix (MR 2252)
Get rid of unused imports and such

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:41 +02:00
Caleb Connolly
6087a9df8f
core: don't re-export get_context (MR 2252)
This makes testing a lot more annoying.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:40 +02:00
Caleb Connolly
efce73df2f
build: adjust logging (MR 2252)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:40 +02:00
Caleb Connolly
6857882cf0
build: finish builder rework (MR 2252)
Rename build.package() to build.packages() and take a list of packages
to build, since every caller was inside a for loop this simplifies
usage and let's us give nicer log output by doing all the builds first,
so log messages don't get lost in the middle.

Behaviour is cleaned up so this shouuuuld work pretty well now. It
properly descends into dependencies and will build dependencies even if
the package given doesn't need building. Technically this was only done
before during install where the dependencies were recursed in
chroot.apk.install().

It probably makes the most sense to have a mode where it doesn't build
dependencies but warns the user about it, at least when invoked via
pmbootstrap build.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:39 +02:00
Caleb Connolly
3ad4ba2818
WIP: build: rewrite package builder (MR 2252)
The package builder has long been a pain point since it recurses the
entire dependency tree.

Convert it to run in two stages, first it walks through the package
dependencies, descending into each one and processing them in a queue.
If a package is determined to need building then it gets pushed onto the
build_queue.

Then, it pops each package off the build queue (which is actually a
stack..) and builds it.

This avoids recursion entirely and should open the door to optimisations
in the future.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:39 +02:00
Caleb Connolly
b447c20545
build: fix arch formatting in check_build_for_arch (MR 2252)
Use f-strings so it's actually converted.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:39 +02:00
Caleb Connolly
a99ae02068
build: slightly less verbose logging (MR 2252)
Don't log about cached packages or on every call to package().

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:39 +02:00
Caleb Connolly
866e5bcfab
core: add an Arch type (MR 2252)
Move pmb/parse/arch.py over to core and refactor it as an Arch type,
similar to how Chroot was done. Fix all the uses (that I can find) of
arch in the codebase that need adjusting.

The new Arch type is an Enum, making it clear what architectures can be
represented and making it much easier to reason about. Since we support
~5 (kinda) different representations of an Architecture (Alpine, Kernel,
target triple, platform, and QEMU), we now formalise that the Alpine
format is what we represent internally, with methods to convert to any
of the others as-needed.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:39 +02:00
Caleb Connolly
b43724fee4
build: multiple binary repos (MR 2252)
Use a different binary repo depending on the source repository for the
package. This makes it possible to split out systemd packages into their
own repository.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:39 +02:00
Caleb Connolly
560cea46ea
treewide: migrate to pkgrepo API (MR 2252)
Make use of the new pmb.core.pkgrepo API to handle multiple aports and
extra-repos.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:39 +02:00