Commit graph

69 commits

Author SHA1 Message Date
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
5ed5817e80
pmb: Add more type hints (MR 2490) 2024-12-19 10:09:22 +00:00
Newbyte
df2593400d
pmb.parse.kconfig: Rename options to arch_options in check_config_options_set (MR 2490)
Otherwise mypy gets confused by the type later in the code, and I also
think it might be confusing behaviour in general that <options> gets
overwritten in this loop.
2024-12-19 10:09:22 +00:00
Newbyte
b2d32a85e9
pmb.parse.kconfig.check_config_options_set: Update docstring (MR 2490)
The mentioned variable no longer exists, so update it to reflect how
things work now.
2024-12-19 10:09:22 +00:00
Newbyte
225d8b30a0
pmb: Add lots of type hints (MR 2464) 2024-10-30 12:39:45 +01:00
Oliver Smith
479bad049f
kconfig check: don't print URL for each warning (MR 2399)
Instead of printing an URL with each warning, print one once at the
end. This gives less cluttered output, and we don't have information
about each and every option on that wiki page anyway (and given that we
now have so many options, I don't think it's good use of time to add it
there.)
2024-09-08 00:09:16 +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
65d23905bc
treewide: another round of mypy fixes (MR 2344)
Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-07-08 16:01:13 +02:00
Oliver Smith
1dfaafe577
kconfig check: move rules to kconfigcheck.toml (MR 2333)
Move all kconfig rules from pmb.config to a separate toml file
pmb/data/kconfigcheck.toml. This is a fallback, pmbootstrap now prefers
loading kconfigcheck.toml from the currently checked out pmaports branch
if it exists.

This finally allows having separate kconfig check rules per pmaports
branch and makes the workflow of adjusting these rules much more
pleasant as the rules and kernel configs can just be adjusted at the
same time in pmaports!

This patch also moves the definition of what rules should be checked for
community and main devices, those that have pmb:kconfigcheck-community
in their linux APKBUILD, to the new kconfigcheck.toml. This should make
it much more intuitive, previously one needed to find the place in the
pmbootstrap source and edit it there.

Furthermore the "enforce_check" logic is removed. Previously pmbootstrap
would print warnings for failed config checks in some cases, but not
exit with error which was very confusing. Now exit 0 means all checks
passed and exit 1 means, that there is at least one error.

Use toml for the file, as discussed in pmbootstrap issue 2165. Python
3.11 has a native toml reader, use tomli for previous Python versions
for compatibility.
2024-06-30 18:04:31 +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
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
de4c912692
WIP: 2024-06-05: args hacking and more (MR 2252)
Continue removing args and do some other optimisations.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
2024-06-23 12:38:38 +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
31cc898dd5
treewide: adopt pathlib.Path and type hinting (MR 2252)
With the new chroot type, we can now write fancy paths in the pythonic
way. Convert most of the codebase over, as well as adding various other
type hints.

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
Newbyte
ced93fee7b
pmb.parse.kconfig: Raise NonBugError on invalid kernel config (MR 2279)
The intent of 9a74848f19 was to not print
a stacktrace when this happened. However, I still opted to raise an
exception, so you still get a stacktrace, just with a more helpful
message. There's no need to give the user a big stacktrace here, so
raise a NonBugError instead of a RuntimeError.
2024-03-27 21:50:28 +01:00
Luca Weiss
d200414d87
kconfig check: Add USB gadget check to community
Make sure that we disable legacy gadgets like USB_ETH. Our initramfs
uses configfs gadgets instead, currently RNDIS for USB networking.

In the future this can be expanded to more options like mass storage,
MIDI or whatever we're going to integrate into the OS that can be
configured by the user.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230423163438.746054-1-luca@z3ntu.xyz%3E
2023-05-02 08:38:04 +02:00
Oliver Smith
89cbae6d31
pmb.parse.kconfig.check: fix writing to list arg
Python passes all arguments by reference. For mutable objects such as
a list used here, changing the object will change the original one. If
components_list is not set, this means the default value gets modified.

This lead to kernels getting checked with the wrong required components.
For example, when checking a kernel from community first with the
default component_list, it would get extended with all options needed
for a kernel in community. When checking another kernel from the
testing category, also with the default component_list, it would now
check for the community options in the testing kernel.

