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)
This commit is contained in:
parent
8e3e296cbd
commit
f37367c57c
|
@ -16,6 +16,7 @@ GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
import pmb.config
|
import pmb.config
|
||||||
import pmb.parse
|
import pmb.parse
|
||||||
import pmb.helpers.mount
|
import pmb.helpers.mount
|
||||||
|
@ -24,14 +25,19 @@ import pmb.helpers.mount
|
||||||
def mount(args, suffix="native"):
|
def mount(args, suffix="native"):
|
||||||
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
|
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
|
||||||
|
|
||||||
# get all mountpoints
|
# Get all mountpoints
|
||||||
mountpoints = {}
|
mountpoints = {}
|
||||||
for source, target in pmb.config.chroot_mount_bind.items():
|
for source, target in pmb.config.chroot_mount_bind.items():
|
||||||
source = source.replace("$WORK", args.work)
|
source = source.replace("$WORK", args.work)
|
||||||
source = source.replace("$ARCH", arch)
|
source = source.replace("$ARCH", arch)
|
||||||
mountpoints[source] = target
|
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():
|
for source, target in mountpoints.items():
|
||||||
target_full = args.work + "/chroot_" + suffix + target
|
target_full = args.work + "/chroot_" + suffix + target
|
||||||
pmb.helpers.mount.bind(args, source, target_full)
|
pmb.helpers.mount.bind(args, source, target_full)
|
||||||
|
|
|
@ -94,7 +94,7 @@ def hash(url, length=8):
|
||||||
return ret
|
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.
|
Get a list of repository URLs, as they are in /etc/apk/repositories.
|
||||||
"""
|
"""
|
||||||
|
@ -104,7 +104,10 @@ def urls(args, user_repository=True):
|
||||||
ret.append("/home/user/packages/user")
|
ret.append("/home/user/packages/user")
|
||||||
|
|
||||||
# Upstream postmarketOS binary repository
|
# Upstream postmarketOS binary repository
|
||||||
if 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)
|
ret.append(args.mirror_postmarketos)
|
||||||
|
|
||||||
# Upstream Alpine Linux repositories
|
# Upstream Alpine Linux repositories
|
||||||
|
@ -116,21 +119,35 @@ def urls(args, user_repository=True):
|
||||||
return ret
|
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
|
Get a list of outside paths to all resolved APKINDEX.tar.gz files for a
|
||||||
from the urls() list for a specific arch.
|
specific arch.
|
||||||
|
:param arch: defaults to native
|
||||||
"""
|
"""
|
||||||
if arch == "native":
|
if not arch:
|
||||||
arch = args.arch_native
|
arch = args.arch_native
|
||||||
|
|
||||||
# Try to get a cached result first.
|
# Try to get a cached result first.
|
||||||
if arch in args.cache["apkindex_files"]:
|
if arch in args.cache["apkindex_files"]:
|
||||||
return args.cache["apkindex_files"][arch]
|
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"]
|
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." +
|
ret.append(args.work + "/cache_apk_" + arch + "/APKINDEX." +
|
||||||
hash(url) + ".tar.gz")
|
hash(url) + ".tar.gz")
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import sys
|
||||||
import pytest
|
import pytest
|
||||||
import types
|
import types
|
||||||
import time
|
import time
|
||||||
|
import logging
|
||||||
|
|
||||||
# Import from parent directory
|
# Import from parent directory
|
||||||
pmb_src = os.path.abspath(os.path.join(os.path.dirname(__file__) + "/.."))
|
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
|
# Make sure, that we have a user's APKINDEX.tar.gz
|
||||||
pmb.build.package(args, "hello-world", args.arch_native)
|
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)
|
files = pmb.helpers.repo.apkindex_files(args)
|
||||||
for file in files:
|
for file in files:
|
||||||
assert os.path.exists(file)
|
assert os.path.exists(file)
|
||||||
|
logging.info(file)
|
||||||
|
|
||||||
# Test cache
|
# Test cache
|
||||||
assert files == pmb.helpers.repo.apkindex_files(args)
|
assert files == pmb.helpers.repo.apkindex_files(args)
|
||||||
|
|
Loading…
Reference in New Issue