Changeset 11869f1 for common


Ignore:
Timestamp:
04/09/2006 08:46:08 AM (18 years ago)
Author:
Manuel Canales Esparcia <manuel@…>
Branches:
experimental
Children:
dc526ea
Parents:
091cc83
Message:

func_ICA.sh clean-up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/func_ICA.sh

    r091cc83 r11869f1  
    7676  done
    7777}
    78 
    79 # Acknowledgment:
    80 #  The following code is a modified version of an original work written by
    81 #  Greg Schafer for the "DIY Linux" project and is included here with his
    82 #  permission.
    83 #  ref: http://www.diy-linux.org
    84 #
    85 #
    86 # ---------------------------------------------------------------------------- #
    87 # Here are the ICA functions.
    88 # ---------------------------------------------------------------------------- #
    89 #
    90 # Here we prepare for the Iterative Comparison Analysis (ICA). Essentially, we
    91 # copy most of our chroot phase files to a new location then perform some
    92 # manipulations on the copied files to make diff comparisons easier. The steps
    93 # involved are:-
    94 #   (1) copy the whole tree (minus the PRUNEPATH defined below) to the CMP_DIR
    95 #       location. Use tar as it seems like the most appropriate tool for copying
    96 #       large directory trees around.
    97 #   (2) delete all symlinks.
    98 #   (3) gunzip all `*.gz' files.
    99 #   (4) delete all hardlinked files (of course trying to leaving the "master"
    100 #       intact)
    101 #   (5) convert all `*.a' files (ar archives) into a directory of the same name
    102 #       containing the unpacked object files.
    103 #   (6) fully strip the whole lot (but being careful to strip only the debug
    104 #       symbols from object `*.o' files).
    105 
    106 #----------------------------------#
    107 do_ica_prep() {                    #
    108 #----------------------------------#
    109 : <<inline_doc
    110     desc:
    111 
    112     usage:
    113 
    114     input vars:
    115     externals:  --
    116     modifies:   --
    117     returns:    --
    118     on error:
    119     on success:
    120 inline_doc
    121 
    122   local CMP_DIR F L BN
    123   local ALL_FILES=/tmp/allfiles.$$
    124   local UNIQUE_FILES=/tmp/uniquefiles.$$
    125   local PRUNEPATH="$TT_PFX $PATCHES_DIR $SCRATCH_DIR $TARBALLS_DIR \
    126                   /dev /home /mnt /proc /root /sys /tmp /usr/src /lost+found"
    127 
    128   if [ ! -f "${STAMP_DIR}/icaprep" ]; then
    129     CMP_DIR="${SCRATCH_DIR}/cmp/iter${ITER}"
    130     test -d "$CMP_DIR" || mkdir -p $CMP_DIR
    131 
    132     echo -e "\n${BORDER}\n${CYAN}[ICA] - starting ICA preparation for\c"
    133     echo -e " Iteration ${ITER}.${OFF}\n"
    134 
    135     # Create a file that we can pass to tar as an "exclude list".
    136     # There might be an easier way to achieve tar exclusions? Strip
    137     # the leading /.
    138     for F in $PRUNEPATH; do
    139       echo ${F#*/} >> $TMP_FILE
    140     done
    141 
    142     echo -n "Copying files to ${CMP_DIR}... "
    143     cd /
    144     tar -X $TMP_FILE -cf - . | tar -C $CMP_DIR -xf - || {
    145         echo -e "\n\n${RED}ERROR:${OFF} tar copy failed!\n" >&2
    146         exit 1
    147         }
    148     echo "done."
    149     rm -f $TMP_FILE
    150 
    151     echo -n "Removing symbolic links in ${CMP_DIR}... "
    152     find $CMP_DIR -type l | xargs rm -f
    153     echo "done."
    154 
    155     echo -n "Gunzipping \".gz\" files in ${CMP_DIR}... "
    156     find $CMP_DIR -name '*.gz' | xargs gunzip
    157     echo "done."
    158 
    159     # This was a bit tricky. You'll probably have to do it by hand
    160     # to see what's actually going on. The "sort/uniq" part is
    161     # inspired from the example DirCmp script from the book "Shell
    162     # Programming Examples" by Bruce Blinn, published by Prentice
    163     # Hall. We are essentially using the `-ls' option of the find
    164     # utility to allow manipulations based on inode numbers.
    165     #
    166     # FIXME - this is a bit unreliable - rem out for now
    167     #echo -n "Removing hardlinked file copies in ${CMP_DIR}... "
    168     #find $CMP_DIR -ls | sort -n > $ALL_FILES
    169     #find $CMP_DIR -ls | sort -n -u > $UNIQUE_FILES
    170     #cat $UNIQUE_FILES $ALL_FILES | sort | uniq -u | awk '{ print $11 }' | xargs rm -f
    171     #rm -f $ALL_FILES $UNIQUE_FILES
    172     #echo "done."
    173 
    174     # ar archives contain date & time stamp info that causes us
    175     # grief when trying to find differences. Here we perform some
    176     # hackery to allow easy diffing. Essentially, replace each
    177     # archive with a dir of the same name and extract the object
    178     # files from the archive into this dir. Despite their names,
    179     # libieee.a & libmcheck.a are not actual ar archives.
    180     #
    181     echo -n "Extracting object files from \".a\" files in ${CMP_DIR}... "
    182     L=$(find $CMP_DIR -name '*.a' ! -name 'libieee.a' ! -name 'libmcheck.a')
    183 
    184     for F in $L; do
    185       mv $F ${F}.XX
    186       mkdir $F
    187       cd $F
    188       BN=${F##*/}
    189       ar x ../${BN}.XX || {
    190         echo -e "\n\n${RED}ERROR:${OFF} ar archive extraction failed!\n" >&2
    191         exit 1
    192         }
    193       rm -f ../${BN}.XX
    194     done
    195     echo "done."
    196 
    197     echo -n "Stripping (debug) symbols from \".o\" files in ${CMP_DIR}... "
    198     find $CMP_DIR -name '*.o' | xargs strip -p -g 2>/dev/null
    199     echo "done."
    200 
    201     echo -n "Stripping (all) symbols from files OTHER THAN \".o\" files in ${CMP_DIR}... "
    202     find $CMP_DIR ! -name '*.o' | xargs strip -p 2>/dev/null || :
    203     echo "done."
    204 
    205     echo -e "\n${CYAN}[ICA] - ICA preparation for Iteration ${ITER}\c"
    206     echo -e " complete.${OFF}\n${BORDER}"
    207     do_stamp icaprep
    208   fi
    209 }
    210 
    211 
    212 #----------------------------------#
    213 do_ica_work() {                    #  Do the ICA grunt work.
    214 #----------------------------------#
    215 : <<inline_doc
    216     desc:
    217 
    218     usage:      do_ica_work 1 2
    219                 do_ica_work 2 3
    220 
    221     input vars: $1 iteration number to use
    222                 $2 iteration number to use
    223     externals:  --
    224     modifies:   --
    225     returns:    --
    226     on error:
    227     on success:
    228 inline_doc
    229 
    230   local ICA_DIR="${SCRATCH_DIR}/cmp"
    231   local RAWDIFF=/tmp/rawdiff.$$
    232   local REPORT="${SCRATCH_DIR}/logs/REPORT.${1}V${2}"
    233 
    234   cd $ICA_DIR
    235 
    236   echo -n "Diffing iter${1} and iter${2}... "
    237   diff -ur iter${1} iter${2} > $RAWDIFF || :
    238   echo "done."
    239 
    240   echo -e "The list of binary files that differ:\n" > $REPORT
    241   grep "iles.*differ$" $RAWDIFF >> $REPORT
    242   echo -e "\n" >> $REPORT
    243 
    244   echo -e "The list of files that exist \"only in\" 1 of the directories:\n" >> $REPORT
    245 
    246   if grep "^Only in" $RAWDIFF >/dev/null 2>&1; then
    247      grep "^Only in" $RAWDIFF >> $REPORT
    248   else
    249     echo NONE >> $REPORT
    250   fi
    251 
    252   grep -v "iles.*differ$" $RAWDIFF | grep -v "^Only in" > ${SCRATCH_DIR}/logs/${1}V${2}.ASCII.DIFF
    253   rm -f $RAWDIFF
    254 
    255 }
Note: See TracChangeset for help on using the changeset viewer.