diff options
author | D.M.D. Ljungmark <spider@gentoo.org> | 2005-04-23 02:24:34 +0000 |
---|---|---|
committer | D.M.D. Ljungmark <spider@gentoo.org> | 2005-04-23 02:24:34 +0000 |
commit | 90e9bf3aaa859b1bd6829f14b62b81e01376c943 (patch) | |
tree | cf4b1867362e62386f1f1a8e57257dfcc85d4bc2 /users/spider | |
parent | Added myself to cvs-utils. (diff) | |
download | gentoo-90e9bf3aaa859b1bd6829f14b62b81e01376c943.tar.gz gentoo-90e9bf3aaa859b1bd6829f14b62b81e01376c943.tar.bz2 gentoo-90e9bf3aaa859b1bd6829f14b62b81e01376c943.zip |
New name for refactoring code. Refactored the list parsers, added debug output, made some (sub)optimizations to run file only once/file
Diffstat (limited to 'users/spider')
-rw-r--r-- | users/spider/depreverse/depreverse | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/users/spider/depreverse/depreverse b/users/spider/depreverse/depreverse new file mode 100644 index 0000000000..0e45a8ad52 --- /dev/null +++ b/users/spider/depreverse/depreverse @@ -0,0 +1,195 @@ +#! /bin/bash + +# Copyright DmD (Spider) Ljungmark 2005 ( spider@gentoo.org ) +# released under the GPL v2 + + + + +# Hackish tool meant to be ran toggled by a FEATURE flag to track dependencies. +# reads a list of files from STDIN and writes a list of files on STDOUT. + +# basically, this currently deals with: +# dynamic executable binaries +# libraries +# python code ( .py files and imports ) +# all scripts (#!/usr/bin/bash and #!/usr/bin/env bash ) +# Perl code + + +# set this to 1 for showing lists, 2 to show lists -and- files as they are matched +DEBUG=0 + +ulimit -c 0 + +# Parse stdin -> list. Ugly sed. Ugly, but works. +# Replaces odd chars with their quoted version. +LIST=`sed "s:[]['\"*?{}]:\\\\\&:g"` + +if [ $DEBUG -gt 0 ]; then + echo List :: $LIST > /dev/stderr +fi + +# Lets multiplex this out with a for loop. +# this loop will expand things neatly to their various objects. + +# Our various kinds of software. +EXELIST="" +SCRIPTLIST="" +LIBLIST="" +PERLLIST="" +PYTHONLIST="" + +# List of engines for scripts (interpreters). +ENGINES="" +for FILE in $LIST; do + # only do this for readable objects. We don't care if we can't read it. + if [ -r "$FILE" -a -f "$FILE" ]; then + # store "file" output + FILEOUT=`file $FILE` + + + # test for normal binary executable. + TEST=`echo $FILEOUT | egrep -v ":.* (commands|script) "| grep ":.*executable"` + if [ -n "$TEST" ]; then + # test if its really -executable- as well. + if [ -x "$FILE" ]; then + EXELIST="$EXELIST $FILE" + [ $DEBUG -gt 1 ] && echo exe: $FILE > /dev/stderr + fi + fi + + + # test for .so file + TEST=`echo $FILEOUT | grep ":.*shared object"` + if [ -n "$TEST" ]; then + LIBLIST="$LIBLIST $FILE" + [ $DEBUG -gt 1 ] && echo lib: $FILE > /dev/stderr + fi + + + # test for a script + TEST=`echo $FILEOUT | egrep ":.* (commands|script) " ` + if [ -n "$TEST" ]; then + SCRIPTLIST="$SCRIPTLIST $FILE" + [ $DEBUG -gt 1 ] && echo script: $FILE > /dev/stderr + fi + + + # test for perl module + if [ "${FILE%.pm}" != "${FILE}" ]; then + PERLLIST="$PERLLIST $FILE" + [ $DEBUG -gt 1 ] && echo perl: $FILE > /dev/stderr + fi + + + # test for python module + if [ "${FILE%.py}" != "${FILE}" ]; then + PYTHONLIST="$PYTHONLIST $FILE" + [ $DEBUG -gt 1 ] && echo python: $FILE > /dev/stderr + fi + fi +done + +if [ $DEBUG -gt 0 ]; then + echo "" > /dev/stderr + echo "Stage 1 scanning gives: " > /dev/stderr + echo Exelist: $EXELIST > /dev/stderr + echo Scriptlist: $SCRIPTLIST > /dev/stderr + echo Liblist: $LIBLIST >/dev/stderr + echo Perl: $PERLLIST >/dev/stderr + echo Python: $PYTHONLIST >/dev/stderr +fi + +PYTHONREQ="" +#extract the python include path +PYTHONPATH=`./python.path | sed -e s:,:\\\n:g -e s:'\['::g -e s:'\]'::g -e s:\'::g` + + + +# Test for loadable libraries +# since we already tested if executables are executable, we only need one pass to test both theese lists. +for FILE in $EXELIST $LIBLIST ; do + if [ -r $FILE ]; then + ldd $FILE |grep -v 'libNoVersion.so' | grep -v 'linux-gate.so' | awk '/=>/ { print $3 }' + fi +done | sort -u | sed "s/['\"]/\\\&/g" | sort -u + +for FILE in $SCRIPTLIST; do + if [ -x $FILE -a -r $FILE ]; then + LINE=`head -n 1 $FILE | sed -e 's/^\#\![ ]*//' ` + # this traps the "real" dependency in case something uses "/usr/bin/env python" or "/bin/env perl" + case $LINE in + *bin/env\ *) + # this is brutish and ugly, can be prettified. + # however, it adds both the real interpreter, and the "env" one. + # Mark though, that "env" is probably not needed, since its in "coreutils" + # might be necessary for something somewhere however, and I want to be complete. + ENGINE=`echo $LINE | cut -d" " -f1` + ENGINES="$ENGINES $ENGINE" + ENGINE=`echo $LINE | cut -d" " -f2` + ENGINES="$ENGINES `which $ENGINE`" ;; + *) + ENGINE=`echo $LINE | cut -d" " -f1` + ENGINES="$ENGINES $ENGINE";; + esac + + # the following appends extra python/perl/other languages in the future. + case $LINE in + *perl*) PERLLIST="$PERLLIST $FILE" + [ $DEBUG -gt 1 ] && echo perl: $FILE > /dev/stderr + ;; + *python*) PYTHONLIST="$PYTHONLIST $FILE" + [ $DEBUG -gt 1 ] && echo python: $FILE > /dev/stderr + ;; + esac + + fi +done + +if [ $DEBUG == 1 ]; then + echo "Stage 2 scanning gives: " > /dev/stderr + echo Perl: $PERLLIST > /dev/stderr + echo Python: $PYTHONLIST >/dev/stderr + echo Engines: $ENGINES >/dev/stderr +fi + + +# Pretty-print our Engines listing, and output it. +if [ -n "$ENGINES" ] ; then + echo $ENGINES | tr '[:blank:]' \\n | sort -u +fi + + +for FILE in $PYTHONLIST; do + grep import $FILE | while read LINE ; do + LINE2=`echo "$LINE" | grep from | cut -d" " -f-2 |sed s:from:import:g` + if [ -n "$LINE2" ]; then + LINE="$LINE2" + fi + echo "$LINE" | sed s/,/\\nimport/g + done +done | sort -u | cut -d" " -f2 | while read MODULE; +do + for PLACE in $PYTHONPATH; do + if [ -f "$PLACE/$MODULE.py" ]; then + ls -1 "$PLACE/$MODULE.py" + fi + if [ -f "$PLACE/$MODULE.so" ] ; then + ls -1 "$PLACE/$MODULE.so" + fi + done +done | sort -u + + + + +for FILE in $PERLLIST; do + echo $FILE | ./perl.req | sed -e s,::,/,g | while read MODULE; do + perl -e ' print join ("\n", @INC);' | while read PLACE; do + if [ -e "$PLACE/$MODULE.pm" ]; then + ls -1 "$PLACE/$MODULE.pm" + fi + done + done +done | sort -u |