Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/scripts/makepkg.sh.in
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2015-05-12 23:27:07 +1000
committerAllan McRae <allan@archlinux.org>2015-05-16 14:10:42 +1000
commitc9a7b7e0bf6a5768f6ca433dc14a3344899bb0cd (patch)
treebec208e5eddd069b02721a645e9906b929af4d21 /scripts/makepkg.sh.in
parentd38c098787ebbedb0f55742dd547a20a7362b0cb (diff)
libmakepkg: extract PKGBUILD linting functions
Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'scripts/makepkg.sh.in')
-rw-r--r--scripts/makepkg.sh.in334
1 files changed, 1 insertions, 333 deletions
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index a00e8a42..4885341c 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -2135,338 +2135,6 @@ install_package() {
fi
}
-lint_pkgbase() {
- if [[ ${pkgbase:0:1} = "-" ]]; then
- error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname"
- return 1
- fi
-}
-
-lint_pkgname() {
- local ret=0 i
-
- for i in "${pkgname[@]}"; do
- if [[ -z $i ]]; then
- error "$(gettext "%s is not allowed to be empty.")" "pkgname"
- ret=1
- continue
- fi
- if [[ ${i:0:1} = "-" ]]; then
- error "$(gettext "%s is not allowed to start with a hyphen.")" "pkgname"
- ret=1
- fi
- if [[ ${i:0:1} = "." ]]; then
- error "$(gettext "%s is not allowed to start with a dot.")" "pkgname"
- ret=1
- fi
- if [[ $i = *[^[:alnum:]+_.@-]* ]]; then
- error "$(gettext "%s contains invalid characters: '%s'")" \
- 'pkgname' "${i//[[:alnum:]+_.@-]}"
- ret=1
- fi
- done
-
- return $ret
-}
-
-lint_pkgrel() {
- if [[ -z $pkgrel ]]; then
- error "$(gettext "%s is not allowed to be empty.")" "pkgrel"
- return 1
- fi
-
- if [[ $pkgrel != +([0-9])?(.+([0-9])) ]]; then
- error "$(gettext "%s must be a decimal, not %s.")" "pkgrel" "$pkgrel"
- return 1
- fi
-}
-
-lint_pkgver() {
- if (( PKGVERFUNC )); then
- # defer check to after getting version from pkgver function
- return 0
- fi
-
- check_pkgver
-}
-
-lint_epoch() {
- if [[ $epoch != *([[:digit:]]) ]]; then
- error "$(gettext "%s must be an integer, not %s.")" "epoch" "$epoch"
- return 1
- fi
-}
-
-lint_arch() {
- local a name list
-
- if [[ $arch == 'any' ]]; then
- return 0
- fi
-
- for a in "${arch[@]}"; do
- if [[ $a = *[![:alnum:]_]* ]]; then
- error "$(gettext "%s contains invalid characters: '%s'")" \
- 'arch' "${a//[[:alnum:]_]}"
- ret=1
- fi
- done
-
- if (( ! IGNOREARCH )) && ! in_array "$CARCH" "${arch[@]}"; then
- error "$(gettext "%s is not available for the '%s' architecture.")" "$pkgbase" "$CARCH"
- plain "$(gettext "Note that many packages may need a line added to their %s")" "$BUILDSCRIPT"
- plain "$(gettext "such as %s.")" "arch=('$CARCH')"
- return 1
- fi
-
- for name in "${pkgname[@]}"; do
- get_pkgbuild_attribute "$name" 'arch' 1 list
- if [[ $list && $list != 'any' ]] && ! in_array $CARCH "${list[@]}"; then
- if (( ! IGNOREARCH )); then
- error "$(gettext "%s is not available for the '%s' architecture.")" "$name" "$CARCH"
- ret=1
- fi
- fi
- done
-}
-
-lint_provides() {
- local a list name provides_list ret=0
-
- provides_list=("${provides[@]}")
- for a in "${arch[@]}"; do
- array_build list "provides_$a"
- provides_list+=("${list[@]}")
- done
-
- for name in "${pkgname[@]}"; do
- if extract_function_variable "package_$name" provides 1 list; then
- provides_list+=("${list[@]}")
- fi
-
- for a in "${arch[@]}"; do
- if extract_function_variable "package_$name" "provides_$a" 1 list; then
- provides_list+=("${list[@]}")
- fi
- done
- done
-
- for provide in "${provides_list[@]}"; do
- if [[ $provide == *['<>']* ]]; then
- error "$(gettext "%s array cannot contain comparison (< or >) operators.")" "provides"
- ret=1
- fi
- done
-
- return $ret
-}
-
-lint_backup() {
- local list name backup_list ret=0
-
- backup_list=("${backup[@]}")
- for name in "${pkgname[@]}"; do
- if extract_function_variable "package_$name" backup 1 list; then
- backup_list+=("${list[@]}")
- fi
- done
-
- for name in "${backup_list[@]}"; do
- if [[ ${name:0:1} = "/" ]]; then
- error "$(gettext "%s entry should not contain leading slash : %s")" "backup" "$name"
- ret=1
- fi
- done
-
- return $ret
-}
-
-lint_optdepends() {
- local a list name optdepends_list ret=0
-
- optdepends_list=("${optdepends[@]}")
- for a in "${arch[@]}"; do
- array_build list "optdepends_$a"
- optdepends_list+=("${list[@]}")
- done
-
- for name in "${pkgname[@]}"; do
- if extract_function_variable "package_$name" optdepends 1 list; then
- optdepends_list+=("${list[@]}")
- fi
-
- for a in "${arch[@]}"; do
- if extract_function_variable "package_$name" "optdepends_$a" 1 list; then
- optdepends_list+=("${list[@]}")
- fi
- done
- done
-
- for name in "${optdepends_list[@]}"; do
- local pkg=${name%%:[[:space:]]*}
- # the '-' character _must_ be first or last in the character range
- if [[ $pkg != +([-[:alnum:]><=.+_:]) ]]; then
- error "$(gettext "Invalid syntax for %s: '%s'")" "optdepend" "$name"
- ret=1
- fi
- done
-
- return $ret
-}
-
-check_files_exist() {
- local kind=$1 files=("${@:2}") file ret
-
- for file in "${files[@]}"; do
- if [[ $file && ! -f $file ]]; then
- error "$(gettext "%s file (%s) does not exist or is not a regular file.")" \
- "$kind" "$file"
- ret=1
- fi
- done
-
- return $ret
-}
-
-lint_install() {
- local list file name install_list ret=0
-
- install_list=("${install[@]}")
- for name in "${pkgname[@]}"; do
- extract_function_variable "package_$name" install 0 file
- install_list+=("$file")
- done
-
- check_files_exist 'install' "${install_list[@]}"
-}
-
-lint_changelog() {
- local list name file changelog_list ret=0
-
- changelog_list=("${changelog[@]}")
- for name in "${pkgname[@]}"; do
- if extract_function_variable "package_$name" changelog 0 file; then
- changelog_list+=("$file")
- fi
- done
-
- check_files_exist 'changelog' "${changelog_list[@]}"
-}
-
-lint_options() {
- local ret=0 list name kopt options_list
-
- options_list=("${options[@]}")
- for name in "${pkgname[@]}"; do
- if extract_function_variable "package_$name" options 1 list; then
- options_list+=("${list[@]}")
- fi
- done
-
- for i in "${options_list[@]}"; do
- # check if option matches a known option or its inverse
- for kopt in "${packaging_options[@]}" "${build_options[@]}"; do
- if [[ $i = "$kopt" || $i = "!$kopt" ]]; then
- # continue to the next $i
- continue 2
- fi
- done
-
- error "$(gettext "%s array contains unknown option '%s'")" "options" "$i"
- ret=1
- done
-
- return $ret
-}
-
-lint_source() {
- local idx=("${!source[@]}")
-
- if (( ${#source[*]} > 0 && (idx[-1] + 1) != ${#source[*]} )); then
- error "$(gettext "Sparse arrays are not allowed for source")"
- return 1
- fi
-}
-
-lint_pkglist() {
- local i ret=0
-
- for i in "${PKGLIST[@]}"; do
- if ! in_array "$i" "${pkgname[@]}"; then
- error "$(gettext "Requested package %s is not provided in %s")" "$i" "$BUILDFILE"
- ret=1
- fi
- done
-
- return $ret
-}
-
-lint_packagefn() {
- local i ret=0
-
- if (( ${#pkgname[@]} == 1 )); then
- if have_function 'build' && ! { have_function 'package' || have_function "package_$pkgname"; }; then
- error "$(gettext "Missing %s function in %s")" "package()" "$BUILDFILE"
- ret=1
- fi
- else
- for i in "${pkgname[@]}"; do
- if ! have_function "package_$i"; then
- error "$(gettext "Missing %s function for split package '%s'")" "package_$i()" "$i"
- ret=1
- fi
- done
- fi
-
- return $ret
-}
-
-check_sanity() {
- # check for no-no's in the build script
- local ret=0
- local lintfn lint_functions
-
- lint_functions=(
- lint_pkgbase
- lint_pkgname
- lint_pkgver
- lint_pkgrel
- lint_epoch
- lint_arch
- lint_provides
- lint_backup
- lint_optdepends
- lint_changelog
- lint_install
- lint_options
- lint_packagefn
- lint_pkglist
- lint_source
- )
-
- for lintfn in "${lint_functions[@]}"; do
- "$lintfn" || ret=1
- done
-
- return $ret
-}
-
-validate_pkgver() {
- if [[ $1 = *[[:space:]:-]* ]]; then
- error "$(gettext "%s is not allowed to contain colons, hyphens or whitespace.")" "pkgver"
- return 1
- fi
-}
-
-check_pkgver() {
- if [[ -z ${pkgver} ]]; then
- error "$(gettext "%s is not allowed to be empty.")" "pkgver"
- return 1
- fi
-
- validate_pkgver "$pkgver"
-}
-
get_vcsclient() {
local proto=${1%%+*}
@@ -3130,7 +2798,7 @@ if have_function pkgver; then
fi
# check the PKGBUILD for some basic requirements
-check_sanity || exit 1
+lint_pkgbuild || exit 1
# check we have the software required to process the PKGBUILD
check_software || exit 1