Commit graph

155 commits

Author SHA1 Message Date
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
Caleb Connolly
34dd9d42ba
WIP: start ripping out args (MR 2252)
Cease merging pmbootstrap.cfg into args, implement a Context type to let
us pull globals out of thin air (as an intermediate workaround) and rip
args out of a lot of the codebase.

This is just a first pass, after this we can split all the state that
leaked over into Context into types with narrower scopes (like a
BuildContext(), etc).

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:38 +02:00
Caleb Connolly
e547bb7f9c
helpers: mount: drop args (MR 2252)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:38 +02:00
Caleb Connolly
2e68f40dd4
pmb.chroot: install() make chroot a required argument (MR 2252)
Defaulting to the native chroot isn't necessarily intuitive. Let's
require this be specified in full.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:37 +02:00
Caleb Connolly
71e7af57e6
pmb.helpers.logging: wrap logging module (MR 2252)
We use a custom verbose log level in pmbootstrap, unfortunately it isn't
possible to correctly type this due to some limitations in the logging
library [1], [2].

Given that our usecase is fairly simple, we can just wrap the module
with our own so we only have to tell mypy to ignore the error once
instead of at every callsite.

[1]: https://github.com/cryptax/droidlysis/issues/15
[2]: https://github.com/python/typing/discussions/980

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:37 +02:00
Caleb Connolly
198f302a36
treewide: add a Chroot type and adopt pathlib.Path (MR 2252)
Introduce a new module: pmb.core to contain explicitly typed pmbootstrap
API. The first component being Suffix and SuffixType. This explicitly
defines what suffixes are possible, future changes should aim to further
constrain this API (e.g. by validating against available device
codenames or architectures for buildroot suffixes).

Additionally, migrate the entire codebase over to using pathlib.Path.
This is a relatively new part of the Python standard library that uses a
more object oriented model for path handling. It also uses strong type
hinting and has other features that make it much cleaner and easier to
work with than pure f-strings. The Chroot class overloads the "/"
operator the same way the Path object does, allowing one to write paths
relative to a given chroot as:

builddir = chroot / "home/pmos/build"

The Chroot class also has a string representation ("native", or
"rootfs_valve-jupiter"), and a .path property for directly accessing the
absolute path (as a Path object).

The general idea here is to encapsulate common patterns into type hinted
code, and gradually reduce the amount of assumptions made around the
codebase so that future changes are easier to implement.

As the chroot suffixes are now part of the Chroot class, we also
implement validation for them, this encodes the rules on suffix naming
and will cause a runtime exception if a suffix doesn't follow the rules.
2024-06-23 12:38:37 +02:00
Robert Eckelmann
044d3b5a6a
pmb.*: various comment reformatting to assist with generating docs (MR 2266) 2024-05-14 14:36:22 +02:00
Oliver Smith
db163aded6
Print ERROR: infront of {NonBug,BuildFailed}Error (MR 2298)
Make the handling of the custom NonBugError and BuildFailedError
exceptions more consistent with the handling of other exceptions, by
printing "ERROR: " infront of the actual error text. Then we don't need
to duplicate that where we raise the errors. pmbootstrap prints "ERROR"
in red.
2024-04-16 19:41:13 +00:00
Clayton Craft
ca844038f1
Revert "pmb.build._package: build depends of subpackages (MR 2292)"
This patch caused a regression[1] that needs to be debugged/fixed, so
reverting in the meantime.

This reverts commit 8b0dfe489a.

1. https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2341
2024-04-15 23:31:14 -07:00
Oliver Smith
8b0dfe489a
pmb.build._package: build depends of subpackages (MR 2292)
Make sure that we build depends of subpackages, to avoid errors like the
following:

* postmarketos-base has a subpackage postmarketos-base-nftables, which
  depends on postmarketos-config-nftables
* when pmbootstrap builds postmarketos-base with all its dependencies,
  it did not realize it depends on postmarketos-config-nftables through
  the subpackage, but it built it anyway
* when trying to install postmarketos-base-nftables, apk complains that
  there is no postmarketos-config-nftables:
  ERROR: unable to select packages:
    postmarketos-config-nftables (no such package):
      required by: postmarketos-base-nftables-32-r2[postmarketos-config-nftables]

This also adds the missing depenendencies to "pmbootstrap repo_missing",
which bpo uses to resolve dependencies.

