source: extras/farce@ 89a2b70

experimental
Last change on this file since 89a2b70 was 89a2b70, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Added inline_doc fragment and trailing space clean-up.

  • Property mode set to 100755
File size: 24.6 KB
Line 
1#!/bin/bash
2
3# Acknowledgment:
4# The following code is a no-modified version (except for this comment
5# and the inline_doc fragment) of an original work written by
6# Ken Moffat and is included here with his permission.
7#
8
9# FARCE: Farce Assists Rebuild Comparison Evaluation ;)
10#
11# to answer the question "can it rebuild itself?"
12#
13# We expect four arguments - first directory path, filelist
14# containing the files in this directory which we wish to compare,
15# second directory path, filelist for second directory.
16#
17# Yes, we could just compare everything in each tree, but the
18# filelist script knows about files it can reasonably ignore,
19# and this also allows us to build a sytem, boot it and get a
20# list of files, build a full desktop environment, and only then
21# build and boot the "can it build itself" test system and get
22# _its_ filelist.
23#
24# What this script aims to do:
25# ____________________________
26#
27# First, report files not in both builds.
28#
29# Then, confirm symlinks point to same targets.
30#
31# After that, compare individual files -
32# if different, run the file name through 'expected'
33# to pick out files that are unlikely to match (logs,
34# pids, fstab [assumes '/' is a different device each time],
35# count these as 'expected'.
36#
37# For whatever is left, check the file type - ar archives
38# have their members extraced and compared (every member has
39# a timestamp), gzipped files are compared beyond their
40# timestamp, binaries, at least those using shared libs or
41# which are shared objects, are copied and subjected to
42# --strip-debug. If files match at this stage, count them as
43# 'accepted'.
44#
45# As a last step for any file that doesn't match, copy it
46# through some perl regexps to "process" it (convert any
47# date, time, kernel-version information from standard formats
48# into tokens, then see if the tokensi match.
49#
50# For details of the regexps, see the tokenize function.
51# Those files that match after this are also counted as
52# 'accepted'. Note that I don't always start from the kernel
53# version that I'm going to build, so this copes with e.g. perl
54# files that hardcode the kernel version.
55#
56# We now have files that don't match. A few of these seem to be
57# common to all builds - some (members of) c++ libraries or ar
58# archives, a few programs which perhaps use some sort of c++ code).
59# The file name # is passed to the 'failure' function - these
60# recognized filenames are labelled as 'predictable FAIL:',
61# anything else is labelled as 'unexpected FAIL:'.
62#
63# output:
64# stderr - files only in one of the builds, failure messages,
65# and totals.
66#
67# farce-results - more details, including which files were treated
68# as expected differences, files where neither copy could be read,
69# files treated as accepted, with the reason (and member for ar
70# archives). This data is typically up to 100 characters wide -
71# sometimes it's a bit more, but it doesn't wrap too badly in a
72# 100 character xterm.
73#
74# farce-extras - diffs for the files, or members, that didn't
75# match. This file is to establish new regexps for picking up
76# date/time/kernel-version formats.
77#
78# farce-identical - the names of the files which are identical
79#
80# farce-substitutions - whenever using tokenizeanddiff results in a
81# difference being accepted, for both versions diff the before and
82# after versions to show what got changed. If the file is a binary,
83# the output may still be hard to read. Note that I _know_ glibc
84# version strings pass one of the regexps looking for a kernel version
85# - since I expect you to use the same version of glibc for each
86# build, this is not a problem.
87#
88# farce-differ - the names of the files which could not be treated
89# as matching (whether or not I regard the failure as predictable)
90# for possible input to ICA processing.
91#
92# Copyright (C) 2005, 2006 Ken Moffat <ken@linuxfromscratch.org>
93#
94# All rights reserved.
95#
96# This program is free software; you can redistribute it and/or modify
97# it under the terms of the GNU General Public License as published by
98# the Free Software Foundation; either version 2 of the License, or (at
99# your option) any later version.
100#
101# This program is distributed in the hope that it will be useful, but
102# WITHOUT ANY WARRANTY; without even the implied warranty of
103# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
104# NON INFRINGEMENT. See the GNU General Public License for more
105# details.
106#
107# You should have received a copy of the GNU General Public License
108# along with this program; if not, write to the Free Software
109# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
110#
111
112set -e
113
114: <<inline_doc
115 desc: do farce analisys and report
116 usage: farce -directory $FARCELOGDIR/dir path1 list1 path2 list2
117 input vars: $1 farce log dir for this comparation
118 $2 full path to previous iteration
119 $2 full path to filelist for previos iteration
120 $3 full path to current iteration
121 $4 full path to filelist for current iteration
122 externals: --
123 modifies: --
124 returns: --
125 on error:
126 on success:
127inline_doc
128
129
130VERSION="002"
131
132# variables for output files
133RESULT=farce-results
134EXTRAS=farce-extras
135IDENTICAL=farce-identical
136SUBS=farce-substitutions
137DIFFER=farce-differ
138
139# documenting the variables
140# C1, C2 temp files to hold disassembled code
141# D1, D2 temp directories for extracting member of ar archive
142# DIFF temp file for diffing the filelists
143# F1, F2 temp files for tokenizeanddiff
144# FTYPE obsolete, commented out
145# M1, M2 temp files to hold members of an ar archive
146# MEMBERS temp file to list members of ar archive
147# OP1, OP2 the original $PWD, needed when extracting members of ar
148# archives
149# P1, P2 paths to first and second build
150# S1, S2 temp files for shared objects
151
152# functions
153function dohelp() {
154 echo "`basename $0`: compare trees of files from a build"
155 echo "and lists of the files they contained"
156 echo ""
157 echo "`basename $0` [ -help | -version ] || path1 list1 path2 list2"
158}
159
160function emessage() {
161 # write a string to both stderr and $RESULT
162 echo "$@" >&2
163 echo "$@" >&5
164}
165
166function expected() {
167 # if we expect it to differ because of its name,
168 # allow it and report, return true ; else return false
169 case $1 in
170 /boot/grub/menu.lst)
171 # just in case somebody puts this into the main filesystem
172 true;;
173 /etc/aliases.db)
174 # some sort of database for postfix, not parsable
175 true;;
176 /etc/blkid.tab)
177 # includes dev name for rootfs
178 true;;
179 /etc/fstab)
180 # fstab, e.g. ' / ' will differ
181 true;;
182 /etc/group*)
183 true;;
184 /etc/hosts)
185 # with dhcp client, I add current ip address to this in a hook
186 true;;
187 /etc/ld.so.*)
188 # .conf and .cache can vary,
189 # particularly if one system has a full build when I run this
190 true;;
191 /etc/lilo.conf|/etc/yaboot.conf)
192 # bootloader control, I assume grub will all be on a separate
193 true;;
194 /etc/mtab)
195 # at a minimum, different '/'
196 true;;
197 /etc/ntp.drift)
198 true;;
199 /etc/passwd*)
200 true;;
201 /etc/shadow*)
202 true;;
203 /etc/ssh/*key|/etc/ssh/*pub)
204 # openssh keys
205 true;;
206 /misc/*)
207 # where I put buildscripts (which mostly won't change)
208 # and stamps containing name/time/space which will differ in the times
209 true;;
210 /root/*)
211 # expect .bash_history etc to differ - if we can read them
212 true;;
213 /usr/bin/lynx)
214 # part of my inital builds, I guess this uses anonymous namespaces
215 true;;
216 /usr/include/c++/*/*/bits/stdc++.h.gch/*)
217 # precompiled headers
218 true;;
219 /usr/lib*/libstdc++.a|/usr/lib*/libstdc++.so*|/usr/lib*/libsupc++.a)
220 # probably, anonymous namespaces
221 # libstdc++.a, libstdc++.so.n.n.n, libsupc++.a
222 true;;
223 /usr/share/info/dir)
224 # if one system has had extra stuff built, this will likely be bigger
225 true;;
226 /usr/share/man/whatis)
227 # if one system has had extra stuff built, this will likely be bigger
228 true;;
229 /var/lib/locate/locatedb)
230 # if one system has had extra stuff built, this will likely be bigger
231 true;;
232 /var/lib/nfs/*)
233 # allow nfs bookkeeping
234 true;;
235 /var/log/*)
236 true;;
237 /var/run/utmp)
238 true;;
239 /var/spool/fcron*)
240 true;;
241 /var/state/*)
242 # allow dhcp leases
243 true;;
244 /var/tmp/random-seed)
245 true;;
246 # following start with wildcards
247 *Image*|*.PPCBoot*|*vmlinuz*|*lfskernel*)
248 # compressed kernels, sometimes just building at a different
249 # date/time is enough to change the length of them, because the
250 # long format date and time is part of the compressed data
251 true;;
252 *pid*)
253 # pids, including e.g. /var/spool/postfix/pid/*
254 true;;
255 *)
256 # nothing else is expected to be different
257 false;;
258 esac
259 if [ $? -eq 0 ]; then
260 message "expected difference in $1"
261 let expected=$expected+1
262 case $TYPE in
263 AR)
264 let EXPAR=$EXPAR+1
265 ;;
266 ELF)
267 let EXPELF=$EXPELF+1
268 ;;
269 UNK)
270 let EXPUNK=$EXPUNK+1
271 ;;
272 # so far, no other valid types, so don't accumulate them
273 *)
274 emessage "internal error, expected difference for $1 of type $TYPE not allowed"
275 exit 2
276 ;;
277 esac
278 true
279 else
280 false
281 fi
282}
283
284function failure() {
285 # first parm is filename or token
286 # second parm is the error message
287 # update the appropriate total
288 # and write to both stderr and the results
289 # by using emessage
290
291 let different=$different+1
292 case $TYPE in
293 AR)
294 let DIFAR=$DIFAR+1
295 ;;
296 ELF)
297 let DIFELF=$DIFELF+1
298 ;;
299 GZ)
300 let DIFGZ=$DIFGZ+1
301 ;;
302 SYM)
303 let DIFSYM=$DIFSYM+1
304 ;;
305 UNK)
306 let DIFUNK=$DIFUNK+1
307 ;;
308 *)
309 emessage "internal error in failure() for TYPE $TYPE"
310 exit 2
311 ;;
312 esac
313 test -f ${P1}$1 && echo $1 >&9
314 emessage "FAIL: $2"
315}
316
317function fatal() {
318 # unrecoverable error
319 echo $*
320 exit 1
321}
322
323function filetype() {
324 TYPE=`file ${P1}${FILE}`
325 case $TYPE in
326 *'current ar archive'*)
327 let TOTAR=$TOTAR+1
328 TYPE=AR
329 ;;
330 *' ELF '*)
331 let TOTELF=$TOTELF+1
332 TYPE=ELF
333 ;;
334 *'gzip compressed data'*)
335 let TOTGZ=$TOTGZ+1
336 TYPE=GZ
337 ;;
338 *)
339 let TOTUNK=$TOTUNK+1
340 TYPE=UNK
341 ;;
342 esac
343}
344
345function message() {
346 # write a string to $RESULT
347 echo $* >&5
348}
349
350function onlyone() {
351 #report files only in one build
352 # text should go to both stderr and the results,
353 # but blank lines only go to the results
354 if [ $1 == '<' ]; then
355 emessage "File(s) only in the first build"
356 else
357 emessage "File(s) only in the second build"
358 fi
359 message ""
360 FILES=`cat $DIFF | grep "^$1" | cut -d ' ' -f 2`
361 for F in $FILES; do
362 emessage $F
363 let only=$only+1
364 done
365 message ""
366}
367
368# 'test' functions are called with three arguments:
369# the two pathes and the filename
370# - we know the file is of this type, so see if we
371# can get it to match by reasonalbe means.
372# if not, treat it as different.
373#
374# NB if pathes are absolute, we need to prefix them
375# with the original $PWD to access the .a files
376#
377function testar() {
378 # ar archives include timestamps for the members,
379 # but diff doesn't show file timestamps unless the data differs
380 # put out a message to help locate which archive any messages
381 # about the members refer to.
382
383 # try just stripping them U1,2 undebuggable
384 U1=`mktemp` || fatal "cannot create a temporary file"
385 U2=`mktemp` || fatal "cannot create a temporary file"
386 cp ${1}${3} $U1
387 cp ${2}${3} $U2
388 strip --strip-debug $U1
389 strip --strip-debug $U2
390 cmp -s $U1 $U2
391 rm $U1 $U2
392 if [ $? -eq 0 ]; then
393 let accepted=$accepted+1
394 let ACCAR=$ACCAR+1
395 message "archive $3 matches after strip --strip-debug"
396 return
397 fi
398 # rest of this function retained primarily for pathologically bad builds
399 # put out a message in the log to help identify which archive has issues.
400 message "examining ar archive $3"
401 D1=`mktemp -d` || fatal "cannot create a temporary directory"
402 D2=`mktemp -d` || fatal "cannot create a temporary directory"
403 cd $D1
404 ar -x ${OP1}${1}${3}
405 cd $D2
406 ar -x ${OP2}${2}${3}
407 cd
408 # diff the members - true means they match
409 diff -Na $D1 $D2 >/dev/null
410 if [ $? -eq 0 ]; then
411 message "accept: $3 after diffing the members"
412 let accepted=$accepted+1
413 let ACCAR=$ACCAR+1
414 else
415 # process individual members to eliminate date/time/kernel-version
416 # first, check the members are the same
417 M1=`mktemp` || fatal "cannot create a temporary file"
418 M2=`mktemp` || fatal "cannot create a temporary file"
419 cd $D1
420 MEMBERS=
421 for F in *; do
422 MEMBERS="$MEMBERS $F"
423 done
424 cd
425 echo $MEMBERS | sort >$M1
426 cd $D2
427 MEMBERS=
428 for F in *; do
429 MEMBERS="$MEMBERS $F"
430 done
431 cd
432 echo $MEMBERS | sort >$M2
433 cmp -s $M1 $M2
434 if [ $? -ne 0 ]; then
435 # oh dear, different members
436 echo "list of members differs for archive $3" >&6
437 diff $M1 $M2 >&6
438 failure $3 "$3 list of members differs"
439 else
440 # members (names) are same,
441 # process each one
442 STATUS=0
443 for M in $MEMBERS; do
444 #avoid firing up perl on matching members
445 cmp -s $D1/$M $D2/$M
446 if [ $? -ne 0 ]; then
447 tokenizeanddiff $D1/$M $D2/$M $FILE:$M
448 if [ $? -eq 0 ]; then
449 message "member $M matches after processing"
450 else
451 message "member $M DIFFERS after processing"
452 STATUS=1
453 fi
454 fi
455 done
456 if [ $STATUS -eq 0 ]; then
457 let accepted=$accepted+1
458 let ACCAR=$ACCAR+1
459 else
460 let different=$different+1
461 let DIFAR=$DIFAR+1
462 echo $3 >&9
463 emessage "FAIL: in $3"
464 fi
465 fi
466 rm $M1 $M2
467 fi
468 rm -rf $D1 $D2
469}
470
471function testgzip() {
472 # bytes 4,5,6,7 are the timestamp, so ignore these
473 cmp -s -i 8 ${1}${3} ${2}${3}
474 if [ $? -eq 0 ]; then
475 message "accept: $3 after ignoring gzip timestamp"
476 let accepted=$accepted+1
477 let ACCGZ=$ACCGZ+1
478 else
479 failure $3 " $3 even after ignoring gzip timestamp"
480 fi
481}
482
483function testso() {
484 # shared object - first try stripping it
485 # in fact, this now handles ALL ELF files
486 S1=`mktemp` || fatal "cannot create a temporary file"
487 S2=`mktemp` || fatal "cannot create a temporary file"
488 cp ${1}${3} $S1
489 strip --strip-debug $S1
490 cp ${2}${3} $S2
491 strip --strip-debug $S2
492 cmp -s $S1 $S2
493 if [ $? -eq 0 ]; then
494 message "accept: $3 after --strip-debug"
495 let accepted=$accepted+1
496 let ACCELF=$ACCELF+1
497 else
498 tokenizeanddiff $S1 $S2 $3
499 if [ $? -ne 0 ]; then
500 failure $3 " $3 differs after stripping and processing"
501 else
502 message "accept: $3 after --strip-debug and processing"
503 let accepted=$accepted+1
504 let ACCELF=$ACCELF+1
505 fi
506 fi
507 rm $S1 $S2
508}
509
510function tokenize() {
511 # use regexes to replace date/time/kernel-version text
512 # with tokens which may allow files to match even though
513 # they have hardcoded date/time/kernel-version.
514 # arguments are file to process, and where to put it.
515 # these regexes are somewhat long, and the order they
516 # are applied in is important (to stop short ones being
517 # used when a longer version would match).
518 # KV00 linux version date (e.g. as in the kernel itself)
519 # allow 2 or 3 groups of three alphas here - optional smp, with day, mon
520 # KV01 kernel version, including possible cpu details (that is for cdda2wav)
521 # KV02 just the version, in quotes e.g. "2.6.12.6" or '2.6.13', for perl stuff
522 # except that "|' gives me grif, so try a boundary
523 # also, it might need local version on the end, I really want
524 # quote2.\d+.\d+.{0,32}quote - it is the quotes that don't work.
525 # DT00 Day Mon .d+ hh:mm:ss TZN CCYY variations include non-caps and 'mon d'
526 # DT01 Mon .d+ CCYY hh:mm:ss
527 # DT02 hh:mm:ss Mon .d CCYY
528 # DT03 Mon .d CCYY
529 # DT04 Day Mon { ,d}d hh:mm:ss CCYY - for groff example postscript files
530 # (somewhat similar to DT00, but ' d' or ' dd' for day of month and no TZN )
531 # DT05 hh:mm:ss
532 # DT06 ISO date using space as separator
533 # DT07 ISO date using dash as separator
534 # DT08 ISO date using slash as separator
535 # DT09 fullmonth (capitalised), day number, comma, 4-digit year (groff 1.18.1 ps)
536 # DT10 dd, fullmonth (capitalised), 4-digit year (groff 1.18.1 manpages)
537 # DT11 '(xample comma space digit(s) backslash ) in groff memef.ps which is
538 # quite clearly the day of the month when it was compiled, preceded by 'example'
539 # with something weird between the e and the x.
540
541 if [ $# -ne 2 ]; then
542 fatal "tokenizing called with $# arguments : $*"
543 fi
544
545 cat $1 | perl -p \
546 -e 's/(L|l)inux.*\d\.\d\.\d+.* \#\d+( [A-Za-z][a-z]{2}){2,3} \d+ \d\d:\d\d:\d\d [A-Za-z]{3} \d{4}\b/%KV00%/g;' \
547 -e 's/(L|l)inux( (\w|_)+)?(-| |_)\d\.\d(\.\d+){1,2}((-|_)?(\w|_)+)?( |\000)*/%KV01%/g;' \
548 -e 's/\W2(\.\d+){2,3}(-|_)?((\w|_)+)?\s*\W/%KV02%/g;' \
549 -e 's/\b([A-Za-z][a-z]{2} ){2}( |\d)?\d \d\d:\d\d:\d\d [A-Za-z]{3} \d{4}\b/%DT00%/g;' \
550 -e 's/\b[A-Z][a-z]{2} ( |\d)\d \d{4} \d\d:\d\d:\d\d\b/%DT01%/g;' \
551 -e 's/\b\d\d:\d\d:\d\d [A-Z][a-z]{2} ( |\d)\d \d{4}\b/%DT02%/g;' \
552 -e 's/\b[A-Z][a-z]{2} ( |\d)\d \d{4}\b/%DT03%/g;' \
553 -e 's/\b([A-Z][a-z]{2} ){2}( |\d)\d \d\d:\d\d:\d\d \d{4}/%DT04%/g;' \
554 -e 's/\b\d\d:\d\d:\d\d\b/%DT05%/g;' \
555 -e 's/\b\d{4} \d\d \d\d\b/%DT06%/g;' \
556 -e 's/\b\d{4}-\d\d-\d\d\b/%DT07%/g;' \
557 -e 's/\b\d{4}\/\d\d\/\d\d\b/%DT08%/g;' \
558 -e 's/\b[A-Z][a-z]{2,} \d{1,2}, \d{4}/%DT09%/g;' \
559 -e 's/\b\d\d [A-Z][a-z]{2,} \d{4}/%DT10%/g;' \
560 -e 's/\(xample, \d{1,2}\\\)/%DT11%/g;' \
561 >$2
562}
563
564function tokenizeanddiff() {
565 # Call tokenize for the inputs, then compare the results
566 # Input arguments are path/filename for old and new versions
567 # third parm is readable name (filename, or archivename:member)
568 # to help understand what is in the extras output.
569 # - sometimes called for files, but other times called for
570 # members of ar archives extracted into temporary directories
571 #message tokenizeanddiff called for $1 $2 $3
572 F1=`mktemp` || fatal "cannot create a temporary file"
573 F2=`mktemp` || fatal "cannot create a temporary file"
574 tokenize $1 $F1
575 tokenize $2 $F2
576
577 # actually, cmp is probably more efficient
578 # but for picking up the pieces it will be better to
579 # use diff to see what got through.
580 cmp -s $F1 $F2
581 TOKENRESULT=$?
582 if [ $TOKENRESULT -ne 0 ]; then
583 echo "failure in $3..." >&6
584 diff -a $F1 $F2 >&6
585 rm $F1 $F2
586 false
587 else
588 # show what we did
589 echo "substitutions for $3" >&8
590 echo "build one" >&8
591 diff -a $1 $F1 >&8
592 echo "build two" >&8
593 diff -a $2 $F2 >&8
594 rm $F1 $F2
595 true
596 fi
597}
598
599function validateargs() {
600# validate the arguments
601BAD=0
602if ! [ -d $1 ]; then
603 echo "Error: first argument is not a directory" >&2
604 let BAD=$BAD+1
605fi
606NAME=`basename ${2%%-*}`
607if [ $NAME != filelist ]; then
608 echo "Error: second argument is not a recognized filelist" >&2
609 let BAD=$BAD+1
610fi
611if ! [ -d $3 ]; then
612 echo "Error: third argument is not a directory" >&2
613 let BAD=$BAD+1
614fi
615NAME=`basename ${4%%-*}`
616if [ $NAME != filelist ]; then
617 echo "Error: fourth argument is not a recognized filelist" >&2
618 let BAD=$BAD+1
619fi
620for I in $1 $2 $3 $4; do
621 if ! [ -r $I ]; then
622 echo "Error: cannot read $I" >&2
623 let BAD=$BAD+1
624 fi
625done
626if [ $1 == $3 ]; then
627 echo "Error: directory pathes are identical" >&2
628 let BAD=$BAD+1
629fi
630if [ $2 == $4 ]; then
631 echo "Error: filelist names are identical" >&2
632 let BAD=$BAD+1
633fi
634if [ $BAD -eq 0 ]; then
635 ARGS=valid
636fi
637}
638
639# Mainline
640ARGS=unproven
641OUTDIR=
642if [ $# -eq 1 ]; then
643 case $1 in
644 -version|--version)
645 echo "`basename $0` version $VERSION"
646 exit 0
647 ;;
648 -help|--help)
649 dohelp
650 exit 0
651 ;;
652 esac
653fi
654if [ $1 = "--directory" ]; then
655 OUTDIR=$2
656 shift 2
657 grep '/$' $OUTDIR >/dev/null 2>&1 || OUTDIR=`echo $OUTDIR | sed 's%$%/%'`
658 echo "creating directory $OUTDIR"
659 mkdir -p $OUTDIR
660 if [ $? -ne 0 ]; then
661 echo "cannot mkdir $OUTDIR"
662 exit 1
663 fi
664fi
665if [ $# -eq 4 ]; then
666 validateargs $*
667fi
668if ! [ $ARGS == valid ]; then
669 dohelp
670 fatal "`basename $0`: error in arguments"
671fi
672
673# ok, we're happy, lets hit these files
674exec 5>${OUTDIR}$RESULT
675exec 6>${OUTDIR}$EXTRAS
676exec 7>${OUTDIR}$IDENTICAL
677exec 8>${OUTDIR}$SUBS
678exec 9>${OUTDIR}$DIFFER
679
680>${OUTDIR}$RESULT
681if [ $? -ne 0 ]; then
682 fatal "cannot write to ${OUTDIR}$RESULT"
683fi
684
685emessage "will compare:"
686emessage " first build at $1 with files listed in $2"
687emessage "second build at $3 with files listed in $4"
688
689let accepted=0
690let different=0
691let expected=0
692let matched=0
693let only=0
694let predictable=0
695let unreadable=0
696let total=0
697
698# break down the accepted
699let ACCAR=0
700let ACCELF=0
701let ACCGZ=0
702let ACCUNK=0
703
704# break down definitely different
705let DIFAR=0
706let DIFELF=0
707let DIFGZ=0
708let DIFSYM=0
709let DIFUNK=0
710
711# break down the expected differences
712let EXPAR=0
713let EXPELF=0
714let EXPGZ=0
715let EXPUNK=0
716
717# break down the identical files
718let MATAR=0
719let MATELF=0
720let MATGZ=0
721let MATSYM=0
722let MATUNK=0
723
724# break down how many of each type
725let TOTAR=0
726let TOTELF=0
727let TOTGZ=0
728let TOTSYM=0
729let TOTUNK=0
730
731# now identify differences between the two trees
732DIFF=`mktemp` || fatal "cannot create a temporary file"
733diff $2 $4 >$DIFF
734
735for RUN in '<' '>' ; do
736 grep -q "$RUN" $DIFF && onlyone "$RUN"
737done
738
739rm $DIFF
740
741# and compare them
742message "Results of file comparison:"
743message ""
744
745# Strip any trailing slash from the path for tidyness,
746# because the filenames all start with a slash. Unfortunately,
747# unfortunately, '/' becomes empty, which breaks subroutines,
748# so special case it.
749# also, to process ar archives we need to extract them in temp
750# directories - that means that after cd'ing we've broken any
751# relative path, so save original pwd as necessary.
752P1=`echo $1 | sed 's%/$%%'`
753echo $1 | grep '^/' >/dev/null
754if [ $? -ne 0 ]; then
755 # relative path
756 OP1=${PWD}/
757 #echo "setting OP1 to $OP1"
758else
759 OP1=
760 #echo "$1 is an absolute path"
761fi
762test -z "$P1" && P1='/'
763P2=`echo $3 | sed 's%/$%%'`
764echo $3 | grep '^/' >/dev/null
765if [ $? -ne 0 ]; then
766 # relative path
767 OP2=${PWD}/
768 #echo "setting OP2 to $OP2"
769else
770 OP2=
771 #echo "$3 is an absolute path"
772fi
773test -z "$P2" && P2='/'
774
775echo "about to read $2"
776while read FILE ; do
777#echo "process $FILE"
778#echo "test existence of ${P2}${FILE}"
779 # confirm it exists in second build
780 # we have already reported files only in one build
781 if [ -f ${P2}"${FILE}" ]; then
782 let total=$total+1
783 # check we can read both of them
784 # or count as unreadable - I used to separate only-one-unreadable,
785 # but if you compre '/' and a _copy_ of /mnt/lfs that assumption
786 # breaks, so be less picky.
787 if ! [ -r "${P1}${FILE}" ] || ! [ -r "${P2}${FILE}" ]; then
788 message "cannot read one or both versions of $FILE"
789 let unreadable=$unreadable+1
790 continue
791 fi
792 if [ -h "${P1}${FILE}" ]; then
793 # for symlink, look at what it points to
794 # exceptionally, do not call filetype
795 TYPE=SYM
796 let TOTSYM=$TOTSYM+1
797 SL1=`ls -l "${P1}${FILE}" | awk '{ print $11 }'`
798 SL2=`ls -l "${P2}${FILE}" | awk '{ print $11 }'`
799 if [ "$SL1" = "$SL2" ]; then
800 echo "symlink $FILE matches for $SL1" >&5
801 let matched=$matched+1
802 let MATSYM=$MATSYM+1
803 else
804 failure TARGET " symlink $FILE points to $SL1 and $SL2"
805 echo $FILE >&9
806 fi
807 else
808 # regular file, start by typing it for accounting,
809 # then compare it
810 filetype ${P1}${FILE}
811 cmp -s "${P1}${FILE}" "${P2}${FILE}"
812 if [ $? -eq 0 ]; then
813 let matched=$matched+1
814 case $TYPE in
815 AR)
816 let MATAR=$MATAR+1
817 ;;
818 ELF)
819 let MATELF=$MATELF+1
820 ;;
821 GZ)
822 let MATGZ=$MATGZ+1
823 ;;
824 UNK)
825 let MATUNK=$MATUNK+1
826 ;;
827 *)
828 echo "unexpected TYPE of $TYPE for $FILE" >&2
829 exit 2
830 ;;
831 esac
832 echo ${FILE} >&7
833 else
834 # seems different, can we do better ?
835 # test if we expect it to differ
836 expected $FILE
837 if [ $? -ne 0 ]; then
838 case $TYPE in
839 GZ)
840 testgzip $P1 $P2 $FILE ;;
841 AR)
842 testar $P1 $P2 $FILE ;;
843 ELF)
844 testso $P1 $P2 $FILE ;;
845 *)
846 # long-stop - strip dates from text files
847 tokenizeanddiff "${P1}${FILE}" "${P2}${FILE}" "$FILE"
848 if [ $? -eq 0 ]; then
849 message "accepted $FILE after processing"
850 let accepted=$accepted+1
851 let ACCUNK=$ACCUNK+1
852 else
853 failure "$FILE" " $FILE is different"
854 fi
855 ;;
856 esac
857 fi
858 fi
859 fi
860 fi
861done < $2
862
863message ""
864# write totals to stderr as well as the results file
865emessage "$only files in only one of the builds"
866emessage "$total files compared, of which"
867emessage "$unreadable files could not be read, skipped"
868emessage "$matched files are identical"
869emessage "$expected files differed as expected"
870emessage "$accepted files had allowable differences"
871#emessage "$predictable files differed as they normally do"
872emessage "$different files differed"
873
874# totals of different file types
875emessage ""
876emessage "$TOTAR ar archives"
877emessage " of which $MATAR are identical"
878emessage " of which $ACCAR are accepted after strip-debug or extracting, diffing, tokenizing"
879emessage " of which $EXPAR differed as expected"
880emessage " of which $DIFAR differed"
881emessage "$TOTELF ELF executables or shared libraries"
882emessage " of which $MATELF are identical"
883emessage " of which $ACCELF are accepted after stripping and tokenizing"
884emessage " of which $EXPELF differed as expected"
885emessage " of which $DIFELF differed"
886emessage "$TOTGZ gzipped files"
887emessage " of which $MATGZ are identical"
888emessage " of which $ACCGZ are accepted after comparing beyond timestamp"
889emessage " of which $DIFGZ are different"
890emessage "$TOTSYM symbolic links"
891emessage " of which $MATSYM are identical"
892emessage " of which $DIFSYM have different targets"
893emessage "$TOTUNK other files"
894emessage " of which $MATUNK are identical"
895emessage " of which $ACCUNK are accepted after tokenizing"
896emessage " of which $EXPUNK differed as expected"
897emessage " of which $DIFUNK differed"
898
Note: See TracBrowser for help on using the repository browser.