source: common/func_ICA.sh@ 106fab9

experimental
Last change on this file since 106fab9 was bfbd927, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Added function to create iteration-N Makefile targets.

  • Property mode set to 100644
File size: 7.1 KB
RevLine 
[1b9148c]1# $Id$
2
[a5fa1a9]3#----------------------------------#
4wrt_ica_targets() { #
[bfbd927]5#----------------------------------#
6 local ICA_rebuild=$1
7 wrt_ica_rebuild "$ICA_rebuild"
8 wrt_iterations "$ICA_rebuild"
9}
10
11#----------------------------------#
12wrt_ica_rebuild() { #
[a5fa1a9]13#----------------------------------#
14 local ICA_rebuild=$1
15(
16 cat << EOF
17ICA_rebuild: $ICA_rebuild
18
19EOF
20) >> $MKFILE
21}
22
[bfbd927]23#----------------------------------#
24wrt_iterations() { #
25#----------------------------------#
26 local ICA_rebuild=$1
27
28 for ((N=1; N <= ITERATIONS ; N++)) ; do # Double parentheses,
29 # and "ITERATIONS" with no "$".
30 ITERATION=iteration-$N
31 if [ "$N" = "1" ] ; then
32(
33 cat << EOF
34$ITERATION: chapter06
35 @do_ica_prep
36 @pushd logs && \\
37 mkdir $ITERATION && \\
38 mv $ICA_rebuild $ITERATION && \\
39 popd
40 @rm -f $ICA_rebuild
41 @touch \$@
42
43EOF
44) >> $MKFILE
45 PREV=$ITERATION
46 elif [ "$N" = "$ITERATIONS" ] ; then
47(
48 cat << EOF
49iteration-last: $PREV ICA_rebuild
50 @do_ica_prep
51 @pushd logs && \\
52 mkdir iteration-last && \\
53 cp $ICA_rebuild iteration-last && \\
54 popd
55 @do_ica_work
56 @touch \$@
57
58EOF
59) >> $MKFILE
60 else
61(
62 cat << EOF
63$ITERATION: $PREV ICA_rebuild
64 @do_ica_prep
65 @pushd logs && \\
66 mkdir $ITERATION && \\
67 mv $ICA_rebuild $ITERATION && \\
68 popd
69 @rm -f $ICA_rebuild
70 @touch \$@
71
72EOF
73) >> $MKFILE
74 PREV=$ITERATION
75 fi
76 done
77}
78
[1b9148c]79# Acknowledgment:
80# The following code is a modified version of an original work written by
[a5fa1a9]81# Greg Schafer for the "DIY Linux" project and is included here with his
82# permission.
[1b9148c]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#----------------------------------#
107do_ica_prep() { #
108#----------------------------------#
109: <<inline_doc
110 desc:
111
[a5fa1a9]112 usage:
113
114 input vars:
[1b9148c]115 externals: --
116 modifies: --
117 returns: --
[a5fa1a9]118 on error:
119 on success:
[1b9148c]120inline_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#----------------------------------#
213do_ica_work() { # Do the ICA grunt work.
214#----------------------------------#
215: <<inline_doc
216 desc:
[a5fa1a9]217
[1b9148c]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: --
[a5fa1a9]226 on error:
227 on success:
[1b9148c]228inline_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 TracBrowser for help on using the repository browser.