|
| 1 | +# SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 | + |
| 3 | +from collections.abc import Sequence |
| 4 | +from pathlib import Path |
| 5 | + |
| 6 | +from mkosi.config import Config |
| 7 | +from mkosi.context import Context |
| 8 | +from mkosi.installer import PackageManager |
| 9 | +from mkosi.run import run |
| 10 | +from mkosi.log import die |
| 11 | + |
| 12 | + |
| 13 | +class BST(PackageManager): |
| 14 | + @classmethod |
| 15 | + def executable(cls, config: Config) -> str: |
| 16 | + return "bst" |
| 17 | + |
| 18 | + @classmethod |
| 19 | + def subdir(cls, config: Config) -> Path: |
| 20 | + return Path("bst") |
| 21 | + |
| 22 | + @classmethod |
| 23 | + def architecture(cls, context: Context) -> str: |
| 24 | + return context.config.distribution.installer.architecture(context.config.architecture) |
| 25 | + |
| 26 | + @classmethod |
| 27 | + def setup(cls, context: Context) -> None: |
| 28 | + if len(context.config.packages) > 1: |
| 29 | + die("Only a single element can be specified in Packages= when using bst") |
| 30 | + |
| 31 | + @classmethod |
| 32 | + def install( |
| 33 | + cls, |
| 34 | + context: Context, |
| 35 | + packages: Sequence[str], |
| 36 | + *, |
| 37 | + apivfs: bool = True, |
| 38 | + allow_downgrade: bool = False, |
| 39 | + ) -> None: |
| 40 | + options = [ |
| 41 | + "--same-dir", |
| 42 | + *context.rootoptions(), |
| 43 | + # bst might need to lookup files/paths across the user's home directory so make sure it is |
| 44 | + # available. |
| 45 | + "--bind", Path.home(), Path.home(), |
| 46 | + "--setenv", "HOME", Path.home(), |
| 47 | + ] |
| 48 | + |
| 49 | + # We don't really want to run bst as (fake) root but it uses bubblewrap which stubbornly refuses to |
| 50 | + # run when invoked unprivileged but with capabilities. We get around this by running as fake root but |
| 51 | + # still setting $HOME to the user's home to reuse the buildstream cache directory. |
| 52 | + run( |
| 53 | + ["bst", "build", *packages], |
| 54 | + sandbox=cls.sandbox(context, apivfs=apivfs, options=options), |
| 55 | + env=cls.finalize_environment(context), |
| 56 | + ) |
| 57 | + run( |
| 58 | + ["bst", "artifact", "checkout", "--force", "--directory=/buildroot", *packages], |
| 59 | + sandbox=cls.sandbox(context, apivfs=apivfs, options=options), |
| 60 | + env=cls.finalize_environment(context), |
| 61 | + ) |
| 62 | + |
| 63 | + @classmethod |
| 64 | + def remove(cls, context: Context, packages: Sequence[str]) -> None: |
| 65 | + die("Removing packages is not supported for bst") |
| 66 | + |
| 67 | + @classmethod |
| 68 | + def sync(cls, context: Context, force: bool) -> None: |
| 69 | + pass |
| 70 | + |
| 71 | + @classmethod |
| 72 | + def createrepo(cls, context: Context) -> None: |
| 73 | + die("Creating package repositories is not supported for bst") |
0 commit comments