Commit Graph

1802 Commits

Author SHA1 Message Date
Oliver Smith f21c216a26
Cosmetic: use SPDX license header (!1877)
While at it, also remove unnecessary "#!/usr/bin/env python3" in files
that only get imported, and adjust other empty/comment lines in the
beginnings of the files for consistency.

This makes files easier to read, and makes the pmbootstrap codebase more
consistent with the build.postmarketos.org codebase.
2020-02-24 03:11:10 +03:00
Oliver Smith e605a0af32
test/pmb_test: prepare for common test code (!1876)
Replace the "Add topdir to import path" boilerplate lines in each test
file with a simple "import pmb_test". Use the "# noqa" comment if
"pmb_test" is not used further in the test file, so flake8 does not
complain about an unused module.

Make the path to the testdata available as pmb_test.const.testdata, and
use pmb.config.pmb_src to access the topdir in all tests.

This is in preparation for new "pmbootstrap status" related tests, which
will have shared test code in test/pmb_test/. Also, this makes the
pmbootstrap codebase more consistent with the bpo codebase, which has a
similar "import bpo_test" mechanism.
2020-02-24 03:01:04 +03:00
Oliver Smith 4a08b5e066
Prepare 1.15.0 release 2020-02-23 03:40:30 +01:00
Luca Weiss b7e47367e5
aportgen: suggest 'pmbootstrap pull' in error message (!1874) 2020-02-21 16:26:08 +01:00
Minecrell 0e27713512
pmb.parse._apkbuild: Extend APKBUILD parser to work for subpackages (!1866)
At the moment we have a simple subpkgdesc() function that can only
parse "pkgdesc" from subpackages, without support for any variables.
But we have a quite nice variable parser now that can be extended
to work for subpackages.

Simply put this works by:
  - Finding the lines that belong to the subpackage function
  - Stripping indentation (tab)
  - Parsing relevant attributes similar to the apkbuild() function

The "subpackages" in the parsed APKBUILD are replaced by a dict
of subpkgname: {"pkgdesc": "...", "depends": "..."} which are
parsed from the subpackage function (if found).
This makes it possible to get the "depends" of a subpackage.
2020-02-19 14:56:57 +03:00
Minecrell 0dad22a112
pmb.parse._apkbuild: Set "array": False by default (!1866)
This avoids having to set all unused options to False.
2020-02-19 14:56:52 +03:00
Minecrell 5f5050f9a3
pmb.parse._apkbuild: Replace variables immediately after parsing (!1866)
At the moment we parse all attributes, split them, and eventually
join them back together for variable replacement.

Replacing variables immediately after parsing (before splitting)
has several advantages:

  - No need to handle different value types
    (e.g. lists by joining them every time they are accessed)

  - Variables like depends="$depends ..." are handled directly
    by the variable parser

  - APKBUILDs are shell scripts, so we match abuild more closely
    if variables defined later do not affect previous attributes
2020-02-19 14:56:46 +03:00
Minecrell 3aabaf451c
pmb.parse._apkbuild: Set default attribute values before starting to parse (!866)
Theoretically it is possible to reference variables before they are defined.
In the shell, these will simply be evaluated to an empty string.
In preparation of replacing variables immediately after parsing attributes,
these variables will be no longer replaced correctly.

We can simplify the code further, and avoid this problem by initializing
the dict with the default values, replacing them with the real values
from the APKBUILD.

This will also avoid a (somewhat unrelated) error in the bootimg test:

  File "pmb/parse/_apkbuild.py", line 46, in replace_variable
    apkbuild["pkgname"], match.group(0),
  KeyError: 'pkgname'
2020-02-19 14:56:35 +03:00
Luca Weiss 33e3553cdd
aportupgrade command for upgrading APKBUILDs (!1752)
The gist of this action is upgrading the specified aport to the latest
version. There are implementations for both stable packages (which check
via the release-monitoring.org API for new versions) and git packages
(which check the GitLab/GitHub API for new commits on the main branch).

There's also the possibility to pass --all, --all-stable & --all-git to
the action which either loops through all packages, or just stable or
git packages and upgrades them.

The --dry argument is also respected.

Note, that the implementation does update the variables pkgver, pkgrel
and _commit but it doesn't update the checksums because that would slow
down the process a lot, and is potentially undesirable.
2020-02-15 20:24:09 +01:00
Luca Weiss dd72fd44db
pmb.helpers.http: add retrieve & retrieve_json helpers (!1752)
Fetch the content of a URL and returns it as string.
2020-02-15 20:24:09 +01:00
Luca Weiss ddb8ff435c
pmb.helpers.file: add replace_apkbuild helper (!1752)
Replace one key=value line in an APKBUILD and verify it afterwards.
2020-02-15 20:24:04 +01:00
Minecrell 87dd071b32
add "fastboot-bootpart" flasher to flash split images with fastboot (!1871)
asus-me176c has a Fastboot interface that can be used for flashing,
but in postmarketOS we do not use Android boot images for it.
This is because is it not very practical - the boot partition is
quite small and there is a (custom) EFI bootloader that can boot
directly from any other FAT32 partition.

At the moment the installation process is manual:
  1. pmbootstrap install --split to have separated boot (FAT32)
     and rootfs images
  2. pmbootstrap export
  3. Flash boot and rootfs images manually using Fastboot

The "fastboot-bootpart" flasher implements that process in a more
convenient way. When a device uses the "fastboot-bootpart" flasher:

  - We generate --split images on "pmbootstrap install" by default.
    (This can be disabled using --no-split instead.)

  - pmbootstrap flasher flash_kernel flashes the raw boot partition
    (not an Android boot image) using Fastboot, just like the rootfs.

There are some limitations that could be improved in the future:

  - "fastboot-bootpart" is not offered in the device wizard.
    I think it is special enough that no-one will be starting with it,
    and the difference to normal "fastboot" might be confusing.

  - Support "pmbootstrap flasher boot". asus-me176c does not support
    "fastboot boot" properly, but theoretically we could still generate
    Android boot images to use when booting an image directly.

  - At the moment the boot partition image is not regenerated when
    using "pmbootstrap flasher flash_kernel" (unlike when using Android
    boot images). "pmbootstrap install" needs to be run manually first.
2020-02-10 00:05:00 +03:00
Minecrell ba1e39f48e
pmb.config: Fix formatting for flash methods (!1871)
For some reason, the formatting for the flash method definitions
is really messed up. Let's fix it!
2020-02-10 00:04:59 +03:00
Clayton Craft fbdc68c3b6
ci: Update docker image to python 3.7, use generic python3
The python3 version in docker image may not be the same in the qemu
test runner VM image, so a more generic 'python3' is used when creating
the venv.
2020-02-08 16:07:31 -08:00
Minecrell 6540c25a9b
envkernel.sh: add dependencies for x86_64 (!1870)
x86_64 kernels require some additional dependencies to build properly.

At this point, the list is getting quite long. Ideally we should only
install the build dependencies that are necessary for a particular
kernel package. Add a FIXME to document this for the future.
2020-02-07 19:20:40 +03:00
Minecrell 569c8ff5b0
envkernel.sh: fix x86_64 (arch == host_arch) (!1870)
Attempting to use envkernel.sh on x86_64 fails at the moment:

$ . ~/pmos/pmbootstrap/helpers/envkernel.sh
Initializing Alpine chroot (details: 'pmbootstrap log')
ERROR: unsatisfiable constraints:
  binutils-x86_64 (missing):
    required by: world[binutils-x86_64]
  gcc-x86_64 (missing):
    required by: world[gcc-x86_64]

We do not need to install a cross compiler if the device arch is
equal to the host architecture. Check if we need a cross compiler
earlier, and avoid installing it if not necessary.

Also rename "is_cc" to "need_cross_compiler". "is_cc" is confusingly
named since "cc" can refer to the compiler symlink ("C compiler")
or "cross compiler".
2020-02-07 19:20:01 +03:00
Oliver Smith fbbcc1c26f
pmb.parse.arguments: common func for packages arg (!1872)
Create add_packages_add() function, so we don't need to write the three
lines for adding the "packages" argument to an action with proper
autocompletion.
2020-02-06 16:29:31 +03:00
Danct12 a021d1924c
pmb.helpers.lint: add simple linting (!1855)
Run linting, just like in pmaports.git CI checks. Start with
apkbuild-lint, eventually this should run all checks.

Related: #1869
2020-02-06 13:45:21 +01:00
Oliver Smith 2f01c91c1a
pmbootstrap -s: remove option (!1868)
Remove in favor of similar, but more visible "--no-install" option for
"pmbootstrap flasher" and "pmbootstrap export".

It seems that the option wasn't really used by anybody, so let's just
remove it without a deprication period. If dear reader thinks otherwise
after this is merged, and is not happy with "--no-install", please state
your reasoning in a new issue, so we can discuss it.

Related: !1863
2020-02-06 12:33:21 +01:00
Minecrell 630310ebfb
pmb.aportgen.linux: Fix linting issues in generated APKBUILDs (!1869)
Avoid generating an APKBUILD with the following linting issues:
  - unnecesary usage of braces: ${_flavor}
  - unnecesary usage of braces: ${arch}
  - unnecesary usage of braces: ${_commit}
  - unnecesary usage of braces: ${_repository}
2020-02-02 06:49:12 +03:00
Minecrell d3fede3262
pmb.qemu.run.install_depends: Fix Mesa Gallium DRI depends (!1867)
Commit 43520967 ("pmb.qemu.run.install_depends: adjust to mesa pkgs (!1865)")
replaced mesa-dri-swrast, mesa-dri-virtio and mesa-dri-vmwgfx with
mesa-va-gallium. But the Gallium DRI drivers are actually provided by
mesa-dri-gallium. mesa-va-gallium contains libva drivers for hardware
video acceleration.

Fortunately this did not break anything because mesa-dri-gallium
was still installed as dependency of mesa-dri-ati/intel/nouveau.

QEMU does not make use of libva, so lets just replace mesa-va-gallium
with mesa-dri-gallium. While we are at it, stop depending on the
deprecated mesa-dri-ati/intel/nouveau packages. Those are only kept
for compatibility reasons and install more dependencies than necessary.
2020-01-31 04:10:50 +01:00
Minecrell 60217d0818
pmb.flasher/export: Add --no-install option to skip kernel/initfs update (!1863)
At the moment, pmbootstrap updates the kernel and the initfs whenever
using the flasher or export. This is useful, but sometimes you just want
to boot exactly the same kernel several times. In that case, having to wait
several seconds for the (redundant) update to complete is quite annoying.

Add a --no-install option that allows skipping the kernel/initfs update.
2020-01-31 01:35:26 +01:00
Oliver Smith 8f4bd7dea1
Prepare 1.14.0 release 2020-01-27 00:35:05 +01:00
Luca Weiss 859159254e
pmb/parse/_apkbuild: wrap more calls in try-catch (!1864)
Otherwise pmb crashes on some APKBUILDs, for example:

source="https://files.pythonhosted.org/packages/source/${_pyname%${_pyname#?}}/$_pyname/$_pyname-$pkgver.tar.gz"
2020-01-26 23:06:39 +01:00
Minecrell c8737740b1
pmb.install: Add pmbootstrap install --(no-)sparse option (!1862)
At the moment, sparse images are generated if the device sets
deviceinfo_flash_sparse="true". But for testing purposes it can be
useful to specifically enable or disable the default behavior.

Add a --sparse and --no-sparse option that enables or disables
sparse image generation.
2020-01-26 22:56:42 +01:00
Oliver Smith 4352096783
pmb.qemu.run.install_depends: adjust to mesa pkgs (!1865)
Adjust the mesa related packages installed for running in qemu, after
the mesa APKBUILD in Alpine was changed. Install mesa-va-gallium instead
of:
* mesa-dri-freedreno
* mesa-dri-swrast
* mesa-dri-virtio
* mesa-dri-vmwgfx

Fix error in pmbootstrap-qemu CI test:
ERROR: Could not find dependency 'mesa-dri-freedreno' in any aports folder or APKINDEX.

Related: 298e20d04f
2020-01-26 21:05:42 +01:00
Minecrell 44e887f11e
pmb.install: remove qemu-user binary stub from device rootfs (!1861)
Now that the qemu-user binary is bind-mounted, we no longer copy
the binary to the device rootfs. However, there is still the empty
stub file that we used as a destination mount point.

Let's remove it before copying it to the device rootfs.
It is automatically re-created the next time the qemu-user binary
is needed.
2020-01-26 19:47:43 +01:00
Minecrell d0376ee0fb
pmb.chroot.init: mount --bind qemu-user binary (!1861)
Avoid copying the qemu-user binary to each chroot by using a bind mount.
This ensures that we remove it when we shutdown the chroot.
2020-01-26 19:47:42 +01:00
Minecrell 81d9bfe3ba
pmb.helpers.mount: bind_file: Add create_folders option (!1861)
Create the necessary directory structure if create_folders=True.
2020-01-26 19:47:42 +01:00
Minecrell f43d552039
pmb.helpers.mount: Rename bind_blockdevice() to bind_file() (!1861)
bind_blockdevice() can be also used to mount --bind files,
rename it to bind_file().
2020-01-26 19:47:28 +01:00
Oliver Smith f3dc6a55cf
gitlab-ci.yml: allow 'git config' cmds to fail
Two "su pmos -c 'git config --global user....'" commands were added to
the before_script in .gitlab-ci.yml. They work fine with the regular
gitlab runners, but fail with the custom gitlab runner that runs the
qemu test. Simply allow the command to fail, because it isn't needed on
the custom gitlab runner, as it doesn't run related tests.

Fixes: 16e2d3c77c ("gitlab-ci.yml: set git user/email (!1848)")
2020-01-24 22:41:23 +01:00
Daniele Debernardi 0244ffbf53
static_code_analysis.sh: find all shell files (!1853) 2020-01-22 00:20:07 +01:00
Daniele Debernardi b0ea7ad8a0
envkernel.sh: fix shellcheck errors (!1853) 2020-01-22 00:17:23 +01:00
Daniele Debernardi 39f6dbef2e
gitlab-ci.yml: remove flake8/shellcheck (!1853) 2020-01-22 00:17:23 +01:00
Daniele Debernardi 3092fcaddb
gitlab-ci.yml: init pmbootstrap for static_code_analysis.sh (!1853) 2020-01-22 00:17:23 +01:00
Daniele Debernardi b60730499c
static_code_analysis.sh: use shellcheck/flake8 from chroot (!1853) 2020-01-22 00:17:23 +01:00
Minecrell 4b2750e4a9
pmb.config: do not force installation of ttf-droid (!1860)
Right now we explicitly add ttf-droid to /etc/apk/world, and force
installation of it on every postmarketOS installation. But there really
is no reason to force this from pmbootstrap:

  - If ttf-droid is really required for every postmarketOS installation,
    it should be a depends of postmarketos-base.

  - Even with this change it is still installed on every device,
    because postmarketos-splash depends on it.

  - There is no need for fonts when using the "none" UI.

For now, the only difference of this change is that we no longer add
ttf-droid explicitly to the APK world. Instead, it is installed as
dependency of postmarketos-splash.
2020-01-20 14:19:41 +03:00
Minecrell 66fdb74b5b
qemu: Make QEMU audio backend configurable (!1859)
At the moment we assume that everyone running QEMU is either using
ALSA, or has the ALSA PulseAudio plugin configured on the host system.
(Since we run QEMU outside of the chroot at the moment, configuration
files are read from the host system instead of the chroot...)

Other distributions have much wider support for PulseAudio,
so not everyone will actually have the ALSA PulseAudio plugin configured.
In that case, it is better to use QEMU's PulseAudio backend since that
does not require any configuration. It also lets us drop the alsa-lib
fork, since that was only needed for loading the ALSA PulseAudio plugin.

In general, it seems difficult to detect which audio backend the user
wants to run (if any). Selecting the wrong one results in ugly warnings
when running QEMU. So let's not assume any by default, and add a
--audio option instead which accepts one of QEMU's audio backends
(alsa, pa or sdl).
2020-01-20 00:53:52 +03:00
Oliver Smith e04712a636
pmbootstrap pull: new action (!1848)
Add a shortcut for "git pull --ff-only" in all repositories cloned by
pmbootstrap (currently pmaports and aports_upstream, new pmdevices
repository coming soon).

