Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • postmarketOS/pmbootstrap
  • fossdd/pmbootstrap
  • Adrian/pmbootstrap
  • JustSoup321/pmbootstrap
  • longnoserob/pmbootstrap
  • sixthkrum/pmbootstrap
  • ollieparanoid/pmbootstrap
  • magdesign/pmbootstrap
  • anjandev/pmbootstrap
  • HenriDellal/pmbootstrap
  • Minecrell/pmbootstrap
  • chipiguay/pmbootstrap
  • ijiki16/pmbootstrap
  • whynothugo/pmbootstrap
  • amessier/pmbootstrap
  • Eisenbahnfan/pmbootstrap
  • user0-07161/pmbootstrap
  • SzczurekYT/pmbootstrap
  • neuschaefer/pmbootstrap
  • knuxify/pmbootstrap
  • Frieder.Hannenheim/pmbootstrap
  • tgirl/pmbootstrap
22 results
Show changes
Commits on Source (13)
......@@ -127,3 +127,5 @@ ENV/
.kdev4/
*.kdev4
*.kate*
/junit.xml
......@@ -142,37 +142,23 @@ def generate_deviceinfo_fastboot_content(bootimg: Bootimg | None = None) -> str:
content = f"""\
deviceinfo_kernel_cmdline="{bootimg["cmdline"]}"
deviceinfo_generate_bootimg="true"
deviceinfo_bootimg_qcdt="{bootimg["qcdt"]}"
deviceinfo_bootimg_dtb_second="{bootimg["dtb_second"]}"
deviceinfo_flash_pagesize="{bootimg["pagesize"]}"
"""
if "qcdt_type" in bootimg.keys():
content += f"""\
deviceinfo_bootimg_qcdt_type="{bootimg["qcdt_type"]}"
"""
if "mtk_label_kernel" in bootimg.keys():
content += f"""\
deviceinfo_mtk_label_kernel="{bootimg["mtk_label_kernel"]}"
"""
if "mtk_label_ramdisk" in bootimg.keys():
content += f"""\
deviceinfo_mtk_label_ramdisk="{bootimg["mtk_label_ramdisk"]}"
"""
for k in ["qcdt_type", "dtb_second", "mtk_label_kernel", "mtk_label_ramdisk", "header_version"]:
v = bootimg[k] # type: ignore
if v:
content += f"""\
deviceinfo_{k}="{v}"
"""
if "header_version" in bootimg.keys():
if bootimg["header_version"] == "2":
content += f"""\
deviceinfo_header_version="{bootimg["header_version"]}"
deviceinfo_append_dtb="false"
deviceinfo_flash_offset_dtb="{bootimg["dtb_offset"]}"
"""
if bootimg["header_version"] == "2":
content += f"""\
deviceinfo_append_dtb="false"
deviceinfo_flash_offset_dtb="{bootimg["dtb_offset"]}"
"""
if "base" in bootimg.keys():
if bootimg["base"]:
content += f"""\
deviceinfo_flash_offset_base="{bootimg["base"]}"
deviceinfo_flash_offset_kernel="{bootimg["kernel_offset"]}"
......
......@@ -355,9 +355,7 @@ def process_package(
" try again"
)
return []
raise RuntimeError(
f"{pkgname}: Could not find aport, and" " could not find this package in any APKINDEX!"
)
raise RuntimeError(f"{pkgname}: Could not find it in pmaports or any APKINDEX!")
if arch is None:
arch = pmb.build.autodetect.arch(base_apkbuild)
......
......@@ -11,13 +11,13 @@ from pmb.meta import Cache
def is_systemd_selected(config: Config) -> bool:
if "systemd" not in pmb.config.pmaports.read_config_repos():
return False
if pmb.helpers.ui.check_option(config.ui, "pmb:systemd-never", skip_extra_repos=True):
if pmb.helpers.ui.check_option(config.ui, "pmb:systemd-never", with_extra_repos="disabled"):
return False
if config.systemd == SystemdConfig.ALWAYS:
return True
if config.systemd == SystemdConfig.NEVER:
return False
return pmb.helpers.ui.check_option(config.ui, "pmb:systemd", skip_extra_repos=True)
return pmb.helpers.ui.check_option(config.ui, "pmb:systemd", with_extra_repos="disabled")
def systemd_selected_str(config: Config) -> tuple[str, str]:
......
......@@ -12,6 +12,9 @@ from pmb.helpers.args import init as init_args
_testdir = Path(__file__).parent / "data/tests"
# request can be specified using parameterize from test cases
# e.g. @pytest.mark.parametrize("config_file", ["no-repos"], indirect=True)
# will set request.param to "no-repos"
@pytest.fixture
def config_file(tmp_path_factory, request):
"""Fixture to create a temporary pmbootstrap_v3.cfg file."""
......
......@@ -6,22 +6,30 @@ from collections.abc import Generator
import pmb.config
from pmb.core.context import get_context
from pmb.meta import Cache
from pmb.types import WithExtraRepos
@Cache(skip_extras=False)
def pkgrepo_paths(skip_extras: bool = False) -> list[Path]:
@Cache("with_extra_repos")
def pkgrepo_paths(with_extra_repos: WithExtraRepos = "default") -> list[Path]:
config = get_context().config
paths = list(map(lambda x: Path(x), config.aports))
if not paths:
raise RuntimeError("No package repositories specified?")
if skip_extras:
return paths
with_systemd = False
match with_extra_repos:
case "disabled":
return paths
case "enabled":
with_systemd = True
case "default":
with_systemd = pmb.config.is_systemd_selected(config)
out_paths = []
for p in paths:
# This isn't very generic, but we don't plan to add new extra-repos...
if (p / "extra-repos/systemd").is_dir() and pmb.config.is_systemd_selected(config):
if (p / "extra-repos/systemd").is_dir() and with_systemd:
out_paths.append(p / "extra-repos/systemd")
out_paths.append(p)
......@@ -30,16 +38,16 @@ def pkgrepo_paths(skip_extras: bool = False) -> list[Path]:
@Cache()
def pkgrepo_default_path() -> Path:
return pkgrepo_paths(skip_extras=True)[0]
return pkgrepo_paths(with_extra_repos="disabled")[0]
def pkgrepo_names(skip_exras: bool = False) -> list[str]:
def pkgrepo_names(with_extra_repos: WithExtraRepos = "default") -> list[str]:
"""
Return a list of all the package repository names. We REQUIRE
that the last repository is "pmaports", though the directory
may be named differently. So we hardcode the name here.
"""
names = [aports.name for aports in pkgrepo_paths(skip_exras)]
names = [aports.name for aports in pkgrepo_paths(with_extra_repos)]
names[-1] = "pmaports"
return names
......@@ -112,14 +120,16 @@ def pkgrepo_iglob(path: str, recursive: bool = False) -> Generator[Path, None, N
yield pdir
def pkgrepo_iter_package_dirs(skip_extra_repos: bool = False) -> Generator[Path, None, None]:
def pkgrepo_iter_package_dirs(
with_extra_repos: WithExtraRepos = "default",
) -> Generator[Path, None, None]:
"""
Yield each matching glob over each aports repository.
Detect duplicates within the same aports repository but otherwise
ignore all but the first. This allows for overriding packages.
"""
seen: dict[str, list[str]] = dict(map(lambda a: (a, []), pkgrepo_names(skip_extra_repos)))
for repo in pkgrepo_paths(skip_extra_repos):
seen: dict[str, list[str]] = dict(map(lambda a: (a, []), pkgrepo_names(with_extra_repos)))
for repo in pkgrepo_paths(with_extra_repos):
for g in glob.iglob(os.path.join(repo, "**/*/APKBUILD"), recursive=True):
pdir = Path(g).parent
# Skip extra-repos when not parsing the extra-repo itself
......
......@@ -19,6 +19,7 @@ def test_pkgrepo_pmaports(pmaports, monkeypatch):
# Disable results caching
pkgrepo_paths.cache_disable()
pkgrepo_default_path.cache_disable()
paths = pkgrepo_paths()
print(f"[master] pkgrepo_paths: {paths}")
......@@ -37,7 +38,10 @@ def test_pkgrepo_pmaports(pmaports, monkeypatch):
== 0
)
paths = pkgrepo_paths()
paths = pkgrepo_paths(with_extra_repos="disabled")
assert len(paths) == 1
paths = pkgrepo_paths(with_extra_repos="enabled")
assert len(paths) == 2
# systemd is the first path, since we want packages there to take priority
......
......@@ -126,10 +126,7 @@ def get(
# Could not find the package
if not must_exist:
return None
raise RuntimeError(
"Package '" + pkgname + "': Could not find aport, and"
" could not find this package in any APKINDEX!"
)
raise RuntimeError(f"Package '{pkgname}': Could not find it in pmaports or any APKINDEX!")
@Cache("pkgname", "arch")
......
......@@ -13,20 +13,16 @@ from pmb.core.pkgrepo import pkgrepo_iter_package_dirs
from pmb.helpers import logging
from pathlib import Path
from typing import Any
from pmb.types import WithExtraRepos
from pmb.meta import Cache
import pmb.parse
def _find_apkbuilds(skip_extra_repos: bool = False) -> dict[str, Path]:
# Try to get a cached result first (we assume that the aports don't change
# in one pmbootstrap call)
apkbuilds = pmb.helpers.other.cache.get("pmb.helpers.pmaports.apkbuilds")
if apkbuilds is not None:
return apkbuilds
@Cache("with_extra_repos")
def _find_apkbuilds(with_extra_repos: WithExtraRepos = "default") -> dict[str, Path]:
apkbuilds = {}
for package in pkgrepo_iter_package_dirs(skip_extra_repos=skip_extra_repos):
for package in pkgrepo_iter_package_dirs(with_extra_repos=with_extra_repos):
pkgname = package.name
if pkgname in apkbuilds:
raise RuntimeError(
......@@ -38,10 +34,6 @@ def _find_apkbuilds(skip_extra_repos: bool = False) -> dict[str, Path]:
# Sort dictionary so we don't need to do it over and over again in
# get_list()
apkbuilds = dict(sorted(apkbuilds.items()))
# Save result in cache
if not skip_extra_repos:
pmb.helpers.other.cache["pmb.helpers.pmaports.apkbuilds"] = apkbuilds
return apkbuilds
......@@ -148,8 +140,21 @@ def _find_package_in_apkbuild(package: str, path: Path) -> bool:
return False
@Cache("package", "subpackages", skip_extra_repos=False)
def find(package, must_exist=True, subpackages=True, skip_extra_repos=False):
def show_pkg_not_found_systemd_hint(package: str, with_extra_repos: WithExtraRepos) -> None:
"""Check if a package would be found if systemd was enabled and display a
hint about it."""
if with_extra_repos != "default" or pmb.config.other.is_systemd_selected():
return
if find(package, False, with_extra_repos="enabled"):
logging.info(
f"NOTE: The package '{package}' exists in extra-repos/systemd, but systemd is currently disabled"
)
@Cache("package", "subpackages", "with_extra_repos")
def find(package, must_exist=True, subpackages=True, with_extra_repos="default"):
"""Find the directory in pmaports that provides a package or subpackage.
If you want the parsed APKBUILD instead, use pmb.helpers.pmaports.get().
......@@ -170,7 +175,7 @@ def find(package, must_exist=True, subpackages=True, skip_extra_repos=False):
raise RuntimeError("Invalid pkgname: " + package)
# Try to find an APKBUILD with the exact pkgname we are looking for
path = _find_apkbuilds(skip_extra_repos).get(package)
path = _find_apkbuilds(with_extra_repos).get(package)
if path:
logging.verbose(f"{package}: found apkbuild: {path}")
ret = path.parent
......@@ -199,7 +204,8 @@ def find(package, must_exist=True, subpackages=True, skip_extra_repos=False):
# Crash when necessary
if ret is None and must_exist:
raise RuntimeError("Could not find aport for package: " + package)
show_pkg_not_found_systemd_hint(package, with_extra_repos)
raise RuntimeError(f"Could not find package '{package}' in pmaports")
return ret
......@@ -212,9 +218,12 @@ def find_optional(package: str) -> Path | None:
# The only caller with subpackages=False is ui.check_option()
@Cache("pkgname", subpackages=True)
@Cache("pkgname", "with_extra_repos", subpackages=True)
def get_with_path(
pkgname: str, must_exist: bool = True, subpackages: bool = True, skip_extra_repos: bool = False
pkgname: str,
must_exist: bool = True,
subpackages: bool = True,
with_extra_repos: WithExtraRepos = "default",
) -> tuple[Path | None, dict[str, Any] | None]:
"""Find and parse an APKBUILD file.
......@@ -225,7 +234,7 @@ def get_with_path(
:param must_exist: raise an exception when it can't be found
:param subpackages: also search for subpackages with the specified
names (slow! might need to parse all APKBUILDs to find it)
:param skip_extra_repos: skip extra repositories (e.g. systemd) when
:param with_extra_repos: use extra repositories (e.g. systemd) when
searching for the package
:returns: relevant variables from the APKBUILD as dictionary, e.g.:
......@@ -237,16 +246,19 @@ def get_with_path(
... }
"""
pkgname = pmb.helpers.package.remove_operators(pkgname)
pmaport = find(pkgname, must_exist, subpackages, skip_extra_repos)
pmaport = find(pkgname, must_exist, subpackages, with_extra_repos)
if pmaport:
return pmaport, pmb.parse.apkbuild(pmaport / "APKBUILD")
return None, None
def get(
pkgname: str, must_exist: bool = True, subpackages: bool = True, skip_extra_repos: bool = False
pkgname: str,
must_exist: bool = True,
subpackages: bool = True,
with_extra_repos: WithExtraRepos = "default",
) -> dict[str, Any]:
return get_with_path(pkgname, must_exist, subpackages, skip_extra_repos)[1]
return get_with_path(pkgname, must_exist, subpackages, with_extra_repos)[1]
def find_providers(provide: str, default: list[str]) -> list[tuple[Any, Any]]:
......
......@@ -2,6 +2,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
import os
from pmb.core.pkgrepo import pkgrepo_iglob
from pmb.types import WithExtraRepos
import pmb.helpers.pmaports
import pmb.helpers.package
import pmb.parse
......@@ -29,7 +30,7 @@ def list_ui(arch):
return ret
def check_option(ui, option, skip_extra_repos=False):
def check_option(ui: str, option: str, with_extra_repos: WithExtraRepos = "default") -> bool:
"""
Check if an option, such as pmb:systemd, is inside an UI's APKBUILD.
"""
......@@ -40,6 +41,6 @@ def check_option(ui, option, skip_extra_repos=False):
pkgname = f"postmarketos-ui-{ui}"
apkbuild = pmb.helpers.pmaports.get(
pkgname, subpackages=False, skip_extra_repos=skip_extra_repos
pkgname, subpackages=False, with_extra_repos=with_extra_repos
)
return option in apkbuild["options"]
......@@ -171,7 +171,7 @@ def bootimg(path: Path) -> Bootimg:
if value is not None
}
)
output["dtb_second"] = "true" if is_dtb(f"{bootimg_path}-second") else "false"
output["dtb_second"] = "true" if is_dtb(f"{bootimg_path}-second") else ""
with open(f"{bootimg_path}-cmdline") as f:
output["cmdline"] = trim_input(f)
......@@ -185,11 +185,11 @@ def bootimg(path: Path) -> Bootimg:
qcdt_type=output.get("qcdt_type"),
dtb_offset=output.get("dtb_offset"),
dtb_second=output["dtb_second"],
base=output["base"],
kernel_offset=output["kernel_offset"],
ramdisk_offset=output["ramdisk_offset"],
second_offset=output["second_offset"],
tags_offset=output["tags_offset"],
base=output.get("base", ""),
kernel_offset=output.get("kernel_offset", ""),
ramdisk_offset=output.get("ramdisk_offset", ""),
second_offset=output.get("second_offset", ""),
tags_offset=output.get("tags_offset", ""),
pagesize=output["pagesize"],
header_version=output.get("header_version"),
mtk_label_kernel=output.get("mtk_label_kernel", ""),
......
......@@ -16,6 +16,7 @@ RunReturnType = str | int | subprocess.Popen
PathString = Path | str
Env = dict[str, PathString]
Apkbuild = dict[str, Any]
WithExtraRepos = Literal["default", "enabled", "disabled"]
# These types are not definitive / API, they exist to describe the current
# state of things so that we can improve our type hinting coverage and make
......