1N/A#!/usr/perl5/5.8.4/bin/perl
1N/A#
1N/A# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
1N/A# Use is subject to license terms.
1N/A#
1N/A#ident "%Z%%M% %I% %E% SMI"
1N/A#
1N/A# This script takes a file mapping CSV file as input (see flist_5.8.4_on10.csv
1N/A# for an example), a perl build directory and a ON workspace and reports files
1N/A# that are different in the build and ON directories. This show up any manual
1N/A# edits that have been made during the integration process, useful for
1N/A# identifying files that need to be preserved during future reintegrations.
1N/A# Run with the '-d' option to produce a diff file suitable for applying with
1N/A# gpatch.
1N/A
1N/Ause strict;
1N/Ause warnings;
1N/Ause POSIX qw(uname);
1N/Ause Getopt::Std;
1N/A
1N/A#
1N/A# Compare two files, return 0 for different, 1 for the same.
1N/A#
1N/Asub file_cmp
1N/A{
1N/A my ($f1, $f2) = @_;
1N/A
1N/A # Quick check - they must exist and be the same size.
1N/A return (0) unless (-e $f1 && -e $f2 && -s $f1 == -s $f2);
1N/A
1N/A # Open the files.
1N/A my ($fh1, $fh2);
1N/A open($fh1, '<', $f1) || return (0);
1N/A open($fh2, '<', $f2) || return (0);
1N/A
1N/A # Compare.
1N/A my ($len1, $len2);
1N/A while (1) {
1N/A my ($buf1, $buf2);
1N/A $len1 = sysread($fh1, $buf1, 4096);
1N/A $len2 = sysread($fh2, $buf2, 4096);
1N/A last if ($len1 == 0 && $len2 == 0);
1N/A if ($len1 != $len2 || $buf1 ne $buf2) {
1N/A $len1 = -1;
1N/A $len2 = -2;
1N/A last;
1N/A }
1N/A }
1N/A close($fh1) || return (0);
1N/A close($fh2) || return (0);
1N/A return ($len1 == $len2 ? 1 : 0);
1N/A}
1N/A
1N/A#
1N/A# Main.
1N/A#
1N/A
1N/A# Basic sanity checks.
1N/Aour $opt_d;
1N/Agetopts('d') && @ARGV == 3 ||
1N/A die("Usage is $0 [ -d ] <mapping file> <perl build dir> <workspace>\n");
1N/Amy ($mapfile, $bld, $ws) = @ARGV;
1N/Adie("$bld is not a perl build dir\n") if (! -f "$bld/config.sh");
1N/Adie("$ws is not a workspace\n") if (! -d "$ws/Codemgr_wsdata");
1N/Amy ($fh, $line);
1N/A
1N/A# Work out perl version.
1N/Aopen($fh, '<', "$bld/patchlevel.h") || die("$bld is not a perl build dir\n");
1N/Amy ($r, $v, $s);
1N/Awhile (defined($line = <$fh>)) {
1N/A ($line =~ /#define\s+PERL_REVISION\s+(\S+)/) && ($r = $1);
1N/A ($line =~ /#define\s+PERL_VERSION\s+(\S+)/) && ($v = $1);
1N/A ($line =~ /#define\s+PERL_SUBVERSION\s+(\S+)/) && ($s = $1);
1N/A last if (defined($r) && defined($v) && defined ($s));
1N/A}
1N/Aclose($fh);
1N/Adie("Can't find perl version\n")
1N/A unless (defined($r) && defined($v) && defined($s));
1N/Amy $ver = "$r.$v.$s";
1N/Aundef($r);
1N/Aundef($v);
1N/Aundef($s);
1N/A
1N/A# Work out directory locations.
1N/Aour $ver_dst = "$ws/usr/src/cmd/perl/$ver";
1N/Amy $arch = ((uname())[4] eq 'i86pc') ? 'i386' : 'sparc';
1N/A
1N/A# Read in the mapping file.
1N/Amy %file;
1N/Aopen($fh, '<', $mapfile) || die("Can't open $mapfile: $!\n");
1N/Awhile (defined($line = <$fh>) && $line !~ m{^"Path",}) {
1N/A ;
1N/A}
1N/Awhile (defined($line = <$fh>)) {
1N/A chomp($line);
1N/A my @field;
1N/A push(@field, $+) while $line =~
1N/A m{["']([^"'\\]*(?:\\.[^"'\\]*)*)["'],?|([^,]+),?|,}g;
1N/A push(@field, undef) if (substr($line, -1, 1) eq ',');
1N/A my $p = shift(@field);
1N/A my $f = shift(@field);
1N/A # We just want the s10 column.
1N/A $file{$p}{$f} = defined($field[3]) ? $field[3] : '';
1N/A}
1N/Aclose($fh);
1N/A
1N/A# Process the mappings.
1N/Aforeach my $p (sort(keys(%file))) {
1N/A foreach my $f (sort(keys(%{$file{$p}}))) {
1N/A my $d = $file{$p}{$f};
1N/A my $pf = ($p ne '' ? "$p/" : $p) . $f;
1N/A my $cpf = ($p ne '' ? "$p/" : $p) . ",$f";
1N/A my ($src, $dst);
1N/A
1N/A # If it has gone into the distrib directory.
1N/A if ($d eq 'distrib') {
1N/A $src = "$bld/$pf";
1N/A $dst = "$ver_dst/distrib/$pf";
1N/A
1N/A # If it has gone into the arch directory.
1N/A } elsif ($d eq 'arch') {
1N/A $src = "$bld/$pf";
1N/A $dst = "$ver_dst/$arch/$f";
1N/A
1N/A # If it is to be copied forwards from the last version.
1N/A } elsif ($d eq 'fwd') {
1N/A $dst = "$ver_dst/distrib/$pf";
1N/A }
1N/A
1N/A
1N/A # Short forms of the filenames.
1N/A my ($ssrc, $sdst);
1N/A if ($src) {
1N/A $ssrc = $src;
1N/A $ssrc =~ s{^$bld/}{}o;
1N/A $ssrc =~ s{[^/]+/\.\./}{}g;
1N/A }
1N/A if ($dst) {
1N/A $sdst = $dst;
1N/A $sdst =~ s{^$ver_dst/}{}o;
1N/A $sdst =~ s{[^/]+/\.\./}{}g;
1N/A }
1N/A
1N/A # New files.
1N/A if (! $src && $dst) {
1N/A if (! $opt_d) {
1N/A print("New: $sdst\n");
1N/A }
1N/A
1N/A # Modified files.
1N/A } elsif ($src && $dst && ! file_cmp($src, $dst)) {
1N/A if ($opt_d) {
1N/A system("diff -u $src $dst | " .
1N/A "sed -e 's!$src!$ssrc!g' " .
1N/A "-e 's!$dst!$sdst!g'");
1N/A } else {
1N/A print("Edited: $sdst\n");
1N/A }
1N/A }
1N/A }
1N/A}