makepkg: add basic support for alternatives

Alternatives are specified in makepkg via (e.g.):

alternative=('sh')

There should be a file (e.g.) sh.alternative alongside the PKGBUILD containing
a list of symlinks to be created with the alternative is active.  This file is
stored in the root of the package as (e.g.) .ALTERNATIVE.sh.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2020-02-10 11:13:19 +10:00
parent d21fb58da3
commit 7ceee8805b
5 changed files with 57 additions and 5 deletions

View file

@ -402,8 +402,8 @@ All options and directives for the split packages default to the global values
given in the PKGBUILD. Nevertheless, the following ones can be overridden within
each split package's packaging function:
`pkgdesc`, `arch`, `url`, `license`, `groups`, `depends`, `optdepends`,
`provides`, `conflicts`, `replaces`, `backup`, `options`, `install`, and
`changelog`.
`provides`, `conflicts`, `replaces`, `backup`, `options`, `install`,
`changelog` and `alternative`.
Note that makepkg does not consider split package `depends` when checking
if dependencies are installed before package building and with `--syncdeps`.

View file

@ -0,0 +1,41 @@
#!/bin/bash
#
# alternative.sh - Check the files associated with the 'alternative'
# array exist.
#
# Copyright (c) 2020 Pacman Development Team <pacman-dev@archlinux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
[[ -n "$LIBMAKEPKG_LINT_PKGBUILD_ALTERNATIVE_SH" ]] && return
LIBMAKEPKG_LINT_PKGBUILD_ALTERNATIVE_SH=1
LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
source "$LIBRARY/util/message.sh"
source "$LIBRARY/util/pkgbuild.sh"
source "$LIBRARY/lint_pkgbuild/util.sh"
lint_pkgbuild_functions+=('lint_alternative')
lint_alternative() {
local ret=0
check_files_exist 'alternative' "${alternative[@]/%/.alternative}" || ret=1
return $ret
}

View file

@ -1,6 +1,7 @@
libmakepkg_module = 'lint_pkgbuild'
sources = [
'alternative.sh.in',
'arch.sh.in',
'arch_specific.sh.in',
'backup.sh.in',

View file

@ -28,8 +28,8 @@ source "$LIBRARY/util/util.sh"
known_hash_algos=({ck,md5,sha{1,224,256,384,512},b2})
pkgbuild_schema_arrays=(arch backup checkdepends conflicts depends groups
license makedepends noextract optdepends options
pkgbuild_schema_arrays=(alternative arch backup checkdepends conflicts depends
groups license makedepends noextract optdepends options
provides replaces source validpgpkeys
"${known_hash_algos[@]/%/sums}")
@ -42,7 +42,7 @@ pkgbuild_schema_arch_arrays=(checkdepends conflicts depends makedepends
pkgbuild_schema_package_overrides=(pkgdesc arch url license groups depends
optdepends provides conflicts replaces
backup options install changelog)
backup options install changelog alternative)
readonly -a known_hash_algos pkgbuild_schema_arrays \
pkgbuild_schema_strings pkgbuild_schema_arch_arrays \

View file

@ -710,6 +710,16 @@ create_package() {
fi
done
# check for alternative files
for i in ${alternative[@]}; do
msg2 "$(gettext "Adding %s file...")" "$i.alternative"
if ! cp "$startdir/$i.alternative" ".ALTERNATIVE.$i"; then
error "$(gettext "Failed to add %s file to package.")" "$i.alternative"
exit $E_MISSING_FILE
fi
chmod 644 ".ALTERNATIVE.$i"
done
# tar it up
local fullver=$(get_full_version)
local pkg_file="$PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT}"