[pacman-dev] [PATCH v3 3/4] Moved dependencies of download functions into a library
Ashley Whetter
ashley at awhetter.co.uk
Sun Sep 22 06:25:31 EDT 2013
Moved functions out in preparation for splitting out download functions.
scripts/libmakepkg/*.sh files only import the files from their relevant
directory.
All libmakepkg files have an inclusion guard.
Also added libmakepkg targets to Makefile.am.
Signed-off-by: Ashley Whetter <ashley at awhetter.co.uk>
---
scripts/.gitignore | 4 +
scripts/Makefile.am | 38 +++++++-
scripts/libmakepkg/util.sh.in | 30 +++++++
scripts/libmakepkg/util/message.sh | 55 ++++++++++++
scripts/libmakepkg/util/url.sh.in | 145 ++++++++++++++++++++++++++++++
scripts/libmakepkg/util/util.sh.in | 58 ++++++++++++
scripts/makepkg.sh.in | 180 ++-----------------------------------
7 files changed, 333 insertions(+), 177 deletions(-)
create mode 100644 scripts/libmakepkg/util.sh.in
create mode 100644 scripts/libmakepkg/util/message.sh
create mode 100644 scripts/libmakepkg/util/url.sh.in
create mode 100644 scripts/libmakepkg/util/util.sh.in
diff --git a/scripts/.gitignore b/scripts/.gitignore
index 8dac503..6f2e84d 100644
--- a/scripts/.gitignore
+++ b/scripts/.gitignore
@@ -8,3 +8,7 @@ pkgdelta
repo-add
repo-elephant
repo-remove
+
+libmakepkg/util.sh
+libmakepkg/util/url.sh
+libmakepkg/util/util.sh
diff --git a/scripts/Makefile.am b/scripts/Makefile.am
index 8130704..4c52bd4 100644
--- a/scripts/Makefile.am
+++ b/scripts/Makefile.am
@@ -36,13 +36,22 @@ LIBRARY = \
library/size_to_human.sh \
library/term_colors.sh
+LIBMAKEPKG = \
+ $(LIBMAKEPKG_INC) \
+ util/message.sh
+
+LIBMAKEPKG_INC = \
+ util.sh \
+ util/url.sh \
+ util/util.sh
+
# Files that should be removed, but which Automake does not know.
MOSTLYCLEANFILES = $(bin_SCRIPTS)
libmakepkgdir = $(libdir)/makepkg
clean-local:
- $(AM_V_at)$(RM) -r .lib
+ $(AM_V_at)$(RM) -r .lib $(addprefix libmakepkg/,$(LIBMAKEPKG_INC))
if USE_GIT_VERSION
GIT_VERSION := $(shell sh -c 'git describe --abbrev=4 --dirty | sed s/^v//')
@@ -83,7 +92,20 @@ $(OURSCRIPTS): Makefile
$(AM_V_at)chmod +x,a-w $@
@$(BASH_SHELL) -O extglob -n $@
+$(addprefix libmakepkg/,$(LIBMAKEPKG_INC)): Makefile
+ $(AM_V_at)$(RM) $@
+ $(AM_V_GEN)test -f $(srcdir)/$@.in && m4 -P -I $(srcdir) $(srcdir)/$@.in | $(edit) >$@
+ $(AM_V_at)chmod a-w $@
+ @$(BASH_SHELL) -O extglob -n $@
+
+libmakepkg: \
+ $(srcdir)/libmakepkg/util.sh \
+ $(srcdir)/libmakepkg/util/message.sh \
+ $(srcdir)/libmakepkg/util/url.sh \
+ $(srcdir)/libmakepkg/util/util.sh
+
makepkg: \
+ libmakepkg \
$(srcdir)/makepkg.sh.in \
$(srcdir)/makepkg-wrapper.sh.in \
$(srcdir)/library/parseopts.sh
@@ -131,7 +153,12 @@ makepkg-wrapper: \
$(srcdir)/makepkg-wrapper.sh.in \
$(srcdir)/makepkg.sh.in \
$(srcdir)/library/parseopts.sh \
- | makepkg
+ $(srcdir)/libmakepkg/util.sh \
+ $(srcdir)/libmakepkg/util/message.sh \
+ $(srcdir)/libmakepkg/util/url.sh \
+ $(srcdir)/libmakepkg/util/util.sh \
+ | libmakepkg \
+ makepkg
$(AM_V_at)$(MKDIR_P) .lib
$(AM_V_at)mv -f makepkg .lib
$(AM_V_at)$(RM) $@
@@ -146,6 +173,10 @@ install-data-hook:
cd $(DESTDIR)$(bindir) && \
$(RM) makepkg makepkg-wrapper
$(INSTALL) .lib/makepkg $(DESTDIR)$(bindir)/makepkg
+ $(AM_V_at)$(MKDIR_P) $(DESTDIR)$(libmakepkgdir)/util
+ for lib in $(LIBMAKEPKG); do \
+ $(INSTALL) libmakepkg/$$lib $(DESTDIR)$(libmakepkgdir)/$$lib; \
+ done
cd $(DESTDIR)$(bindir) && \
$(RM) repo-elephant && \
( $(LN_S) repo-add repo-elephant || \
@@ -160,5 +191,8 @@ install-data-hook:
uninstall-hook:
cd $(DESTDIR)$(bindir) && \
$(RM) repo-remove repo-elephant
+ for lib in $(LIBMAKEPKG); do \
+ $(RM) -r $(DESTDIR)$(libmakepkgdir)/$$lib; \
+ done
# vim:set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/util.sh.in b/scripts/libmakepkg/util.sh.in
new file mode 100644
index 0000000..11626bd
--- /dev/null
+++ b/scripts/libmakepkg/util.sh.in
@@ -0,0 +1,30 @@
+#!/bin/bash
+#
+# util.sh
+#
+# Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at 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_UTIL_SH" ] && return
+LIBMAKEPKG_UTIL_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+for lib in "$LIBRARY/util/"*.sh; do
+ source "$lib"
+done
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/util/message.sh b/scripts/libmakepkg/util/message.sh
new file mode 100644
index 0000000..ad134fe
--- /dev/null
+++ b/scripts/libmakepkg/util/message.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+#
+# message.sh
+#
+# Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at archlinux.org>
+# Copyright (c) 2002-2006 by Judd Vinet <jvinet at zeroflux.org>
+# Copyright (c) 2005 by Aurelien Foret <orelien at chez.com>
+# Copyright (c) 2006 by Miklos Vajna <vmiklos at frugalware.org>
+# Copyright (c) 2005 by Christian Hamar <krics at linuxforum.hu>
+# Copyright (c) 2006 by Alex Smith <alex at alex-smith.me.uk>
+# Copyright (c) 2006 by Andras Voroskoi <voroskoi at frugalware.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_UTIL_MESSAGE_SH" ] && return
+LIBMAKEPKG_UTIL_MESSAGE_SH=1
+
+error() {
+ local mesg=$1; shift
+ printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+msg() {
+ local mesg=$1; shift
+ printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+msg2() {
+ local mesg=$1; shift
+ printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+plain() {
+ local mesg=$1; shift
+ printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+warning() {
+ local mesg=$1; shift
+ printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/util/url.sh.in b/scripts/libmakepkg/util/url.sh.in
new file mode 100644
index 0000000..595ce16
--- /dev/null
+++ b/scripts/libmakepkg/util/url.sh.in
@@ -0,0 +1,145 @@
+#!/bin/bash
+#
+# url.sh
+#
+# Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at 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_UTIL_URL_SH" ] && return
+LIBMAKEPKG_UTIL_URL_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+
+get_downloadclient() {
+ local proto=$1
+
+ # loop through DOWNLOAD_AGENTS variable looking for protocol
+ local i
+ for i in "${DLAGENTS[@]}"; do
+ local handler="${i%%::*}"
+ if [[ $proto = "$handler" ]]; then
+ local agent="${i##*::}"
+ break
+ fi
+ done
+
+ # if we didn't find an agent, return an error
+ if [[ -z $agent ]]; then
+ error "$(gettext "Unknown download protocol: %s")" "$proto"
+ plain "$(gettext "Aborting...")"
+ exit 1 # $E_CONFIG_ERROR
+ fi
+
+ # ensure specified program is installed
+ local program="${agent%% *}"
+ if [[ ! -x $program ]]; then
+ local baseprog="${program##*/}"
+ error "$(gettext "The download program %s is not installed.")" "$baseprog"
+ plain "$(gettext "Aborting...")"
+ exit 1 # $E_MISSING_PROGRAM
+ fi
+
+ printf "%s\n" "$agent"
+}
+
+# extract the filename from a source entry
+get_filename() {
+ local netfile=$1
+
+ # if a filename is specified, use it
+ if [[ $netfile = *::* ]]; then
+ printf "%s\n" ${netfile%%::*}
+ return
+ fi
+
+ local proto=$(get_protocol "$netfile")
+
+ case $proto in
+ bzr*|git*|hg*|svn*)
+ filename=${netfile%%#*}
+ filename=${filename%/}
+ filename=${filename##*/}
+ if [[ $proto = bzr* ]]; then
+ filename=${filename#*lp:}
+ fi
+ if [[ $proto = git* ]]; then
+ filename=${filename%%.git*}
+ fi
+ ;;
+ *)
+ # if it is just an URL, we only keep the last component
+ filename="${netfile##*/}"
+ ;;
+ esac
+ printf "%s\n" "${filename}"
+}
+
+# a source entry can have two forms :
+# 1) "filename::http://path/to/file"
+# 2) "http://path/to/file"
+
+# Return the absolute filename of a source entry
+get_filepath() {
+ local file="$(get_filename "$1")"
+ local proto="$(get_protocol "$1")"
+
+ case $proto in
+ bzr*|git*|hg*|svn*)
+ if [[ -d "$startdir/$file" ]]; then
+ file="$startdir/$file"
+ elif [[ -d "$SRCDEST/$file" ]]; then
+ file="$SRCDEST/$file"
+ else
+ return 1
+ fi
+ ;;
+ *)
+ if [[ -f "$startdir/$file" ]]; then
+ file="$startdir/$file"
+ elif [[ -f "$SRCDEST/$file" ]]; then
+ file="$SRCDEST/$file"
+ else
+ return 1
+ fi
+ ;;
+ esac
+
+ printf "%s\n" "$file"
+}
+
+# extract the protocol from a source entry - return "local" for local sources
+get_protocol() {
+ if [[ $1 = *://* ]]; then
+ # strip leading filename
+ local proto="${1##*::}"
+ printf "%s\n" "${proto%%://*}"
+ elif [[ $1 = *lp:* ]]; then
+ local proto="${1##*::}"
+ printf "%s\n" "${proto%%lp:*}"
+ else
+ printf "%s\n" local
+ fi
+}
+
+# extract the URL from a source entry
+get_url() {
+ # strip an eventual filename
+ printf "%s\n" "${1#*::}"
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/libmakepkg/util/util.sh.in b/scripts/libmakepkg/util/util.sh.in
new file mode 100644
index 0000000..76418b0
--- /dev/null
+++ b/scripts/libmakepkg/util/util.sh.in
@@ -0,0 +1,58 @@
+#!/bin/bash
+#
+# util.sh
+#
+# Copyright (c) 2006-2013 Pacman Development Team <pacman-dev at 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_UTIL_UTIL_SH" ] && return
+LIBMAKEPKG_UTIL_UTIL_SH=1
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+
+cd_safe() {
+ if ! cd "$1"; then
+ error "$(gettext "Failed to change to directory %s")" "$1"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+}
+
+dir_is_empty() {
+ (
+ shopt -s dotglob nullglob
+ files=("$1"/*)
+ (( ${#files} == 0 ))
+ )
+}
+
+##
+# usage : in_array( $needle, $haystack )
+# return : 0 - found
+# 1 - not found
+##
+in_array() {
+ local needle=$1; shift
+ local item
+ for item in "$@"; do
+ [[ $item = "$needle" ]] && return 0 # Found
+ done
+ return 1 # Not Found
+}
+
+# vim: set ts=2 sw=2 noet:
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 5ac00a1..d1dd964 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -97,33 +97,12 @@ PACMAN_OPTS=
shopt -s extglob
-### SUBROUTINES ###
-
-plain() {
- local mesg=$1; shift
- printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
-
-msg() {
- local mesg=$1; shift
- printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
-
-msg2() {
- local mesg=$1; shift
- printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
-
-warning() {
- local mesg=$1; shift
- printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
-
-error() {
- local mesg=$1; shift
- printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
-}
+# Import libmakepkg
+for lib in "$LIBRARY"/*.sh; do
+ source "$lib"
+done
+### SUBROUTINES ###
##
# Special exit call for traps, Don't print any error messages when inside,
@@ -198,124 +177,6 @@ enter_fakeroot() {
fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
}
-
-# a source entry can have two forms :
-# 1) "filename::http://path/to/file"
-# 2) "http://path/to/file"
-
-# Return the absolute filename of a source entry
-get_filepath() {
- local file="$(get_filename "$1")"
- local proto="$(get_protocol "$1")"
-
- case $proto in
- bzr*|git*|hg*|svn*)
- if [[ -d "$startdir/$file" ]]; then
- file="$startdir/$file"
- elif [[ -d "$SRCDEST/$file" ]]; then
- file="$SRCDEST/$file"
- else
- return 1
- fi
- ;;
- *)
- if [[ -f "$startdir/$file" ]]; then
- file="$startdir/$file"
- elif [[ -f "$SRCDEST/$file" ]]; then
- file="$SRCDEST/$file"
- else
- return 1
- fi
- ;;
- esac
-
- printf "%s\n" "$file"
-}
-
-# extract the filename from a source entry
-get_filename() {
- local netfile=$1
-
- # if a filename is specified, use it
- if [[ $netfile = *::* ]]; then
- printf "%s\n" ${netfile%%::*}
- return
- fi
-
- local proto=$(get_protocol "$netfile")
-
- case $proto in
- bzr*|git*|hg*|svn*)
- filename=${netfile%%#*}
- filename=${filename%/}
- filename=${filename##*/}
- if [[ $proto = bzr* ]]; then
- filename=${filename#*lp:}
- fi
- if [[ $proto = git* ]]; then
- filename=${filename%%.git*}
- fi
- ;;
- *)
- # if it is just an URL, we only keep the last component
- filename="${netfile##*/}"
- ;;
- esac
- printf "%s\n" "${filename}"
-}
-
-# extract the URL from a source entry
-get_url() {
- # strip an eventual filename
- printf "%s\n" "${1#*::}"
-}
-
-# extract the protocol from a source entry - return "local" for local sources
-get_protocol() {
- if [[ $1 = *://* ]]; then
- # strip leading filename
- local proto="${1##*::}"
- printf "%s\n" "${proto%%://*}"
- elif [[ $1 = *lp:* ]]; then
- local proto="${1##*::}"
- printf "%s\n" "${proto%%lp:*}"
- else
- printf "%s\n" local
- fi
-}
-
-get_downloadclient() {
- local proto=$1
-
- # loop through DOWNLOAD_AGENTS variable looking for protocol
- local i
- for i in "${DLAGENTS[@]}"; do
- local handler="${i%%::*}"
- if [[ $proto = "$handler" ]]; then
- local agent="${i##*::}"
- break
- fi
- done
-
- # if we didn't find an agent, return an error
- if [[ -z $agent ]]; then
- error "$(gettext "Unknown download protocol: %s")" "$proto"
- plain "$(gettext "Aborting...")"
- exit 1 # $E_CONFIG_ERROR
- fi
-
- # ensure specified program is installed
- local program="${agent%% *}"
- if [[ ! -x $program ]]; then
- local baseprog="${program##*/}"
- error "$(gettext "The download program %s is not installed.")" "$baseprog"
- plain "$(gettext "Aborting...")"
- exit 1 # $E_MISSING_PROGRAM
- fi
-
- printf "%s\n" "$agent"
-}
-
download_local() {
local netfile=$1
local filepath=$(get_filepath "$netfile")
@@ -966,21 +827,6 @@ in_opt_array() {
return 127
}
-
-##
-# usage : in_array( $needle, $haystack )
-# return : 0 - found
-# 1 - not found
-##
-in_array() {
- local needle=$1; shift
- local item
- for item in "$@"; do
- [[ $item = "$needle" ]] && return 0 # Found
- done
- return 1 # Not Found
-}
-
source_has_signatures() {
local file
for file in "${source[@]}"; do
@@ -1372,14 +1218,6 @@ error_function() {
exit 2 # $E_BUILD_FAILED
}
-cd_safe() {
- if ! cd "$1"; then
- error "$(gettext "Failed to change to directory %s")" "$1"
- plain "$(gettext "Aborting...")"
- exit 1
- fi
-}
-
source_safe() {
shopt -u extglob
if ! source "$@"; then
@@ -2473,14 +2311,6 @@ canonicalize_path() {
fi
}
-dir_is_empty() {
- (
- shopt -s dotglob nullglob
- files=("$1"/*)
- (( ${#files} == 0 ))
- )
-}
-
m4_include(library/parseopts.sh)
usage() {
--
1.8.4
More information about the pacman-dev
mailing list