Another patch :)
This one targets the 3 dep check functions (handledeps, resolvedeps,
removedeps). The bulk of the changes are whitespace and removing the
repetitive if..then...else checks. Also some bits have been reordered to
stop functions/external programs being called unnecessarily.
This still includes the fakeroot hacks, if you need it rediffed without
the fakeroot hacks, I'll post a new patch.
Andrew
------------------------------------------------------------
revno: 3
committer: Andrew Fyfe
branch nick: feature_handledeps
timestamp: Sat 2007-03-24 12:12:48 +0000
message:
* cleaned up
handledeps ()
resolvedeps ()
removedeps ()
=== modified file 'scripts/makepkg'
--- old/scripts/makepkg 2007-03-24 03:49:27 +0000
+++ new/scripts/makepkg 2007-03-24 12:12:35 +0000
@@ -191,91 +191,85 @@
}
handledeps() {
- local missingdeps=0
+ local R_DEPS_SATISFIED=0
+ local R_DEPS_MISSING=1
+
+ [ $# -eq 0 ] && return $R_DEPS_SATISFIED
+
local deplist="$*"
- local depstrip=""
- local striplist=""
- local haveperm=0
- if [ \( "$EUID" = "0" -a "$INFAKEROOT" != "1" \) -o "$SUDO" = 1 ]; then
- haveperm=1
- fi
-
+ local striplist
+ local dep
for dep in $deplist; do
- depstrip=$(echo $dep | sed 's|=.*$||' | sed 's|>.*$||' | sed 's|<.*$||')
- striplist="$striplist $depstrip"
+ striplist="$striplist $(echo $dep | sed -e 's|=.*$||' -e 's|>.&$||' -e 's|<.*$||')"
done
- if [ "$deplist" != "" -a $haveperm -eq 1 ]; then
- if [ "$DEP_BIN" = "1" -a "$SUDO" = "1" ]; then
- # install missing deps from binary packages (using pacman -S and sudo)
- msg "Installing missing dependencies..."
+ if [ "$DEP_SRC" = "0" -a "$DEP_BIN" = "0" ]; then
+ return $R_DEPS_MISSING
+ elif [ "$SUDO" = 0 -a $EUID -gt 0 ]; then
+ warning "Cannot auto-install missing dependencies as a normal user without sudo!"
+ plain "Run makepkg as root or with -S to resolve dependencies automatically."
+ return $R_DEPS_MISSING
+ fi
+
+ if [ "$DEP_BIN" = "1" ]; then
+ # install missing deps from binary packages (using pacman -S)
+ msg "Installing missing dependencies..."
+ local ret=0
+
+ if [ "$SUDO" = 1 ]; then
if [ "$INFAKEROOT" = "1" ]; then
# kinda hacky, but we need to make pacman think that we're NOT
# in fakeroot so it will go ahead and install the dependencies.
FAKEROOTKEY2=$FAKEROOTKEY
unset FAKEROOTKEY
fi
- sudo pacman $PACMAN_OPTS -S $striplist
- if [ $? -eq 1 ]; then
- error "Pacman failed to install missing dependencies."
- exit 1
- fi
+ sudo pacman $PACMAN_OPTS -S $striplist || ret=$?
if [ "$INFAKEROOT" = "1" ]; then
export FAKEROOTKEY=$FAKEROOTKEY2
unset FAKEROOTKEY2
fi
- elif [ "$DEP_BIN" = "1" ]; then
- # install missing deps from binary packages (using pacman -S)
- msg "Installing missing dependencies..."
- pacman $PACMAN_OPTS -S $striplist
- if [ $? -eq 1 ]; then
- error "Pacman failed to install missing dependencies."
- exit 1
- fi
- elif [ "$DEP_SRC" = "1" ]; then
- # install missing deps by building them from source.
- # we look for each package name in $SRCROOT and build it.
- if [ "$SRCROOT" = "" ]; then
- error "Source root cannot be found - please make sure it is specified in /etc/makepkg.conf"
- exit 1
- fi
- # TODO: handle version comparators (eg, glibc>=2.2.5)
- msg "Building missing dependencies..."
- for dep in $striplist; do
- candidates=$(find $SRCROOT -type d -name "$dep")
- if [ "$candidates" = "" ]; then
- error "Could not find \"$dep\" under $SRCROOT"
- exit 1
- fi
- success=0
- for pkgdir in $candidates; do
- if [ -f "$pkgdir/$BUILDSCRIPT" ]; then
- cd "$pkgdir"
- if [ "$RMDEPS" = "1" ]; then
- makepkg -i -c -b -r -w $PKGDEST
- else
- makepkg -i -c -b -w $PKGDEST
- fi
- if [ $? -eq 0 ]; then
- success=1
- break
- fi
- fi
- done
- if [ "$success" = "0" ]; then
- error "Failed to build \"$dep\""
- exit 1
+ else
+ pacman $PACMAN_OPTS -S $striplist || ret=$?
+ fi
+
+ if [ $ret -ne 0 ]; then
+ error "Pacman failed to install missing dependencies."
+ exit 1 # TODO: error code
+ fi
+ elif [ "$DEP_SRC" = "1" ]; then
+ msg "Building missing dependencies..."
+
+ # install missing deps by building them from source.
+ # we look for each package name in $SRCROOT and build it.
+ if [ "$SRCROOT" = "" ]; then
+ error "Source root cannot be found - please make sure it is specified in /etc/makepkg.conf"
+ exit 1 # TODO: error code
+ fi
+
+ # TODO: handle version comparators (eg, glibc>=2.2.5)
+ for dep in $striplist; do
+ local candidates="$(find "$SRCROOT" -type d -name "$dep")"
+ if [ "$candidates" = "" ]; then
+ error "Could not find \"$dep\" under $SRCROOT"
+ exit 1 # TODO: error code
+ fi
+
+ local makepkg_opts='-i -c -b'
+ [ "$RMDEPS" = "1" ] && makepkg_opts="$makepkg_opts -r"
+ local ret
+ local pkgdir
+ for pkgdir in $candidates; do
+ if [ -f "$pkgdir/$BUILDSCRIPT" ]; then
+ cd "$pkgdir"
+ ret=0
+ PKGDEST="$PKGDEST" makepkg $makepkg_opts || ret=$?
+ [ $ret -eq 0 ] && continue 2
fi
done
- else
- missingdeps=1
- fi
- elif [ "$deplist" != "" -a $haveperm -eq 0 ]; then
- if [ "$DEP_SRC" = "1" -o "$DEP_BIN" = "1" ]; then
- warning "Cannot auto-install missing dependencies as a normal user without sudo!"
- plain "Run makepkg as root or with -S to resolve dependencies automatically."
- fi
- missingdeps=1
+
+ error "Failed to build \"$dep\""
+ exit 1 # TODO: error code
+ done
fi
# rerun any additional sh scripts found in /etc/profile.d/
@@ -286,53 +280,51 @@
fi
done
- return $missingdeps
+ return $R_DEPS_SATISFIED
}
resolvedeps() {
- deplist=""
- newdeplist=""
-
- deplist=$(checkdeps $*)
- if [ -n "${deplist}" ]; then
- handledeps $deplist
- if [ $? -eq 0 ]; then
- # check deps again to make sure they were resolved
- newdeplist=$(checkdeps $*)
- if [ -n "${newdeplist}" ]; then
- error "Failed to install all missing dependencies."
- fi
- else
- newdeplist="$deplist"
- fi
- fi
-
- # if new dep list is not empty, print the list
- if [ -n "${newdeplist}" ]; then
- msg "Missing Dependencies:"
- for dep in ${newdeplist}; do
- msg2 "${dep}"
- done
- return 1
- else
- return 0
- fi
+ local R_DEPS_SATISFIED=0
+ local R_DEPS_MISSING=0
+
+ deplist="$(checkdeps $*)"
+ [ "$deplist" = "" ] && return $R_DEPS_SATISFIED
+
+ if handledeps $deplist; then
+ # check deps again to make sure they were resolved
+ deplist="$(checkdeps $*)"
+ [ "$deplist" = "" ] && return $R_DEPS_SATISFIED
+ elif [ "$DEP_BIN" = "1" -o "$DEP_SRC" = "1" ]; then
+ error "Failed to install all missing dependencies."
+ fi
+
+ msg "Missing Dependencies:"
+ local dep
+ for dep in $deplist; do
+ msg2 "$dep"
+ done
+
+ return $R_DEPS_MISSING
}
# fix flyspray bug #5923
removedeps() {
+ [ "$RMDEPS" = "0" ] && return
+ [ "$SUDO" = "0" -a $EUID -gt 0 ] && return
+
# runtimedeps and buildtimedeps are set when resolving deps
local deplist="$runtimedeps $buildtimedeps"
- local depstrip=""
- local striplist=""
-
+ local striplist
+
+ [ "$deplist" = "" ] && return
+
+ local dep
for dep in $deplist; do
- depstrip=$(echo $dep | sed 's|=.*$||' | sed 's|>.*$||' | sed 's|<.*$||')
- striplist="$striplist $depstrip"
+ striplist="$striplist $(echo $dep | sed -e 's|=.*$||' -e 's|>.*$||' -e 's|<.*$||')"
done
- if [ "$RMDEPS" = "1" -a "$SUDO" = "1" -a -n "$deplist" ]; then
- msg "Removing installed dependencies..."
+ msg "Removing installed dependencies..."
+ if [ "$SUDO" = "1" ]; then
if [ "$INFAKEROOT" = "1" ]; then
export FAKEROOTKEY2=$FAKEROOTKEY
unset FAKEROOTKEY
@@ -342,8 +334,7 @@
export FAKEROOTKEY=$FAKEROOTKEY2
unset FAKEROOTKEY2
fi
- elif [ "$RMDEPS" = "1" -a "$EUID" = "0" -a "$INFAKEROOT" != "1" -a -n "$deplist" ]; then
- msg "Removing installed dependencies..."
+ else
pacman $PACMAN_OPTS -Rs $striplist
fi
}