mirror of
https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git
synced 2025-07-13 11:29:46 +03:00
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>
73 lines
1.7 KiB
Python
73 lines
1.7 KiB
Python
# Copyright 2024 Caleb Connolly
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
"""Global runtime context"""
|
|
|
|
from typing import List, Optional
|
|
from pathlib import Path
|
|
from pmb.core.arch import Arch
|
|
from .config import Config
|
|
|
|
|
|
class Context():
|
|
details_to_stdout: bool = False
|
|
quiet: bool = False
|
|
command_timeout: float = 900
|
|
sudo_timer: bool = False
|
|
force: bool = False
|
|
log: Path
|
|
|
|
# assume yes to prompts
|
|
assume_yes: bool = False
|
|
|
|
# Operate offline
|
|
offline: bool = False
|
|
|
|
# Device we are operating on
|
|
# FIXME: should not be in global context, only
|
|
# specific actions actually depend on this
|
|
device: str = ""
|
|
|
|
# The pmbootstrap subcommand
|
|
command: str = ""
|
|
|
|
## FIXME: build options, should not be here ##
|
|
# disable cross compilation and use QEMU
|
|
cross: bool = False
|
|
no_depends: bool = False
|
|
ignore_depends: bool = False
|
|
ccache: bool = False
|
|
go_mod_cache: bool = False
|
|
|
|
config: Config
|
|
|
|
def __init__(self, config: Config):
|
|
self.log = config.work / "log.txt"
|
|
self.config = config
|
|
|
|
|
|
__context: Context
|
|
|
|
# mypy: disable-error-code="return-value"
|
|
def get_context(allow_failure: bool=False) -> Context:
|
|
"""Get immutable global runtime context."""
|
|
global __context
|
|
|
|
# We must defer this to first call to avoid
|
|
# circular imports.
|
|
if "__context" not in globals():
|
|
if allow_failure:
|
|
return None
|
|
raise RuntimeError("Context not loaded yet")
|
|
return __context
|
|
|
|
def set_context(context: Context):
|
|
"""Set global runtime context."""
|
|
global __context
|
|
|
|
if "__context" in globals():
|
|
raise RuntimeError("Context already loaded")
|
|
|
|
__context = context
|
|
|
|
|