summaryrefslogtreecommitdiffstats
path: root/scripts/makepkg.sh.in
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/makepkg.sh.in')
-rw-r--r--scripts/makepkg.sh.in190
1 files changed, 113 insertions, 77 deletions
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 7b2ce511..0218e13b 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -3,7 +3,7 @@
# makepkg - make packages compatible for use with pacman
# @configure_input@
#
-# Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org>
+# Copyright (c) 2006-2017 Pacman Development Team <pacman-dev@archlinux.org>
# Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
# Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
# Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
@@ -28,7 +28,7 @@
# makepkg uses quite a few external programs during its execution. You
# need to have at least the following installed for makepkg to function:
# awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, file, find (findutils),
-# gettext, gpg, grep, gzip, openssl, sed, tput (ncurses), xz
+# gettext, gpg, grep, gzip, sed, tput (ncurses), xz
# gettext initialization
export TEXTDOMAIN='pacman-scripts'
@@ -137,6 +137,12 @@ clean_up() {
if [[ -n $pkgbase ]]; then
local fullver=$(get_full_version)
# Can't do this unless the BUILDSCRIPT has been sourced.
+ if (( PKGVERFUNC )); then
+ rm -f "${pkgbase}-${fullver}-${CARCH}-pkgver.log"*
+ fi
+ if (( PREPAREFUNC )); then
+ rm -f "${pkgbase}-${fullver}-${CARCH}-prepare.log"*
+ fi
if (( BUILDFUNC )); then
rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"*
fi
@@ -243,7 +249,7 @@ handle_deps() {
(( $# == 0 )) && return $R_DEPS_SATISFIED
- local deplist="$*"
+ local deplist=("$@")
if (( ! DEP_BIN )); then
return $R_DEPS_MISSING
@@ -253,7 +259,7 @@ handle_deps() {
# install missing deps from binary packages (using pacman -S)
msg "$(gettext "Installing missing dependencies...")"
- if ! run_pacman -S --asdeps $deplist; then
+ if ! run_pacman -S --asdeps "${deplist[@]}"; then
error "$(gettext "'%s' failed to install missing dependencies.")" "$PACMAN"
exit 1 # TODO: error code
fi
@@ -276,12 +282,12 @@ resolve_deps() {
# deplist cannot be declared like this: local deplist=$(foo)
# Otherwise, the return value will depend on the assignment.
local deplist
- deplist="$(set +E; check_deps $*)" || exit 1
+ deplist=($(check_deps "$@")) || exit 1
[[ -z $deplist ]] && return $R_DEPS_SATISFIED
- if handle_deps $deplist; then
+ if handle_deps "${deplist[@]}"; then
# check deps again to make sure they were resolved
- deplist="$(set +E; check_deps $*)" || exit 1
+ deplist=$(check_deps "$@") || exit 1
[[ -z $deplist ]] && return $R_DEPS_SATISFIED
fi
@@ -398,20 +404,23 @@ prepare_buildenv() {
}
run_function_safe() {
- local restoretrap
+ local restoretrap restoreset restoreshopt
- set -e
- set -E
+ # we don't set any special shopts of our own, but we don't want the user to
+ # muck with our environment.
+ restoreshopt=$(shopt -p)
+
+ restoreset=$(shopt -o -p)
+ shopt -o -s errexit errtrace
restoretrap=$(trap -p ERR)
- trap 'error_function $pkgfunc' ERR
+ trap "error_function '$1'" ERR
run_function "$1"
- eval $restoretrap
-
- set +E
- set +e
+ eval "$restoretrap"
+ eval "$restoreset"
+ eval "$restoreshopt"
}
run_function() {
@@ -494,7 +503,7 @@ find_libdepends() {
done
if (( sodepends == 0 )); then
- printf '%s\n' "${depends[@]}"
+ (( ${#depends[@]} )) && printf '%s\n' "${depends[@]}"
return;
fi
@@ -543,7 +552,7 @@ find_libdepends() {
esac
done
- printf '%s\n' "${libdepends[@]}"
+ (( ${#libdepends[@]} )) && printf '%s\n' "${libdepends[@]}"
}
@@ -594,7 +603,20 @@ find_libprovides() {
fi
done
- printf '%s\n' "${libprovides[@]}"
+ (( ${#libprovides[@]} )) && printf '%s\n' "${libprovides[@]}"
+}
+
+write_kv_pair() {
+ local key="$1"
+ shift
+
+ for val in "$@"; do
+ if [[ $val = *$'\n'* ]]; then
+ error "$(gettext "Invalid value for %s: %s")" "$key" "$val"
+ exit 1
+ fi
+ printf "%s = %s\n" "$key" "$val"
+ done
}
write_pkginfo() {
@@ -615,15 +637,15 @@ write_pkginfo() {
printf "# using %s\n" "$(fakeroot -v)"
printf "# %s\n" "$(LC_ALL=C date -u)"
- printf "pkgname = %s\n" "$pkgname"
+ write_kv_pair "pkgname" "$pkgname"
if (( SPLITPKG )) || [[ "$pkgbase" != "$pkgname" ]]; then
- printf "pkgbase = %s\n" "$pkgbase"
+ write_kv_pair "pkgbase" "$pkgbase"
fi
local fullver=$(get_full_version)
- printf "pkgver = %s\n" "$fullver"
+ write_kv_pair "pkgver" "$fullver"
if [[ "$fullver" != "$basever" ]]; then
- printf "basever = %s\n" "$basever"
+ write_kv_pair "basever" "$basever"
fi
# TODO: all fields should have this treatment
@@ -631,43 +653,52 @@ write_pkginfo() {
spd=("${spd[@]#[[:space:]]}")
spd=("${spd[@]%[[:space:]]}")
- printf "pkgdesc = %s\n" "$spd"
- printf "url = %s\n" "$url"
- printf "builddate = %s\n" "$builddate"
- printf "packager = %s\n" "$packager"
- printf "size = %s\n" "$size"
- printf "arch = %s\n" "$pkgarch"
+ write_kv_pair "pkgdesc" "$spd"
+ write_kv_pair "url" "$url"
+ write_kv_pair "builddate" "$builddate"
+ write_kv_pair "packager" "$packager"
+ write_kv_pair "size" "$size"
+ write_kv_pair "arch" "$pkgarch"
mapfile -t provides < <(find_libprovides)
mapfile -t depends < <(find_libdepends)
- [[ $license ]] && printf "license = %s\n" "${license[@]}"
- [[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}"
- [[ $groups ]] && printf "group = %s\n" "${groups[@]}"
- [[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}"
- [[ $provides ]] && printf "provides = %s\n" "${provides[@]}"
- [[ $backup ]] && printf "backup = %s\n" "${backup[@]}"
- [[ $depends ]] && printf "depend = %s\n" "${depends[@]}"
- [[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]//+([[:space:]])/ }"
- [[ $makedepends ]] && printf "makedepend = %s\n" "${makedepends[@]}"
- [[ $checkdepends ]] && printf "checkdepend = %s\n" "${checkdepends[@]}"
+ write_kv_pair "license" "${license[@]}"
+ write_kv_pair "replaces" "${replaces[@]}"
+ write_kv_pair "group" "${groups[@]}"
+ write_kv_pair "conflict" "${conflicts[@]}"
+ write_kv_pair "provides" "${provides[@]}"
+ write_kv_pair "backup" "${backup[@]}"
+ write_kv_pair "depend" "${depends[@]}"
+ write_kv_pair "optdepend" "${optdepends[@]//+([[:space:]])/ }"
+ write_kv_pair "makedepend" "${makedepends[@]}"
+ write_kv_pair "checkdepend" "${checkdepends[@]}"
}
write_buildinfo() {
msg2 "$(gettext "Generating %s file...")" ".BUILDINFO"
- printf "builddir = %s\n" "${BUILDDIR}"
+ write_kv_pair "builddir" "${BUILDDIR}"
- local sum="$(openssl dgst -sha256 "${BUILDFILE}")"
- sum=${sum##* }
+ local sum="$(sha256sum "${BUILDFILE}")"
+ sum=${sum%% *}
- printf "pkgbuild_sha256sum = %s\n" $sum
+ write_kv_pair "pkgbuild_sha256sum" $sum
- printf "buildenv = %s\n" "${BUILDENV[@]}"
- printf "options = %s\n" "${OPTIONS[@]}"
+ write_kv_pair "buildenv" "${BUILDENV[@]}"
+ write_kv_pair "options" "${OPTIONS[@]}"
local pkglist=($(run_pacman -Q | sed "s# #-#"))
- printf "installed = %s\n" "${pkglist[@]}"
+ write_kv_pair "installed" "${pkglist[@]}"
+}
+
+# build a sorted NUL-separated list of the full contents of the current
+# directory suitable for passing to `bsdtar --files-from`
+# database files are placed at the beginning of the package regardless of
+# sorting
+list_package_files() {
+ (find . -path './.*' \! -name '.'; find . \! -path './.*' \! -name '.' | LC_ALL=C sort) |
+ sed -e 's|^\./||' | tr '\n' '\0'
}
create_package() {
@@ -686,8 +717,6 @@ create_package() {
write_pkginfo > .PKGINFO
write_buildinfo > .BUILDINFO
- local comp_files=('.PKGINFO' '.BUILDINFO')
-
# check for changelog/install files
for i in 'changelog/.CHANGELOG' 'install/.INSTALL'; do
IFS='/' read -r orig dest < <(printf '%s\n' "$i")
@@ -699,7 +728,6 @@ create_package() {
exit 1
fi
chmod 644 "$dest"
- comp_files+=("$dest")
fi
done
@@ -711,15 +739,10 @@ create_package() {
[[ -f $pkg_file ]] && rm -f "$pkg_file"
[[ -f $pkg_file.sig ]] && rm -f "$pkg_file.sig"
- # when fileglobbing, we want * in an empty directory to expand to
- # the null string rather than itself
- shopt -s nullglob
-
msg2 "$(gettext "Generating .MTREE file...")"
- LANG=C bsdtar -czf .MTREE --format=mtree \
+ list_package_files | LANG=C bsdtar -cnzf .MTREE --format=mtree \
--options='!all,use-set,type,uid,gid,mode,time,size,md5,sha256,link' \
- "${comp_files[@]}" *
- comp_files+=(".MTREE")
+ --null --files-from - --exclude .MTREE
msg2 "$(gettext "Compressing package...")"
# TODO: Maybe this can be set globally for robustness
@@ -727,7 +750,7 @@ create_package() {
# bsdtar's gzip compression always saves the time stamp, making one
# archive created using the same command line distinct from another.
# Disable bsdtar compression and use gzip -n for now.
- LANG=C bsdtar -cf - "${comp_files[@]}" * |
+ list_package_files | LANG=C bsdtar -cnf - --null --files-from - |
case "$PKGEXT" in
*tar.gz) ${COMPRESSGZ[@]:-gzip -c -f -n} ;;
*tar.bz2) ${COMPRESSBZ2[@]:-bzip2 -c -f} ;;
@@ -740,7 +763,6 @@ create_package() {
"$PKGEXT"; cat ;;
esac > "${pkg_file}" || ret=$?
- shopt -u nullglob
shopt -u -o pipefail
if (( ret )); then
@@ -771,18 +793,24 @@ create_debug_package() {
return
fi
- pkgdir="${pkgdir}-@DEBUGSUFFIX@"
+ pkgdir="$pkgdirbase/$pkgbase-@DEBUGSUFFIX@"
# check if we have any debug symbols to package
if dir_is_empty "$pkgdir/usr/lib/debug"; then
return
fi
- depends=("$pkgname=$(get_full_version)")
- pkgdesc="Detached debugging symbols for $pkgname"
- pkgname=$pkgname-@DEBUGSUFFIX@
+ unset groups depends optdepends provides conflicts replaces backup install changelog
- unset groups optdepends provides conflicts replaces backup install changelog
+ local pkg
+ for pkg in ${pkgname[@]}; do
+ if [[ $pkg != $pkgbase ]]; then
+ provides+=("$pkg-@DEBUGSUFFIX@")
+ fi
+ done
+
+ pkgdesc="Detached debugging symbols for $pkgname"
+ pkgname=$pkgbase-@DEBUGSUFFIX@
create_package
}
@@ -959,7 +987,7 @@ check_vcs_software() {
client=$(get_vcsclient "$proto") || exit $?
# ensure specified program is installed
local uninstalled
- uninstalled="$(set +E; check_deps $client)" || exit 1
+ uninstalled=$(check_deps "$client") || exit 1
# if not installed, check presence in depends or makedepends
if [[ -n "$uninstalled" ]] && (( ! NODEPS || ( VERIFYSOURCE && !DEP_BIN ) )); then
if ! in_array "$client" ${all_deps[@]}; then
@@ -1022,12 +1050,18 @@ check_software() {
fi
fi
- # openssl - checksum operations
- if (( ! SKIPCHECKSUMS )); then
- if ! type -p openssl >/dev/null; then
- error "$(gettext "Cannot find the %s binary required for validating source file checksums.")" "openssl"
- ret=1
- fi
+ # checksum operations
+ if (( GENINTEG || ! SKIPCHECKSUMS )); then
+ local integlist
+ IFS=$'\n' read -rd '' -a integlist < <(get_integlist)
+
+ local integ
+ for integ in "${integlist[@]}"; do
+ if ! type -p "${integ}sum" >/dev/null; then
+ error "$(gettext "Cannot find the %s binary required for source file checksums operations.")" "${integ}sum"
+ ret=1
+ fi
+ done
fi
# distcc - compilation with distcc
@@ -1145,16 +1179,14 @@ run_split_packaging() {
backup_package_variables
run_package $pkgname
tidy_install
- lint_package
+ lint_package || exit 1
create_package
- create_debug_package
restore_package_variables
done
pkgname=("${pkgname_backup[@]}")
+ create_debug_package
}
-m4_include(library/parseopts.sh)
-
usage() {
printf "makepkg (pacman) %s\n" "$makepkg_version"
echo
@@ -1212,7 +1244,7 @@ usage() {
version() {
printf "makepkg (pacman) %s\n" "$makepkg_version"
printf -- "$(gettext "\
-Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org>.\n\
+Copyright (c) 2006-2017 Pacman Development Team <pacman-dev@archlinux.org>.\n\
Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>.\n\n\
This is free software; see the source for copying conditions.\n\
There is NO WARRANTY, to the extent permitted by law.\n")"
@@ -1448,7 +1480,11 @@ fi
unset pkgname pkgbase pkgver pkgrel epoch pkgdesc url license groups provides
unset md5sums replaces depends conflicts backup source install changelog build
-unset makedepends optdepends options noextract validpgpkeys
+unset sha{1,224,256,384,512}sums makedepends optdepends options noextract validpgpkeys
+unset "${!makedepends_@}" "${!depends_@}" "${!source_@}" "${!checkdepends_@}"
+unset "${!optdepends_@}" "${!conflicts_@}" "${!provides_@}" "${!replaces_@}"
+unset "${!md5sums_@}" "${!sha1sums_@}" "${!sha224sums_@}" "${!sha256sums_@}"
+unset "${!sha384sums_@}" "${!sha512sums_@}"
BUILDFILE=${BUILDFILE:-$BUILDSCRIPT}
if [[ ! -f $BUILDFILE ]]; then
@@ -1476,7 +1512,7 @@ pkgbase=${pkgbase:-${pkgname[0]}}
# check the PKGBUILD for some basic requirements
lint_pkgbuild || exit 1
-if (( !SOURCEONLY )); then
+if (( !SOURCEONLY && !PRINTSRCINFO )); then
merge_arch_attrs
fi
@@ -1581,7 +1617,7 @@ if (( INFAKEROOT )); then
run_package
fi
tidy_install
- lint_package
+ lint_package || exit 1
create_package
create_debug_package
else