Merge pull request #1056 from AladW/depends-assume-installed
[aurutils.git] / lib / aur-build--pkglist
blob11c1d8c95801821e905f8286e893c9c3ad809827
1 #!/bin/bash
2 [[ -v AUR_DEBUG ]] && set -o xtrace
3 argv0=build--pkglist
4 PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
6 # default options
7 lint=0 mode=pkglist
9 usage() {
10 printf >&2 'usage: %s [--srcinfo] [--lint] [--config <file>]' "$argv0"
11 exit 1
14 # mollyguard for sourcing PKGBUILDs
15 if (( UID == 0 )) && [[ ! -v AUR_ASROOT ]]; then
16 printf >&2 'warning: aur-%s is not meant to be run as root.\n' "$argv0"
17 printf >&2 'warning: To proceed anyway, set the %s variable.\n' 'AUR_ASROOT'
18 exit 1
21 source /usr/share/makepkg/util/option.sh
22 source /usr/share/makepkg/util/parseopts.sh
23 source /usr/share/makepkg/util/config.sh
25 # option parsing
26 opt_short='p:'
27 opt_long=('buildscript:' 'config:' 'lint' 'srcinfo')
28 opt_hidden=('dump-options')
30 if ! parseopts "$opt_short" "${opt_long[@]}" "${opt_hidden[@]}" -- "$@"; then
31 usage
33 set -- "${OPTRET[@]}"
35 unset buildscript build_user makepkg_conf
36 while true; do
37 case "$1" in
38 -p|--buildscript)
39 shift; buildscript=$1 ;;
40 --config)
41 shift; makepkg_conf=$1 ;;
42 --srcinfo)
43 mode=srcinfo ;;
44 --lint)
45 lint=1 ;;
46 --dump-options)
47 printf -- '--%s\n' "${opt_long[@]}" ${AUR_DEBUG+"${opt_hidden[@]}"}
48 printf -- '%s' "${opt_short}" | sed 's/.:\?/-&\n/g'
49 exit ;;
50 --) shift; break ;;
51 esac
52 shift
53 done
55 # Sourcing the PKGBUILD should be done without set -e or other modes
56 # to match makepkg behavior (e.g. aur/cemu, aur/nicotine-plus-git)
57 # shellcheck disable=SC1090
58 source "${buildscript-PKGBUILD}"
59 PKGDEST=${PKGDEST:-$PWD}
61 # PKGEXT (packagelist), CARCH (lint)
62 load_makepkg_config "${makepkg_conf-}"
64 if (( lint )); then
65 source /usr/share/makepkg/lint_pkgbuild.sh
66 lint_pkgbuild
69 case $mode in
70 pkglist)
71 source /usr/share/makepkg/util/pkgbuild.sh
72 print_all_package_names
74 srcinfo)
75 source /usr/share/makepkg/srcinfo.sh
76 write_srcinfo_content
78 esac