forked from Mirror/pmbootstrap
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>
This commit is contained in:
parent
505165dc13
commit
866e5bcfab
42 changed files with 389 additions and 303 deletions
|
@ -4,6 +4,7 @@ import copy
|
|||
from pathlib import Path
|
||||
from typing import Dict, Optional
|
||||
from pmb.core import get_context
|
||||
from pmb.core.arch import Arch
|
||||
from pmb.helpers import logging
|
||||
import os
|
||||
import pmb.config
|
||||
|
@ -97,7 +98,7 @@ class Deviceinfo:
|
|||
codename: str
|
||||
year: str
|
||||
dtb: str
|
||||
arch: str
|
||||
arch: Arch
|
||||
|
||||
# device
|
||||
chassis: str
|
||||
|
@ -222,10 +223,10 @@ class Deviceinfo:
|
|||
if "arch" not in info or not info["arch"]:
|
||||
raise RuntimeError(f"Please add 'deviceinfo_arch' to: {path}")
|
||||
|
||||
arch = info["arch"]
|
||||
if (arch != pmb.config.arch_native and
|
||||
arch not in pmb.config.build_device_architectures):
|
||||
raise ValueError("Arch '" + arch + "' is not available in"
|
||||
arch = Arch.from_str(info["arch"])
|
||||
if (not arch.is_native() and
|
||||
arch not in Arch.supported()):
|
||||
raise ValueError(f"Arch '{arch}' is not available in"
|
||||
" postmarketOS. If you would like to add it, see:"
|
||||
" <https://postmarketos.org/newarch>")
|
||||
|
||||
|
@ -257,7 +258,10 @@ class Deviceinfo:
|
|||
# FIXME: something to turn on and fix in the future
|
||||
# if key not in Deviceinfo.__annotations__.keys():
|
||||
# logging.warning(f"deviceinfo: {key} is not a known attribute")
|
||||
setattr(self, key, value)
|
||||
if key == "arch":
|
||||
setattr(self, key, Arch(value))
|
||||
else:
|
||||
setattr(self, key, value)
|
||||
|
||||
if not self.flash_method:
|
||||
self.flash_method = "none"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue