2021-01-07 22:30:30 +00:00
|
|
|
# Copyright 2021 Oliver Smith
|
2020-02-20 20:07:28 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2017-08-07 22:53:54 +00:00
|
|
|
import logging
|
2020-01-06 16:55:26 +00:00
|
|
|
import os
|
|
|
|
import re
|
2020-01-27 23:23:09 +00:00
|
|
|
from collections import OrderedDict
|
2020-01-06 16:55:26 +00:00
|
|
|
|
2017-05-26 20:08:45 +00:00
|
|
|
import pmb.config
|
2020-02-26 11:13:26 +00:00
|
|
|
import pmb.helpers.devices
|
2018-01-18 22:05:27 +00:00
|
|
|
import pmb.parse.version
|
2017-05-26 20:08:45 +00:00
|
|
|
|
2020-01-06 16:55:26 +00:00
|
|
|
# sh variable name regex: https://stackoverflow.com/a/2821201/3527128
|
|
|
|
|
|
|
|
# ${foo}
|
|
|
|
revar = re.compile(r"\${([a-zA-Z_]+[a-zA-Z0-9_]*)}")
|
|
|
|
|
|
|
|
# $foo
|
|
|
|
revar2 = re.compile(r"\$([a-zA-Z_]+[a-zA-Z0-9_]*)")
|
|
|
|
|
|
|
|
# ${var/foo/bar}, ${var/foo/}, ${var/foo} -- replace foo with bar
|
|
|
|
revar3 = re.compile(r"\${([a-zA-Z_]+[a-zA-Z0-9_]*)/([^/]+)(?:/([^/]*?))?}")
|
|
|
|
|
|
|
|
# ${foo#bar} -- cut off bar from foo from start of string
|
|
|
|
revar4 = re.compile(r"\${([a-zA-Z_]+[a-zA-Z0-9_]*)#(.*)}")
|
|
|
|
|
|
|
|
|
|
|
|
def replace_variable(apkbuild, value: str) -> str:
|
2021-01-31 18:16:56 +00:00
|
|
|
def log_key_not_found(match):
|
|
|
|
logging.verbose(f"{apkbuild['pkgname']}: key '{match.group(1)}' for"
|
|
|
|
f" replacing '{match.group(0)}' not found, ignoring")
|
|
|
|
|
2020-01-06 16:55:26 +00:00
|
|
|
# ${foo}
|
|
|
|
for match in revar.finditer(value):
|
|
|
|
try:
|
|
|
|
logging.verbose("{}: replace '{}' with '{}'".format(
|
|
|
|
apkbuild["pkgname"], match.group(0),
|
|
|
|
apkbuild[match.group(1)]))
|
|
|
|
value = value.replace(match.group(0), apkbuild[match.group(1)], 1)
|
|
|
|
except KeyError:
|
2021-01-31 18:16:56 +00:00
|
|
|
log_key_not_found(match)
|
2020-01-06 16:55:26 +00:00
|
|
|
|
|
|
|
# $foo
|
|
|
|
for match in revar2.finditer(value):
|
|
|
|
try:
|
|
|
|
newvalue = apkbuild[match.group(1)]
|
|
|
|
logging.verbose("{}: replace '{}' with '{}'".format(
|
|
|
|
apkbuild["pkgname"], match.group(0),
|
|
|
|
newvalue))
|
|
|
|
value = value.replace(match.group(0), newvalue, 1)
|
|
|
|
except KeyError:
|
2021-01-31 18:16:56 +00:00
|
|
|
log_key_not_found(match)
|
2020-01-06 16:55:26 +00:00
|
|
|
|
|
|
|
# ${var/foo/bar}, ${var/foo/}, ${var/foo}
|
|
|
|
for match in revar3.finditer(value):
|
2020-01-25 19:23:41 +00:00
|
|
|
try:
|
|
|
|
newvalue = apkbuild[match.group(1)]
|
|
|
|
search = match.group(2)
|
|
|
|
replacement = match.group(3)
|
|
|
|
if replacement is None: # arg 3 is optional
|
|
|
|
replacement = ""
|
|
|
|
newvalue = newvalue.replace(search, replacement, 1)
|
|
|
|
logging.verbose("{}: replace '{}' with '{}'".format(
|
|
|
|
apkbuild["pkgname"], match.group(0), newvalue))
|
|
|
|
value = value.replace(match.group(0), newvalue, 1)
|
|
|
|
except KeyError:
|
2021-01-31 18:16:56 +00:00
|
|
|
log_key_not_found(match)
|
2020-01-06 16:55:26 +00:00
|
|
|
|
|
|
|
# ${foo#bar}
|
|
|
|
rematch4 = revar4.finditer(value)
|
|
|
|
for match in rematch4:
|
2020-01-25 19:23:41 +00:00
|
|
|
try:
|
|
|
|
newvalue = apkbuild[match.group(1)]
|
|
|
|
substr = match.group(2)
|
|
|
|
if newvalue.startswith(substr):
|
|
|
|
newvalue = newvalue.replace(substr, "", 1)
|
|
|
|
logging.verbose("{}: replace '{}' with '{}'".format(
|
|
|
|
apkbuild["pkgname"], match.group(0), newvalue))
|
|
|
|
value = value.replace(match.group(0), newvalue, 1)
|
|
|
|
except KeyError:
|
2021-01-31 18:16:56 +00:00
|
|
|
log_key_not_found(match)
|
2020-01-06 16:55:26 +00:00
|
|
|
|
|
|
|
return value
|
|
|
|
|
2017-05-26 20:08:45 +00:00
|
|
|
|
2019-02-05 16:22:27 +00:00
|
|
|
def function_body(path, func):
|
|
|
|
"""
|
|
|
|
Get the body of a function in an APKBUILD.
|
|
|
|
|
|
|
|
:param path: full path to the APKBUILD
|
|
|
|
:param func: name of function to get the body of.
|
|
|
|
:returns: function body in an array of strings.
|
|
|
|
"""
|
|
|
|
func_body = []
|
|
|
|
in_func = False
|
|
|
|
lines = read_file(path)
|
|
|
|
for line in lines:
|
|
|
|
if in_func:
|
|
|
|
if line.startswith("}"):
|
|
|
|
in_func = False
|
|
|
|
break
|
|
|
|
func_body.append(line)
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
if line.startswith(func + "() {"):
|
|
|
|
in_func = True
|
|
|
|
continue
|
|
|
|
return func_body
|
|
|
|
|
|
|
|
|
2019-02-05 16:20:48 +00:00
|
|
|
def read_file(path):
|
|
|
|
"""
|
|
|
|
Read an APKBUILD file
|
|
|
|
|
|
|
|
:param path: full path to the APKBUILD
|
|
|
|
:returns: contents of an APKBUILD as a list of strings
|
|
|
|
"""
|
|
|
|
with open(path, encoding="utf-8") as handle:
|
|
|
|
lines = handle.readlines()
|
|
|
|
if handle.newlines != '\n':
|
2021-01-31 18:16:56 +00:00
|
|
|
raise RuntimeError(f"Wrong line endings in APKBUILD: {path}")
|
2019-02-05 16:20:48 +00:00
|
|
|
return lines
|
|
|
|
|
|
|
|
|
2019-11-30 10:24:35 +00:00
|
|
|
def parse_attribute(attribute, lines, i, path):
|
|
|
|
"""
|
|
|
|
Parse one attribute from the APKBUILD.
|
|
|
|
|
|
|
|
It may be written across multiple lines, use a quoting sign and/or have
|
|
|
|
a comment at the end. Some examples:
|
|
|
|
|
|
|
|
pkgrel=3
|
|
|
|
options="!check" # ignore this comment
|
|
|
|
arch='all !armhf'
|
|
|
|
depends="
|
|
|
|
first-pkg
|
|
|
|
second-pkg"
|
|
|
|
|
|
|
|
:param attribute: from the APKBUILD, i.e. "pkgname"
|
|
|
|
:param lines: \n-terminated list of lines from the APKBUILD
|
|
|
|
:param i: index of the line we are currently looking at
|
|
|
|
:param path: full path to the APKBUILD (for error message)
|
|
|
|
:returns: (found, value, i)
|
|
|
|
found: True if the attribute was found in line i, False otherwise
|
|
|
|
value: that was parsed from the line
|
|
|
|
i: line that was parsed last
|
|
|
|
"""
|
|
|
|
# Check for and cut off "attribute="
|
|
|
|
if not lines[i].startswith(attribute + "="):
|
|
|
|
return (False, None, i)
|
|
|
|
value = lines[i][len(attribute + "="):-1]
|
|
|
|
|
|
|
|
# Determine end quote sign
|
|
|
|
end_char = None
|
|
|
|
for char in ["'", "\""]:
|
|
|
|
if value.startswith(char):
|
|
|
|
end_char = char
|
|
|
|
value = value[1:]
|
|
|
|
break
|
|
|
|
|
|
|
|
# Single line
|
|
|
|
if not end_char:
|
2021-12-12 09:00:32 +00:00
|
|
|
value = value.split("#")[0].rstrip()
|
2019-11-30 10:24:35 +00:00
|
|
|
return (True, value, i)
|
|
|
|
if end_char in value:
|
|
|
|
value = value.split(end_char, 1)[0]
|
|
|
|
return (True, value, i)
|
|
|
|
|
|
|
|
# Parse lines until reaching end quote
|
|
|
|
i += 1
|
|
|
|
while i < len(lines):
|
|
|
|
line = lines[i]
|
|
|
|
value += " "
|
|
|
|
if end_char in line:
|
|
|
|
value += line.split(end_char, 1)[0].strip()
|
|
|
|
return (True, value.strip(), i)
|
|
|
|
value += line.strip()
|
|
|
|
i += 1
|
|
|
|
|
2021-01-31 18:16:56 +00:00
|
|
|
raise RuntimeError(f"Can't find closing quote sign ({end_char}) for"
|
|
|
|
f" attribute '{attribute}' in: {path}")
|
2019-11-30 10:24:35 +00:00
|
|
|
|
|
|
|
|
2020-01-27 23:23:09 +00:00
|
|
|
def _parse_attributes(path, lines, apkbuild_attributes, ret):
|
|
|
|
"""
|
|
|
|
Parse attributes from a list of lines. Variables are replaced with values
|
2021-01-31 18:16:56 +00:00
|
|
|
from ret (if found) and split into the format configured in
|
|
|
|
apkbuild_attributes.
|
2020-01-27 23:23:09 +00:00
|
|
|
|
|
|
|
:param lines: the lines to parse
|
|
|
|
:param apkbuild_attributes: the attributes to parse
|
|
|
|
:param ret: a dict to update with new parsed variable
|
|
|
|
"""
|
|
|
|
for i in range(len(lines)):
|
|
|
|
for attribute, options in apkbuild_attributes.items():
|
|
|
|
found, value, i = parse_attribute(attribute, lines, i, path)
|
|
|
|
if not found:
|
|
|
|
continue
|
|
|
|
|
|
|
|
ret[attribute] = replace_variable(ret, value)
|
|
|
|
|
|
|
|
if "subpackages" in apkbuild_attributes:
|
|
|
|
subpackages = OrderedDict()
|
|
|
|
for subpkg in ret["subpackages"].split(" "):
|
|
|
|
if subpkg:
|
|
|
|
_parse_subpackage(path, lines, ret, subpackages, subpkg)
|
|
|
|
ret["subpackages"] = subpackages
|
|
|
|
|
|
|
|
# Split attributes
|
|
|
|
for attribute, options in apkbuild_attributes.items():
|
|
|
|
if options.get("array", False):
|
|
|
|
# Split up arrays, delete empty strings inside the list
|
|
|
|
ret[attribute] = list(filter(None, ret[attribute].split(" ")))
|
2021-11-01 08:39:45 +00:00
|
|
|
if options.get("int", False):
|
|
|
|
if ret[attribute]:
|
|
|
|
ret[attribute] = int(ret[attribute])
|
|
|
|
else:
|
|
|
|
ret[attribute] = 0
|
2020-01-27 23:23:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _parse_subpackage(path, lines, apkbuild, subpackages, subpkg):
|
|
|
|
"""
|
|
|
|
Attempt to parse attributes from a subpackage function.
|
|
|
|
This will attempt to locate the subpackage function in the APKBUILD and
|
|
|
|
update the given attributes with values set in the subpackage function.
|
|
|
|
|
|
|
|
:param path: path to APKBUILD
|
|
|
|
:param lines: the lines to parse
|
|
|
|
:param apkbuild: dict of attributes already parsed from APKBUILD
|
|
|
|
:param subpackages: the subpackages dict to update
|
|
|
|
:param subpkg: the subpackage to parse
|
|
|
|
(may contain subpackage function name separated by :)
|
|
|
|
"""
|
|
|
|
subpkgparts = subpkg.split(":")
|
|
|
|
subpkgname = subpkgparts[0]
|
|
|
|
subpkgsplit = subpkgname[subpkgname.rfind("-") + 1:]
|
|
|
|
if len(subpkgparts) > 1:
|
|
|
|
subpkgsplit = subpkgparts[1]
|
|
|
|
|
|
|
|
# Find start and end of package function
|
|
|
|
start = end = 0
|
|
|
|
prefix = subpkgsplit + "() {"
|
|
|
|
for i in range(len(lines)):
|
|
|
|
if lines[i].startswith(prefix):
|
|
|
|
start = i + 1
|
|
|
|
elif start and lines[i].startswith("}"):
|
|
|
|
end = i
|
|
|
|
break
|
|
|
|
|
|
|
|
if not start:
|
|
|
|
# Unable to find subpackage function in the APKBUILD.
|
2021-01-31 18:16:56 +00:00
|
|
|
# The subpackage function could be actually missing, or this is a
|
|
|
|
# problem in the parser. For now we also don't handle subpackages with
|
|
|
|
# default functions (e.g. -dev or -doc).
|
2020-01-27 23:23:09 +00:00
|
|
|
# In the future we may want to specifically handle these, and throw
|
|
|
|
# an exception here for all other missing subpackage functions.
|
|
|
|
subpackages[subpkgname] = None
|
2021-01-31 18:16:56 +00:00
|
|
|
logging.verbose(
|
|
|
|
f"{apkbuild['pkgname']}: subpackage function '{subpkgsplit}' for "
|
|
|
|
f"subpackage '{subpkgname}' not found, ignoring")
|
2020-01-27 23:23:09 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
if not end:
|
2021-01-31 18:16:56 +00:00
|
|
|
raise RuntimeError(
|
|
|
|
f"Could not find end of subpackage function, no line starts with "
|
|
|
|
f"'}}' after '{prefix}' in {path}")
|
2020-01-27 23:23:09 +00:00
|
|
|
|
|
|
|
lines = lines[start:end]
|
|
|
|
# Strip tabs before lines in function
|
|
|
|
lines = [line.strip() + "\n" for line in lines]
|
|
|
|
|
|
|
|
# Copy variables
|
|
|
|
apkbuild = apkbuild.copy()
|
|
|
|
apkbuild["subpkgname"] = subpkgname
|
|
|
|
|
|
|
|
# Parse relevant attributes for the subpackage
|
2021-01-31 18:16:56 +00:00
|
|
|
_parse_attributes(
|
|
|
|
path, lines, pmb.config.apkbuild_package_attributes, apkbuild)
|
2020-01-27 23:23:09 +00:00
|
|
|
|
|
|
|
# Return only properties interesting for subpackages
|
|
|
|
ret = {}
|
|
|
|
for key in pmb.config.apkbuild_package_attributes:
|
|
|
|
ret[key] = apkbuild[key]
|
|
|
|
subpackages[subpkgname] = ret
|
|
|
|
|
|
|
|
|
2021-11-09 11:52:10 +00:00
|
|
|
def apkbuild(path, check_pkgver=True, check_pkgname=True):
|
2017-05-26 20:08:45 +00:00
|
|
|
"""
|
|
|
|
Parse relevant information out of the APKBUILD file. This is not meant
|
|
|
|
to be perfect and catch every edge case (for that, a full shell parser
|
|
|
|
would be necessary!). Instead, it should just work with the use-cases
|
|
|
|
covered by pmbootstrap and not take too long.
|
new action: 'pmbootstrap repo_missing'
Add a new action that lists all aports, for which no binary packages
exist. Only list packages that can be built for the relevant arch
(specified with --arch). This works recursively: when a package can be
built for a certain arch, but one of its dependencies
(or their depends) can not be built for that arch, then don't list it.
This action will be used for the new sr.ht based build infrastructure,
to figure out which packages need to be built ahead of time (so we can
trigger each of them as single build job). Determining the order of the
packages to be built is not determined with pmbootstrap, the serverside
code of build.postmarketos.org takes care of that.
For testing purposes, a single package can also be specified and the
action will list if it can be built for that arch with its
dependencies, and what needs to be built exactly.
Add pmb/helpers/package.py to hold functions that work on both pmaports
and (binary package) repos - in contrary to the existing
pmb/helpers/pmaports.py (see previous commit) and pmb/helpers/repo.py,
which only work with one of those.
Refactoring:
* pmb/helpers/pmaports.py: add a get_list() function, which lists all
aports and use it instead of writing the same glob loop over and over
* add pmb.helpers.pmaports.get(), which finds an APKBUILD and parses it
in one step.
* rename pmb.build._package.check_arch to ...check_arch_abort to
distinguish it from the other check_arch function
2018-11-15 07:36:39 +00:00
|
|
|
Run 'pmbootstrap apkbuild_parse hello-world' for a full output example.
|
2017-05-26 20:08:45 +00:00
|
|
|
|
2018-01-18 22:05:27 +00:00
|
|
|
:param path: full path to the APKBUILD
|
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
|
|
|
:param check_pkgver: verify that the pkgver is valid.
|
|
|
|
:param check_pkgname: the pkgname must match the name of the aport folder
|
2018-01-18 22:05:27 +00:00
|
|
|
:returns: relevant variables from the APKBUILD. Arrays get returned as
|
|
|
|
arrays.
|
2017-05-26 20:08:45 +00:00
|
|
|
"""
|
2021-09-26 15:50:11 +00:00
|
|
|
# Try to get a cached result first (we assume that the aports don't change
|
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
|
|
|
# in one pmbootstrap call)
|
2021-10-30 12:20:57 +00:00
|
|
|
if path in pmb.helpers.other.cache["apkbuild"]:
|
|
|
|
return pmb.helpers.other.cache["apkbuild"][path]
|
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
|
|
|
|
2017-11-04 16:12:33 +00:00
|
|
|
# Read the file and check line endings
|
2019-02-05 16:20:48 +00:00
|
|
|
lines = read_file(path)
|
2017-05-26 20:08:45 +00:00
|
|
|
|
2020-01-28 10:12:26 +00:00
|
|
|
# Parse all attributes from the config
|
2020-01-27 21:24:45 +00:00
|
|
|
ret = {key: "" for key in pmb.config.apkbuild_attributes.keys()}
|
2020-01-27 23:23:09 +00:00
|
|
|
_parse_attributes(path, lines, pmb.config.apkbuild_attributes, ret)
|
2017-08-08 13:03:17 +00:00
|
|
|
|
2017-08-07 22:53:54 +00:00
|
|
|
# Sanity check: pkgname
|
2021-01-31 18:16:56 +00:00
|
|
|
suffix = f"/{ret['pkgname']}/APKBUILD"
|
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 check_pkgname:
|
|
|
|
if not os.path.realpath(path).endswith(suffix):
|
2021-01-31 18:16:56 +00:00
|
|
|
logging.info(f"Folder: '{os.path.dirname(path)}'")
|
|
|
|
logging.info(f"Pkgname: '{ret['pkgname']}'")
|
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
|
|
|
raise RuntimeError("The pkgname must be equal to the name of"
|
2021-09-26 15:50:11 +00:00
|
|
|
" the folder that contains the APKBUILD!")
|
2017-08-07 22:53:54 +00:00
|
|
|
|
2018-01-18 22:05:27 +00:00
|
|
|
# Sanity check: pkgver
|
|
|
|
if check_pkgver:
|
2021-01-31 18:16:56 +00:00
|
|
|
if ("-r" in ret["pkgver"] or not
|
|
|
|
pmb.parse.version.validate(ret["pkgver"])):
|
|
|
|
logging.info(
|
|
|
|
"NOTE: Valid pkgvers are described here: "
|
|
|
|
"https://wiki.alpinelinux.org/wiki/APKBUILD_Reference#pkgver")
|
|
|
|
raise RuntimeError(f"Invalid pkgver '{ret['pkgver']}' in"
|
|
|
|
f" APKBUILD: {path}")
|
2018-01-18 22:05:27 +00:00
|
|
|
|
2017-08-07 22:53:54 +00:00
|
|
|
# Fill cache
|
2021-10-30 12:20:57 +00:00
|
|
|
pmb.helpers.other.cache["apkbuild"][path] = ret
|
2017-05-26 20:08:45 +00:00
|
|
|
return ret
|
2018-02-24 21:49:10 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
def kernels(args, device):
|
|
|
|
"""
|
|
|
|
Get the possible kernels from a device-* APKBUILD.
|
|
|
|
|
|
|
|
:param device: the device name, e.g. "lg-mako"
|
|
|
|
:returns: None when the kernel is hardcoded in depends
|
|
|
|
:returns: kernel types and their description (as read from the subpackages)
|
|
|
|
possible types: "downstream", "stable", "mainline"
|
|
|
|
example: {"mainline": "Mainline description",
|
|
|
|
"downstream": "Downstream description"}
|
|
|
|
"""
|
|
|
|
# Read the APKBUILD
|
2020-02-26 11:13:26 +00:00
|
|
|
apkbuild_path = pmb.helpers.devices.find_path(args, device, 'APKBUILD')
|
|
|
|
if apkbuild_path is None:
|
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
|
|
|
return None
|
2021-11-09 11:52:10 +00:00
|
|
|
subpackages = apkbuild(apkbuild_path)["subpackages"]
|
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
|
|
|
|
|
|
|
# Read kernels from subpackages
|
|
|
|
ret = {}
|
2021-01-31 18:16:56 +00:00
|
|
|
subpackage_prefix = f"device-{device}-kernel-"
|
2020-01-27 23:23:09 +00:00
|
|
|
for subpkgname, subpkg in subpackages.items():
|
|
|
|
if not subpkgname.startswith(subpackage_prefix):
|
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
|
|
|
continue
|
2020-01-27 23:23:09 +00:00
|
|
|
if subpkg is None:
|
2021-01-31 18:16:56 +00:00
|
|
|
raise RuntimeError(
|
|
|
|
f"Cannot find subpackage function for: {subpkgname}")
|
2020-01-27 23:23:09 +00:00
|
|
|
name = subpkgname[len(subpackage_prefix):]
|
|
|
|
ret[name] = subpkg["pkgdesc"]
|
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
|
|
|
|
|
|
|
# Return
|
|
|
|
if ret:
|
|
|
|
return ret
|
|
|
|
return None
|
2021-01-30 12:19:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _parse_comment_tags(lines, tag):
|
|
|
|
"""
|
|
|
|
Parse tags defined as comments in a APKBUILD file. This can be used to
|
|
|
|
parse e.g. the maintainers of a package (defined using # Maintainer:).
|
|
|
|
|
|
|
|
:param lines: lines of the APKBUILD
|
|
|
|
:param tag: the tag to parse, e.g. Maintainer
|
|
|
|
:returns: array of values of the tag, one per line
|
|
|
|
"""
|
|
|
|
prefix = f'# {tag}:'
|
|
|
|
ret = []
|
|
|
|
for line in lines:
|
|
|
|
if line.startswith(prefix):
|
|
|
|
ret.append(line[len(prefix):].strip())
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
def maintainers(path):
|
|
|
|
"""
|
|
|
|
Parse maintainers of an APKBUILD file. They should be defined using
|
|
|
|
# Maintainer: (first maintainer) and # Co-Maintainer: (additional
|
|
|
|
maintainers).
|
|
|
|
|
|
|
|
:param path: full path to the APKBUILD
|
|
|
|
:returns: array of (at least one) maintainer, or None
|
|
|
|
"""
|
|
|
|
lines = read_file(path)
|
|
|
|
maintainers = _parse_comment_tags(lines, 'Maintainer')
|
|
|
|
if not maintainers:
|
|
|
|
return None
|
|
|
|
|
|
|
|
# An APKBUILD should only have one Maintainer:,
|
|
|
|
# in pmaports others should be defined using Co-Maintainer:
|
|
|
|
if len(maintainers) > 1:
|
|
|
|
raise RuntimeError("Multiple Maintainer: lines in APKBUILD")
|
|
|
|
|
|
|
|
maintainers += _parse_comment_tags(lines, 'Co-Maintainer')
|
|
|
|
if '' in maintainers:
|
|
|
|
raise RuntimeError("Empty (Co-)Maintainer: tag")
|
|
|
|
return maintainers
|
2021-01-30 12:21:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
def unmaintained(path):
|
|
|
|
"""
|
|
|
|
Return if (and why) an APKBUILD might be unmaintained. This should be
|
|
|
|
defined using a # Unmaintained: <reason> tag in the APKBUILD.
|
|
|
|
|
|
|
|
:param path: full path to the APKBUILD
|
|
|
|
:returns: reason why APKBUILD is unmaintained, or None
|
|
|
|
"""
|
|
|
|
unmaintained = _parse_comment_tags(read_file(path), 'Unmaintained')
|
|
|
|
if not unmaintained:
|
|
|
|
return None
|
|
|
|
return '\n'.join(unmaintained)
|