--- src/revdep-rebuild/revdep-rebuild 2009-05-06 01:21:08 +0400 +++ src/revdep-rebuild/revdep-rebuild 2009-05-06 01:18:16 +0400 @@ -87,6 +87,10 @@ declare WORKING_TEXT # Feedback about the search declare WORKING_DIR # Working directory where cache files are kept +# Who's root? +declare ROOT_UID # User ID of root +ROOT_UID=`python -c 'import sys; import portage; import portage.const, portage.exception, portage.output; print portage.const_autotool.rootuid;'` + main() { # preliminary setup get_opts "$@" @@ -98,7 +103,14 @@ # Search for broken binaries get_files get_ldpath - main_checks + case `python -c 'import platform; print platform.system()'` in + Darwin) + darwin_main_checks + ;; + *) + main_checks + ;; + esac # Associate broken binaries with packages to rebuild if [[ $PACKAGE_NAMES ]]; then @@ -430,7 +442,7 @@ normalize_emerge_opts # If the user is not super, add --pretend to EMERGE_OPTIONS - if [[ ${EMERGE_OPTIONS[@]} != *--pretend* && $UID -ne 0 ]]; then + if [[ ${EMERGE_OPTIONS[@]} != *--pretend* && $UID -ne ${ROOT_UID} ]]; then ewarn "You are not superuser. Adding --pretend to emerge options." EMERGE_OPTIONS+=(--pretend) fi @@ -525,9 +537,9 @@ get_search_env() { local new_env local old_env - local uid=$(python -c 'import os; import pwd; print pwd.getpwuid(os.getuid())[0]') + local uid=$(python -c 'import os; import pwd; print os.getuid()') # Find a place to put temporary files - if [[ "$uid" == "root" ]]; then + if [[ $uid -eq ${ROOT_UID} ]]; then local tmp_target="@GENTOO_PORTAGE_EPREFIX@/var/cache/${APP_NAME}" else local tmp_target="$(mktemp -d -t revdep-rebuild.XXXXXXXXXX)" @@ -653,9 +665,9 @@ COMPLETE_LD_LIBRARY_PATH=( @GENTOO_PORTAGE_EPREFIX@/lib* @GENTOO_PORTAGE_EPREFIX@/usr/lib* - $(sed '/^#/d;s/#.*$//' < /etc/ld.so.conf) + $(sed '/^#/d;s/#.*$//' 2>/dev/null < /etc/ld.so.conf ) $(sed 's:/[^/]*$::' < "$FILES_FILE" | sort -ru) - ) + ) IFS=':' COMPLETE_LD_LIBRARY_PATH="${COMPLETE_LD_LIBRARY_PATH[*]}" IFS="$OIFS" @@ -663,6 +675,41 @@ einfo "Generated new $LDPATH_FILE" fi } + +darwin_main_checks() { + local master_file + local dep_file + local master_version + local i=0 + local numFiles=$(wc -l ${FILES_FILE} | cut -d ' ' -f 1) + einfo "Checking dynamic linking $WORKING_TEXT" + if [[ -r "$BROKEN_FILE" && -s "$BROKEN_FILE" ]]; then + einfo "Found existing $BROKEN_FILE." + else + ( + while read master_file; do + # + # Read what libraries we depend upon and whether these + # files exist and contain the same compatibility + # version as referenced in the master file + # + otool -L "${master_file}" 2>>${ERRORS_FILE} | \ + grep 'compatibility version' | \ + sed 's!^[ ]*\([^ ][^(]*\) (compatibility version \([^,]*\).*!\1 \2!' | \ + while read dep_file master_version; do + if ! test -e "${dep_file}" || ! otool -L "${dep_file}" 2>>${ERRORS_FILE} | grep "${dep_file} (compatibility version ${master_version}" >/dev/null; then + echo obj ${master_file} >&3 + break + fi + done + [[ $VERBOSE ]] && + progress $((++i)) $numFiles $master_file || + progress $((++i)) $numFiles + done + ) < "${FILES_FILE}" 3> "${BROKEN_FILE}" + fi +} + main_checks() { local target_file local -a files