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