--- revdep-rebuild.orig 2007-07-03 13:41:25.000000000 -0400 +++ revdep-rebuild 2007-07-03 16:48:08.000000000 -0400 @@ -1,6 +1,5 @@ -#!/bin/sh -# Copyright 1999-2005 Gentoo Foundation -# $Header$ +#!/bin/bash +# Copyright 1999-2007 Gentoo Foundation # revdep-rebuild: Reverse dependency rebuilder. # Original Author: Stanislav Brabec @@ -80,15 +79,20 @@ -h, --help Print this usage -k, --keep-temp Do not delete temporary files on exit - -X, --package-names Emerge based on package names, not exact versions - -L, --library NAME Emerge existing packages that use the library with NAME - --library=NAME NAME can be a full path to the library or a basic - regular expression (man grep) + -e, --exact Emerge based on exact package version -l, --no-ld-path Do not set LD_LIBRARY_PATH -C, --nocolor Turn off colored output -i, --ignore Ignore temporary files from previous runs + -o, --no-order Do not check the build order + (Saves time, but may cause breakage.) -q, --quiet Be less verbose (also passed to emerge command) -v, --verbose Be more verbose + -u, --no-util UTIL Do not use features provided by UTIL + --no-util=UTIL UTIL can be one of portage-utils, pkgcore, or equery + or it can be a *quoted* space-delimited list. + -L, --library NAME Emerge existing packages that use the library with NAME + --library=NAME NAME can be a full path to the library or a basic + regular expression (man grep) Calls emerge, all other options are used for it (e. g. -p, --pretend). @@ -125,6 +129,12 @@ echo "$@" >&2 exit $status } +# What to do when dynamic linking is consistent +clean_exit() { + [[ $KEEP_TEMP ]] || rm $LIST.?_* + set_color green + die 0 $'\n'"$OK_TEXT... All done. " +} # Set the output color set_color() { # sets itself the first time it's called, so we don't have to check $NOCOLOR @@ -158,30 +168,25 @@ } get_args() { appname="${0##*/}" - # Check if various utils are installed - # TODO: give the user the option to turn off detection of various utils? - if hash q 2> /dev/null; then - PORTAGE_UTILS=1 - elif hash pquery 2> /dev/null; then - PKGCORE=1 - elif hash equery 2> /dev/null; then - # Well... if equery doesn't work something's definitely broken ;) - EQUERY=1 - fi echo_v() { echo "$@"; } - unset PACKAGE_NAMES VERBOSE KEEP_TEMP EMERGE_OPTIONS CALLED_OPTIONS + unset VERBOSE KEEP_TEMP EMERGE_OPTIONS remove_old_tempfiles + order_packages=1 + PACKAGE_NAMES=1 SONAME="not found" SEARCH_BROKEN=1 FULL_LD_PATH=1 + local avoid_utils while [[ $1 ]]; do case $1 in -h|--help) print_usage exit 0 ;; - -X|--package-names) - PACKAGE_NAMES=1 - CALLED_OPTIONS+=" --package_names" # TODO: inconsistency _ versus - ? + -e|--exact) + unset PACKAGE_NAMES + ;; + -o|--no-order) + unset order_packages ;; -q|--quiet) echo_v() { : ; } @@ -191,30 +196,37 @@ -L=*|--library=*|--soname=*|--soname-regexp=*) SONAME="${1#*=}" unset SEARCH_BROKEN - CALLED_OPTIONS+=" --library=$SONAME" ;; -L|--library|--soname|--soname-regexp) - [[ $2 = -* ]] && die 1 "Missing expected argument to $1" + [[ ! $2 || $2 = -* ]] && die 1 "Missing expected argument to $1" shift SONAME="$1" unset SEARCH_BROKEN - CALLED_OPTIONS+=" --library=$SONAME" + ;; + -u=*|--no-util=*) + # TODO: check for invalid values + avoid_utils="${1#*=}" + ;; + -u|--no-util) + [[ ! $2 || $2 = -* ]] && die 1 "Missing expected argument to $1" + shift + avoid_utils="$1" ;; -nc|-C|--no-color|--nocolor) - NOCOLOR=1 + export NOCOLOR=1 ;; -l|-np|--no-ld-path) unset FULL_LD_PATH - CALLED_OPTIONS+=" --no-ld-path" ;; -i|--ignore) - rm -f $LIST* + remove_old_tempfiles=1 ;; -k|--keep-temp) - KEEPTEMP=1 + KEEP_TEMP=1 ;; -vv|--extra-verbose|-v|--verbose) VERBOSE=1 + EMERGE_OPTIONS+=" $1" ;; --) ;; @@ -224,6 +236,14 @@ esac shift done + # Check if various utils are allowed and installed + if [[ avoid_utils != *portage-utils* ]] && hash q 2> /dev/null; then + PORTAGE_UTILS=1 + elif [[ avoid_utils != *pkgcore* ]] && hash pquery 2> /dev/null; then + PKGCORE=1 + elif [[ avoid_utils != *equery* ]] && hash equery 2> /dev/null; then + EQUERY=1 + fi } get_args "$@" @@ -295,8 +315,8 @@ if [[ $LIST = .$appname ]]; then die 1 "!!! Unable to find a satisfactory location for temporary files !!!" fi +[[ $remove_old_tempfiles ]] && rm -f $LIST.* -CALLED_OPTIONS=$(clean_var "$CALLED_OPTIONS") function set_trap () { trap "rm_temp $1" SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM } @@ -335,21 +355,20 @@ $( find -L "$LIST" -type f -mmin +1440 -print | while read; do echo 1; break; done - ) ]] && rm -f $LIST* + ) ]] && rm -f $LIST.* # Don't use our previous files if environment doesn't match if [[ -r $LIST.0_env ]]; then oIFS="$IFS"; IFS=$'\a' PREVS=( $( source "$LIST.0_env" - echo "$SEARCH_DIRS"$'\a'"$SEARCH_DIRS_MASK"$'\a'"$LD_LIBRARY_MASK"$'\a'"$PORTAGE_ROOT"$'\a'"$CALLED_OPTIONS" + echo "$SEARCH_DIRS"$'\a'"$SEARCH_DIRS_MASK"$'\a'"$LD_LIBRARY_MASK"$'\a'"$PORTAGE_ROOT" ) ) IFS="$oIFS" if [[ ${PREVS[0]} != $SEARCH_DIRS || ${PREVS[1]} != $SEARCH_DIRS_MASK || ${PREVS[2]} != $LD_LIBRARY_MASK || - ${PREVS[3]} != $PORTAGE_ROOT || - ${PREVS[4]} != $CALLED_OPTIONS ]]; then + ${PREVS[3]} != $PORTAGE_ROOT ]]; then echo 'Environment mismatch from previous run, deleting temporary files...' rm -f $LIST* fi @@ -362,7 +381,6 @@ SEARCH_DIRS_MASK="$SEARCH_DIRS_MASK" LD_LIBRARY_MASK="$LD_LIBRARY_MASK" PORTAGE_ROOT="$PORTAGE_ROOT" - CALLED_OPTIONS="$CALLED_OPTIONS" EMERGE_OPTIONS="$EMERGE_OPTIONS" EOF @@ -424,7 +442,7 @@ echo color_echo green -n "Checking dynamic linking$WORKING_TEXT..." -if [[ -f $LIST.3_rebuild ]]; then +if [[ -s $LIST.3_rebuild ]]; then echo " using existing $LIST.3_rebuild." else [[ $LIST ]] || die 1 "$LIST" 'is undefined! (This is a bug.)' @@ -515,6 +533,7 @@ echo_v " broken $FILE (no version information available)" done fi + [[ -s $LIST.3_rebuild ]] || clean_exit echo -e " done.\n ($LIST.3_rebuild)" fi @@ -530,7 +549,7 @@ if [[ $PORTAGE_UTILS ]]; then EXACT_PKG=$(qfile -qvC $FILE) elif [[ $PKGCORE ]]; then - EXACT_PKG=$(pquery --nocolor --early-out --vdb --owns="$FILE") + EXACT_PKG=$(pquery --nocolor --owns="$FILE") elif [[ $EQUERY ]]; then EXACT_PKG=$(equery -q -C b $FILE) else @@ -583,7 +602,7 @@ echo -e " done.\n ($LIST.4_ebuilds)" else echo " Nothing to rebuild" - rm "$LIST.4_ebuilds" + rm -f "$LIST.4_ebuilds" fi fi else @@ -593,7 +612,8 @@ echo " using existing $LIST.4_ebuilds." else if [[ -s $LIST.3_rebuild ]]; then - rebuildList=$(awk '{print $2}' "$LIST.3_rebuild") + rebuildList=" $(<"$LIST.3_rebuild") " + rebuildList="${rebuildList//[[:space:]]obj[[:space:]]/ }" if [[ $PORTAGE_UTILS ]]; then qfile -qvC $rebuildList # Don't put quotes around $rebuildList # elif [[ $PKGCORE ]]; then @@ -609,16 +629,16 @@ echo -e " done.\n ($LIST.4_ebuilds)" else echo " Nothing to rebuild" - rm > $LIST.4_ebuilds + rm -f $LIST.4_ebuilds fi fi fi -# TODO: let the user skip this step -color_echo green -n $'\nEvaluating package order...' -if [[ -r $LIST.5_order ]]; then +if [[ $order_packages ]]; then + color_echo green -n $'\nEvaluating package order...' + if [[ -r $LIST.5_order ]]; then echo " using existing $LIST.5_order." -else + else set_trap "$LIST.5_order" RAW_REBUILD_LIST=$(<"$LIST.4_ebuilds") if [[ $RAW_REBUILD_LIST ]]; then @@ -651,22 +671,20 @@ fi [[ -f $LIST.5_order ]] && echo -e " done.\n ($LIST.5_order)" || echo -e " done.\n ($LIST.4_ebuilds)" + fi +else + color_echo green "Skipping package ordering" fi # Clean up no longer needed environment variables -unset COMPLETE_LD_LIBRARY_PATH SEARCH_DIRS SEARCH_DIRS_MASK LD_LIBRARY_MASK PORTAGE_ROOT CALLED_OPTIONS +unset COMPLETE_LD_LIBRARY_PATH SEARCH_DIRS SEARCH_DIRS_MASK LD_LIBRARY_MASK PORTAGE_ROOT [[ -f $LIST.5_order ]] && REBUILD_LIST=$(<"$LIST.5_order") || REBUILD_LIST=$(<"$LIST.4_ebuilds") -REBUILD_LIST="=${REBUILD_LIST//[[:space:]]/ =}" trap - SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM -if [[ ! $REBUILD_LIST ]]; then - [[ $KEEPTEMP ]] || rm $LIST.?_* - set_color green - die 0 $'\n'"$OK_TEXT... All done. " -fi +REBUILD_LIST="=${REBUILD_LIST//[[:space:]]/ =}" IS_REAL_MERGE=1 for option in $EMERGE_OPTIONS; do