pmbootstrap/pmb/parse/arguments.py

910 lines
44 KiB
Python
Raw Normal View History

2023-01-22 18:11:10 +00:00
# Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
2017-05-26 20:08:45 +00:00
import argparse
import copy
import os
2018-08-27 21:35:05 +00:00
try:
import argcomplete
except ImportError:
argcomplete = False
2017-05-26 20:08:45 +00:00
import pmb.config
import pmb.parse.arch
import pmb.helpers.args
2018-11-15 07:36:39 +00:00
import pmb.helpers.pmaports
""" This file is about parsing command line arguments passed to pmbootstrap, as
well as generating the help pages (pmbootstrap -h). All this is done with
Python's argparse. The parsed arguments get extended and finally stored in
the "args" variable, which is prominently passed to most functions all
over the pmbootstrap code base.
See pmb/helpers/args.py for more information about the args variable. """
2017-05-26 20:08:45 +00:00
def toggle_other_boolean_flags(*other_destinations, value=True):
""" Helper function to group several argparse flags to one. Sets multiple
other_destination to value.
:param other_destinations: 'the other argument names' str
:param value 'the value to set the other_destinations to' bool
:returns custom Action"""
class SetOtherDestinationsAction(argparse.Action):
def __init__(self, option_strings, dest, **kwargs):
super().__init__(option_strings, dest, nargs=0, const=value,
default=value, **kwargs)
def __call__(self, parser, namespace, values, option_string=None):
for destination in other_destinations:
setattr(namespace, destination, value)
return SetOtherDestinationsAction
def type_ondev_cp(val):
""" Parse and validate arguments to 'pmbootstrap install --ondev --cp'.
:param val: 'HOST_SRC:CHROOT_DEST' string
:returns: (HOST_SRC, CHROOT_DEST) """
ret = val.split(":")
if len(ret) != 2:
raise argparse.ArgumentTypeError("does not have HOST_SRC:CHROOT_DEST"
f" format: {val}")
host_src = ret[0]
if not os.path.exists(host_src):
raise argparse.ArgumentTypeError(f"HOST_SRC not found: {host_src}")
if not os.path.isfile(host_src):
raise argparse.ArgumentTypeError(f"HOST_SRC is not a file: {host_src}")
chroot_dest = ret[1]
if not chroot_dest.startswith("/"):
raise argparse.ArgumentTypeError("CHROOT_DEST must start with '/':"
f" {chroot_dest}")
return ret
def arguments_install(subparser):
ret = subparser.add_parser("install", help="set up device specific"
" chroot and install to SD card or image file")
# Other arguments (that don't fit categories below)
ret.add_argument("--no-sshd", action="store_true",
help="do not enable the SSH daemon by default")
ret.add_argument("--no-firewall", action="store_true",
help="do not enable the firewall by default")
ret.add_argument("--password", help="dummy password for automating the"
" installation - will be handled in PLAIN TEXT during"
" install and may be logged to the logfile, do not use an"
" important password!")
ret.add_argument("--no-cgpt", help="do not use cgpt partition table",
dest="install_cgpt", action="store_false", default=True)
# Image type
group_desc = ret.add_argument_group(
"optional image type",
"Format of the resulting image. Default is generating a combined image"
" of the postmarketOS boot and root partitions (--no-split). (If the"
" device's deviceinfo_flash_method requires separate boot and root"
" partitions, then --split is the default.) Related:"
" https://postmarketos.org/partitions")
group = group_desc.add_mutually_exclusive_group()
group.add_argument("--no-split", help="create combined boot and root image"
" file", dest="split", action="store_false",
default=None)
group.add_argument("--split", help="create separate boot and root image"
" files", action="store_true")
group.add_argument("--sdcard", help="do not create an image file, instead"
" write to the given SD card device (e.g."
" '/dev/mmcblk0')", metavar="BLOCKDEV")
group.add_argument("--android-recovery-zip",
help="generate TWRP flashable zip (recommended read:"
" https://postmarketos.org/recoveryzip)",
action="store_true", dest="android_recovery_zip")
group.add_argument("--no-image", help="do not generate an image",
action="store_true", dest="no_image")
# Image type "--sdcard" related
group = ret.add_argument_group("optional image type 'sdcard' arguments")
group.add_argument("--rsync", help="update the SD card using rsync",
action="store_true")
# Image type "--android-recovery-zip" related
group = ret.add_argument_group("optional image type 'android-recovery-zip'"
" arguments")
group.add_argument("--recovery-install-partition", default="system",
help="partition to flash from recovery (e.g."
" 'external_sd')",
dest="recovery_install_partition")
group.add_argument("--recovery-no-kernel",
help="do not overwrite the existing kernel",
action="store_false", dest="recovery_flash_kernel")
# Full disk encryption (disabled by default, --no-fde has no effect)
group = ret.add_argument_group("optional full disk encryption arguments")
group.add_argument("--fde", help="use full disk encryption",
action="store_true", dest="full_disk_encryption")
group.add_argument("--no-fde", help=argparse.SUPPRESS,
action="store_true", dest="no_fde")
group.add_argument("--cipher", help="cryptsetup cipher used to encrypt the"
" the rootfs (e.g. 'aes-xts-plain64')")
group.add_argument("--iter-time", help="cryptsetup iteration time (in"
" milliseconds) to use when encrypting the system"
" partition")
# Packages
group = ret.add_argument_group(
"optional packages arguments",
"Select or deselect packages to be included in the installation.")
group.add_argument("--add", help="comma separated list of packages to be"
" added to the rootfs (e.g. 'vim,gcc')",
metavar="PACKAGES")
group.add_argument("--no-base",
help="do not install postmarketos-base (advanced)",
action="store_false", dest="install_base")
group.add_argument("--no-recommends", dest="install_recommends",
help="do not install packages listed in _pmb_recommends"
" of the UI pmaports",
action="store_false")
# Sparse image
group_desc = ret.add_argument_group(
"optional sparse image arguments",
"Override deviceinfo_flash_sparse for testing purpose.")
group = group_desc.add_mutually_exclusive_group()
group.add_argument("--sparse", help="generate sparse image file",
default=None, action="store_true")
group.add_argument("--no-sparse", help="do not generate sparse image file",
dest="sparse", action="store_false")
# On-device installer
group = ret.add_argument_group(
"optional on-device installer arguments",
"Wrap the resulting image in a postmarketOS based installation OS, so"
" it can be encrypted and customized on first boot."
" Related: https://postmarketos.org/on-device-installer")
group.add_argument("--on-device-installer", "--ondev", action="store_true",
help="enable on-device installer")
group.add_argument("--no-local-pkgs", dest="install_local_pkgs",
help="do not install locally compiled packages and"
" package signing keys", action="store_false")
group.add_argument("--cp", dest="ondev_cp", nargs="+",
metavar="HOST_SRC:CHROOT_DEST", type=type_ondev_cp,
help="copy one or more files from the host system path"
" HOST_SRC to the target path CHROOT_DEST")
group.add_argument("--no-rootfs", dest="ondev_no_rootfs",
help="do not generate a pmOS rootfs as"
" /var/lib/rootfs.img (install chroot). The file"
" must either exist from a previous"
" 'pmbootstrap install' run or by providing it"
" as CHROOT_DEST with --cp", action="store_true")
# Other
group = ret.add_argument_group("other optional arguments")
group.add_argument("--filesystem", help="root filesystem type",
choices=["ext4", "f2fs", "btrfs"])
def arguments_export(subparser):
ret = subparser.add_parser("export", help="create convenience symlinks"
" to generated image files (system, kernel,"
" initramfs, boot.img, ...)")
ret.add_argument("export_folder", help="export folder, defaults to"
" /tmp/postmarketOS-export",
default="/tmp/postmarketOS-export", nargs="?")
ret.add_argument("--odin", help="odin flashable tar"
" (boot.img/kernel+initramfs only)",
action="store_true", dest="odin_flashable_tar")
ret.add_argument("--no-install", dest="autoinstall", default=True,
help="skip updating kernel/initfs", action="store_false")
return ret
def arguments_sideload(subparser):
ret = subparser.add_parser("sideload", help="Push packages to a running"
" phone connected over usb or wifi")
add_packages_arg(ret, nargs="+")
ret.add_argument("--host", help="ip of the device over wifi"
" (defaults to 172.16.42.1)",
default="172.16.42.1")
ret.add_argument("--port", help="SSH port of the device over wifi"
" (defaults to 22)",
default="22")
ret.add_argument("--user", help="use a different username than the"
" one set in init")
ret.add_argument("--arch", help="use a different architecture than the one"
" set in init")
ret.add_argument("--install-key", help="install the apk key from this"
" machine if needed",
action="store_true", dest="install_key")
return ret
2017-05-26 20:08:45 +00:00
def arguments_flasher(subparser):
ret = subparser.add_parser("flasher", help="flash something to the"
" target device")
ret.add_argument("--method", help="override flash method",
dest="flash_method", default=None)
sub = ret.add_subparsers(dest="action_flasher")
sub.required = True
2017-05-26 20:08:45 +00:00
# Boot, flash kernel
2017-05-26 20:08:45 +00:00
boot = sub.add_parser("boot", help="boot a kernel once")
boot.add_argument("--cmdline", help="override kernel commandline")
2017-05-26 20:08:45 +00:00
flash_kernel = sub.add_parser("flash_kernel", help="flash a kernel")
for action in [boot, flash_kernel]:
action.add_argument("--no-install", dest="autoinstall", default=True,
help="skip updating kernel/initfs",
action="store_false")
flash_kernel.add_argument("--partition", default=None,
help="partition to flash the kernel to (defaults"
" to deviceinfo_flash_*_partition_kernel)")
2017-05-26 20:08:45 +00:00
# Flash lk2nd
flash_lk2nd = sub.add_parser("flash_lk2nd",
help="flash lk2nd, a secondary bootloader"
" needed for various Android devices")
flash_lk2nd.add_argument("--partition", default=None,
help="partition to flash lk2nd to (defaults to"
" default boot image partition ")
# Flash rootfs
flash_rootfs = sub.add_parser("flash_rootfs",
help="flash the rootfs to a partition on the"
" device (partition layout does not get"
" changed)")
flash_rootfs.add_argument("--partition", default=None,
help="partition to flash the rootfs to (defaults"
" to deviceinfo_flash_*_partition_rootfs,"
" 'userdata' on Android may have more"
" space)")
# Flash vbmeta
flash_vbmeta = sub.add_parser("flash_vbmeta",
help="generate and flash AVB 2.0 image with"
" disable verification flag set to a"
" partition on the device (typically called"
" vbmeta)")
flash_vbmeta.add_argument("--partition", default=None,
help="partition to flash the vbmeta to (defaults"
" to deviceinfo_flash_*_partition_vbmeta")
# Flash dtbo
flash_dtbo = sub.add_parser("flash_dtbo",
help="flash dtbo image")
flash_dtbo.add_argument("--partition", default=None,
help="partition to flash the dtbo to (defaults"
" to deviceinfo_flash_*_partition_dtbo)")
# Actions without extra arguments
sub.add_parser("sideload", help="sideload recovery zip")
sub.add_parser("list_flavors", help="list installed kernel flavors" +
" inside the device rootfs chroot on this computer")
sub.add_parser("list_devices", help="show connected devices")
2017-05-26 20:08:45 +00:00
return ret
def arguments_initfs(subparser):
ret = subparser.add_parser(
"initfs", help="do something with the initramfs")
sub = ret.add_subparsers(dest="action_initfs")
# hook ls
sub.add_parser(
"hook_ls",
help="list available and installed hook packages")
# hook add/del
hook_add = sub.add_parser("hook_add", help="add a hook package")
hook_del = sub.add_parser("hook_del", help="uninstall a hook package")
for action in [hook_add, hook_del]:
action.add_argument("hook", help="name of the hook aport, without"
f" the '{pmb.config.initfs_hook_prefix}' prefix,"
" for example: 'debug-shell'")
# ls, build, extract
sub.add_parser("ls", help="list initramfs contents")
sub.add_parser("build", help="(re)build the initramfs")
sub.add_parser("extract",
help="extract the initramfs to a temporary folder")
return ret
Close #453: Support mesa-dri-virtio in Qemu (#861) The mesa driver, which ends up in the installation image, needs to be known before the installation is done (in other words: when running the qemu action, it is to late as the image has already been generated). That's why one can choose the Qemu mesa driver in `pmbootstrap init` now: ``` Device [qemu-amd64]: Which mesa driver do you prefer for your Qemu device? Only select something other than the default if you are having graphical problems (such as glitches). Mesa driver (dri-swrast/dri-virtio) [dri-virtio]: ``` It is still possible to select `dri-swrast`, because `dri-virtio` may not work in all cases, and that way we could easily debug it or experiment with other mesa drivers (e.g. the "vmware" one, which is supported by mesa and Qemu). Other changes: * `pmbootstrap qemu` accepts a `--display` variable now, which passes the value directly to `qemu`'s `display` option. It defaults to `sdl,gl=on` (@PureTryOut reported that to work best with plasma mobile on his PC). `--display` and `--spice` (which is still working) are mutually exclusive. * Removed obsolete telnet port pass-through: We only use the debug telnet port since osk-sdl has been merged. * Add show-cursor to the Qemu command line, so it shows a cursor in X11 * Refactored the spice code (`command_spice` only returns the spice command, because it has all necessary information already) and the spice port can be specified on the commandline now (previously it was hardcoded in one place and then always looked up from there). * Start comments with capital letters. * Keep the log on the screen a bit shorter (e.g. Qemu command is written to the "pmbootstrap log" anyway, so there's no need to display it again). * linux-postmarketos-stable: Adjust kernel configs x86_64, armhf: enable as modules: CONFIG_DRM_VIRTIO_GPU, CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_BALLOON aarch64: all 3 options were already enabled as built-in (no change) * Set '-vga virtio' for mesa-dri-virtio
2017-11-05 13:48:49 +00:00
def arguments_qemu(subparser):
ret = subparser.add_parser("qemu")
ret.add_argument("--cmdline", help="override kernel commandline")
ret.add_argument("--image-size", default="4G",
help="set rootfs size, e.g. 2048M or 2G (default: 4G)")
ret.add_argument("--second-storage", metavar="IMAGE_SIZE",
help="add a second storage with the given size (default:"
" 4G), gets created if it does not exist. Use to"
" test install from SD to eMMC",
nargs="?", default=None, const="4G")
Close #453: Support mesa-dri-virtio in Qemu (#861) The mesa driver, which ends up in the installation image, needs to be known before the installation is done (in other words: when running the qemu action, it is to late as the image has already been generated). That's why one can choose the Qemu mesa driver in `pmbootstrap init` now: ``` Device [qemu-amd64]: Which mesa driver do you prefer for your Qemu device? Only select something other than the default if you are having graphical problems (such as glitches). Mesa driver (dri-swrast/dri-virtio) [dri-virtio]: ``` It is still possible to select `dri-swrast`, because `dri-virtio` may not work in all cases, and that way we could easily debug it or experiment with other mesa drivers (e.g. the "vmware" one, which is supported by mesa and Qemu). Other changes: * `pmbootstrap qemu` accepts a `--display` variable now, which passes the value directly to `qemu`'s `display` option. It defaults to `sdl,gl=on` (@PureTryOut reported that to work best with plasma mobile on his PC). `--display` and `--spice` (which is still working) are mutually exclusive. * Removed obsolete telnet port pass-through: We only use the debug telnet port since osk-sdl has been merged. * Add show-cursor to the Qemu command line, so it shows a cursor in X11 * Refactored the spice code (`command_spice` only returns the spice command, because it has all necessary information already) and the spice port can be specified on the commandline now (previously it was hardcoded in one place and then always looked up from there). * Start comments with capital letters. * Keep the log on the screen a bit shorter (e.g. Qemu command is written to the "pmbootstrap log" anyway, so there's no need to display it again). * linux-postmarketos-stable: Adjust kernel configs x86_64, armhf: enable as modules: CONFIG_DRM_VIRTIO_GPU, CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_BALLOON aarch64: all 3 options were already enabled as built-in (no change) * Set '-vga virtio' for mesa-dri-virtio
2017-11-05 13:48:49 +00:00
ret.add_argument("-m", "--memory", type=int, default=1024,
help="guest RAM (default: 1024)")
ret.add_argument("-p", "--port", type=int, default=2222,
help="SSH port (default: 2222)")
ret.add_argument("--no-kvm", dest="qemu_kvm", default=True,
action='store_false', help="Avoid using hardware-assisted"
" virtualization with KVM even when available (SLOW!)")
ret.add_argument("--cpu", dest="qemu_cpu",
help="Override emulated QEMU CPU. By default, the host"
" CPU will be emulated when using KVM and the QEMU"
" default otherwise (usually a CPU with minimal"
" features). A useful value is 'max' (emulate all"
" features that are available), use --cpu help to get a"
" list of possible values from QEMU.")
ret.add_argument("--tablet", dest="qemu_tablet", action='store_true',
default=False, help="Use 'tablet' instead of 'mouse'"
" input for QEMU. The tablet input device automatically"
" grabs/releases the mouse when moving in/out of the QEMU"
" window. (NOTE: For some reason the mouse position is"
" not reported correctly with this in some cases...)")
ret.add_argument("--display", dest="qemu_display",
choices=["sdl", "gtk", "none"],
help="QEMU's display parameter (default: gtk,gl=on)",
default="gtk", nargs="?")
ret.add_argument("--no-gl", dest="qemu_gl", default=True,
action='store_false', help="Avoid using GL for"
" accelerating graphics in QEMU (use software"
" rasterizer, slow!)")
ret.add_argument("--video", dest="qemu_video", default="1024x768@60",
help="Video resolution for QEMU"
" (WidthxHeight@RefreshRate). Default is 1024x768@60.")
ret.add_argument("--audio", dest="qemu_audio",
choices=["alsa", "pa", "sdl"],
help="QEMU's audio backend (default: none)",
default=None, nargs="?")
ret.add_argument("--host-qemu", dest="host_qemu", action='store_true',
help="Use the host system's qemu")
ret.add_argument("--efi", action="store_true",
help="Use EFI boot (default: direct kernel image boot)")
Close #453: Support mesa-dri-virtio in Qemu (#861) The mesa driver, which ends up in the installation image, needs to be known before the installation is done (in other words: when running the qemu action, it is to late as the image has already been generated). That's why one can choose the Qemu mesa driver in `pmbootstrap init` now: ``` Device [qemu-amd64]: Which mesa driver do you prefer for your Qemu device? Only select something other than the default if you are having graphical problems (such as glitches). Mesa driver (dri-swrast/dri-virtio) [dri-virtio]: ``` It is still possible to select `dri-swrast`, because `dri-virtio` may not work in all cases, and that way we could easily debug it or experiment with other mesa drivers (e.g. the "vmware" one, which is supported by mesa and Qemu). Other changes: * `pmbootstrap qemu` accepts a `--display` variable now, which passes the value directly to `qemu`'s `display` option. It defaults to `sdl,gl=on` (@PureTryOut reported that to work best with plasma mobile on his PC). `--display` and `--spice` (which is still working) are mutually exclusive. * Removed obsolete telnet port pass-through: We only use the debug telnet port since osk-sdl has been merged. * Add show-cursor to the Qemu command line, so it shows a cursor in X11 * Refactored the spice code (`command_spice` only returns the spice command, because it has all necessary information already) and the spice port can be specified on the commandline now (previously it was hardcoded in one place and then always looked up from there). * Start comments with capital letters. * Keep the log on the screen a bit shorter (e.g. Qemu command is written to the "pmbootstrap log" anyway, so there's no need to display it again). * linux-postmarketos-stable: Adjust kernel configs x86_64, armhf: enable as modules: CONFIG_DRM_VIRTIO_GPU, CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_BALLOON aarch64: all 3 options were already enabled as built-in (no change) * Set '-vga virtio' for mesa-dri-virtio
2017-11-05 13:48:49 +00:00
return ret
def arguments_pkgrel_bump(subparser):
ret = subparser.add_parser("pkgrel_bump", help="increase the pkgrel to"
" indicate that a package must be rebuilt"
" because of a dependency change")
ret.add_argument("--dry", action="store_true", help="instead of modifying"
" APKBUILDs, exit with >0 when a package would have been"
" bumped")
# Mutually exclusive: "--auto" or package names
mode = ret.add_mutually_exclusive_group(required=True)
mode.add_argument("--auto", action="store_true", help="all packages which"
" depend on a library which had an incompatible update"
" (libraries with a soname bump)")
mode.add_argument("packages", nargs="*", default=[])
return ret
def arguments_aportupgrade(subparser):
ret = subparser.add_parser("aportupgrade", help="check for outdated"
" packages that need upgrading")
ret.add_argument("--dry", action="store_true", help="instead of modifying"
" APKBUILDs, print the changes that would be made")
ret.add_argument("--ref", help="git ref (tag, commit, etc) to use")
# Mutually exclusive: "--all" or package names
mode = ret.add_mutually_exclusive_group(required=True)
mode.add_argument("--all", action="store_true", help="iterate through all"
" packages")
mode.add_argument("--all-stable", action="store_true", help="iterate"
" through all non-git packages")
mode.add_argument("--all-git", action="store_true", help="iterate through"
" all git packages")
mode.add_argument("packages", nargs="*", default=[])
return ret
def arguments_newapkbuild(subparser):
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
"""
Wrapper for Alpine's "newapkbuild" command.
Most parameters will get directly passed through, and they are defined in
"pmb/config/__init__.py". That way they can be used here and when passing
them through in "pmb/helpers/frontend.py". The order of the parameters is
kept the same as in "newapkbuild -h".
"""
sub = subparser.add_parser("newapkbuild", help="get a template to package"
" new software")
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
sub.add_argument("--folder", help="set postmarketOS aports folder"
" (default: main)", default="main")
# Passthrough: Strings (e.g. -d "my description")
for entry in pmb.config.newapkbuild_arguments_strings:
sub.add_argument(entry[0], dest=entry[1], help=entry[2])
# Passthrough: Package type switches (e.g. -C for CMake)
group = sub.add_mutually_exclusive_group()
for entry in pmb.config.newapkbuild_arguments_switches_pkgtypes:
group.add_argument(entry[0], dest=entry[1], help=entry[2],
action="store_true")
# Passthrough: Other switches (e.g. -c for copying sample files)
for entry in pmb.config.newapkbuild_arguments_switches_other:
sub.add_argument(entry[0], dest=entry[1], help=entry[2],
action="store_true")
# Force switch
sub.add_argument("-f", dest="force", action="store_true",
help="force even if directory already exists")
# Passthrough: PKGNAME[-PKGVER] | SRCURL
sub.add_argument("pkgname_pkgver_srcurl",
metavar="PKGNAME[-PKGVER] | SRCURL",
help="set either the package name (optionally with the"
" PKGVER at the end, e.g. 'hello-world-1.0') or the"
" download link to the source archive")
def arguments_kconfig(subparser):
# Allowed architectures
arch_native = pmb.config.arch_native
arch_choices = set(pmb.config.build_device_architectures + [arch_native])
# Kconfig subparser
ret = subparser.add_parser("kconfig", help="change or edit kernel configs")
sub = ret.add_subparsers(dest="action_kconfig")
sub.required = True
# "pmbootstrap kconfig check"
check = sub.add_parser("check", help="check kernel aport config")
check.add_argument("-f", "--force", action="store_true", help="check all"
" kernels, even the ones that would be ignored by"
" default")
check.add_argument("--arch", choices=arch_choices, dest="arch")
check.add_argument("--file", action="store_true", help="check a file"
" directly instead of a config in a package")
check.add_argument("--no-details", action="store_false",
dest="kconfig_check_details",
help="print one generic error per component instead of"
" listing each option that needs to be adjusted")
for name in pmb.parse.kconfig.get_all_component_names():
check.add_argument(f"--{name}", action="store_true",
dest=f"kconfig_check_{name}",
help=f"check options needed for {name} too")
add_kernel_arg(check)
# "pmbootstrap kconfig edit"
edit = sub.add_parser("edit", help="edit kernel aport config")
edit.add_argument("--arch", choices=arch_choices, dest="arch")
edit.add_argument("-x", dest="xconfig", action="store_true",
help="use xconfig rather than menuconfig for kernel"
" configuration")
edit.add_argument("-n", dest="nconfig", action="store_true",
help="use nconfig rather than menuconfig for kernel"
" configuration")
add_kernel_arg(edit)
# "pmbootstrap kconfig migrate"
migrate = sub.add_parser("migrate",
help="Migrate kconfig from older version to "
"newer. Internally runs 'make oldconfig', "
"which asks question for every new kernel "
"config option.")
migrate.add_argument("--arch", choices=arch_choices, dest="arch")
add_kernel_arg(migrate)
2018-11-15 07:36:39 +00:00
def arguments_repo_missing(subparser):
ret = subparser.add_parser("repo_missing")
package = ret.add_argument("package", nargs="?", help="only look at a"
" specific package and its dependencies")
if argcomplete:
package.completer = package_completer
2018-11-15 07:36:39 +00:00
ret.add_argument("--arch", choices=pmb.config.build_device_architectures,
default=pmb.config.arch_native)
2018-11-15 07:36:39 +00:00
ret.add_argument("--built", action="store_true",
help="include packages which exist in the binary repos")
ret.add_argument("--overview", action="store_true",
help="only print the pkgnames without any details")
return ret
def arguments_lint(subparser):
lint = subparser.add_parser("lint", help="run quality checks on pmaports"
" (required to pass CI)")
add_packages_arg(lint, nargs="*")
def arguments_status(subparser):
ret = subparser.add_parser("status",
help="quick health check for the work dir")
ret.add_argument("--details", action="store_true",
help="list passing checks in detail, not as summary")
return ret
def arguments_netboot(subparser):
ret = subparser.add_parser("netboot",
help="launch nbd server with pmOS rootfs")
sub = ret.add_subparsers(dest="action_netboot")
sub.required = True
start = sub.add_parser("serve", help="start nbd server")
start.add_argument("--replace", action="store_true",
help="replace stored netboot image")
return ret
def arguments_ci(subparser):
ret = subparser.add_parser("ci", help="run continuous integration scripts"
" locally of git repo in current"
" directory")
script_args = ret.add_mutually_exclusive_group()
script_args.add_argument("-a", "--all", action="store_true",
help="run all scripts")
script_args.add_argument("-f", "--fast", action="store_true",
help="run fast scripts only")
ret.add_argument("scripts", nargs="*", metavar="script",
help="name of the CI script to run, depending on the git"
" repository")
return ret
def package_completer(prefix, action, parser=None, parsed_args=None):
2018-08-27 21:35:05 +00:00
args = parsed_args
pmb.config.merge_with_args(args)
pmb.helpers.args.replace_placeholders(args)
pmb.helpers.other.init_cache()
packages = set(
package for package in pmb.helpers.pmaports.get_list(args)
if package.startswith(prefix))
2018-08-27 21:35:05 +00:00
return packages
def kernel_completer(prefix, action, parser=None, parsed_args=None):
""" :returns: matched linux-* packages, with linux-* prefix and without """
ret = []
# Full package name, starting with "linux-"
if (len("linux-") < len(prefix) and prefix.startswith("linux-") or
"linux-".startswith(prefix)):
ret += package_completer(prefix, action, parser, parsed_args)
# Kernel name without "linux-"
packages = package_completer(f"linux-{prefix}", action, parser,
parsed_args)
ret += [package.replace("linux-", "", 1) for package in packages]
return ret
def add_packages_arg(subparser, name="packages", *args, **kwargs):
arg = subparser.add_argument(name, *args, **kwargs)
if argcomplete:
arg.completer = package_completer
def add_kernel_arg(subparser, name="package", nargs="?", *args, **kwargs):
arg = subparser.add_argument("package", nargs=nargs, help="kernel package"
" (e.g. linux-postmarketos-allwinner)")
if argcomplete:
arg.completer = kernel_completer
2017-05-26 20:08:45 +00:00
def arguments():
parser = argparse.ArgumentParser(prog="pmbootstrap")
arch_native = pmb.config.arch_native
arch_choices = set(pmb.config.build_device_architectures + [arch_native])
mirrors_pmos_default = pmb.config.defaults["mirrors_postmarketos"]
2017-05-26 20:08:45 +00:00
# Other
parser.add_argument("-V", "--version", action="version",
version=pmb.__version__)
2017-05-26 20:08:45 +00:00
parser.add_argument("-c", "--config", dest="config",
default=pmb.config.defaults["config"],
help="path to pmbootstrap.cfg file (default in"
" ~/.config/)")
parser.add_argument("--config-channels",
help="path to channels.cfg (which is by default"
" read from pmaports.git, origin/master branch)")
parser.add_argument("-mp", "--mirror-pmOS", dest="mirrors_postmarketos",
help="postmarketOS mirror, disable with: -mp='',"
" specify multiple with: -mp='one' -mp='two',"
f" default: {mirrors_pmos_default}",
metavar="URL", action="append", default=[])
parser.add_argument("-m", "--mirror-alpine", dest="mirror_alpine",
help="Alpine Linux mirror, default: " +
pmb.config.defaults["mirror_alpine"],
metavar="URL")
2017-05-26 20:08:45 +00:00
parser.add_argument("-j", "--jobs", help="parallel jobs when compiling")
parser.add_argument("-E", "--extra-space",
help="specify an integer with the amount of additional"
"space to allocate to the image in MB (default"
" 0)")
parser.add_argument("-B", "--boot-size",
help="specify an integer with your preferred boot"
"partition size on target machine in MB (default"
" 128)")
2017-05-26 20:08:45 +00:00
parser.add_argument("-p", "--aports",
help="postmarketos aports (pmaports) path")
parser.add_argument("-t", "--timeout", help="seconds after which processes"
" get killed that stopped writing any output (default:"
" 900)", default=900, type=float)
2017-05-26 20:08:45 +00:00
parser.add_argument("-w", "--work", help="folder where all data"
" gets stored (chroots, caches, built packages)")
parser.add_argument("-y", "--assume-yes", help="Assume 'yes' to all"
" question prompts. WARNING: this option will"
" cause normal 'are you sure?' prompts to be"
" disabled!",
action="store_true")
parser.add_argument("--as-root", help="Allow running as root (not"
" recommended, may screw up your work folders"
" directory permissions!)", dest="as_root",
action="store_true")
parser.add_argument("-o", "--offline", help="Do not attempt to update"
" the package index files", action="store_true")
2017-05-26 20:08:45 +00:00
pmb: adjust to distcc 3.3 and wrap it with sshd Overview: Since Alpine updated to distcc 3.3 last week, pmbootstrap wasn't able to use distcc for cross compilation anymore. It always falled back to running the compiler in QEMU (which works, but is a lot slower). The reason for that is, that distcc requires all compilers that are being used in a whitelist now. This partially fixes CVE-2004-2687 in distccd, which allowed trivial remote code execution by any process connecting to the distccd server. We only run distccd on localhost, but still this can be used for privilege escalation of sandboxed processes running on the host system (not part of pmbootstrap chroots). Because the CVE is only partially fixed (see the comment in `pmb/chroot/distccd.py` for details), we make sure that only the building chroots can talk to the distcc server by running distcc over ssh. Details: * Completely refactored `pmb/chroot/distccd.py` to run distcc over ssh * Store the running distcc server's arguments as JSON now, not as INI * Make debugging distcc issues easy: * Set DISTCC_BACKOFF_PERIOD=0, so the distcc client will not ignore the server after errors happened (this masks the original error!) * New pmbootstrap parameters: * `--distcc-nofallback`: avoids falling back to compiling with QEMU and not throwing an error * `--ccache-disable`: avoid ccache (when the compiler output is cached, distcc does not get used) * `--verbose` prints verbose output of the distcc too * New test case, that uses the new pmbootstrap parameters to force compilation through distcc, and shows the output of distcc and distccd in verbose mode on error (as well as the log of sshd)
2018-07-25 19:09:45 +00:00
# Compiler
parser.add_argument("--no-ccache", action="store_false",
pmb: adjust to distcc 3.3 and wrap it with sshd Overview: Since Alpine updated to distcc 3.3 last week, pmbootstrap wasn't able to use distcc for cross compilation anymore. It always falled back to running the compiler in QEMU (which works, but is a lot slower). The reason for that is, that distcc requires all compilers that are being used in a whitelist now. This partially fixes CVE-2004-2687 in distccd, which allowed trivial remote code execution by any process connecting to the distccd server. We only run distccd on localhost, but still this can be used for privilege escalation of sandboxed processes running on the host system (not part of pmbootstrap chroots). Because the CVE is only partially fixed (see the comment in `pmb/chroot/distccd.py` for details), we make sure that only the building chroots can talk to the distcc server by running distcc over ssh. Details: * Completely refactored `pmb/chroot/distccd.py` to run distcc over ssh * Store the running distcc server's arguments as JSON now, not as INI * Make debugging distcc issues easy: * Set DISTCC_BACKOFF_PERIOD=0, so the distcc client will not ignore the server after errors happened (this masks the original error!) * New pmbootstrap parameters: * `--distcc-nofallback`: avoids falling back to compiling with QEMU and not throwing an error * `--ccache-disable`: avoid ccache (when the compiler output is cached, distcc does not get used) * `--verbose` prints verbose output of the distcc too * New test case, that uses the new pmbootstrap parameters to force compilation through distcc, and shows the output of distcc and distccd in verbose mode on error (as well as the log of sshd)
2018-07-25 19:09:45 +00:00
dest="ccache", help="do not cache the compiled output")
parser.add_argument("--no-cross", action="store_false", dest="cross",
help="disable cross compiler, build only with QEMU and"
" gcc (slow!)")
2017-05-26 20:08:45 +00:00
# Logging
parser.add_argument("-l", "--log", dest="log", default=None,
help="path to log file")
parser.add_argument("--details-to-stdout", dest="details_to_stdout",
help="print details (e.g. build output) to stdout,"
" instead of writing to the log",
action="store_true")
2017-05-26 20:08:45 +00:00
parser.add_argument("-v", "--verbose", dest="verbose",
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129) TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution. --- pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has. I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository. To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on. In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option. In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds". This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before. Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases). The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
action="store_true", help="write even more to the"
" logfiles (this may reduce performance)")
parser.add_argument("-q", "--quiet", dest="quiet", action="store_true",
help="do not output any log messages")
2017-05-26 20:08:45 +00:00
# Actions
sub = parser.add_subparsers(title="action", dest="action")
sub.add_parser("init", help="initialize config file")
sub.add_parser("shutdown", help="umount, unregister binfmt")
sub.add_parser("index", help="re-index all repositories with custom built"
" packages (do this after manually removing package files)")
sub.add_parser("work_migrate", help="run this before using pmbootstrap"
" non-interactively to migrate the"
" work folder version on demand")
2018-11-15 07:36:39 +00:00
arguments_repo_missing(sub)
arguments_kconfig(sub)
arguments_export(sub)
arguments_sideload(sub)
arguments_netboot(sub)
2017-05-26 20:08:45 +00:00
arguments_flasher(sub)
arguments_initfs(sub)
Close #453: Support mesa-dri-virtio in Qemu (#861) The mesa driver, which ends up in the installation image, needs to be known before the installation is done (in other words: when running the qemu action, it is to late as the image has already been generated). That's why one can choose the Qemu mesa driver in `pmbootstrap init` now: ``` Device [qemu-amd64]: Which mesa driver do you prefer for your Qemu device? Only select something other than the default if you are having graphical problems (such as glitches). Mesa driver (dri-swrast/dri-virtio) [dri-virtio]: ``` It is still possible to select `dri-swrast`, because `dri-virtio` may not work in all cases, and that way we could easily debug it or experiment with other mesa drivers (e.g. the "vmware" one, which is supported by mesa and Qemu). Other changes: * `pmbootstrap qemu` accepts a `--display` variable now, which passes the value directly to `qemu`'s `display` option. It defaults to `sdl,gl=on` (@PureTryOut reported that to work best with plasma mobile on his PC). `--display` and `--spice` (which is still working) are mutually exclusive. * Removed obsolete telnet port pass-through: We only use the debug telnet port since osk-sdl has been merged. * Add show-cursor to the Qemu command line, so it shows a cursor in X11 * Refactored the spice code (`command_spice` only returns the spice command, because it has all necessary information already) and the spice port can be specified on the commandline now (previously it was hardcoded in one place and then always looked up from there). * Start comments with capital letters. * Keep the log on the screen a bit shorter (e.g. Qemu command is written to the "pmbootstrap log" anyway, so there's no need to display it again). * linux-postmarketos-stable: Adjust kernel configs x86_64, armhf: enable as modules: CONFIG_DRM_VIRTIO_GPU, CONFIG_VIRTIO_PCI, CONFIG_VIRTIO_BALLOON aarch64: all 3 options were already enabled as built-in (no change) * Set '-vga virtio' for mesa-dri-virtio
2017-11-05 13:48:49 +00:00
arguments_qemu(sub)
arguments_pkgrel_bump(sub)
arguments_aportupgrade(sub)
arguments_newapkbuild(sub)
arguments_lint(sub)
arguments_status(sub)
arguments_ci(sub)
2017-05-26 20:08:45 +00:00
# Action: log
log = sub.add_parser("log", help="follow the pmbootstrap logfile")
log.add_argument("-n", "--lines", default="60",
help="count of initial output lines")
log.add_argument("-c", "--clear", help="clear the log",
action="store_true", dest="clear_log")
2017-05-26 20:08:45 +00:00
# Action: zap
2017-06-20 17:12:41 +00:00
zap = sub.add_parser("zap", help="safely delete chroot folders")
zap.add_argument("--dry", action="store_true", help="instead of actually"
" deleting anything, print out what would have been"
" deleted")
zap.add_argument("-hc", "--http", action="store_true", help="also delete"
" http cache")
zap.add_argument("-d", "--distfiles", action="store_true", help="also"
" delete downloaded source tarballs")
zap.add_argument("-p", "--pkgs-local", action="store_true",
dest="pkgs_local",
help="also delete *all* locally compiled packages")
zap.add_argument("-m", "--pkgs-local-mismatch", action="store_true",
dest="pkgs_local_mismatch",
help="also delete locally compiled packages without"
" existing aport of same version")
zap.add_argument("-n", "--netboot", action="store_true",
help="also delete stored images for netboot")
zap.add_argument("-o", "--pkgs-online-mismatch", action="store_true",
dest="pkgs_online_mismatch",
help="also delete outdated packages from online mirrors"
" (that have been downloaded to the apk cache)")
zap.add_argument("-r", "--rust", action="store_true",
help="also delete rust related caches")
2017-05-26 20:08:45 +00:00
zap_all_delete_args = ["http", "distfiles", "pkgs_local",
"pkgs_local_mismatch", "netboot", "pkgs_online_mismatch",
"rust"]
zap_all_delete_args_print = [arg.replace("_", "-")
for arg in zap_all_delete_args]
zap.add_argument("-a", "--all",
action=toggle_other_boolean_flags(*zap_all_delete_args),
help="delete everything, equivalent to: "
f"--{' --'.join(zap_all_delete_args_print)}")
2017-05-26 20:08:45 +00:00
# Action: stats
stats = sub.add_parser("stats", help="show ccache stats")
stats.add_argument("--arch", default=arch_native, choices=arch_choices)
2017-05-26 20:08:45 +00:00
# Action: update
update = sub.add_parser("update", help="update all existing APKINDEX"
" files")
update.add_argument("--arch", default=None, choices=arch_choices,
help="only update a specific architecture")
update.add_argument("--non-existing", action="store_true", help="do not"
" only update the existing APKINDEX files, but all of"
" them", dest="non_existing")
# Action: build_init / chroot
2017-05-26 20:08:45 +00:00
build_init = sub.add_parser("build_init", help="initialize build"
" environment (usually you do not need to call"
" this)")
2017-05-26 20:08:45 +00:00
chroot = sub.add_parser("chroot", help="start shell in chroot")
chroot.add_argument("--add", help="build/install comma separated list of"
" packages in the chroot before entering it")
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
chroot.add_argument("--user", help="run the command as user, not as root",
action="store_true")
chroot.add_argument("--output", choices=["log", "stdout", "interactive",
"tui", "background"], help="how the output of the"
" program should be handled, choose from: 'log',"
" 'stdout', 'interactive', 'tui' (default),"
" 'background'. Details: pmb/helpers/run_core.py",
default="tui")
chroot.add_argument("command", default=["sh", "-i"], help="command"
" to execute inside the chroot. default: sh",
nargs='*')
chroot.add_argument("-x", "--xauth", action="store_true",
help="Copy .Xauthority and set environment variables,"
" so X11 applications can be started (native"
" chroot only)")
chroot.add_argument("-i", "--install-blockdev", action="store_true",
help="Create a sparse image file and mount it as"
" /dev/install, just like during the"
" installation process.")
2017-05-26 20:08:45 +00:00
for action in [build_init, chroot]:
suffix = action.add_mutually_exclusive_group()
if action == chroot:
suffix.add_argument("-r", "--rootfs", action="store_true",
help="Chroot for the device root file system")
suffix.add_argument("-b", "--buildroot", nargs="?", const="device",
choices={"device"} | arch_choices,
help="Chroot for building packages, defaults to"
" device architecture")
suffix.add_argument("-s", "--suffix", default=None,
help="Specify any chroot suffix, defaults to"
" 'native'")
2017-05-26 20:08:45 +00:00
# Action: install
arguments_install(sub)
2017-05-26 20:08:45 +00:00
# Action: checksum
checksum = sub.add_parser("checksum", help="update aport checksums")
checksum.add_argument("--verify", action="store_true", help="download"
" sources and verify that the checksums of the"
" APKBUILD match, instead of updating them")
add_packages_arg(checksum, nargs="+")
# Action: aportgen
aportgen = sub.add_parser("aportgen", help="generate a postmarketOS"
" specific package build recipe"
" (aport/APKBUILD)")
aportgen.add_argument("--fork-alpine", help="fork the alpine upstream"
" package", action="store_true",
dest="fork_alpine")
add_packages_arg(aportgen, nargs="+")
# Action: build
2017-05-26 20:08:45 +00:00
build = sub.add_parser("build", help="create a package for a"
" specific architecture")
build.add_argument("--arch", choices=arch_choices, default=None,
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
help="CPU architecture to build for (default: " +
arch_native + " or first available architecture in"
" APKBUILD)")
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.add_argument("--force", action="store_true", help="even build if not"
" necessary")
build.add_argument("--strict", action="store_true", help="(slower) zap and"
" install only required depends when building, to"
" detect dependency errors")
build.add_argument("--src", help="override source used to build the"
" package with a local folder (the APKBUILD must"
" expect the source to be in $builddir, so you might"
" need to adjust it)",
nargs=1)
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.add_argument("-i", "--ignore-depends", action="store_true",
help="only build and install makedepends from an"
" APKBUILD, ignore the depends (old behavior). This is"
" faster for device packages for example, because then"
" you don't need to build and install the kernel. But"
" it is incompatible with how Alpine's abuild handles"
" it.",
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
dest="ignore_depends")
build.add_argument("-n", "--no-depends", action="store_true",
help="never build dependencies, abort instead",
dest="no_depends")
build.add_argument("--go-mod-cache", action="store_true", default=None,
help="for go packages: Usually they should bundle the"
" dependency sources instead of downloading them"
" at build time. But if they don't (e.g. with"
" pmbootstrap build --src), then this option can"
" be used to let GOMODCACHE point into"
" pmbootstrap's work dir to only download"
" dependencies once. (default: true with --src,"
" false otherwise)")
build.add_argument("--no-go-mod-cache",
action="store_false", dest="go_mod_cache", default=None,
help="don't set GOMODCACHE")
build.add_argument("--envkernel", action="store_true",
help="Create an apk package from the build output of"
" a kernel compiled locally on the host or with envkernel.sh.")
add_packages_arg(build, nargs="+")
2017-05-26 20:08:45 +00:00
# Action: deviceinfo_parse
deviceinfo_parse = sub.add_parser("deviceinfo_parse")
deviceinfo_parse.add_argument("devices", nargs="*")
deviceinfo_parse.add_argument("--kernel", help="the kernel to select (for"
" device packages with multiple kernels),"
" e.g. 'downstream', 'mainline'",
dest="deviceinfo_parse_kernel",
metavar="KERNEL")
# Action: apkbuild_parse
apkbuild_parse = sub.add_parser("apkbuild_parse")
add_packages_arg(apkbuild_parse, nargs="*")
# Action: apkindex_parse
apkindex_parse = sub.add_parser("apkindex_parse")
apkindex_parse.add_argument("apkindex_path")
add_packages_arg(apkindex_parse, "package", nargs="?")
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129) TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution. --- pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has. I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository. To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on. In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option. In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds". This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before. Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases). The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
# Action: config
config = sub.add_parser("config",
help="get and set pmbootstrap options")
config.add_argument("-r", "--reset", action="store_true",
help="Reset config options with the given name to it's"
" default.")
config.add_argument("name", nargs="?", help="variable name, one of: " +
", ".join(sorted(pmb.config.config_keys)),
choices=pmb.config.config_keys, metavar="name")
config.add_argument("value", nargs="?", help="set variable to value")
# Action: bootimg_analyze
bootimg_analyze = sub.add_parser("bootimg_analyze", help="Extract all the"
" information from an existing boot.img")
bootimg_analyze.add_argument("path", help="path to the boot.img")
2018-07-08 21:49:03 +00:00
bootimg_analyze.add_argument("--force", "-f", action="store_true",
help="force even if the file seems to be"
" invalid")
# Action: pull
sub.add_parser("pull", help="update all git repositories that pmbootstrap"
" cloned (pmaports, etc.)")
2018-08-27 21:35:05 +00:00
if argcomplete:
argcomplete.autocomplete(parser, always_complete_options="long")
# Parse and extend arguments (also backup unmodified result from argparse)
2017-05-26 20:08:45 +00:00
args = parser.parse_args()
setattr(args, "from_argparse", copy.deepcopy(args))
setattr(args.from_argparse, "from_argparse", args.from_argparse)
pmb.helpers.args.init(args)
if getattr(args, "go_mod_cache", None) is None:
gomodcache = True if getattr(args, "src", None) else False
setattr(args, "go_mod_cache", gomodcache)
2017-05-26 20:08:45 +00:00
return args