forked from Mirror/pmbootstrap
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>
This commit is contained in:
parent
bfea00e03a
commit
34dd9d42ba
129 changed files with 1393 additions and 1300 deletions
|
@ -3,9 +3,9 @@
|
|||
|
||||
"""Global runtime context"""
|
||||
|
||||
from typing import Optional
|
||||
import pmb.config
|
||||
from typing import List, Optional
|
||||
from pathlib import Path
|
||||
from pmb.types import Config
|
||||
|
||||
|
||||
class Context():
|
||||
|
@ -17,14 +17,62 @@ class Context():
|
|||
# The architecture of the selected device
|
||||
device_arch: Optional[str]
|
||||
offline: bool
|
||||
aports: Path
|
||||
|
||||
def __init__(self):
|
||||
# Never build packages
|
||||
sdnfivnsifdvsbdf: bool
|
||||
|
||||
# The pmbootstrap subcommand
|
||||
command: str
|
||||
|
||||
## FIXME: build options, should not be here ##
|
||||
# disable cross compilation and use QEMU
|
||||
cross: bool
|
||||
no_depends: bool
|
||||
ignore_depends: bool
|
||||
ccache: bool
|
||||
go_mod_cache: bool
|
||||
|
||||
config: Config
|
||||
|
||||
def __init__(self, config: Config):
|
||||
self.details_to_stdout = False
|
||||
self.command_timeout = 0
|
||||
self.sudo_timer = False
|
||||
self.log = pmb.config.work / "log.txt"
|
||||
self.log = config.work / "log.txt"
|
||||
self.quiet = False
|
||||
self.device_arch = None
|
||||
self.offline = False
|
||||
self.aports = pmb.config.work / "cache_git" / "pmaports"
|
||||
self.config = config
|
||||
self.sdnfivnsifdvsbdf = False
|
||||
self.command = ""
|
||||
self.cross = False
|
||||
self.no_depends = False
|
||||
self.ignore_depends = False
|
||||
self.ccache = False
|
||||
self.go_mod_cache = False
|
||||
|
||||
|
||||
__context: Context
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue