1#!/usr/perl5/5.8.4/bin/perl
2#
3# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
4# Use is subject to license terms.
5#
6#ident	"%Z%%M%	%I%	%E% SMI"
7#
8# This script takes a file mapping CSV file as input (see flist_s10_5-8-4.csv
9# for an example), a perl build directory and an ON workspace and outputs a ksh
10# script containing the SCCS and Teamware commands necessary to copy the
11# required files from the perl build directory into the ON workspace.  Note that
12# the 'sleep 1' commands are because Teamware can't cope with rapid check-ins of
13# large numbers of files.
14#
15
16use strict;
17use warnings;
18use POSIX qw(uname);
19
20# SCCS comment, perl versions.
21our $Comment =
22    qq('5040539 Perl 5.8.4 should be integrated into S10');
23our $Ver     = '5.8.4';
24our $PrevVer = '5.8.3';
25
26# Cache of already-created directories.
27our %DirsMade;
28
29#
30# Make a directory if it hasn't already been made.
31#
32sub make_dir
33{
34	my ($dir) = @_;
35
36	if (! exists($DirsMade{$dir})) {
37		print("mkdir -p $dir\n");
38		$DirsMade{$dir}++;
39	}
40}
41
42#
43# Main.
44#
45
46# Basic sanity checks.
47@ARGV == 3 || die("Usage is $0 <mapping file> <perl build dir> <workspace>\n");
48my ($mapfile, $bld, $ws) = @ARGV;
49die("$bld is not a perl build dir\n") if (! -f "$bld/config.sh");
50die("$ws is not a workspace\n") if (! -d "$ws/Codemgr_wsdata");
51
52# Work out directory locations.
53my $ver_dst = "$ws/usr/src/cmd/perl/$Ver";
54my $prev_ver_dst = "$ws/usr/src/cmd/perl/$PrevVer";
55my $arch = ((uname())[4] eq 'i86pc') ? 'i386' : 'sparc';
56
57# Read in the mapping file.
58my ($fh, $line, %file);
59open($fh, '<', $mapfile) || die("Can't open $mapfile: $!\n");
60while (defined($line = <$fh>) && $line !~ m{^"Path",}) {
61	;
62}
63while (defined($line = <$fh>)) {
64	chomp($line);
65	my @field;
66	push(@field, $+) while $line =~
67	    m{["']([^"'\\]*(?:\\.[^"'\\]*)*)["'],?|([^,]+),?|,}g;
68	push(@field, undef) if (substr($line, -1, 1) eq ',');
69	my $p = shift(@field);
70	my $f = shift(@field);
71	# We just want the s10 column.
72	$file{$p}{$f} = defined($field[3]) ? $field[3] : '';
73}
74close($fh);
75
76# Process the mappings.
77print("#!/bin/ksh\n\nunalias rm\ntypeset -r comment=$Comment\n",
78    "set -ex\nexport CODEMGR_WS=$ws\n\n");
79foreach my $p (sort(keys(%file))) {
80	foreach my $f (sort(keys(%{$file{$p}}))) {
81		my $d = $file{$p}{$f};
82		my $pf = ($p ne '' ? "$p/" : $p) . $f;
83		my $cpf = ($p ne '' ? "$p/" : $p) . ",$f";
84
85		# If it is to go into the distrib directory.
86		if ($d eq 'distrib') {
87			make_dir("$ver_dst/distrib/$p");
88			print("cp $bld/$pf $ver_dst/distrib/$pf\n");
89			print("( cd $ver_dst/distrib/$p && ",
90			    "sccs create $f -y\"\$comment\" )\n");
91			print("rm -f $ver_dst/distrib/$cpf\n");
92			print("sleep 1\n");
93
94		# If it is to go into the arch directory.
95		} elsif ($d eq 'arch') {
96			make_dir("$ver_dst/$arch");
97			print("cp $bld/$pf $ver_dst/$arch/$f\n");
98			print("( cd $ver_dst/$arch/$p && ",
99			    "sccs create $f -y\"\$comment\" )\n");
100			print("rm -f $ver_dst/$arch/$cpf\n");
101			print("sleep 1\n");
102
103		# If it is to be copied forwards from the last version.
104		} elsif ($d eq 'fwd') {
105			make_dir("$ver_dst/distrib/$p");
106			print("( cd $prev_ver_dst/distrib/$p && ",
107			    "sccs edit $f && cp $f $ver_dst/distrib/$pf && ",
108			    "sccs unedit $f )\n");
109			print("( cd $ver_dst/distrib/$p && ",
110			    "sccs create $f -y\"\$comment\" )\n");
111			print("rm -f $ver_dst/distrib/$cpf\n");
112			print("sleep 1\n");
113		}
114	}
115}
116
117# Write a fake MANIFEST file, for 'make test'.
118print("cat > $ver_dst/distrib/MANIFEST <<EOF\n");
119foreach my $p (sort(keys(%file))) {
120	foreach my $f (sort(keys(%{$file{$p}}))) {
121		print(($p ne '' ? "$p/" : $p) . $f . "\n")
122		    if ($file{$p}{$f} eq 'distrib');
123	}
124}
125print("EOF\n");
126print("( cd $ver_dst/distrib && sccs create MANIFEST -y\"\$comment\" )\n");
127print("rm -f $ver_dst/distrib/,MANIFEST\n");
128
129print("echo SUCCESS\n");
130