mirror of
https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git
synced 2025-07-13 11:29:46 +03:00
core: pkgrepo: support arbitrarily named pmaports directories (MR 2470)
There was an oversight when this API was originally created and it implicitly assumed that the pmaports repository was always named "pmaports". This unfortunately broke some peoples workflows. Introduce a new "pkgrepo_name()" function and adjust the codebase to use it, as well as adjusting pkgrepo internally to special case the "pmaports" repo so that it's always named pmaports no matter what the directory itself is named. This is probably more complexity than we should be dealing with here, we should probably create a new type to encode this behaviour. Fixes: #2412 Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
parent
70dc855281
commit
a72a60f546
5 changed files with 49 additions and 15 deletions
|
@ -1,6 +1,6 @@
|
||||||
import enum
|
import enum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pmb.core.pkgrepo import pkgrepo_paths
|
from pmb.core.pkgrepo import pkgrepo_name, pkgrepo_paths
|
||||||
import pmb.helpers.run
|
import pmb.helpers.run
|
||||||
import pmb.chroot
|
import pmb.chroot
|
||||||
|
|
||||||
|
@ -126,10 +126,10 @@ def mount_pmaports(chroot: Chroot = Chroot.native()) -> dict[str, Path]:
|
||||||
"""
|
"""
|
||||||
dest_paths = {}
|
dest_paths = {}
|
||||||
for repo in pkgrepo_paths(skip_extras=True):
|
for repo in pkgrepo_paths(skip_extras=True):
|
||||||
destination = Path("/mnt") / repo.name
|
destination = Path("/mnt") / pkgrepo_name(repo)
|
||||||
outside_destination = chroot / destination
|
outside_destination = chroot / destination
|
||||||
pmb.helpers.mount.bind(repo, outside_destination, umount=True)
|
pmb.helpers.mount.bind(repo, outside_destination, umount=True)
|
||||||
dest_paths[repo.name] = destination
|
dest_paths[pkgrepo_name(repo)] = destination
|
||||||
|
|
||||||
return dest_paths
|
return dest_paths
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,12 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
import configparser
|
import configparser
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pmb.core.pkgrepo import pkgrepo_default_path, pkgrepo_paths, pkgrepo_relative_path
|
from pmb.core.pkgrepo import (
|
||||||
|
pkgrepo_default_path,
|
||||||
|
pkgrepo_name,
|
||||||
|
pkgrepo_paths,
|
||||||
|
pkgrepo_relative_path,
|
||||||
|
)
|
||||||
from pmb.helpers import logging
|
from pmb.helpers import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -97,7 +102,7 @@ def read_config(aports: Path | None = None) -> dict[str, Any]:
|
||||||
if aports is None:
|
if aports is None:
|
||||||
aports = pkgrepo_paths()[0]
|
aports = pkgrepo_paths()[0]
|
||||||
|
|
||||||
systemd = aports.name == "systemd"
|
systemd = pkgrepo_name(aports) == "systemd"
|
||||||
# extra-repos don't have a pmaports.cfg
|
# extra-repos don't have a pmaports.cfg
|
||||||
# so jump up the main aports dir
|
# so jump up the main aports dir
|
||||||
if "extra-repos" in aports.parts:
|
if "extra-repos" in aports.parts:
|
||||||
|
|
|
@ -28,21 +28,42 @@ def pkgrepo_paths(skip_extras: bool = False) -> list[Path]:
|
||||||
return out_paths
|
return out_paths
|
||||||
|
|
||||||
|
|
||||||
|
@Cache()
|
||||||
def pkgrepo_default_path() -> Path:
|
def pkgrepo_default_path() -> Path:
|
||||||
return pkgrepo_paths(skip_extras=True)[0]
|
return pkgrepo_paths(skip_extras=True)[0]
|
||||||
|
|
||||||
|
|
||||||
def pkgrepo_names(skip_exras: bool = False) -> list[str]:
|
def pkgrepo_names(skip_exras: bool = False) -> list[str]:
|
||||||
"""
|
"""
|
||||||
Return a list of all the package repository names.
|
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.
|
||||||
"""
|
"""
|
||||||
return [aports.name for aports in pkgrepo_paths(skip_exras)]
|
names = [aports.name for aports in pkgrepo_paths(skip_exras)]
|
||||||
|
names[-1] = "pmaports"
|
||||||
|
return names
|
||||||
|
|
||||||
|
|
||||||
|
def pkgrepo_name(path: Path) -> str:
|
||||||
|
"""
|
||||||
|
Return the name of the package repository with the given path. This
|
||||||
|
MUST be used instead of "path.name" as we need special handling
|
||||||
|
for the pmaports repository.
|
||||||
|
"""
|
||||||
|
if path == get_context().config.aports[-1]:
|
||||||
|
return "pmaports"
|
||||||
|
|
||||||
|
return path.name
|
||||||
|
|
||||||
|
|
||||||
def pkgrepo_path(name: str) -> Path:
|
def pkgrepo_path(name: str) -> Path:
|
||||||
"""
|
"""
|
||||||
Return the absolute path to the package repository with the given name.
|
Return the absolute path to the package repository with the given name.
|
||||||
"""
|
"""
|
||||||
|
# The pmaports repo is always last, and we hardcode the name.
|
||||||
|
if name == "pmaports":
|
||||||
|
return get_context().config.aports[-1]
|
||||||
|
|
||||||
for aports in pkgrepo_paths():
|
for aports in pkgrepo_paths():
|
||||||
if aports.name == name:
|
if aports.name == name:
|
||||||
return aports
|
return aports
|
||||||
|
@ -56,7 +77,7 @@ def pkgrepo_name_from_subdir(subdir: Path) -> str:
|
||||||
"""
|
"""
|
||||||
for aports in pkgrepo_paths():
|
for aports in pkgrepo_paths():
|
||||||
if subdir.is_relative_to(aports):
|
if subdir.is_relative_to(aports):
|
||||||
return aports.name
|
return pkgrepo_name(aports)
|
||||||
raise RuntimeError(f"aports subdir '{subdir}' not found")
|
raise RuntimeError(f"aports subdir '{subdir}' not found")
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,14 +126,14 @@ def pkgrepo_iter_package_dirs(skip_extra_repos: bool = False) -> Generator[Path,
|
||||||
if "extra-repos" not in repo.parts and "extra-repos" in pdir.parts:
|
if "extra-repos" not in repo.parts and "extra-repos" in pdir.parts:
|
||||||
continue
|
continue
|
||||||
pkg = os.path.basename(pdir)
|
pkg = os.path.basename(pdir)
|
||||||
if pkg in seen[repo.name]:
|
if pkg in seen[pkgrepo_name(repo)]:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"Package {pkg} found in multiple aports "
|
f"Package {pkg} found in multiple aports "
|
||||||
"subfolders. Please put it only in one folder."
|
"subfolders. Please put it only in one folder."
|
||||||
)
|
)
|
||||||
if pkg in [x for li in seen.values() for x in li]:
|
if pkg in [x for li in seen.values() for x in li]:
|
||||||
continue
|
continue
|
||||||
seen[repo.name].append(pkg)
|
seen[pkgrepo_name(repo)].append(pkg)
|
||||||
yield pdir
|
yield pdir
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ from enum import Enum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Final
|
from typing import Final
|
||||||
from pmb.core.context import get_context
|
from pmb.core.context import get_context
|
||||||
from pmb.core.pkgrepo import pkgrepo_default_path, pkgrepo_path
|
from pmb.core.pkgrepo import pkgrepo_default_path, pkgrepo_path, pkgrepo_name
|
||||||
from pmb.helpers import logging
|
from pmb.helpers import logging
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
@ -107,7 +107,10 @@ def get_upstream_remote(aports: Path) -> str:
|
||||||
|
|
||||||
Usually "origin", but the user may have set up their git repository differently.
|
Usually "origin", but the user may have set up their git repository differently.
|
||||||
"""
|
"""
|
||||||
name_repo = aports.parts[-1]
|
name_repo = pkgrepo_name(aports)
|
||||||
|
if name_repo not in pmb.config.git_repos:
|
||||||
|
logging.warning(f"WARNING: can't determine remote for {name_repo}, using 'origin'")
|
||||||
|
return "origin"
|
||||||
urls = pmb.config.git_repos[name_repo]
|
urls = pmb.config.git_repos[name_repo]
|
||||||
lines = list_remotes(aports)
|
lines = list_remotes(aports)
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
|
|
@ -2,7 +2,12 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from pmb.core.chroot import Chroot
|
from pmb.core.chroot import Chroot
|
||||||
from pmb.core.pkgrepo import pkgrepo_iter_package_dirs, pkgrepo_names, pkgrepo_relative_path
|
from pmb.core.pkgrepo import (
|
||||||
|
pkgrepo_iter_package_dirs,
|
||||||
|
pkgrepo_name,
|
||||||
|
pkgrepo_names,
|
||||||
|
pkgrepo_relative_path,
|
||||||
|
)
|
||||||
from pmb.helpers import logging
|
from pmb.helpers import logging
|
||||||
from pmb.helpers.exceptions import NonBugError
|
from pmb.helpers.exceptions import NonBugError
|
||||||
from pmb.helpers.toml import load_toml_file
|
from pmb.helpers.toml import load_toml_file
|
||||||
|
@ -69,7 +74,7 @@ def check(pkgnames: Sequence[str]) -> None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
repo, relpath = pkgrepo_relative_path(pkgdir)
|
repo, relpath = pkgrepo_relative_path(pkgdir)
|
||||||
apkbuilds[repo.name].append(os.fspath(relpath / "APKBUILD"))
|
apkbuilds[pkgrepo_name(repo)].append(os.fspath(relpath / "APKBUILD"))
|
||||||
found_pkgnames.add(pkgdir.name)
|
found_pkgnames.add(pkgdir.name)
|
||||||
|
|
||||||
# Check we found all the packages in pkgnames
|
# Check we found all the packages in pkgnames
|
||||||
|
@ -94,7 +99,7 @@ def check(pkgnames: Sequence[str]) -> None:
|
||||||
["apkbuild-lint"] + apkbuild_paths,
|
["apkbuild-lint"] + apkbuild_paths,
|
||||||
check=False,
|
check=False,
|
||||||
output="stdout",
|
output="stdout",
|
||||||
working_dir=dest_paths[repo.name],
|
working_dir=dest_paths[pkgrepo_name(repo)],
|
||||||
env={"CUSTOM_VALID_OPTIONS": " ".join(get_custom_valid_options())},
|
env={"CUSTOM_VALID_OPTIONS": " ".join(get_custom_valid_options())},
|
||||||
):
|
):
|
||||||
has_failed = True
|
has_failed = True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue