summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2020-02-10 02:13:19 +0100
committerAllan McRae <allan@archlinux.org>2020-03-09 08:05:24 +0100
commita40e652359ed8b2c5dec9d8efbead8a8afbfdf8d (patch)
tree9ae04fa0279171fbd172b6642bb982e8b5bcdd05
parente578903b60081bb8a7ddd094ed67946d5e48b719 (diff)
downloadpacman-a40e652359ed8b2c5dec9d8efbead8a8afbfdf8d.tar.gz
pacman-a40e652359ed8b2c5dec9d8efbead8a8afbfdf8d.tar.xz
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>
-rw-r--r--doc/PKGBUILD.5.asciidoc4
-rw-r--r--scripts/Makefile.am1
-rw-r--r--scripts/libmakepkg/lint_pkgbuild/alternative.sh.in41
-rw-r--r--scripts/libmakepkg/lint_pkgbuild/meson.build1
-rw-r--r--scripts/libmakepkg/util/schema.sh.in6
-rw-r--r--scripts/makepkg.sh.in10
6 files changed, 58 insertions, 5 deletions
diff --git a/doc/PKGBUILD.5.asciidoc b/doc/PKGBUILD.5.asciidoc
index 2e2108a0..42958933 100644
--- a/doc/PKGBUILD.5.asciidoc
+++ b/doc/PKGBUILD.5.asciidoc
@@ -398,8 +398,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`.
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 47455ed2..8dc1f000 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -80,6 +80,7 @@ LIBMAKEPKG_IN = \
libmakepkg/lint_package/file_names.sh \
libmakepkg/lint_package/missing_backup.sh \
libmakepkg/lint_pkgbuild.sh \
+ libmakepkg/lint_pkgbuild/alternative.sh \
libmakepkg/lint_pkgbuild/arch.sh \
libmakepkg/lint_pkgbuild/arch_specific.sh \
libmakepkg/lint_pkgbuild/backup.sh \
diff --git a/scripts/libmakepkg/lint_pkgbuild/alternative.sh.in b/scripts/libmakepkg/lint_pkgbuild/alternative.sh.in
new file mode 100644
index 00000000..75f71317
--- /dev/null
+++ b/scripts/libmakepkg/lint_pkgbuild/alternative.sh.in
@@ -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
+}
diff --git a/scripts/libmakepkg/lint_pkgbuild/meson.build b/scripts/libmakepkg/lint_pkgbuild/meson.build
index 6050df2f..ab7a2872 100644
--- a/scripts/libmakepkg/lint_pkgbuild/meson.build
+++ b/scripts/libmakepkg/lint_pkgbuild/meson.build
@@ -1,6 +1,7 @@
libmakepkg_module = 'lint_pkgbuild'
sources = [
+ 'alternative.sh.in',
'arch.sh.in',
'arch_specific.sh.in',
'backup.sh.in',
diff --git a/scripts/libmakepkg/util/schema.sh.in b/scripts/libmakepkg/util/schema.sh.in
index b42b8ae9..21ccaf2e 100644
--- a/scripts/libmakepkg/util/schema.sh.in
+++ b/scripts/libmakepkg/util/schema.sh.in
@@ -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 \
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index d1416d15..859c6953 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -695,6 +695,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}"