build/tools/gencmd.pl
branchRCL_3
changeset 21 ea3e26ea6629
parent 6 c8ecf89eb77f
equal deleted inserted replaced
6:c8ecf89eb77f 21:ea3e26ea6629
     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 "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 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description:  
       
    15 #    Generate xml that can give input for symbian tbs build system 
       
    16 #
       
    17 # ============================================================================
       
    18 #  Name     : gencmd.pl
       
    19 #  Part of  : Generate cmd file from input file
       
    20 #  Origin   : S60 2.0,NMP
       
    21 #  Created  : Tue Oct 6 11:32:47 2003
       
    22 #  Version  : 1.0
       
    23 #  Description: 
       
    24 #    Generate xml that can give input for symbian tbs build system 
       
    25 #	
       
    26 #	
       
    27 # structure of input file: 
       
    28 # <[build]>         open specific build tag, not required, multiply allowed ( like <[build]><[build1]> )
       
    29 #   [build] is given with parameter -b 
       
    30 #   if [build] not match with given -b parameter, all lines inside this tag will ignore
       
    31 # <\>               close specific build tag
       
    32 #
       
    33 # <#[name]>         open task block
       
    34 #  cd \             specify directory where followed lines will be launch
       
    35 #  command.cmd      command that will launch in above directory. command can be whatever (perl, cmd, exe...)
       
    36 #  cd \temp         redefine directory where followed lines will be launch
       
    37 #  command2.cmd     command that will launch in above directory. command can be whatever (perl, cmd, exe...)
       
    38 # <\#>              close task block, close also specific build tag if open
       
    39 #
       
    40 # <parallel>        open parallel block, all task blocks that located inside same parallel block will be run parallel in tbs
       
    41 # <\parallel>       close parallel block, close also task block and specific build tag
       
    42 #
       
    43 # comment (\\,#) and empty lines ingnore 
       
    44 #
       
    45 # example:
       
    46 #
       
    47 # <parallel>                        1st parallel block
       
    48 # <#commonengine>                   first task
       
    49 # cd \S60\commonengine\group       
       
    50 # call bldmake bldfiles -k          command that will lauch 1st state
       
    51 # call abld export -k               command that will lauch 2nd state
       
    52 # <\#>
       
    53 #  
       
    54 # <#bldvariant>                     second task
       
    55 # <S60_3_1>                         specify directory for 'S60_3_1' build
       
    56 # cd \S60\misc\release\bldvariant\Series_60_3_1_elaf\group
       
    57 # <\>
       
    58 # <S60_3_2><S60_3_3>                specify directory for 'S60_3_2' and 'S60_3_3' build
       
    59 # cd \S60\misc\release\bldvariant\elaf\group
       
    60 # <\>
       
    61 # call bldmake bldfiles -k          command that will lauch 1st state
       
    62 # call abld export -k               command that will lauch 2nd state
       
    63 # call abld export -w               command that will lauch 3rd state
       
    64 # <\#>
       
    65 # <\parallel>
       
    66 #
       
    67 # <parallel>                        2nd parallel block
       
    68 # <#build_platforms>
       
    69 # cd \s60\build_platforms\group
       
    70 # call bldmake bldfiles -k          command that will lauch 4th state
       
    71 # call abld export -k               command that will lauch 5th state
       
    72 # <\#>
       
    73 # <\parallel>
       
    74 #
       
    75 
       
    76 use strict;
       
    77 use File::Find;     # for finding
       
    78 use File::Basename; # for fileparse
       
    79 use Getopt::Long;
       
    80 
       
    81 #
       
    82 # Variables...
       
    83 #
       
    84 my $version = "V1.0";
       
    85 my $inputfile; # input filename
       
    86 my $build; # S60_2X
       
    87 my $outputfile; # input filename
       
    88 my $component = "";
       
    89 my ($cmdfile, $xmlfile, $product_name);
       
    90 my $skip = 0;
       
    91 my ($c, $i, $j);
       
    92 
       
    93 if ( !GetOptions('i=s' => \$inputfile, 'b=s' => \$build, 'o=s' =>\$outputfile))
       
    94 {
       
    95 	&error_msg("Invalid arguments\n");
       
    96 }
       
    97 
       
    98 #
       
    99 # Hello text
       
   100 #
       
   101 hello();
       
   102 
       
   103 $build =~ tr/A-Z/a-z/; #Change all capitals to small    
       
   104   
       
   105 open (INPUT,"$inputfile") or &error_msg("Cannot open $inputfile");
       
   106   open (XML_FILE,">$outputfile") or &error_msg("Cannot open $outputfile");
       
   107   pre_xml(\*XML_FILE);
       
   108   gen_xml_file(\*XML_FILE);
       
   109   post_xml(\*XML_FILE);
       
   110   close XML_FILE;
       
   111 close INPUT;
       
   112 
       
   113 sub gen_xml_file {
       
   114   my ($outputfile)=@_;
       
   115   my $parallel = 0;
       
   116   my $component_name = "";
       
   117   my $component_path = "\\";
       
   118   my @component_command;
       
   119   my %component_parallel;
       
   120   my $id = 1;
       
   121   my $stage = 1;
       
   122   
       
   123   while (<INPUT>) {
       
   124     next if (/^\/\//); # Skip comment lines
       
   125     next if (/^#/); # Skip comment lines
       
   126     next if (/^ *$/); # Skip empty lines 
       
   127   
       
   128   #  $_ =~ s/\//\\/g;    #Change / marks to \
       
   129     $_ =~ tr/A-Z/a-z/; #Change all capitals to small    
       
   130   
       
   131     chomp; #Remove line feed and carriage return  
       
   132  
       
   133 # parallel block opened, components should build parallel 
       
   134     if (/^<parallel>/){
       
   135       $parallel = 1;
       
   136       next;
       
   137     }
       
   138 # parallel block closed, write components that can build parallel to output file
       
   139     if (/^<\\parallel>/){
       
   140       my $loop = 1;
       
   141       my $line = 0;
       
   142       while ($loop) {
       
   143         my $found = 0;
       
   144         foreach $c (keys %component_parallel)
       
   145         {
       
   146           my @temp;
       
   147 #            print "  $c : $i = $component_parallel{$c}[$i] : \n";
       
   148             @temp=keys %{$component_parallel{$c}[$line]};
       
   149             $j = "";
       
   150             $j = @temp[0];
       
   151             if ($j ne "") {
       
   152               print $outputfile "\t\t<Execute ID=\"$id\" Stage=\"$stage\" Component=\"$c\" Cwd=\"$j\" CommandLine=\"$component_parallel{$c}[$line]{$j}\"/>\n";
       
   153 #              print "   \;command path = $j:command = $component_parallel{$c}[$line]{$j}\;\n";
       
   154               $found = 1;
       
   155               $id++;
       
   156             }
       
   157         }
       
   158         $line++;
       
   159 
       
   160         if (!$found) {
       
   161           $loop = 0;
       
   162         }
       
   163         else {
       
   164                   $stage++;
       
   165 
       
   166         }
       
   167       }
       
   168 
       
   169 # clear variables
       
   170       %component_parallel =();
       
   171       $component_path = "\\";
       
   172       $parallel = 0;
       
   173       next;
       
   174     }
       
   175 # component block end
       
   176     if (/^<\\#/){
       
   177     	if (!$skip) {
       
   178     	  $component_parallel{$component_name}=[@component_command];
       
   179   		}
       
   180   	  $skip = 0;
       
   181   	  @component_command = ();
       
   182   	  next;
       
   183   	}
       
   184 # block end
       
   185     if (/^<\\>/) {
       
   186   	  $skip = 0;
       
   187   		next;
       
   188     }
       
   189     
       
   190     next if ($skip);
       
   191     if (!/^</) {
       
   192 # get path for xml
       
   193       if (/^cd /){
       
   194       	$component_path = $_;
       
   195       	$component_path =~ s/^cd //;
       
   196     	  next;
       
   197     	}
       
   198     	my $rec = {};
       
   199 # store command to @component_command variable
       
   200     	$rec->{$component_path} = $_;
       
   201       push (@component_command, $rec);
       
   202   		next;
       
   203     }
       
   204     
       
   205 # get component name for xml
       
   206     if (/^<\#/){
       
   207     	$component_name = $_;
       
   208     	$component_name =~ s/^<\#//;
       
   209     	$component_name =~ s/>\Z//;
       
   210   	  next;
       
   211   	}
       
   212   	
       
   213 # check build version, if not match skip next lines
       
   214     elsif (!/<$build>/){
       
   215     	$skip = 1;
       
   216     	next;
       
   217   	}
       
   218   }
       
   219 }
       
   220 
       
   221 
       
   222 sub hello
       
   223 {
       
   224 print "\nThis is gencmd.pl Version $version (C)Nokia Corporation 2002-2003\n"; 
       
   225 }
       
   226 
       
   227 sub error_msg ($){
       
   228   my($ErrorMsg);
       
   229   ($ErrorMsg)=@_;
       
   230   my $given_command=$0;
       
   231   $given_command =~ s/.*\\(\w+\.\w+)$/$1/;
       
   232   print "";
       
   233   print "\n";
       
   234   print "Error: $ErrorMsg \n\n";
       
   235   print "Usage: \n$given_command -b <build_name> -i <input file name> -o <output file>\n";
       
   236   print "Example:  \n$given_command bldmefirst.txt -b S60_3_1 -i data\bldmelast.txt -o \epoc32\tools\s60Build\bldmelast.xml\n";
       
   237   print "Example2: \n$given_command bldmefirst.txt -b S60_3_1_western -i data\variant_build.txt -o \epoc32\tools\s60Build\variant_build_western.xml\n";
       
   238   print "\n";  
       
   239   die "\n";    
       
   240 }
       
   241 
       
   242 # write pre information to output file
       
   243 sub pre_xml {
       
   244   my ($outputfile)=@_;
       
   245   print $outputfile "<?xml version=\"1.0\"?>\n";
       
   246   print $outputfile "\t<!DOCTYPE Build  [\n";
       
   247   print $outputfile "\t<!ELEMENT Product (Commands)>\n";
       
   248   print $outputfile "\t<!ATTLIST Product name CDATA #REQUIRED>\n";
       
   249   print $outputfile "\t<!ELEMENT Commands (Execute+ | SetEnv*)>\n";
       
   250   print $outputfile "\t<!ELEMENT Execute EMPTY>\n";
       
   251   print $outputfile "\t<!ATTLIST Execute ID CDATA #REQUIRED>\n";
       
   252   print $outputfile "\t<!ATTLIST Execute Stage CDATA #REQUIRED>\n";
       
   253   print $outputfile "\t<!ATTLIST Execute Component CDATA #REQUIRED>\n";
       
   254   print $outputfile "\t<!ATTLIST Execute Cwd CDATA #REQUIRED>\n";
       
   255   print $outputfile "\t<!ATTLIST Execute CommandLine CDATA #REQUIRED>\n";
       
   256   print $outputfile "\t<!ELEMENT SetEnv EMPTY>\n";
       
   257   print $outputfile "\t<!ATTLIST SetEnv Order ID #REQUIRED>\n";
       
   258   print $outputfile "\t<!ATTLIST SetEnv Name CDATA #REQUIRED>\n";
       
   259   print $outputfile "\t<!ATTLIST SetEnv Value CDATA #REQUIRED>\n";
       
   260   print $outputfile "]>\n\n";
       
   261   print $outputfile "<Product Name=\"$product_name\">\n";
       
   262   print $outputfile "\t<Commands>\n";
       
   263   print $outputfile "\t\t<!--Set Env-->\n";
       
   264   print $outputfile "\t\t<SetEnv Order=\"1\" Name=\"EPOCROOT\" Value=\"\\\"/>\n";
       
   265   print $outputfile "\t\t<SetEnv Order=\"2\" Name=\"PATH\" Value=\"\\epoc32\\gcc\\bin\;\\epoc32\\tools\;\%PATH\%\"/>\n\n";
       
   266 }
       
   267 
       
   268 # write post information to output file
       
   269 sub post_xml {
       
   270   my ($outputfile)=@_;
       
   271   print $outputfile "\t</Commands>\n";
       
   272   print $outputfile "</Product>\n";
       
   273 }
       
   274