Revert "makechrootpkg: Avoid having code floating around outside of a function."

This reverts commit 49088b0860.

The fundamental intention was flawed and broken, it caused annoying
issues and regressions, and the self-avowed sole purpose of the change
was so that a downstream project could *post-modify the script and
source it as a library*.

That is not okay. You don't wrap non-factorable code in a function
called main() and call it a library. The only possible use for this is
to treat makechrootpkg *internals* as a library, which is not supported.

Downstream projects that wish to use the functionality of makechrootpkg
should treat makepkg as a command with a public API in the form of
command line options. That is kind of how commands of all kinds work,
since forever. That is how all users of makechrootpkg *except for
parabola* use it.

Arguments that "it saves us the cost of fork+exec to bash" are simply
invalid.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
This commit is contained in:
Eli Schwartz 2019-02-13 02:02:40 -05:00 committed by Levente Polyak
parent 8f5a02b23d
commit df0d6b867b
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8
1 changed files with 117 additions and 121 deletions

View File

@ -15,6 +15,27 @@ m4_include(lib/archroot.sh)
shopt -s nullglob
default_makepkg_args=(--syncdeps --noconfirm --log --holdver --skipinteg)
makepkg_args=("${default_makepkg_args[@]}")
keepbuilddir=false
update_first=false
clean_first=false
run_namcap=false
temp_chroot=false
chrootdir=
passeddir=
makepkg_user=
declare -a install_pkgs
declare -i ret=0
bindmounts_ro=()
bindmounts_rw=()
copy=$USER
[[ -n ${SUDO_USER:-} ]] && copy=$SUDO_USER
[[ -z "$copy" || $copy = root ]] && copy=copy
src_owner=${SUDO_USER:-$USER}
usage() {
echo "Usage: ${0##*/} [options] -r <chrootdir> [--] [makepkg args]"
echo ' Run this script in a PKGBUILD dir to build a package inside a'
@ -293,28 +314,6 @@ move_products() {
}
# }}}
main() {
default_makepkg_args=(--syncdeps --noconfirm --log --holdver --skipinteg)
makepkg_args=("${default_makepkg_args[@]}")
keepbuilddir=false
update_first=false
clean_first=false
run_namcap=false
temp_chroot=false
chrootdir=
passeddir=
makepkg_user=
declare -a install_pkgs
declare -i ret=0
bindmounts_ro=()
bindmounts_rw=()
copy=$USER
[[ -n ${SUDO_USER:-} ]] && copy=$SUDO_USER
[[ -z "$copy" || $copy = root ]] && copy=copy
src_owner=${SUDO_USER:-$USER}
while getopts 'hcur:I:l:nTD:d:U:' arg; do
case "$arg" in
c) clean_first=true ;;
@ -427,6 +426,3 @@ main() {
else
true
fi
}
main "$@"