pmbootstrap/pmb/helpers/frontend.py

381 lines
12 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""
Copyright 2019 Oliver Smith
This file is part of pmbootstrap.
pmbootstrap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
pmbootstrap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 <http://www.gnu.org/licenses/>.
"""
import glob
import json
import logging
import os
import sys
import pmb.aportgen
import pmb.build
import pmb.build.autodetect
import pmb.config
import pmb.chroot
import pmb.chroot.initfs
import pmb.chroot.other
import pmb.export
import pmb.flasher
import pmb.helpers.logging
import pmb.helpers.pkgrel_bump
import pmb.helpers.pmaports
import pmb.helpers.repo
2018-11-15 07:36:39 +00:00
import pmb.helpers.repo_missing
import pmb.helpers.run
import pmb.install
import pmb.parse
Close #226: Launch postmarketOS in a qemu virtual machine (#350) Thanks to Pablo Castellano and Martijn Braam! In postmarketOS we are now able to generate system images with the correct configuration so that they can boot already using qemu This commit brings the `pmbootstrap qemu` action. This command is very handy because you don't have to set all the qemu parameters, pmbootstrap does it for you. * device-qemu-vexpress: Added kernel command line according to wiki * qemu: Added workaround for image writing permissions * qemu: Added support to launch postmarketOS in a QEMU virtual machine - Support for emulating these architectures in QEMU: arm, aarch64, x86_84 - Generate QEMU command correctly depending no guest architecture (arm/x86) - Run QEMU in the same architecture as the host by default - Refactoring in pmb.parse.arch and pmb.qemu.run - Raise exception if DTB file or system image are not present - Display more useful information when something fails (e.g. image not found) - Run qemu version depending on arch (host or argument), not device configured * device-qemu-amd64: set deviceinfo_kernel_cmdline to "PMOS_NO_OUTPUT_REDIRECT" * qemu: added --memory argument to specific guest RAM * device-qemu-amd64: adjusted deviceinfo_kernel_cmdline (console=tty1) * Added /etc/network/interfaces for qemu-amd64 * qemu: Added KVM support if /dev/kvm if present * Specify separate machines for architecture * qemu: Check if QEMU is installed instead of crashing * Added graphics driver to qemu-aarch64 - Use arm (as used in qemu) instead of armhf (used in Alpine) - qemu argument is -dtb - Follow same style to build the command + arguments * qemu: Added SSH port redirection: ./pmbootstrap.py qemu -p 2222
2017-08-09 20:26:40 +00:00
import pmb.qemu
def _parse_flavor(args):
"""
Verify the flavor argument if specified, or return a default value.
"""
pmbootstrap init: kernel selection / remove linux-pmos-lts (#1363) * As discussed in IRC/matrix, we're removing `linux-postmarketos-lts` for now. The kernel isn't used right now, and we save lots of maintenance effort with not updating it every week or so. * new config option `"kernel"` with possible values: `"downstream", "mainline", "stable"` (downstream is always `linux-$devicename`) * ask for the kernel during `pmbootstrap init` if the device package has kernel subpackages and install it in `_install.py` * postmarketos-mkinitfs: display note instead of exit with error when the `deviceinfo_dtb` file is missing (because we expect it to be missing for downstream kernels) * device-sony-amami: * add kernel subpackages for downstream, mainline * set `deviceinfo_dtb` * device-qemu-amd64: add kernel subpackages for stable, lts, mainline * test cases and test data for new functions * test case that checks all aports for right usage of the feature: * don't mix specifying kernels in depends *and* subpackages * 1 kernel in depends is maximum * kernel subpackages must have a valid name * Test if devices packages reference at least one kernel * Remove `_build_device_depends_note()` which informs the user that `--ignore-depends` can be used with device packages to avoid building the kernel. The idea was to make the transition easier after a change we did months ago, and now the kernel doesn't always get built before building the device package so it's not relevant anymore. * pmb/chroot/other.py: * Add autoinstall=True to kernel_flavors_installed(). When the flag is set, the function makes sure that at least one kernel for the device is installed. * Remove kernel_flavor_autodetect() function, wherever it was used, it has been replaced with kernel_flavors_installed()[0]. * pmb.helpers.frontend.py: remove code to install at least one kernel, kernel_flavors_installed() takes care of that now.
2018-04-03 23:50:09 +00:00
# Install at least one kernel and get installed flavors
suffix = "rootfs_" + args.device
pmbootstrap init: kernel selection / remove linux-pmos-lts (#1363) * As discussed in IRC/matrix, we're removing `linux-postmarketos-lts` for now. The kernel isn't used right now, and we save lots of maintenance effort with not updating it every week or so. * new config option `"kernel"` with possible values: `"downstream", "mainline", "stable"` (downstream is always `linux-$devicename`) * ask for the kernel during `pmbootstrap init` if the device package has kernel subpackages and install it in `_install.py` * postmarketos-mkinitfs: display note instead of exit with error when the `deviceinfo_dtb` file is missing (because we expect it to be missing for downstream kernels) * device-sony-amami: * add kernel subpackages for downstream, mainline * set `deviceinfo_dtb` * device-qemu-amd64: add kernel subpackages for stable, lts, mainline * test cases and test data for new functions * test case that checks all aports for right usage of the feature: * don't mix specifying kernels in depends *and* subpackages * 1 kernel in depends is maximum * kernel subpackages must have a valid name * Test if devices packages reference at least one kernel * Remove `_build_device_depends_note()` which informs the user that `--ignore-depends` can be used with device packages to avoid building the kernel. The idea was to make the transition easier after a change we did months ago, and now the kernel doesn't always get built before building the device package so it's not relevant anymore. * pmb/chroot/other.py: * Add autoinstall=True to kernel_flavors_installed(). When the flag is set, the function makes sure that at least one kernel for the device is installed. * Remove kernel_flavor_autodetect() function, wherever it was used, it has been replaced with kernel_flavors_installed()[0]. * pmb.helpers.frontend.py: remove code to install at least one kernel, kernel_flavors_installed() takes care of that now.
2018-04-03 23:50:09 +00:00
flavors = pmb.chroot.other.kernel_flavors_installed(args, suffix)
# Parse and verify the flavor argument
flavor = args.flavor
if flavor:
if flavor not in flavors:
raise RuntimeError("No kernel installed with flavor " + flavor + "!" +
" Run 'pmbootstrap flasher list_flavors' to get a list.")
return flavor
if not len(flavors):
raise RuntimeError(
"No kernel flavors installed in chroot " + suffix + "! Please let"
" your device package depend on a package starting with 'linux-'.")
return flavors[0]
def _parse_suffix(args):
if "rootfs" in args and args.rootfs:
return "rootfs_" + args.device
elif args.buildroot:
if args.buildroot == "device":
return "buildroot_" + args.deviceinfo["arch"]
else:
return "buildroot_" + args.buildroot
elif args.suffix:
return args.suffix
else:
return "native"
def aportgen(args):
for package in args.packages:
logging.info("Generate aport: " + package)
pmb.aportgen.generate(args, package)
def build(args):
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935) * Rename pmb/build/package.py to pmb/build/_package.py, so we can access the functions it contains in testcases, and still use pmb.build.package() * Refactor the entire file. Instead of one big function that does too many things, we have many small ones now, that are tested in the testsuite and easier to modify * Whenever building a package, pmbootstrap does not only build and install the "makedepends" (like we did before), now it does the same for the "depends". That's required to be compatible with abuild. The old behavior can still be used with 'pmbootstrap build --ignore-depends'. * Because of that change, noarch packages can no longer be built in the native chroot if we need them for a foreign chroot. A device- package depending on a kernel would pull in the same kernel for the native architecture otherwise. * Running 'pmbootstrap build device-...' without '--ignore-depends' and without a matching '--arch' displays a note that explains this change to the user and tells how to use it instead. * Noarch packages no longer get symlinked. That was only implemented for packages built in the native chroot, and now that is not always the case anymore. Symlinking these packages creates packages with broken dependencies anyway (e.g. device-samsung-i9100 can't be installed in x86_64, because linux-samsung-i9100 is armhf only). * Rename "carch" to "arch" wherever used. Naming it "carch" sometimes is confusing with no benefit. * Add a testcase for the aarch64 qemu workaround (because it failed first and I needed to know for sure if it is working again). * Improved some verbose logging, which helped with development of this feature. * Removed the old "build" test case (which was disabled in testcases_fast.sh) as the new "build_package" test case covers its functionallity. * Only build indexes if the packages folder exists for that arch (Travis couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
# Strict mode: zap everything
if args.strict:
pmb.chroot.zap(args, False)
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935) * Rename pmb/build/package.py to pmb/build/_package.py, so we can access the functions it contains in testcases, and still use pmb.build.package() * Refactor the entire file. Instead of one big function that does too many things, we have many small ones now, that are tested in the testsuite and easier to modify * Whenever building a package, pmbootstrap does not only build and install the "makedepends" (like we did before), now it does the same for the "depends". That's required to be compatible with abuild. The old behavior can still be used with 'pmbootstrap build --ignore-depends'. * Because of that change, noarch packages can no longer be built in the native chroot if we need them for a foreign chroot. A device- package depending on a kernel would pull in the same kernel for the native architecture otherwise. * Running 'pmbootstrap build device-...' without '--ignore-depends' and without a matching '--arch' displays a note that explains this change to the user and tells how to use it instead. * Noarch packages no longer get symlinked. That was only implemented for packages built in the native chroot, and now that is not always the case anymore. Symlinking these packages creates packages with broken dependencies anyway (e.g. device-samsung-i9100 can't be installed in x86_64, because linux-samsung-i9100 is armhf only). * Rename "carch" to "arch" wherever used. Naming it "carch" sometimes is confusing with no benefit. * Add a testcase for the aarch64 qemu workaround (because it failed first and I needed to know for sure if it is working again). * Improved some verbose logging, which helped with development of this feature. * Removed the old "build" test case (which was disabled in testcases_fast.sh) as the new "build_package" test case covers its functionallity. * Only build indexes if the packages folder exists for that arch (Travis couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
if args.envkernel:
pmb.build.envkernel.package_kernel(args)
return
# Set src and force
src = os.path.realpath(os.path.expanduser(args.src[0])) if args.src else None
force = True if src else args.force
if src and not os.path.exists(src):
raise RuntimeError("Invalid path specified for --src: " + src)
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935) * Rename pmb/build/package.py to pmb/build/_package.py, so we can access the functions it contains in testcases, and still use pmb.build.package() * Refactor the entire file. Instead of one big function that does too many things, we have many small ones now, that are tested in the testsuite and easier to modify * Whenever building a package, pmbootstrap does not only build and install the "makedepends" (like we did before), now it does the same for the "depends". That's required to be compatible with abuild. The old behavior can still be used with 'pmbootstrap build --ignore-depends'. * Because of that change, noarch packages can no longer be built in the native chroot if we need them for a foreign chroot. A device- package depending on a kernel would pull in the same kernel for the native architecture otherwise. * Running 'pmbootstrap build device-...' without '--ignore-depends' and without a matching '--arch' displays a note that explains this change to the user and tells how to use it instead. * Noarch packages no longer get symlinked. That was only implemented for packages built in the native chroot, and now that is not always the case anymore. Symlinking these packages creates packages with broken dependencies anyway (e.g. device-samsung-i9100 can't be installed in x86_64, because linux-samsung-i9100 is armhf only). * Rename "carch" to "arch" wherever used. Naming it "carch" sometimes is confusing with no benefit. * Add a testcase for the aarch64 qemu workaround (because it failed first and I needed to know for sure if it is working again). * Improved some verbose logging, which helped with development of this feature. * Removed the old "build" test case (which was disabled in testcases_fast.sh) as the new "build_package" test case covers its functionallity. * Only build indexes if the packages folder exists for that arch (Travis couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
# Build all packages
for package in args.packages:
arch_package = args.arch or pmb.build.autodetect.arch(args, package)
if not pmb.build.package(args, package, arch_package, force,
args.strict, src=src):
logging.info("NOTE: Package '" + package + "' is up to date. Use"
" 'pmbootstrap build " + package + " --force'"
" if needed.")
def build_init(args):
suffix = _parse_suffix(args)
pmb.build.init(args, suffix)
def checksum(args):
for package in args.packages:
if args.verify:
pmb.build.checksum.verify(args, package)
else:
pmb.build.checksum.update(args, package)
def chroot(args):
aportgen: Gracefully handle old aports_upstream (#1291) In order to get cross-compilers, we generate a few aports (e.g. binutils-armhf, gcc-armhf) automatically from Alpine's aports. pmbootstrap was already able to perform a git checkout of Alpine's aports repository. But it needed to be manually updated. Otherwise the `pmbootstrap aportgen` command could actually downgrade the aport instead of updating it to the current version. After thinking about adding a dedicated pmbootstrap command for updating git repositories, I thought it would be better to not open that can of worms (pmbootstrap as general git wrapper? no thanks). The solution implemented here compares the upstream aport version of the git checkout of a certain package (e.g. gcc for gcc-armhf) with the version in Alpine's binary package APKINDEX. When the aport version is lower than the binary package version, it shows the user how to update the git repository with just one command: pmbootstrap chroot --add=git --user -- \ git -C /mnt/pmbootstrap-git/aports_upstream pull Changes: * `pmb.aportgen.core.get_upstream_aport()`: new function, that returns the absolute path to the upstream aport on disk, after checking the version of the aport against the binary package. * Use that new function in pmb.aportgen.gcc and pmb.aportgen.binutils * New function `pmb.helpers.repo.alpine_apkindex_path()`: updates the APKINDEX if necessary and returns the absolute path to the APKINDEX. This code was basically present already, but not as function, so now we have a bit less overhead there. * `pmbootstrap chroot`: new `--user` argument * `pmb.parse.apkbuild`: make pkgname check optional, as it fails with the official gcc APKBUILD before we modify it (the current APKBUILD parser is not meant to be perfect, as this would require a full shell parsing implementation). * Extended `test_aportgen.py` and enabled it by default in `testcases_fast.sh`. Previously it was disabled due to traffic concerns (cloning the aports repo, but then again we do a full KDE plasma mobile installation in Travis now, so that shouldn't matter too much). * `testcases_fast.sh`: With "test_aport_in_sync_with_git" removed from the disabled-by-default list (left over from timestamp based rebuilds), there were no more test cases disabled by default. I've changed it, so now the qemu_running_processes test case is disabled, and added an `--all` parameter to the script to disable no test cases. Travis runs with the `--all` parameter while it's useful to do a quick local test without `--all` in roughly 2 minutes instead of 10. * `aports/cross/binutils-*`: Fix `_mirror` variable to point to current default Alpine mirror (so the aportgen testcase runs through).
2018-03-11 14:18:21 +00:00
# Suffix
suffix = _parse_suffix(args)
aportgen: Gracefully handle old aports_upstream (#1291) In order to get cross-compilers, we generate a few aports (e.g. binutils-armhf, gcc-armhf) automatically from Alpine's aports. pmbootstrap was already able to perform a git checkout of Alpine's aports repository. But it needed to be manually updated. Otherwise the `pmbootstrap aportgen` command could actually downgrade the aport instead of updating it to the current version. After thinking about adding a dedicated pmbootstrap command for updating git repositories, I thought it would be better to not open that can of worms (pmbootstrap as general git wrapper? no thanks). The solution implemented here compares the upstream aport version of the git checkout of a certain package (e.g. gcc for gcc-armhf) with the version in Alpine's binary package APKINDEX. When the aport version is lower than the binary package version, it shows the user how to update the git repository with just one command: pmbootstrap chroot --add=git --user -- \ git -C /mnt/pmbootstrap-git/aports_upstream pull Changes: * `pmb.aportgen.core.get_upstream_aport()`: new function, that returns the absolute path to the upstream aport on disk, after checking the version of the aport against the binary package. * Use that new function in pmb.aportgen.gcc and pmb.aportgen.binutils * New function `pmb.helpers.repo.alpine_apkindex_path()`: updates the APKINDEX if necessary and returns the absolute path to the APKINDEX. This code was basically present already, but not as function, so now we have a bit less overhead there. * `pmbootstrap chroot`: new `--user` argument * `pmb.parse.apkbuild`: make pkgname check optional, as it fails with the official gcc APKBUILD before we modify it (the current APKBUILD parser is not meant to be perfect, as this would require a full shell parsing implementation). * Extended `test_aportgen.py` and enabled it by default in `testcases_fast.sh`. Previously it was disabled due to traffic concerns (cloning the aports repo, but then again we do a full KDE plasma mobile installation in Travis now, so that shouldn't matter too much). * `testcases_fast.sh`: With "test_aport_in_sync_with_git" removed from the disabled-by-default list (left over from timestamp based rebuilds), there were no more test cases disabled by default. I've changed it, so now the qemu_running_processes test case is disabled, and added an `--all` parameter to the script to disable no test cases. Travis runs with the `--all` parameter while it's useful to do a quick local test without `--all` in roughly 2 minutes instead of 10. * `aports/cross/binutils-*`: Fix `_mirror` variable to point to current default Alpine mirror (so the aportgen testcase runs through).
2018-03-11 14:18:21 +00:00
if (args.user and suffix != "native" and
not suffix.startswith("buildroot_")):
raise RuntimeError("--user is only supported for native or"
" buildroot_* chroots.")
# apk: check minimum version, install packages
pmb.chroot.apk.check_min_version(args, suffix)
if args.add:
pmb.chroot.apk.install(args, args.add.split(","), suffix)
aportgen: Gracefully handle old aports_upstream (#1291) In order to get cross-compilers, we generate a few aports (e.g. binutils-armhf, gcc-armhf) automatically from Alpine's aports. pmbootstrap was already able to perform a git checkout of Alpine's aports repository. But it needed to be manually updated. Otherwise the `pmbootstrap aportgen` command could actually downgrade the aport instead of updating it to the current version. After thinking about adding a dedicated pmbootstrap command for updating git repositories, I thought it would be better to not open that can of worms (pmbootstrap as general git wrapper? no thanks). The solution implemented here compares the upstream aport version of the git checkout of a certain package (e.g. gcc for gcc-armhf) with the version in Alpine's binary package APKINDEX. When the aport version is lower than the binary package version, it shows the user how to update the git repository with just one command: pmbootstrap chroot --add=git --user -- \ git -C /mnt/pmbootstrap-git/aports_upstream pull Changes: * `pmb.aportgen.core.get_upstream_aport()`: new function, that returns the absolute path to the upstream aport on disk, after checking the version of the aport against the binary package. * Use that new function in pmb.aportgen.gcc and pmb.aportgen.binutils * New function `pmb.helpers.repo.alpine_apkindex_path()`: updates the APKINDEX if necessary and returns the absolute path to the APKINDEX. This code was basically present already, but not as function, so now we have a bit less overhead there. * `pmbootstrap chroot`: new `--user` argument * `pmb.parse.apkbuild`: make pkgname check optional, as it fails with the official gcc APKBUILD before we modify it (the current APKBUILD parser is not meant to be perfect, as this would require a full shell parsing implementation). * Extended `test_aportgen.py` and enabled it by default in `testcases_fast.sh`. Previously it was disabled due to traffic concerns (cloning the aports repo, but then again we do a full KDE plasma mobile installation in Travis now, so that shouldn't matter too much). * `testcases_fast.sh`: With "test_aport_in_sync_with_git" removed from the disabled-by-default list (left over from timestamp based rebuilds), there were no more test cases disabled by default. I've changed it, so now the qemu_running_processes test case is disabled, and added an `--all` parameter to the script to disable no test cases. Travis runs with the `--all` parameter while it's useful to do a quick local test without `--all` in roughly 2 minutes instead of 10. * `aports/cross/binutils-*`: Fix `_mirror` variable to point to current default Alpine mirror (so the aportgen testcase runs through).
2018-03-11 14:18:21 +00:00
# Run the command as user/root
if args.user:
logging.info("(" + suffix + ") % su pmos -c '" +
" ".join(args.command) + "'")
pmb.chroot.user(args, args.command, suffix, output=args.output)
aportgen: Gracefully handle old aports_upstream (#1291) In order to get cross-compilers, we generate a few aports (e.g. binutils-armhf, gcc-armhf) automatically from Alpine's aports. pmbootstrap was already able to perform a git checkout of Alpine's aports repository. But it needed to be manually updated. Otherwise the `pmbootstrap aportgen` command could actually downgrade the aport instead of updating it to the current version. After thinking about adding a dedicated pmbootstrap command for updating git repositories, I thought it would be better to not open that can of worms (pmbootstrap as general git wrapper? no thanks). The solution implemented here compares the upstream aport version of the git checkout of a certain package (e.g. gcc for gcc-armhf) with the version in Alpine's binary package APKINDEX. When the aport version is lower than the binary package version, it shows the user how to update the git repository with just one command: pmbootstrap chroot --add=git --user -- \ git -C /mnt/pmbootstrap-git/aports_upstream pull Changes: * `pmb.aportgen.core.get_upstream_aport()`: new function, that returns the absolute path to the upstream aport on disk, after checking the version of the aport against the binary package. * Use that new function in pmb.aportgen.gcc and pmb.aportgen.binutils * New function `pmb.helpers.repo.alpine_apkindex_path()`: updates the APKINDEX if necessary and returns the absolute path to the APKINDEX. This code was basically present already, but not as function, so now we have a bit less overhead there. * `pmbootstrap chroot`: new `--user` argument * `pmb.parse.apkbuild`: make pkgname check optional, as it fails with the official gcc APKBUILD before we modify it (the current APKBUILD parser is not meant to be perfect, as this would require a full shell parsing implementation). * Extended `test_aportgen.py` and enabled it by default in `testcases_fast.sh`. Previously it was disabled due to traffic concerns (cloning the aports repo, but then again we do a full KDE plasma mobile installation in Travis now, so that shouldn't matter too much). * `testcases_fast.sh`: With "test_aport_in_sync_with_git" removed from the disabled-by-default list (left over from timestamp based rebuilds), there were no more test cases disabled by default. I've changed it, so now the qemu_running_processes test case is disabled, and added an `--all` parameter to the script to disable no test cases. Travis runs with the `--all` parameter while it's useful to do a quick local test without `--all` in roughly 2 minutes instead of 10. * `aports/cross/binutils-*`: Fix `_mirror` variable to point to current default Alpine mirror (so the aportgen testcase runs through).
2018-03-11 14:18:21 +00:00
else:
logging.info("(" + suffix + ") % " + " ".join(args.command))
pmb.chroot.root(args, args.command, suffix, output=args.output)
def config(args):
keys = pmb.config.config_keys
if args.name and args.name not in keys:
logging.info("NOTE: Valid config keys: " + ", ".join(keys))
raise RuntimeError("Invalid config key: " + args.name)
cfg = pmb.config.load(args)
if args.value:
cfg["pmbootstrap"][args.name] = args.value
logging.info("Config changed: " + args.name + "='" + args.value + "'")
pmb.config.save(args, cfg)
elif args.name:
value = cfg["pmbootstrap"].get(args.name, "")
print(value)
else:
cfg.write(sys.stdout)
# Don't write the "Done" message
pmb.helpers.logging.disable()
2018-11-15 07:36:39 +00:00
def repo_missing(args):
missing = pmb.helpers.repo_missing.generate(args, args.arch, args.overview,
args.package, args.built)
print(json.dumps(missing, indent=4))
def index(args):
Fix #824: Refactor pmb/build/package.py (make depends work like in abuild) (#935) * Rename pmb/build/package.py to pmb/build/_package.py, so we can access the functions it contains in testcases, and still use pmb.build.package() * Refactor the entire file. Instead of one big function that does too many things, we have many small ones now, that are tested in the testsuite and easier to modify * Whenever building a package, pmbootstrap does not only build and install the "makedepends" (like we did before), now it does the same for the "depends". That's required to be compatible with abuild. The old behavior can still be used with 'pmbootstrap build --ignore-depends'. * Because of that change, noarch packages can no longer be built in the native chroot if we need them for a foreign chroot. A device- package depending on a kernel would pull in the same kernel for the native architecture otherwise. * Running 'pmbootstrap build device-...' without '--ignore-depends' and without a matching '--arch' displays a note that explains this change to the user and tells how to use it instead. * Noarch packages no longer get symlinked. That was only implemented for packages built in the native chroot, and now that is not always the case anymore. Symlinking these packages creates packages with broken dependencies anyway (e.g. device-samsung-i9100 can't be installed in x86_64, because linux-samsung-i9100 is armhf only). * Rename "carch" to "arch" wherever used. Naming it "carch" sometimes is confusing with no benefit. * Add a testcase for the aarch64 qemu workaround (because it failed first and I needed to know for sure if it is working again). * Improved some verbose logging, which helped with development of this feature. * Removed the old "build" test case (which was disabled in testcases_fast.sh) as the new "build_package" test case covers its functionallity. * Only build indexes if the packages folder exists for that arch (Travis couldn't run a test case otherwise)
2017-11-26 14:32:02 +00:00
pmb.build.index_repo(args)
def initfs(args):
pmb.chroot.initfs.frontend(args)
def install(args):
if args.rsync and args.full_disk_encryption:
raise ValueError("Installation using rsync is not compatible with full"
" disk encryption.")
if args.rsync and not args.sdcard:
raise ValueError("Installation using rsync only works on sdcard.")
pmb.install.install(args)
def flasher(args):
pmb.flasher.frontend(args)
def export(args):
pmb.export.frontend(args)
def update(args):
existing_only = not args.non_existing
if not pmb.helpers.repo.update(args, args.arch, True, existing_only):
logging.info("No APKINDEX files exist, so none have been updated."
" The pmbootstrap command downloads the APKINDEX files on"
" demand.")
logging.info("If you want to force downloading the APKINDEX files for"
" all architectures (not recommended), use:"
" pmbootstrap update --non-existing")
def newapkbuild(args):
pmbootstrap newapkbuild: Properly parse arguments (#1320) * pmbootstrap newapkbuild: Properly parse arguments The `pmbootstrap newapkbuild` action wraps Alpine's `newapkbuild`. We used to directly pass all arguments to `newapkbuild` without verifying in Python whether they make sense or not. However, as `newpakbuild` doesn't do strict sanity checks on the arguments, it is easy to end up with unexpected behavior when using the command for the first time. For example, `newapkbuild` allows either specifying a PKGNAME or SRCURL as last parameter, and also allows setting a PKGNAME with the `-n` parameter. It only makes sense to use that option when passing a SRCURL. With this commit, we duplicate the optins that should be passed through to `newapkbuild` and use argparse to fully sanitize the options and display a help page (`pmbootstrap newapkbuild -h`) that is consistent with the other help pages. Details: * The `-f` (force) flag does not get passed through anymore. Instead we use it in Python to skip asking if an existing aport should be overwritten (the aports are outside of the chroot, so `newapkbuild` can't handle it in a way that makes sense for pmbootstrap). * Output of `newapkbuild` gets redirected to the log file now, as we don't need it to display a help page. * Don't verify the pkgver while creating the new APKBUILD. When passing a SRCURL, the pkgver gets extracted from the end of the URL and may not have a valid format yet (but we want the APKBUILD anyway). * Stored options passed through in `pmb/config/__init__.py` and use it in both `pmb/parse/arguments.py` and `pmb/helpers/frontend.py`. * Only allow `-n` with SRCURL * The postmarketOS aports folder gets specified with `--folder` now. That way the generated help page is much closer to the original one from `newapkbuild`. The default is `main`. * Made the package type flags (CMake, autotools, ...) exclusive so only one of them can be specified
2018-03-15 21:42:34 +00:00
# Check for SRCURL usage
is_url = False
for prefix in ["http://", "https://", "ftp://"]:
if args.pkgname_pkgver_srcurl.startswith(prefix):
is_url = True
break
# Sanity check: -n is only allowed with SRCURL
if args.pkgname and not is_url:
raise RuntimeError("You can only specify a pkgname (-n) when using"
" SRCURL as last parameter.")
# Passthrough: Strings (e.g. -d "my description")
pass_through = []
for entry in pmb.config.newapkbuild_arguments_strings:
value = getattr(args, entry[1])
if value:
pass_through += [entry[0], value]
# Passthrough: Switches (e.g. -C for CMake)
for entry in (pmb.config.newapkbuild_arguments_switches_pkgtypes +
pmb.config.newapkbuild_arguments_switches_other):
if getattr(args, entry[1]) is True:
pass_through.append(entry[0])
# Passthrough: PKGNAME[-PKGVER] | SRCURL
pass_through.append(args.pkgname_pkgver_srcurl)
pmb.build.newapkbuild(args, args.folder, pass_through, args.force)
def kconfig(args):
if args.action_kconfig == "check":
# Default to all kernel packages
packages = []
if args.package == "" or args.package is None:
for aport in glob.glob(args.aports + "/*/linux-*"):
packages.append(os.path.basename(aport).split("linux-")[1])
else:
packages = [args.package]
# Iterate over all kernels
error = False
skipped = 0
packages.sort()
for package in packages:
if not args.force:
aport = pmb.helpers.pmaports.find(args, "linux-" + package)
apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD")
if "!pmb:kconfigcheck" in apkbuild["options"]:
skipped += 1
continue
if not pmb.parse.kconfig.check(args, package, details=True):
error = True
# At least one failure
if error:
raise RuntimeError("kconfig check failed!")
else:
if skipped:
logging.info("NOTE: " + str(skipped) + " kernel(s) was skipped"
" (consider 'pmbootstrap kconfig check -f')")
logging.info("kconfig check succeeded!")
elif args.action_kconfig == "edit":
pmb.build.menuconfig(args, args.package)
def apkbuild_parse(args):
# Default to all packages
packages = args.packages
if not packages:
2018-11-15 07:36:39 +00:00
packages = pmb.helpers.pmaports.get_list(args)
# Iterate over all packages
for package in packages:
print(package + ":")
aport = pmb.helpers.pmaports.find(args, package)
path = aport + "/APKBUILD"
print(json.dumps(pmb.parse.apkbuild(args, path), indent=4,
sort_keys=True))
def apkindex_parse(args):
result = pmb.parse.apkindex.parse(args, args.apkindex_path)
if args.package:
if args.package not in result:
raise RuntimeError("Package not found in the APKINDEX: " +
args.package)
result = result[args.package]
print(json.dumps(result, indent=4))
def pkgrel_bump(args):
would_bump = True
if args.auto:
would_bump = pmb.helpers.pkgrel_bump.auto(args, args.dry)
else:
# Each package must exist
for package in args.packages:
pmb.helpers.pmaports.find(args, package)
# Increase pkgrel
for package in args.packages:
pmb.helpers.pkgrel_bump.package(args, package, dry=args.dry)
if args.dry and would_bump:
logging.info("Pkgrels of package(s) would have been bumped!")
sys.exit(1)
Close #226: Launch postmarketOS in a qemu virtual machine (#350) Thanks to Pablo Castellano and Martijn Braam! In postmarketOS we are now able to generate system images with the correct configuration so that they can boot already using qemu This commit brings the `pmbootstrap qemu` action. This command is very handy because you don't have to set all the qemu parameters, pmbootstrap does it for you. * device-qemu-vexpress: Added kernel command line according to wiki * qemu: Added workaround for image writing permissions * qemu: Added support to launch postmarketOS in a QEMU virtual machine - Support for emulating these architectures in QEMU: arm, aarch64, x86_84 - Generate QEMU command correctly depending no guest architecture (arm/x86) - Run QEMU in the same architecture as the host by default - Refactoring in pmb.parse.arch and pmb.qemu.run - Raise exception if DTB file or system image are not present - Display more useful information when something fails (e.g. image not found) - Run qemu version depending on arch (host or argument), not device configured * device-qemu-amd64: set deviceinfo_kernel_cmdline to "PMOS_NO_OUTPUT_REDIRECT" * qemu: added --memory argument to specific guest RAM * device-qemu-amd64: adjusted deviceinfo_kernel_cmdline (console=tty1) * Added /etc/network/interfaces for qemu-amd64 * qemu: Added KVM support if /dev/kvm if present * Specify separate machines for architecture * qemu: Check if QEMU is installed instead of crashing * Added graphics driver to qemu-aarch64 - Use arm (as used in qemu) instead of armhf (used in Alpine) - qemu argument is -dtb - Follow same style to build the command + arguments * qemu: Added SSH port redirection: ./pmbootstrap.py qemu -p 2222
2017-08-09 20:26:40 +00:00
def qemu(args):
pmb.qemu.run(args)
def shutdown(args):
pmb.chroot.shutdown(args)
def stats(args):
# Chroot suffix
suffix = "native"
if args.arch != args.arch_native:
suffix = "buildroot_" + args.arch
# Install ccache and display stats
pmb.chroot.apk.install(args, ["ccache"], suffix)
logging.info("(" + suffix + ") % ccache -s")
pmb.chroot.user(args, ["ccache", "-s"], suffix, output="stdout")
def work_migrate(args):
# do nothing (pmb/__init__.py already did the migration)
pmb.helpers.logging.disable()
def log(args):
if args.clear_log:
pmb.helpers.run.user(args, ["truncate", "-s", "0", args.log])
pmb.helpers.run.user(args, ["tail", "-f", args.log, "-n", args.lines],
output="tui")
def log_distccd(args):
logpath = "/home/pmos/distccd.log"
if args.clear_log:
pmb.chroot.user(args, ["truncate", "-s", "0", logpath])
pmb.chroot.user(args, ["tail", "-f", logpath, "-n", args.lines],
output="tui")
def zap(args):
pmb.chroot.zap(args, dry=args.dry, http=args.http,
distfiles=args.distfiles, pkgs_local=args.pkgs_local,
pkgs_local_mismatch=args.pkgs_local_mismatch,
pkgs_online_mismatch=args.pkgs_online_mismatch)
# Don't write the "Done" message
pmb.helpers.logging.disable()
def bootimg_analyze(args):
bootimg = pmb.parse.bootimg(args, args.path)
tmp_output = "Put these variables in the deviceinfo file of your device:\n"
for line in pmb.aportgen.device.generate_deviceinfo_fastboot_content(args, bootimg).split("\n"):
tmp_output += "\n" + line.lstrip()
logging.info(tmp_output)