imgtools/imaker/buildrom_plugins/obyparse.pm
changeset 1 be27ed110b50
child 584 56dd7656a965
equal deleted inserted replaced
0:044383f39525 1:be27ed110b50
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Symbian Foundation License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description:
       
    15 # Split core image components to ROM/ROFS1.
       
    16 # Make UREL <-> UDEB conversions.
       
    17 #
       
    18 
       
    19 
       
    20 
       
    21 package obyparse;
       
    22 
       
    23 use strict;
       
    24 use warnings;
       
    25 use plugincommon;
       
    26 
       
    27 BEGIN
       
    28 {
       
    29     use Exporter();
       
    30     our($VERSION, @ISA, @EXPORT);
       
    31     $VERSION = 1.00;
       
    32     @ISA     = qw(Exporter);
       
    33     @EXPORT  = qw(&obyparse_info &obyparse_init &obyparse_process);
       
    34 }
       
    35 
       
    36 my $conf = "";
       
    37 
       
    38 sub obyparse_info()
       
    39 {
       
    40     return({
       
    41         name       => "obyparse",
       
    42         invocation => "InvocationPoint2",
       
    43         initialize => "obyparse::obyparse_init",
       
    44         single     => "obyparse::obyparse_process"});
       
    45 }
       
    46 
       
    47 sub obyparse_init($)
       
    48 {
       
    49     plugin_init("obyparse.pm", $conf = shift());
       
    50 }
       
    51 
       
    52 sub obyparse_readconffile($$$$$);
       
    53 
       
    54 
       
    55 sub obyparse_process($)
       
    56 {
       
    57     plugin_start("obyparse.pm", $conf);
       
    58 
       
    59     my $obydata = shift();
       
    60     my %targets = ();
       
    61     my %patchdata = ();
       
    62     my ($romfiles, $rofs1files, $udebfiles, $urelfiles) = (undef, undef, "", "");
       
    63     my $fname = "";
       
    64 
       
    65     foreach (@$obydata)
       
    66     {
       
    67         next if (my $parse = parse_obyline($_)) < 0;
       
    68 
       
    69         if (($parse == 1) && ($gKeyword =~ FILEBITMAPSPECKEYWORD)) {
       
    70             ($fname = lc($gTarget)) =~ /^(?:.*\\)?(.+?)$/;
       
    71             my $tname = $1;
       
    72             $targets{$fname} = $targets{$tname} = [$gLnum - 1, !$gRomid && ($gKeyword =~ ROFSBITMAPFILESPECKEYWORD)];
       
    73             next;
       
    74         }
       
    75 
       
    76         next if !/^\s*OBYPARSE_(ROM|ROFS1|UDEB|UREL)\s+(.+?)\s*$/i;
       
    77 
       
    78         (my $rule, $fname) = (uc($1), $2);
       
    79         my $files = ($rule eq "ROM" ? \$romfiles : ($rule eq "ROFS1" ? \$rofs1files :
       
    80             ($rule eq "UDEB" ? \$udebfiles : \$urelfiles)));
       
    81         $$files = "" if !defined($$files);
       
    82         dprint(2, "#$gLnum: `$gLine'");
       
    83 
       
    84         if ($fname ne "*") {
       
    85             my $basedir = "";
       
    86             ($basedir, $fname) = ($1, $2) if $fname =~ /^(.*[\/\\])(.+?)$/;
       
    87             dprint(3, "Found " . obyparse_readconffile($basedir, $fname, $rule, $files, 0) . " entries");
       
    88         }
       
    89         else {
       
    90             $$files = ".*";
       
    91             dprint(3, "Move/change all possible components to $rule");
       
    92         }
       
    93         $_ = "$gHandlestr $_";
       
    94     }
       
    95 
       
    96     $romfiles   = qr/^($romfiles)$/i   if defined($romfiles);
       
    97     $rofs1files = qr/^($rofs1files)$/i if defined($rofs1files);
       
    98     ($udebfiles, $urelfiles) = (qr/^($udebfiles)$/i, qr/^($urelfiles)$/i);
       
    99 
       
   100     ($gLnum, $gRomid) = (0, 0);
       
   101     my ($rofs1cnt, $udebcnt, $urelcnt, $offset, @torofs1) = (0, 0, 0, 0, ());
       
   102 
       
   103     foreach (@$obydata)
       
   104     {
       
   105         my $parse = parse_obyline($_);
       
   106         $offset++ if $gRomid < 2;
       
   107         next if $parse != 1;
       
   108 
       
   109         if ($gKeyword =~ /^patchdata$/i) {
       
   110             $gSource =~ /^(.+?)(?:@.+)?$/;
       
   111             $fname = lc($1);
       
   112             $patchdata{$fname} = $targets{$fname}[0] if !exists($patchdata{$fname});
       
   113         }
       
   114         else {
       
   115             $gTarget =~ /^(?:.*\\)?(.+?)$/;
       
   116             $fname = $1;
       
   117             if ($fname =~ $urelfiles && s/(?<=[\/\\])udeb(?=[\/\\])/urel/i) {
       
   118                 $urelcnt++;
       
   119                 dprint(2, "Changed to UREL: `$_'");
       
   120             }
       
   121             elsif ($fname =~ $udebfiles && s/(?<=[\/\\])urel(?=[\/\\])/udeb/i) {
       
   122                 $udebcnt++;
       
   123                 dprint(2, "Changed to UDEB: `$_'");
       
   124             }
       
   125         }
       
   126 
       
   127         next if $gRomid || !defined($romfiles) && !defined($rofs1files);
       
   128 
       
   129         if (($gKeyword =~ ROFSBITMAPFILESPECKEYWORD) ||
       
   130             ($gKeyword =~ /^patchdata$/i) && exists($targets{$fname}) && $targets{$fname}[1]) {
       
   131         }
       
   132         elsif ($gKeyword =~ /^(?:alias|rename)/i && exists($targets{lc($gSource)}) && $targets{lc($gSource)}[1]) {
       
   133             $gSource =~ /^(?:.*\\)?(.+?)$/;
       
   134             $fname = $1;
       
   135         }
       
   136         else {
       
   137             next;
       
   138         }
       
   139         if (defined($rofs1files) && ($fname =~ $rofs1files) || defined($romfiles) && ($fname !~ $romfiles)) {
       
   140             $rofs1cnt++;
       
   141             push(@torofs1, $_);
       
   142             $_ = "$gHandlestr =>ROFS1 $_";
       
   143         }
       
   144     }
       
   145 
       
   146     dprint(3, "Moved $rofs1cnt entries to ROFS1")    if $rofs1cnt;
       
   147     dprint(3, "Changed $udebcnt components to UDEB") if $udebcnt;
       
   148     dprint(3, "Changed $urelcnt components to UREL") if $urelcnt;
       
   149 
       
   150     dprint(2, "Found " . keys(%patchdata) . " ROM-patched components:") if %patchdata;
       
   151     foreach (sort({$a <=> $b} values(%patchdata))) {
       
   152         ${$obydata}[$_] =~ /^(?:$gHandlestr =>ROFS1 )?(.+)$/;
       
   153         parse_keyline($1);
       
   154         dprint(2, "`$gSource'");
       
   155     }
       
   156 
       
   157     splice(@$obydata, $offset, 0, @torofs1) if @torofs1;
       
   158 
       
   159     plugin_end();
       
   160 }
       
   161 
       
   162 
       
   163 sub obyparse_readconffile($$$$$)
       
   164 {
       
   165     my ($basedir, $file, $type, $files, $indent) = @_;
       
   166     $file = $basedir . $file;
       
   167     my $filecnt = 0;
       
   168 
       
   169     dprint(3, "Reading $type files") if $type;
       
   170     dprint(3, ("." x $indent) . "`$file'");
       
   171 
       
   172     open(FILE, $file) or die("ERROR: Can't open `$file'\n");
       
   173 
       
   174     foreach my $line (<FILE>) {
       
   175         if ($line =~ /^\s*#include\s+(.+?)\s*$/i) {
       
   176             $filecnt += obyparse_readconffile($basedir, $1, "", $files, $indent + 2);
       
   177             next;
       
   178         }
       
   179         next if ($line =~ /^\s*$/) || ($line =~ /^\s*(?:#|\/\/|REM\s)/i);
       
   180         $filecnt++;
       
   181         (my $fname = $line) =~ s/^\s+|\s+$//g;
       
   182         $fname =~ s/(.)/{'*' => '.*', '?' => '.', '[' => '[', ']' => ']'}->{$1} || "\Q$1\E"/ge;
       
   183         $$files .= ($$files eq "" ? "" : "|") . $fname;
       
   184     }
       
   185     close(FILE);
       
   186     return($filecnt);
       
   187 }
       
   188 
       
   189 1;
       
   190 
       
   191 __END__ # OF OBYPARSE.PM