From 1adeee70b6576031e41a7474b5589379115ec257 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Thu, 15 Jun 2017 02:26:32 +0200 Subject: [PATCH] Fix #90: noarch: create symlinks for all supported architectures * The supported architectures are inside the config now * Symlinks get created for that list of supported architectures now. * During initialization, the architecture from the selected device gets checked against the list of supported architectures. When it is not included, a meaningful exception gets raised. * the aportgen and (cross-compiler) build tests make use of the new variable now (they had armhf and aarch64 hardcoded previously). --- pmb/build/other.py | 21 ++++++++++----------- pmb/config/__init__.py | 6 ++++++ pmb/parse/arguments.py | 12 +++++++++++- test/test_aportgen.py | 3 ++- test/test_build.py | 3 ++- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/pmb/build/other.py b/pmb/build/other.py index e45efe82..8d499568 100644 --- a/pmb/build/other.py +++ b/pmb/build/other.py @@ -129,18 +129,17 @@ def symlink_noarch_package(args, arch_apk): :param arch_apk: for example: x86_64/mypackage-1.2.3-r0.apk """ - # Create the arch folder - device_arch = args.deviceinfo["arch"] - device_repo = args.work + "/packages/" + device_arch - if not os.path.exists(device_repo): - pmb.chroot.user(args, ["mkdir", "-p", "/home/user/packages/user/" + - device_arch]) + for arch in pmb.config.build_device_architectures: + # Create the arch folder + arch_folder = "/home/user/packages/user/" + arch + arch_folder_outside = args.work + "/packages/" + arch + if not os.path.exists(arch_folder_outside): + pmb.chroot.user(args, ["mkdir", "-p", arch_folder]) - # Add symlink, rewrite index - device_repo_chroot = "/home/user/packages/user/" + device_arch - pmb.chroot.user(args, ["ln", "-sf", "../" + arch_apk, "."], - working_dir=device_repo_chroot) - index_repo(args, device_arch) + # Add symlink, rewrite index + pmb.chroot.user(args, ["ln", "-sf", "../" + arch_apk, "."], + working_dir=arch_folder) + index_repo(args, arch) def ccache_stats(args, arch): diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index a93a9229..f6527b0e 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -109,6 +109,12 @@ chroot_device_nodes = [ # BUILD # +# Officially supported target architectures for postmarketOS. Only +# specify architectures supported by Alpine here. When creating a noarch +# package, symlinks for all architectures get created - so only specify +# architectures, where we really have device-* packages for. +build_device_architectures = ["armhf", "aarch64"] + # Packages, that will be installed in a chroot before it builds packages # for the first time build_packages = ["abuild", "build-base", "ccache"] diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index 04a20fbe..8e9ce001 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -194,8 +194,18 @@ def arguments(): # Add convinience shortcuts setattr(args, "arch_native", pmb.parse.arch.alpine_native()) - # Add the deviceinfo (only after initialization) + # Add and verify the deviceinfo (only after initialization) if args.action != "init": setattr(args, "deviceinfo", pmb.parse.deviceinfo(args)) + arch = args.deviceinfo["arch"] + if (arch != args.arch_native and + arch not in pmb.config.build_device_architectures): + raise ValueError("Arch '" + arch + "' is not officially enabled" + " in postmarketOS yet. However, this should be straight" + " forward. Simply enable it in pmb/config/__init__.py" + " in build_device_architectures, zap your package cache" + " (otherwise you will have issues with noarch packages)" + " and try again. Some other things might break, but" + " they should be easy to fix them.") return args diff --git a/test/test_aportgen.py b/test/test_aportgen.py index f5db1523..5ccc3eec 100644 --- a/test/test_aportgen.py +++ b/test/test_aportgen.py @@ -25,6 +25,7 @@ import filecmp sys.path.append(os.path.abspath( os.path.join(os.path.dirname(__file__) + "/.."))) import pmb.aportgen +import pmb.config @pytest.fixture @@ -45,7 +46,7 @@ def test_aportgen(args): # Generate all valid packages pkgnames = [] - for arch in ["armhf", "aarch64"]: + for arch in pmb.config.build_device_architectures: # gcc twice, so the output folder already exists -> different code path for pkgname in ["binutils", "musl", "gcc", "gcc"]: pkgnames.append(pkgname + "-" + arch) diff --git a/test/test_build.py b/test/test_build.py index d5985bf5..ca72f353 100644 --- a/test/test_build.py +++ b/test/test_build.py @@ -24,6 +24,7 @@ import pytest sys.path.append(os.path.abspath( os.path.join(os.path.dirname(__file__) + "/.."))) import pmb.aportgen +import pmb.config @pytest.fixture @@ -44,5 +45,5 @@ def test_build_cross(args): """ Build in non-native chroot, with cross-compiler through distcc. """ - for arch in ["armhf", "aarch64"]: + for arch in pmb.config.build_device_architectures: pmb.build.package(args, "hello-world", arch, True)