Fixes: issue 2084
2024-04-12 14:03:15 +02:00
Newbyte
d5badd1b0e
pmb.build._package: Raise BuildFailedError when build fails (MR 2288)
This allows us to differentiate between the build failing and any other
runtime error that may be raised from calling this function.
2024-04-10 20:49:21 +00:00
Oliver Smith
fafd4e7304
Add "pmbootstrap repo_bootstrap" (MR 2273)
Related: https://postmarketos.org/pmaports.cfg bootstrap_1 etc.
2024-03-12 23:53:47 +00:00
Caleb Connolly
384c843a25
pmb.build: ensure all specified packages are built with --force (MR 2244)
When running build --force, if a later package is a dependency of an
earlier package, it will be "visited" by the dependency resolver,
erroneously causing it to be skipped when later in the session it's
visited to force build. This is because previously visited packages are
marked as such in a hashmap, but skip_already_built() assumes that a
package which has been visited would have already been built.

Fix this by overriding skip_already_built() if doing a force build. This
works because package dependencies are only built if the APKBUILD
version is newer than the binary repo, even when --force is specified.
So there is no risk of an infinite loop here.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-02-06 18:07:07 +00:00
Oliver Smith
6a77991bb7
pkg resolve: add more verbose logs
Make debugging easier with more logs in e.g.
$ pmbootstrap --verbose install

Reviewed-By: Clayton (via chat)
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20231121213640.2237-1-ollieparanoid@postmarketos.org%3E
2023-11-26 11:02:07 +01:00
Oliver Smith
147a0f5c4d
build: use sccache for rust
Cache the compiler output of rust code with sccache, like we use ccache
for c code.

I've considered using sccache to completely replace ccache since it can
cache output of C/C++ code too. But let's not do it for now since ccache
doesn't need to run a daemon in the background that needs to be stopped
when shutting down / zapping. Also it would need more refactoring.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230806184729.4891-5-ollieparanoid@postmarketos.org%3E
2023-08-14 09:52:22 +02:00
Oliver Smith
fdbb8eebb8
chroot: /mnt/pmbootstrap-* -> /mnt/pmbootstrap/*
Have one /mnt/pmbootstrap directory with subdirectories, instead of
several /mnt/pmbootstrap-* directories.

Reviewed-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230806184729.4891-2-ollieparanoid@postmarketos.org%3E
2023-08-14 09:52:17 +02:00
Oliver Smith
185973fd97
Remove distcc support
With this code path, pmbootstrap would start a distccd + sshd in the
native chroot, and configure it so it runs the cross compiler. The
foreign arch chroots would then call this cross compiler from localhost
by calling the distcc client instead of gcc.

This code has been obsoleted by the much simpler crossdirect in 2019.
Let's finally remove it.

Fixes: issue 2179
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230613161437.570196-4-ollieparanoid@postmarketos.org%3E
2023-06-15 08:31:03 +02:00
Oliver Smith
7f5c87e5dd
Remove workaround for gcc with !tracedeps
Get rid of a workaround that isn't needed anymore. Also this makes use
of the get_gcc_version() function that is otherwise only needed for
the long obsolete distcc code, which I'm about to remove in the next
patch.

Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230613161437.570196-2-ollieparanoid@postmarketos.org%3E
2023-06-15 08:31:03 +02:00
Oliver Smith
a0cea6255a
pmb.config: mount go caching directories
Always set GOCACHE during build and let it point to pmbootstrap's work
dir. This has a similar effect as using ccache for C/C++.

Set GOMODCACHE conditionally: this is for caching the go modules (git
repositories) that get cloned during a build if they are not bundled
with the source. Usually APKBUILDs should cache them, but when using
pmbootstrap build --src, they would get downloaded over and over again.
Set GOMODCACHE automatically for --src and allow enabling/disabling this
manually with new --go-mod-cache / --no-go-mod-cache.

This speeds up multiple iterations of building the same package
significantly. I'm using it for:

$ pmbootstrap build postmarketos-mkinitfs --src=...

I've verified that using the same GOCACHE dir for multiple architectures
doesn't result in build artifacts for the wrong arch getting used.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230223064743.1773-1-ollieparanoid@postmarketos.org%3E
2023-02-26 19:37:30 +01:00
Oliver Smith
9975d373b0
Bump copyright to 2023 2023-01-22 19:18:06 +01:00
Oliver Smith
f41659d4ae
pmb.build._package: update isl workaround (MR 2213)
The plan was to drop this workaround, once alpine releases a new gcc
version, and we regenerate our cross compilers against that version
_and_ drop options="!tracedeps", as latest pmbootstrap aportgen would
do. However !tracedeps wasn't dropped in the latest upgrade. This was
too easy to miss, I'll add a comment to the gcc-cross APKBUILDs so we
see it next time. Let's just update the workaround for this version.
2022-10-16 18:02:26 +02:00