From f37367c57c14159d9f61fb6058257814daa1c047 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Wed, 12 Jul 2017 21:55:47 +0200 Subject: [PATCH] Properly support specifying a local folder as --mirror-pmOS This is required for developing and testing the binary repository scripts (see #64). Changes: * When specified, the local folder gets mounted inside the chroots as /mnt/postmarketos-mirror * The apkindex_files() function outputs the correct path to the local repository (it does *not* hash the URL in that case, which would be wrong) * /etc/apk/repositories: when the pmOS mirror is a local folder, the path "/mnt/postmarketos-mirror" gets added to that file instead of the outside path (so apk finds it properly inside the chroot) --- pmb/chroot/mount.py | 10 ++++++++-- pmb/helpers/repo.py | 35 ++++++++++++++++++++++++++--------- test/test_repo.py | 8 ++++++++ 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/pmb/chroot/mount.py b/pmb/chroot/mount.py index d3ccaaa4..60055c4e 100644 --- a/pmb/chroot/mount.py +++ b/pmb/chroot/mount.py @@ -16,6 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with pmbootstrap. If not, see . """ +import os import pmb.config import pmb.parse import pmb.helpers.mount @@ -24,14 +25,19 @@ import pmb.helpers.mount def mount(args, suffix="native"): arch = pmb.parse.arch.from_chroot_suffix(args, suffix) - # get all mountpoints + # Get all mountpoints mountpoints = {} for source, target in pmb.config.chroot_mount_bind.items(): source = source.replace("$WORK", args.work) source = source.replace("$ARCH", arch) mountpoints[source] = target - # mount if necessary + # Add the pmOS binary repo (in case it is set and points to a local folder) + mirror = args.mirror_postmarketos + if os.path.exists(mirror): + mountpoints[mirror] = "/mnt/postmarketos-mirror" + + # Mount if necessary for source, target in mountpoints.items(): target_full = args.work + "/chroot_" + suffix + target pmb.helpers.mount.bind(args, source, target_full) diff --git a/pmb/helpers/repo.py b/pmb/helpers/repo.py index 60816bf7..5f756b47 100644 --- a/pmb/helpers/repo.py +++ b/pmb/helpers/repo.py @@ -94,7 +94,7 @@ def hash(url, length=8): return ret -def urls(args, user_repository=True): +def urls(args, user_repository=True, postmarketos_mirror=True): """ Get a list of repository URLs, as they are in /etc/apk/repositories. """ @@ -104,8 +104,11 @@ def urls(args, user_repository=True): ret.append("/home/user/packages/user") # Upstream postmarketOS binary repository - if args.mirror_postmarketos: - ret.append(args.mirror_postmarketos) + if postmarketos_mirror and args.mirror_postmarketos: + if os.path.exists(args.mirror_postmarketos): + ret.append("/mnt/postmarketos-mirror") + else: + ret.append(args.mirror_postmarketos) # Upstream Alpine Linux repositories directories = ["main", "community"] @@ -116,21 +119,35 @@ def urls(args, user_repository=True): return ret -def apkindex_files(args, arch="native"): +def apkindex_files(args, arch=None): """ - Get a list of outside paths to all resolved APKINDEX.tar.gz files - from the urls() list for a specific arch. + Get a list of outside paths to all resolved APKINDEX.tar.gz files for a + specific arch. + :param arch: defaults to native """ - if arch == "native": + if not arch: arch = args.arch_native # Try to get a cached result first. if arch in args.cache["apkindex_files"]: return args.cache["apkindex_files"][arch] - # Add the non-hashed user path and the upstream paths with hashes + # Local user repository (for packages compiled with pmbootstrap) ret = [args.work + "/packages/" + arch + "/APKINDEX.tar.gz"] - for url in urls(args, False): + + # Upstream postmarketOS binary repository + urls_todo = [] + mirror = args.mirror_postmarketos + if mirror: + if os.path.exists(mirror): + ret.append(mirror + "/" + arch + "/APKINDEX.tar.gz") + else: + # Non-local path: treat it like other URLs + urls_todo.append(mirror) + + # Resolve the APKINDEX.$HASH.tar.gz files + urls_todo += urls(args, False, False) + for url in urls_todo: ret.append(args.work + "/cache_apk_" + arch + "/APKINDEX." + hash(url) + ".tar.gz") diff --git a/test/test_repo.py b/test/test_repo.py index 6960f230..389e8c0b 100644 --- a/test/test_repo.py +++ b/test/test_repo.py @@ -21,6 +21,7 @@ import sys import pytest import types import time +import logging # Import from parent directory pmb_src = os.path.abspath(os.path.join(os.path.dirname(__file__) + "/..")) @@ -113,9 +114,16 @@ def test_apkindex_files(args): # Make sure, that we have a user's APKINDEX.tar.gz pmb.build.package(args, "hello-world", args.arch_native) + # Reset the cache + del args.cache["apkindex_files"][args.arch_native] + + # Fake the upstream folder to be the same as the normal packages folder + args.mirror_postmarketos = args.work + "/packages" + files = pmb.helpers.repo.apkindex_files(args) for file in files: assert os.path.exists(file) + logging.info(file) # Test cache assert files == pmb.helpers.repo.apkindex_files(args)