Related: https://stackoverflow.com/a/986145
Reviewed-by: Luca Weiss <luca@z3ntu.xyz>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230402124338.64886-1-ollieparanoid@postmarketos.org%3E
2023-04-05 08:53:05 +02:00
Oliver Smith
3b1ec76395
kconfig check: extract_arch: support riscv64
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-12-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith
905ccbb840
kconfig check: extract_version: replace - with _
Replace the dash in rc kernels with an underscore, so the resulting
version of e.g. 6.1.0-rc3 becomes a valid alpine pkgver (6.1.0_rc3).
This is needed so pmbootstrap can properly parse and compare the
version.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-11-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith
f393bbdab1
kconfig check: less errors for non-detailed mode
Don't print more than one non-detailed error per component, as it
results in the same message. Adjust the description of the details
parameter to reflect this.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-10-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith
9bbb1c11fc
kconfig check: add descriptions to more functions
Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-8-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith
23014ef76f
kconfig check: move check_config_options_set up
In this file and throughout most of the rest of the pmbootstrap code,
functions that get called by other functions are defined on top of them
if they are in the same file. check_config_options_set gets called by
check_config, so put it above.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-7-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith
fd1b4e5d19
kconfig check: drop "necessary_"
Rename necessary_kconfig_options_* variables to kconfig_options_*. It's
clear that these are necessary to pass the check, so let's shorten them.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-6-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:47 +01:00
Oliver Smith
a568cf4520
kconfig check: config_file -> config_path
Rename config_file to config_path for consistency with the rest of the
file. Both are used to point to the full path of the config file.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-5-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:46 +01:00
Oliver Smith
1a124ec2b6
kconfig check: remove redundant component lists
Components are the sets of kernel config options in
pmb/config/__init__.py, such as the ones for waydroid, nftables, etc.

Generate the list of components dynamically and refactor the code, so we
can add/remove components in just one place.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-4-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:46 +01:00
Oliver Smith
d14dbd49de
pmb.parse.kconfig: remove config_path_pretty
Don't set the config_path_pretty variable and pass it through various
functions until it ends up being used in check_option. This was just the
directory name of the kernel config and the kernel config filename (or
in case of pmbootstrap kconfig check --file, just the same as the
config path).

Instead we can just print the filename of the kernel config, for example
"config-postmarketos-qcom-sdm845.aarch64". It is shorter and already
obvious to which package it belongs.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-3-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:46 +01:00
Oliver Smith
dbe13fa812
pmb.parse.kconfig.check_option: refactor
Deduplicate the code for printing warnings and tweak it slightly:
* Shorten ".See <$url> for details." to ": $url".
* Include the component in the detailed output too.

Reviewed-by: Clayton Craft <clayton@craftyguy.net>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20230312151325.1968-2-ollieparanoid@postmarketos.org%3E
2023-03-24 09:11:41 +01:00
Oliver Smith
9975d373b0
Bump copyright to 2023 2023-01-22 19:18:06 +01:00
Luca Weiss
4a6c5657d5
pmb.parse.kconfig: don't enforce non-core checks for testing devices
Currently when any device does not conform to the options they declare,
we fail the whole kconfig check.

Now that we start requiring more options, especially with
pmb:kconfigcheck-community it makes sense to relax these restrictions so
we're more free to edit kconfig options and don't have to adjust all
testing devices that may or may not be properly maintained.

As a side effect this patch makes it practically impossible to make
kconfig check actually fail for any testing device which might not be
optimal. If these use cases appear in the future we will want to adjust
pmbootstrap to allow for that.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221105074432.13804-2-luca@z3ntu.xyz%3E
2022-11-12 14:28:41 +01:00
Luca Weiss
381a1ca907
pmb.parse.kconfig: add wireguard, filesystems & more to community check
Add wireguard options, supported file systems and some extra options to
the community kconfig check.

