tools/filter_obyfile.pl
changeset 14 4331846fc8cb
child 15 330c2ceccdc6
equal deleted inserted replaced
13:4f959124999b 14:4331846fc8cb
       
     1 # Copyright (c) 2010 Symbian Foundation Ltd.
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of the License "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Symbian Foundation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description: 
       
    14 # This script filters an OBY file given a rom_content.csv and a static_dependencies.txt
       
    15 
       
    16 use strict;
       
    17 
       
    18 if (scalar @ARGV < 2)
       
    19 	{
       
    20 	die ("Must specify at least two arguments: rom_content.csv and static_dependencies.txt");
       
    21 	}
       
    22 
       
    23 my $rom_content_csv = shift @ARGV;
       
    24 my $static_dependencies_txt = shift @ARGV;
       
    25 
       
    26 open ROM_CONTENT, "<$rom_content_csv" or die("Cannot read $rom_content_csv: $!\n");
       
    27 my @rom_content = <ROM_CONTENT>;
       
    28 close ROM_CONTENT;
       
    29 
       
    30 my $rom_content_header = shift @rom_content;
       
    31 die("Not a valid rom_content.csv file") if ($rom_content_header !~ /^ROM file,/);
       
    32 
       
    33 # read through the rom_content_csv looking for direct instructions
       
    34 my %stem_substitutions;
       
    35 my %deletions;
       
    36 my %must_have;
       
    37 foreach my $line (@rom_content)
       
    38 	{
       
    39 	my ($romfile,$hostfile,$ibyfile,$package,$cmd,@rest) = split /,/, $line;
       
    40 	
       
    41 	next if ($cmd eq "");
       
    42 
       
    43 	$cmd = lc $cmd;
       
    44 	if ($cmd eq "stem")
       
    45 		{
       
    46 		$stem_substitutions{$romfile} = $hostfile;
       
    47 		next;
       
    48 		}
       
    49 	
       
    50 	if ($cmd eq "out")
       
    51 		{
       
    52 		$deletions{$romfile} = "";
       
    53 		next;
       
    54 		}
       
    55 	
       
    56 	if ($cmd eq "in")
       
    57 		{
       
    58 		$must_have{$romfile} = 1;
       
    59 		next;
       
    60 		}
       
    61 	}
       
    62 
       
    63 printf STDERR "%d stem, %d out, %d in\n", 
       
    64 	scalar keys %stem_substitutions, 
       
    65 	scalar keys %deletions, 
       
    66 	scalar keys %must_have;
       
    67 
       
    68 # read static dependencies file
       
    69 # process the "out" commands to recursively expand the deletions
       
    70 
       
    71 # read the oby file and apply the commands
       
    72 
       
    73 my $line;
       
    74 while ($line = <>)
       
    75 	{
       
    76 	chomp $line;
       
    77 	if ($line =~ /^(.*=)(\S+\s+)(\S+)(\s.*)?$/)
       
    78 		{
       
    79 		my $romcmd = $1;
       
    80 		my $hostfile = $2;
       
    81 		my $romfile = $3;
       
    82 		my $rest = $4;
       
    83 		$rest = "" if (!defined $rest);
       
    84 		
       
    85 		if ($romfile =~ /^"(.*)"$/)
       
    86 			{
       
    87 			$romfile = $1;
       
    88 			$hostfile .= '"';
       
    89 			$rest = '"'. $rest;
       
    90 			}
       
    91 		
       
    92 		next if ($deletions{$romfile});
       
    93 		
       
    94 		if (defined $stem_substitutions{$romfile})
       
    95 			{
       
    96 			# print STDERR "Applying stem_ prefix to $hostfile in $line\n";
       
    97 			$hostfile =~ s/(\/|\\)([^\\\/]+)$/$1stem_$2/;
       
    98 			}
       
    99 		print $romcmd, $hostfile, $romfile, $rest, "\n";
       
   100 		next;
       
   101 		}
       
   102 	
       
   103 	print $line,"\n";
       
   104 	}