common/tools/cachefiles.pl
author Brendan Donegan brendand@symbian.org
Mon, 24 Aug 2009 11:01:37 +0100
changeset 408 0c558d696e7a
parent 227 ab5a0930b5c8
permissions -rw-r--r--
Build machine registration files removed.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
166
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
     1
#!/usr/bin/perl
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
     2
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
     3
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
     4
use strict;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
     5
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
     6
#my $cache = "d:/HG_cache/";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
     7
#my $master = "//v800008/Builds01/";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
     8
my $cache = shift @ARGV;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
     9
my $csv = shift @ARGV;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    10
my $generated = shift @ARGV;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    11
my @recover;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    12
my @nospace;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    13
my $exitcode = 0;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    14
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    15
if(defined $cache && defined $generated && defined $csv)
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    16
{ 
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    17
  print "Cache:$cache\nIn:$csv\nOut:$generated\n";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    18
  
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    19
  # Format the cache directory path
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    20
  if ( $cache !~ /(.*)[\\\/]$/ )
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    21
  {
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    22
	$cache .= "/";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    23
  }
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    24
  
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    25
  open(IN, "<$csv") or die "Couldn't open $csv for reading";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    26
  open(OUT,">$generated") or die "Couldn't open $generated for writing";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    27
  my $header = <IN>;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    28
  print OUT $header;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    29
  while( my $line = <IN>)
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    30
  {
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    31
    my @args = split(',',$line);
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    32
    my $repo = shift @args;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    33
	my $master = "";
227
ab5a0930b5c8 cachefiles.pl - stopped cache from being excessively flattened, which could cause problems.
MattD <mattd@symbian.org>
parents: 166
diff changeset
    34
	if ( $repo =~ m/^(.*\/)(.*\/(oss|rnd|sfl)\/.*\/)$/i )
166
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    35
	{
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    36
		$master = $1;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    37
		$repo = $2;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    38
	}
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    39
    if(-d $master.$repo.".hg")
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    40
    {
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    41
  #    print "Found:\t".$master.$repo.".hg\n";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    42
      my $cmd;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    43
      if(-d $cache.$repo.".hg") # update
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    44
      {
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    45
        $cmd = "hg pull -R $cache$repo $master$repo";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    46
      }
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    47
      else #clone
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    48
      {
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    49
        #taken from the normal clone script...
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    50
        my @dirs = split ('\/', $cache.$repo);
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    51
        my $destdir = pop @dirs;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    52
        my $path = "";    
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    53
        foreach my $dir (@dirs)
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    54
          {
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    55
          $path = ($path eq "") ? $dir : "$path/$dir";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    56
          if (!-d $path)
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    57
            {
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    58
            mkdir $path;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    59
            }
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    60
          }
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    61
            
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    62
        $cmd = "hg clone -U $master$repo $cache$repo";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    63
      }  
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    64
      if(cache($cmd))
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    65
        {
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    66
          print OUT $cache.$repo.",".join(',', @args);
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    67
        }
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    68
      else
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    69
        {
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    70
           print OUT $master.$repo.",".join(',', @args);
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    71
		   $exitcode = 1;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    72
        }
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    73
    }
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    74
    else
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    75
    {
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    76
      print "Error: cannot find ".$master.$repo.".hg\n";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    77
	  $exitcode = 1;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    78
    }
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    79
  }
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    80
  
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    81
  close OUT;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    82
  close IN;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    83
}
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    84
else
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    85
{
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    86
  print "Usage: <cache_path> <source_csv> <generated_csv>";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    87
  $exitcode = 1;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    88
}
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    89
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    90
foreach my $line (@recover)
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    91
{
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    92
  print "WARNING: HG Recover: $line\n";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    93
}
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    94
foreach my $line (@nospace)
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    95
{
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    96
  print "WARNING: No Space: $line\n";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    97
}
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    98
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
    99
exit $exitcode;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   100
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   101
sub cache($cmd)
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   102
{
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   103
  my $cmd = shift;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   104
  print "$cmd\n";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   105
  
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   106
  open(CMD, "$cmd 2>&1 |") or die "Couldn't execute $cmd";
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   107
  while(my $line = <CMD>)
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   108
  {
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   109
#    print $line;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   110
    # parse the output for failures. On fail return 0;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   111
    if($line =~ m/abort/i)
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   112
    {
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   113
      print $line;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   114
      if($line =~ m/hg\s+recover/i)
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   115
      {
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   116
        push(@recover, $cmd);
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   117
      }
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   118
      elsif($line =~ m/No\s+space/i)
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   119
      {
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   120
        push(@nospace, $cmd);
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   121
      }
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   122
      close CMD;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   123
      return 0;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   124
    }    
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   125
  }
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   126
  close CMD;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   127
  return 1;
32693583e769 Added Hg local cache management feature.
ThomasE
parents:
diff changeset
   128
}