stif/TestModuleTemplates/STIFUnitXXX/CreateSTIFUnitModuleVar2.bat
branchRCL_3
changeset 59 8ad140f3dd41
parent 0 a03f92240627
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     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: This file contains capsmodifier implementation.
       
    15 ::
       
    16 
       
    17 @perl -x CreateSTIFUnitModule.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 
       
    18 @goto end
       
    19 
       
    20 #!perl
       
    21 use strict;
       
    22 use File::Find;
       
    23 
       
    24 # Verify command line parameters
       
    25 if   ($#ARGV == -1 || $#ARGV > 1 )
       
    26 {
       
    27 	PrintHelp();
       
    28 }
       
    29 
       
    30 # Take module name
       
    31 my $moduleName = $ARGV[0];
       
    32 my $MODULENAME = $moduleName;
       
    33 $MODULENAME =~ tr/[a-z]/[A-Z]/;
       
    34 
       
    35 # Take target path or use default
       
    36 my $targetPath="\\";
       
    37 if ( $#ARGV == 1 )
       
    38 {
       
    39 	$targetPath = $ARGV[1];
       
    40 }
       
    41 
       
    42 
       
    43 # Create directory
       
    44 my $targetDir = $targetPath;
       
    45 
       
    46 unless(-d $targetDir)
       
    47 {
       
    48   die ("Specified target path does not exists. Cannot create test module.\n");
       
    49 }
       
    50 
       
    51 print "Starting module creation to $targetDir\n";
       
    52 mkdir $targetDir, 0777 || die ("Can't create directory $targetDir");
       
    53 
       
    54 # Loop through the file structure
       
    55 find(\&renamerename, '.');
       
    56 
       
    57 unlink $targetDir."CreateSTIFUnitModuleVar2.bat";
       
    58 unlink $targetDir."CreateSTIFUnitModule.bat";
       
    59 unlink $targetDir."/group/$moduleName"."_nrm.mmp";
       
    60 
       
    61 ModifyBldInf();
       
    62 
       
    63 print "Module created to $targetDir\n";
       
    64 
       
    65 # This function will be called for each file or directory
       
    66 sub renamerename
       
    67 {
       
    68 	my $oldName = $_;
       
    69 	print "Processing $oldName\n";
       
    70 
       
    71 	# Construct new filename if that needed
       
    72 	s/STIFUnitXXX/$moduleName/i;
       
    73 	my $newName = $targetDir.$File::Find::dir."/".$_;  
       
    74 
       
    75 	# Process directories
       
    76 	if (opendir(DIR, $oldName))
       
    77 	{
       
    78 		closedir (DIR);
       
    79 		mkdir $newName, 0777 || die ("Can't create directory $newName");
       
    80 		return;
       
    81 	}
       
    82   
       
    83   if (uc($oldName) eq "BLD.INF")
       
    84   {
       
    85     print "Skipping $oldName\n";
       
    86     return;
       
    87   }
       
    88                         
       
    89 	# Open input file
       
    90 	open (INFILE, $oldName ) || die ("Can not find $oldName");
       
    91 
       
    92 	#Open output file
       
    93 	my $newOutput = $newName."new";
       
    94 	open (OUTFILE, ">".$newOutput ) || die ("Can not open $newOutput");
       
    95 
       
    96 	# Replace text in files
       
    97 	while (<INFILE>)
       
    98 	{
       
    99 	  s/STIFUnitXXX/$moduleName/g;
       
   100 	  s/STIFUNITXXX/$MODULENAME/g;
       
   101 	  s/XXX/$moduleName/g;
       
   102 	  s/STIFUnitYYY/$targetDir/g;
       
   103 	  print OUTFILE $_;
       
   104 	}
       
   105 
       
   106 	# Close filehandles
       
   107 	close (INFILE);
       
   108 	close (OUTFILE);
       
   109 
       
   110 	# Rename result file
       
   111 	rename $newOutput,$newName;
       
   112 }
       
   113 
       
   114 sub ModifyBldInf()
       
   115 {
       
   116   print "Modifying bld.inf of existing project\n";
       
   117   my $bldName = $targetDir."group/Bld.inf";
       
   118   my $newBldName = $targetDir."group/Bld.inf.new";
       
   119   my $found = 0;
       
   120   
       
   121   open INFILE, $bldName or die "Cannot open $bldName: $!";
       
   122   open (OUTFILE, ">".$newBldName) or die "Cannot create $newBldName: $!";
       
   123   
       
   124   while (<INFILE>) 
       
   125   {
       
   126     print OUTFILE $_ unless /^warning:/i;
       
   127     if ($found eq 0 && trim(uc($_)) eq "PRJ_TESTMMPFILES")
       
   128     {
       
   129       print OUTFILE "$moduleName.mmp\n";
       
   130       $found = 1;
       
   131     }
       
   132   }
       
   133   if($found eq 0)
       
   134   {
       
   135     print OUTFILE "PRJ_TESTMMPFILES\n$moduleName.mmp\n";
       
   136   }
       
   137   
       
   138   close INFILE;
       
   139   close OUTFILE;
       
   140   
       
   141   rename $bldName, "$bldName.old" or die "Could not rename $bldName to $bldName.old\n";
       
   142   rename $newBldName, $bldName or die "Could not rename $newBldName to $bldName\n";
       
   143   
       
   144   print "Bld.inf file has been modified.\n";
       
   145   print "Original file is stored as $bldName.old\n";
       
   146 }
       
   147 
       
   148 sub PrintHelp()
       
   149 {
       
   150 	print "createSTIFUnitModule ModuleName [path]\n";
       
   151 	print "\n";
       
   152 	print "Creates a new test module\n";
       
   153 	print "If [path] is not given, module is created to root of current drive.\n";
       
   154 	print "If [path] is given, it must contain the final \'\\\' in path name.\n";
       
   155 	print "Command must be executed in directory where the template exist.\n";
       
   156 	exit;
       
   157 }
       
   158 
       
   159 sub trim($)
       
   160 {
       
   161 	my $string = shift;
       
   162 	$string =~ s/^\s+//;
       
   163 	$string =~ s/\s+$//;
       
   164 	return $string;
       
   165 }
       
   166 
       
   167 __END__
       
   168 :end