'pmbootstrap pull' will only update the repositories, if:
* they are on an officially supported branch (e.g. master)
* the history is not conflicting (fast-forward is possible)
* the git workdirs are clean

Otherwise it shows the user a descriptive message about what to do. The
list of supported branches is only "master" right now, and will be
extended in later commits, so we can have a stable branch for pmaports
based on Alpine's releases. More about that in the project direction
2020 issue.

Closes: #1858
2020-01-19 20:37:46 +03:00
Oliver Smith 16e2d3c77c
gitlab-ci.yml: set git user/email (!1848)
Prevent upcoming tests for "pmbootstrap pull" from failing, when trying
to create a git repository.
2020-01-19 20:37:46 +03:00
Oliver Smith 107c9f8b06
pmb.helpers.git.get_path: new function (!1848)
Get the path to the repository, which is either the default one in the
work dir, or a user-specified one in args.
2020-01-19 20:37:46 +03:00
Oliver Smith bbe3f5a219
pmb.helpers.git.rev_parse: add extra_args argument (!1848) 2020-01-19 20:37:46 +03:00
Oliver Smith 9ca06bc6c2
pmb.helpers.git.rev_parse: add path argument (!1848) 2020-01-19 20:37:46 +03:00
Oliver Smith 2b1dfe7cfc
pmb.helpers.git.rev_parse: don't return "" on err (!1848)
Remove a legacy code path from back in the day, where pmaports were in
the same repository as pmbootstrap ([1]). Nowadays, pmaports are always in a
git repository, so this is not necessary anymore. If git fails at this
point, crash hard and don't carry on with an empty string.

This is in preparation for using rev_parse in new code paths, so we
don't need to check the return value of rev_parse.

[1] 39548835 "Write custom os-release (closes #324) (#439)"
    https://github.com/postmarketOS/pmbootstrap/pull/439
2020-01-19 20:37:43 +03:00
Minecrell 7907e91879
pmb/parse/_apkbuild: Fix locating kernel subpackages with "-" in name (!1857)
When defining a new kernel subpackage with a "-" in it
(e.g. $pkgname-kernel-mainline-modem), then pmbootstrap is unable to
find the function that builds the subpackage:

ERROR: Could not find subpackage function, no line starts with 'kernel_mainline-modem() {'

This is because it assumes that a $pkgname-kernel-<name> subpackage
is built by a kernel_<name> function, but this does not have to be the case.

We should really respect the name of the subpackage function that
is specified when defining the subpackage, but unfortunately it is
stripped away in cut_off_function_names().

For now let's fix this by replacing "-" with "_", but ideally the
APKBUILD parser API should be refactored to expose the subpackage
function in the future.
2020-01-19 19:36:11 +03:00
Luca Weiss 2320e0100c
pmb/parse/_apkbuild: implement parsing for more variable styles (!1854)
Add a test for APKBUILD variable parsing as well
2020-01-19 11:30:59 +01:00
Luca Weiss b0563c54d0
test: fix small mistake (!1854) 2020-01-19 11:30:59 +01:00
Oliver Smith 3f5cc734d9
pmb.config: add deviceinfo_boot_part_start
Fixes: 9f1dd64fa1 ("install/partition: allow specifying a different boot partition start (!1856)")
2020-01-18 23:03:32 +01:00
Clayton Craft 9f1dd64fa1
install/partition: allow specifying a different boot partition start (!1856)
This adds a new deviceinfo parameter, 'boot_part_start' which accepts an
int and indicates the number of sectors from the start of the drive to
place the boot partition.

The librem5 devkit (and actual phone) u-boot has grown beyond the 2048
sector space previously before the boot partition, so this is necessary in
order to boot pmos on this device.
2020-01-18 19:26:31 +00:00
Minecrell 1fa61aad37 test: parse_depends: Fix hello-world test after pkgrel bump 2020-01-18 11:23:01 +01:00