Reviewed-by: Oliver Smith <ollieparanoid@postmarketos.org>
Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221105074432.13804-1-luca@z3ntu.xyz%3E
2022-11-12 14:28:40 +01:00
Luca Weiss
f7fb1fe078
pmb.parse.kconfig: rename anbox check to waydroid (MR 2204)
Change the naming to fit what software is actually used in postmarketOS.
2022-09-13 09:30:23 +02:00
Luca Weiss
e468fc518e
pmb.parse.kconfig: add 'community' option (MR 2204)
Add the new option that will be mandatory for all devices in
community/main category. This is just a combination of anbox + iwd +
nftables + containers + zram + netboot.

While the existing options could be removed we're keeping it for now
given that also some devices with downstream kernel might find some
options useful.
2022-09-13 09:30:23 +02:00
Luca Weiss
52530caaf8
pmb.parse.kconfig: remove apparmor check (MR 2200)
Remove the check as apparmor is not the way we want to go for privilege
separation anymore.
See https://gitlab.com/postmarketOS/pmaports/-/issues/1596
2022-09-04 19:10:48 +02:00
Minecrell
f1cbcb7b3b
pmb: flasher: frontend: don't fail if kernel config cannot be found (MR 2184)
When using a kernel from Alpine the kernel configuration cannot be
found in pmaports. We cannot check the kernel config for missing
options in that case, but that's no reason to break the flasher
entirely.
2022-06-06 09:52:17 +02:00
Newbyte
9a74848f19
pmb.parse.kconfig: print a helpful error message on invalid kconfig name (MR 2172)
Currently pmbootstrap prints a stacktrace if there's no . in the
kernel configuration name. Let's make it more helpful.
2022-04-02 16:36:17 +02:00
Bart Ribbers
1eef7fbdeb
pmb.parse.kconfig: implement UEFI kconfig check (MR 2169) 2022-03-16 09:25:00 +01:00
Oliver Smith
301f0995fb
pmb.parse.kconfig.check_file: fix broken f-string (MR 2169) 2022-03-16 09:24:55 +01:00
Mark Hargreaves
ff0942b12d
pmbootstrap kconfig check: add netboot check (MR 2064)
Allow checking for the necessary kernel option for netboot.

Co-authored-by: Luca Weiss <luca@z3ntu.xyz>
2022-01-20 22:29:46 +01:00
Oliver Smith
6f6a3b0408
Happy new year 2022! 2022-01-02 22:39:14 +01:00
BO41
99bed38272
pmb.parse.apkbuild: remove unused args argument (MR 2136) 2021-11-27 14:13:33 +01:00
Oliver Smith
6557e6892a
kconfig argcomplete: support full pkgname (MR 2134)
Support full linux-* package names in argument completion for
"pmbootstrap kconfig ..." command-lines and get rid of related PROTIP
messages:
  PROTIP: You can simply do 'pmbootstrap kconfig check postmarketos-allwinner'

This improves consistency, as in other places we expect the user to
supply full package names as well (e.g. pmbootstrap build).
2021-11-06 15:23:37 +01:00
Oliver Smith
aead36d5ac
pmbootstrap kconfig check: add iwd check (MR 2133)
iwd seems like a promising alternative to wpa_supplicant. It uses crypto
implementations from the kernel, so let's make kconfig check aware of
the options it needs.
2021-11-06 14:28:53 +01:00
Oliver Smith
93e7a1d876
pmbootstrap kconfig check: add apparmor check (MR 2133)
SECURITY_APPARMOR_BOOTPARAM_VALUE was required to enable it by default
until 5.1 where the option was removed.

Related: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=0102fb83f90050b86ce37aec810ea17bb4448e0c
Related: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/security/Kconfig?id=fe91c4725aeed35023ba4f7a1e1adfebb6878c23#n285
2021-11-06 14:28:53 +01:00
Oliver Smith
dcedc4bc1f
kconfig check: support strings too (MR 2133)
Extend the kconfig check code to not only support booleans and arrays,
but also strings. This will be used for CONFIG_LSM with apparmor where
it's important that "apparmor" has a certain spot in the list.
2021-11-06 14:28:53 +01:00
Oliver Smith
6b8fa93d37
pmb.parse.kconfig.check: git friendly arguments (MR 2133)
Put each component argument into a separate line, as these get changed
whenever adding a new kernel config check. I'm about to add two new
ones.
2021-11-06 14:28:49 +01:00
bo41
a8d425554c
remove unused args argument (MR 2130) 2021-10-24 14:34:26 +02:00