imgtools/imaker/buildrom_plugins/override.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 # Enabler for overriding file and data entries from platform iby files.
       
    16 #
       
    17 
       
    18 
       
    19 
       
    20 ##############################################################################
       
    21 #
       
    22 # Example 1: Replace an existing file with a different source files
       
    23 # This replaces the original line with the override line.
       
    24 # NOTE! One must define the ROM_IMAGE section for the overrides correctly.
       
    25 #
       
    26 # Some platform.iby
       
    27 # data=file.txt         sys\bin\file.txt // In ROM_IMAGE[3]
       
    28 #
       
    29 # product.iby
       
    30 # ROM_IMAGE[3] data-override=file_product.txt        sys\bin\file.txt
       
    31 #
       
    32 # output
       
    33 # data=file_product.txt         sys\bin\file.txt
       
    34 #
       
    35 # Example 2: Remove an existing file from a platform iby
       
    36 # This deletes the original line from the iby structure.
       
    37 #
       
    38 # Some platform.iby
       
    39 # data=file.txt         sys\bin\file.txt // In ROM_IMAGE[3]
       
    40 #
       
    41 # product.iby
       
    42 # ROM_IMAGE[3] {
       
    43 # data-override=empty   sys\bin\file.txt
       
    44 # }
       
    45 # output
       
    46 # REM OVERRIDE data=file_product.txt    sys\bin\file.txt
       
    47 #
       
    48 ##############################################################################
       
    49 
       
    50 
       
    51 
       
    52 package override;
       
    53 
       
    54 use strict;
       
    55 use warnings;
       
    56 use plugincommon;
       
    57 
       
    58                                  # OVERRIDE TARGET FOUND  OVERRIDE TARGET NOT FOUND
       
    59 use constant REPLACE_ADD  => 0;  # Replace with override  Add override
       
    60 use constant REPLACE_SKIP => 1;  # Replace with override  Do nothing
       
    61 use constant REPLACE_WARN => 2;  # Replace with override  Do nothing but warn
       
    62 use constant SKIP_ADD     => 3;  # Do nothing             Add override
       
    63 
       
    64 BEGIN
       
    65 {
       
    66     use Exporter();
       
    67     our ($VERSION, @ISA, @EXPORT);
       
    68     $VERSION = 1.00;
       
    69     @ISA     = qw(Exporter);
       
    70     @EXPORT  = qw(&override_info &override_init &override_process);
       
    71 }
       
    72 
       
    73 my $conf = "";
       
    74 
       
    75 sub override_info
       
    76 {
       
    77     return({
       
    78         name       => "override",
       
    79         invocation => "InvocationPoint2",
       
    80         initialize => "override::override_init",
       
    81         single     => "override::override_process"});
       
    82 }
       
    83 
       
    84 sub override_init
       
    85 {
       
    86     plugin_init("override.pm", $conf = shift());
       
    87 }
       
    88 
       
    89 sub override_process
       
    90 {
       
    91     plugin_start("override.pm", $conf);
       
    92 
       
    93     my $obydata    = shift();
       
    94     my %targets    = ();
       
    95     my @overrides  = ();
       
    96     my @oconfstack = (REPLACE_WARN);
       
    97     my @romelemcnt = (0, 0, 0, 0, 0, 0, 0, 0);
       
    98 
       
    99     # Go through all the tmp6.oby (InvocationPoint2) lines and store
       
   100     # normal targets' data to %targets and override targets' data to @overrides
       
   101 
       
   102     dprint(2, "Finding overrides...");
       
   103 
       
   104     foreach (@{$obydata})
       
   105     {
       
   106         my $parse = parse_obyline($_);
       
   107 
       
   108         if ($parse == 2) {
       
   109             # REM ROM_IMAGE[id]
       
   110             dprint(2, "#$gLnum: `$gLine'");
       
   111         }
       
   112         elsif (/^\s*OVERRIDE_(?:(END)|(REPLACE\/ADD)|(REPLACE\/SKIP)|(REPLACE\/WARN)|SKIP\/ADD)\s*$/i) {
       
   113             # Override configuration keyword
       
   114             if (defined($1)) {
       
   115                 # OVERRIDE_END
       
   116                 pop(@oconfstack);
       
   117             } else {
       
   118                 # OVERRIDE_REPLACE/ADD|REPLACE/SKIP|REPLACE/WARN|SKIP/ADD
       
   119                 push(@oconfstack, defined($2) ? REPLACE_ADD : (defined($3) ? REPLACE_SKIP : (defined($4) ? REPLACE_WARN : SKIP_ADD)));
       
   120             }
       
   121             dprint(2, "#$gLnum: `$gLine'");
       
   122             $_ = "$gHandlestr $gLine";
       
   123         }
       
   124         elsif ($parse == 1 && $gKeyword =~ /-override/i) {
       
   125             # Override entry
       
   126             dprint(2, "#$gLnum: `$gLine'");
       
   127             push(@overrides, [$gLnum - 1, $gRomid, $oconfstack[$#oconfstack]]);
       
   128         }
       
   129         elsif ($parse == 1 && $gKeyword =~ FILESPECKEYWORD) {
       
   130             # Normal file specification entry
       
   131             $targets{lc("$gTarget/$gRomid")} = $gLnum - 1;
       
   132             $romelemcnt[$gRomid]++;
       
   133         }
       
   134     }
       
   135 
       
   136     # Loop through all overrides and handle them
       
   137     dprint(3, @overrides ? "Handling overrides..." : "No override entries found");
       
   138 
       
   139     foreach (@overrides)
       
   140     {
       
   141         my ($lnum, $romid, $type) = @{$_};
       
   142         parse_keyline(${$obydata}[$lnum], 1);
       
   143         dprint(2, "Handling    : `$gLine' ($romid, " . ("REPLACE/ADD", "REPLACE/SKIP", "REPLACE/WARN", "SKIP/ADD")[$type] . ")");
       
   144         ${$obydata}[$lnum] = "$gHandlestr $gLine";
       
   145         (my $target = $gTarget) =~ s/^"(.*)"$/$1/;
       
   146 
       
   147         if (exists($targets{lc("$target/$romid")})) {
       
   148             # Override target found
       
   149 
       
   150             my ($line, $keyword, $source, $attrib) = ($gLine, $gKeyword, $gSource, $gAttrib);
       
   151             parse_keyline(${$obydata}[$lnum = $targets{lc("$target/$romid")}], 1);
       
   152             dprint(2, "Target      : `$gLine' ($romid, #" . ($lnum + 1) . ")");
       
   153 
       
   154             if ($type == SKIP_ADD) {
       
   155                 dprint(2, "Do nothing  : Target found and override type SKIP");
       
   156             }
       
   157             elsif ($source =~ /^"?empty"?$/i) {
       
   158                 # Empty keyword -> comment line out
       
   159                 ${$obydata}[$lnum] = "$gHandlestr $gLine";
       
   160                 dprint(1, "Remove ROM_IMAGE[$romid] `$gLine' due to `$line'");
       
   161                 dprint(2, "Replace with: `${$obydata}[$lnum]' (Override source EMPTY)");
       
   162             }
       
   163             else {
       
   164                 # Replace existing line with new line
       
   165                 $keyword =~ s/-override//i;
       
   166                 $attrib = ($attrib eq "" ? $gAttrib : ($attrib =~ /^\s*empty$/i ? "" : $attrib));
       
   167                 $line = ${$obydata}[$lnum] = "$keyword=$source  $gTarget$attrib\n";
       
   168                 dprint(1, "Replace ROM_IMAGE[$romid] `$gLine' with `$line'");
       
   169                 dprint(2, "Replace with: `$line'");
       
   170             }
       
   171         }
       
   172         else {
       
   173             # Override target not found
       
   174 
       
   175             if (!$romelemcnt[$romid] && $type != REPLACE_ADD && $type != SKIP_ADD) {
       
   176                 # Ignore override non-XXX/ADD targets on empty ROM_IMAGE sections
       
   177                 dprint(2, "Do nothing  : Target not found, override target's ROM_IMAGE[$romid] section is empty");
       
   178                 next;
       
   179             }
       
   180             # Check if override target exists in different ROM section
       
   181             my $warn = "";
       
   182             foreach my $tromid (0 .. 7) {
       
   183                 $warn = "Override target `$target' found from ROM_IMAGE[$tromid] while override is for ROM_IMAGE[$romid]", last
       
   184                     if exists($targets{lc("$target/$tromid")});
       
   185             }
       
   186             if ($type == REPLACE_SKIP) {
       
   187                 dprint(2, "Do nothing  : Target not found " . ($warn ? "from ROM_IMAGE[$romid] " : "") . "and override type SKIP");
       
   188             }
       
   189             elsif ($type == REPLACE_WARN) {
       
   190                 dprint(-3, $warn ? "$warn, ignoring `$target'" : "Ignoring override target `$target', target not found");
       
   191                 dprint(2, "Do nothing  : Target not found and override type WARN");
       
   192             }
       
   193             else {
       
   194                 # OVERRIDE_XXX/ADD
       
   195                 (my $line = $gLine) =~ s/^(\S+?)-override/$1/i;
       
   196                 ${$obydata}[$lnum] = $line;
       
   197                 dprint(-3, $warn) if $warn;
       
   198                 dprint(1, "Add ROM_IMAGE[$romid] `$line' from `$gLine'");
       
   199                 dprint(2, "Add new     : `$line' (Target not found, override type ADD)");
       
   200             }
       
   201         }
       
   202     }
       
   203     plugin_end();
       
   204 }
       
   205 
       
   206 1;
       
   207 
       
   208 __END__ # OF OVERRIDE.PM