1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-13 11:29:46 +03:00
pmbootstrap/pmb/core/context.py
Casey Connolly 9f8edf539d treewide: split chroots from workdir
Introduce a new "cache" subdirectory in the pmbootstrap workdir, all the
cache and config bits go in here, anything that needs to be accessible
from inside a chroot. The whole dir is then bind-mounted into the chroot
as /cache with appropriate symlinks.

This dir is in the config as config.cache.

In addition, all the cache_* and other config dirs are renamed to
be closer to the names of the equivalent dirs in the chroot (e.g.
abuild-config) and to avoid redundant naming since they are now under a
"cache" dir.

Signed-off-by: Casey Connolly <kcxt@postmarketos.org>
2025-07-11 19:36:23 +02:00

77 lines
1.7 KiB
Python

# Copyright 2024 Caleb Connolly
# SPDX-License-Identifier: GPL-3.0-or-later
"""Global runtime context"""
from pathlib import Path
from typing import overload, Literal
from .config import Config
class Context:
details_to_stdout: bool = False
quiet: bool = False
command_timeout: float = 900
force: bool = False
log: Path
# assume yes to prompts
assume_yes: bool = False
# Operate offline
offline: bool = False
# 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
# Disk image sector size (not filesystem block size!)
sector_size: int | None = None
config: Config
def __init__(self, config: Config):
self.log = config.cache / "log.txt"
self.config = config
__context: Context
@overload
def get_context(allow_failure: Literal[False] = ...) -> Context: ...
@overload
def get_context(allow_failure: Literal[True] = ...) -> Context | None: ...
def get_context(allow_failure: bool = False) -> Context | None:
"""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) -> None:
"""Set global runtime context."""
global __context
if "__context" in globals():
raise RuntimeError("Context already loaded")
__context = context