williamr/check_sources_csv.pl
changeset 163 4a47f1403d9b
equal deleted inserted replaced
162:fb679efeb2dd 163:4a47f1403d9b
       
     1 #!/usr/bin/perl
       
     2 
       
     3 # Copyright (c) 2009 Symbian Foundation Ltd
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Symbian Foundation Ltd - initial contribution.
       
    11 # 
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 # Update sources.csv files in a subtree of interim/fbf/projects/packages,
       
    16 # based on a sources.csv file from the corresponding interim/fbf/projects/platforms 
       
    17 # definition. Will use "hg remove" to get rid of dirs for obsolete packages
       
    18 #
       
    19 # Stand in the root of the tree in packages, e.g. Symbian3, and run this script
       
    20 # supplying the single model sources.csv file as input, e.g. 
       
    21 # platforms/Symbian3/single/sources_fcl.csv
       
    22 
       
    23 use strict;
       
    24 
       
    25 my $headerline = <>;
       
    26 my $line;
       
    27 
       
    28 my %dirs;
       
    29 while ($line =<>)
       
    30 	{
       
    31 	if ($line =~ /\/(oss|sfl)\/(MCL|FCL)\/sf\/([^,]+)\/,/)
       
    32 		{
       
    33 		my $license = $1;
       
    34 		my $codeline = $2;
       
    35 		my $path = $3;
       
    36 		
       
    37 		$dirs{$path} = $line;
       
    38 		next;
       
    39 		}
       
    40 	}
       
    41 
       
    42 sub update_csv_file($)
       
    43 	{
       
    44 	my ($path) = @_;
       
    45 	open FILE, "<$path/sources.csv";
       
    46 	my @lines = <FILE>;
       
    47 	close FILE;
       
    48 	
       
    49 	# replace the existing lines with ones from the main sources.csv
       
    50 	my @newlines;
       
    51 	foreach my $line (@lines)
       
    52 		{
       
    53 		if ($line =~ /\/(oss|sfl)\/(MCL|FCL)\/sf\/([^,]+)\/,/)
       
    54 			{
       
    55 			my $license = $1;
       
    56 			my $codeline = $2;
       
    57 			my $package = $3;
       
    58 			
       
    59 			push @newlines, $dirs{$package};
       
    60 			next;
       
    61 			}
       
    62 		push @newlines, $line;
       
    63 		}
       
    64 	
       
    65 	open FILE, ">$path/sources.csv";
       
    66 	print FILE @newlines;
       
    67 	close FILE;
       
    68 	}
       
    69 
       
    70 my %found_dirs;
       
    71 my @listing = `dir /s/b sources.csv`;
       
    72 foreach $line (@listing)
       
    73 	{
       
    74 	# G:\system_model\packages\CompilerCompatibility\app\commonemail\sources.csv
       
    75 	if ($line =~ /\\([^\\]+)\\([^\\]+)\\sources.csv/)
       
    76 		{
       
    77 		my $layer = $1;
       
    78 		my $package = $2;
       
    79 		my $path = "$layer/$package";
       
    80 		
       
    81 		if (defined $dirs{$path})
       
    82 			{
       
    83 			if (!-e "$path/package_definition.xml")
       
    84 				{
       
    85 				print "$path needs a package_definition.xml file\n";
       
    86 				}
       
    87 			update_csv_file($path);
       
    88 			$found_dirs{$path} = 1;
       
    89 			next;
       
    90 			}
       
    91 		else
       
    92 			{
       
    93 			system("hg", "remove", "$layer//$package");
       
    94 			}
       
    95 		}
       
    96 	}
       
    97 
       
    98 foreach my $path (sort keys %dirs)
       
    99 	{
       
   100 	next if $found_dirs{$path};
       
   101 	
       
   102 	mkdir $path;
       
   103 	open FILE, ">$path/sources.csv";
       
   104 	print FILE $headerline, $dirs{$path};
       
   105 	close FILE;
       
   106 	system("hg", "add", "$path/sources.csv");
       
   107 	}