tsrc/testing/tools/siscreator.pl
branchRCL_3
changeset 15 8f0df5c82986
child 16 67eb01668b0e
equal deleted inserted replaced
14:55fa1ec415c6 15:8f0df5c82986
       
     1 use warnings;
       
     2 use Cwd; # for cwd
       
     3 use File::Copy;
       
     4 use File::Path;
       
     5 
       
     6 my $debug = 0;
       
     7 my $allowRun = 1;
       
     8 my $relType = "";
       
     9 my $sisPath = "videoplayer\\tsrc\\testing\\sis";
       
    10 my $certFile = "Nokia_RnDCert_02\.der";
       
    11 my $keyFile = "Nokia_RnDCert_02\.key";
       
    12 my $comment = ";TEMPCOMMENT ";
       
    13 
       
    14 
       
    15 ########################################
       
    16 # PKG LISTS
       
    17 #
       
    18 
       
    19 my @engineTests = (
       
    20 		"videoplayer\\tsrc\\testing\\sis\\fusion_engine_tests.pkg",
       
    21 		"videoplayer\\mediasettings\\mediasettingsengine\\tsrc\\mediasettingsenginetest\\group\\mpxmediasettingsenginetest.pkg",
       
    22 		"videoplayer\\mediasettings\\videoplayersettingsengine\\tsrc\\vpsettingsenginetest\\group\\vcxnssettingsenginetest.pkg",
       
    23 		"videoplayer\\videocollection\\mpxmyvideoscollection\\tsrc\\mpxmvcolltest\\group\\VCXMyVideosCollectionPluginTest.pkg",
       
    24 		"videoplayer\\videoplayer_plat\\videoplayer_startup_api\\tsrc\\group\\VideoPlayerStartupApiTest.pkg",
       
    25 		"videoplayer\\videoplayer_plat\\video_player_file_details_dialog_api\\tsrc\\group\\ui_FileDetailsDialogtest.pkg",
       
    26 		"videoutils\\videoutils_plat\\videoscheduler_api\\tsrc\\group\\videoscheduler_apitest.pkg",
       
    27 		"videoutils\\videoutils_plat\\videoconnutility_api\\tsrc\\group\\videoconnutility_apitest.pkg"
       
    28 	);
       
    29 
       
    30 my @unitTests = (
       
    31 		"videoplayer\\videoplayback\\videohelix\\tsrc\\ut_videohelixtest\\group\\videohelixtest.pkg",
       
    32 		"videoplayer\\videoplayback\\videoplaybackcontrols\\tsrc\\videoplaybackcontrols_test\\group\\videoplaybackcontrolstest.pkg",
       
    33 		"videoplayer\\videoplayback\\videoplaybackviews\\tsrc\\ut_userinputhandlertest\\group\\userinputhandlertest.pkg",
       
    34 		"videoplayer\\videoplayerapp\\mpxvideoplayer\\tsrc\\ut_mpxvideoplayertest\\group\\mpxvideoplayertest.pkg",
       
    35 		"videoplayer\\videocollection\\hgmyvideos\\tsrc\\ut_vcxhgmyvideosmainview\\group\\VcxHgMyVideosMainViewTest.pkg"
       
    36 	);
       
    37 
       
    38 ########################################
       
    39 # PARSE ARGUMENTS
       
    40 #
       
    41 
       
    42 while(scalar(@ARGV) >= 1)
       
    43 {
       
    44 	my $argument = shift(@ARGV);
       
    45 
       
    46 	if($argument eq "-sispath")
       
    47 	{
       
    48 		$sisPath = shift();
       
    49 	}
       
    50 
       
    51 	elsif($argument eq "-type")
       
    52 	{
       
    53 		$relType = shift();
       
    54 	}
       
    55 	
       
    56 	elsif($argument eq "-norun")
       
    57 	{
       
    58 		$allowRun = 0;
       
    59 	}
       
    60 	
       
    61 	elsif($argument eq "-debug")
       
    62 	{
       
    63 		$debug = 1;
       
    64 	}
       
    65 	
       
    66 	elsif($argument eq "-help")
       
    67 	{
       
    68 		ShowHelp();
       
    69 	}
       
    70 	
       
    71 	else
       
    72 	{
       
    73 		ShowHelp();
       
    74 	}
       
    75 }
       
    76 
       
    77 ########################################
       
    78 # MAIN FUNCTION
       
    79 #
       
    80 
       
    81 my $basepath = FindBasePath();
       
    82 die("NO VIDEOAPP_DOMAIN FOLDER FOUND") if $basepath eq "";
       
    83 
       
    84 print "CREATING ${basepath}\\${sisPath}\n" if $debug;
       
    85 mkpath("${basepath}\\${sisPath}");
       
    86 
       
    87 # if sispath doesn't contain files for signing, then search them under basepath
       
    88 if ( !-e "${basepath}\\${sisPath}\\${certFile}" and !-e "${basepath}\\${sisPath}\\${keyFile}" )
       
    89 {
       
    90 	my @certfiles;
       
    91 	FindFiles($basepath, $certFile, 1, \@certfiles);
       
    92 	die("No $certFile found under ${basepath} !\n") if ( !$certfiles[0] );
       
    93 	my @keyfiles;
       
    94 	FindFiles($basepath, $keyFile, 1, \@keyfiles);
       
    95 	die("No $keyFile found under ${basepath} !\n") if ( !$keyfiles[0] );
       
    96 
       
    97 	print "COPYING $keyfiles[0] TO ${basepath}\\${sisPath}\\${keyFile}\n" if $debug;
       
    98 	copy( $keyfiles[0], "${basepath}\\${sisPath}\\${keyFile}" ) if $allowRun;
       
    99 
       
   100 	print "COPYING $keyfiles[0] TO ${basepath}\\${sisPath}\\${certFile}\n" if $debug;
       
   101 	copy( $certfiles[0], "${basepath}\\${sisPath}\\${certFile}" ) if $allowRun;
       
   102 }
       
   103 
       
   104 die("No $certFile found in ${basepath}\\${sisPath}\n") if ( !-e "${basepath}\\${sisPath}\\${certFile}" );
       
   105 die("No $keyFile found in ${basepath}\\${sisPath}\n") if ( !-e "${basepath}\\${sisPath}\\${keyFile}" );
       
   106 
       
   107 foreach my $pkg ( @engineTests )
       
   108 {
       
   109     CreateSis( $basepath, $pkg, $sisPath, $relType );
       
   110 }
       
   111 
       
   112 foreach my $pkg ( @unitTests )
       
   113 {
       
   114     CreateSis( $basepath, $pkg, $sisPath, $relType );
       
   115 }
       
   116 
       
   117 ########################################
       
   118 # FindBasePath
       
   119 #
       
   120 
       
   121 sub FindBasePath
       
   122 {
       
   123 	print ">> FindBasePath\n" if $debug;
       
   124 	$currpath = cwd;
       
   125 	$basepath = "";
       
   126 	my $domain = "VideoApp_Domain";
       
   127 	
       
   128 	my $pos = rindex( $currpath, $domain );
       
   129 	
       
   130 	if( $pos != -1 )
       
   131 	{
       
   132 		$basepath = "\\" . substr( $currpath, 3, $pos + length( $domain ) - 3 );
       
   133 		$basepath =~ s/\//\\/g;
       
   134 	  print "BASEPATH FOUND: $basepath\n" if $debug;
       
   135 	}
       
   136 	
       
   137 	print "<< FindBasePath (" . $basepath . ")\n" if $debug;
       
   138 	return $basepath;
       
   139 }
       
   140 
       
   141 ########################################
       
   142 # CreateSis
       
   143 #
       
   144 
       
   145 sub CreateSis
       
   146 {
       
   147 	my ( $baseDir, $pkgPath, $targetDir, $relType ) = @_;
       
   148 	print ">>> CREATESIS\n" if $debug;
       
   149 	my $cmd = "";
       
   150 	print "baseDir: $baseDir\n" if $debug;
       
   151 	print "pkgPath: $pkgPath\n" if $debug;
       
   152 	print "targetDir: $targetDir\n" if $debug;
       
   153 	
       
   154 	my $pos = rindex( $pkgPath, '\\' );
       
   155 	print "rindex: $pos\n" if $debug;
       
   156 	
       
   157 	my $temppath = substr( $pkgPath, 0, $pos );
       
   158 	my $filename = substr( $pkgPath, $pos + 1, -4 );
       
   159 	
       
   160 	# add type to the end of the filename
       
   161 	my $relfilename = $filename;
       
   162 	if( $relType ne "" )
       
   163 	{
       
   164 		$relfilename .= "_" . $relType;
       
   165 	}
       
   166 	
       
   167 	print "path: $temppath\n" if $debug;
       
   168 	print "file: $filename\n" if $debug;
       
   169 	print "relfile: $relfilename\n" if $debug;
       
   170 	
       
   171 
       
   172 	chdir("${basepath}\\${temppath}");
       
   173 	
       
   174 	AddComment( "${filename}.pkg" ) if $allowRun;
       
   175 	if( $relType ne "" )
       
   176 	{
       
   177 		print "\nCREATE TEMPORARY PKG\n\n" if $debug;
       
   178 		CreatePkg( $filename, $relType );
       
   179 	}
       
   180 	$cmd = "call makesis ${relfilename}\.pkg ${relfilename}\.sis";	
       
   181 	print $cmd . "\n" if $debug;
       
   182 	system($cmd) if $allowRun;
       
   183 	RemComment( "${filename}.pkg" ) if $allowRun;
       
   184 	copy( "${relfilename}\.sis", "${baseDir}\\${targetDir}\\${relfilename}\.sis" ) if $allowRun;
       
   185 	chdir("${baseDir}\\${targetDir}");
       
   186 	$cmd = "signsis ${relfilename}\.sis ${relfilename}\.sisx Nokia_RnDCert_02.der Nokia_RnDCert_02.key";
       
   187 	system($cmd) if $allowRun;
       
   188 	unlink ( "${relfilename}\.sis" ) if $allowRun;
       
   189 	print "<<< CREATESIS\n" if $debug;
       
   190 }
       
   191 
       
   192 	
       
   193 ########################################
       
   194 # AddComment
       
   195 #
       
   196 
       
   197 sub AddComment
       
   198 {
       
   199 	my ($file) = @_;
       
   200 	
       
   201 	open(FILE_HANDLE, $file) or die ("Could not read file '$file'\n");
       
   202 	my @lines = <FILE_HANDLE>;
       
   203 	close(FILE_HANDLE);
       
   204 	    
       
   205   open(FILE_HANDLE, ">$file") or die ("Could not write file '$file'\n");
       
   206   foreach my $line ( @lines )
       
   207   {
       
   208 	  if( $line =~ /\.\.\/init\/testframework\.ini/i or $line =~ /\/cccccc00\.cre/i or
       
   209 	      $line =~ /\.\.\\init\\testframework\.ini/i or $line =~ /\\cccccc00\.cre/i )
       
   210 	  {
       
   211 	    if( $line !~ /$comment/ )
       
   212 	    {
       
   213 	    	print $line . "\n" if $debug;
       
   214 				$line = $comment . $line;
       
   215 				print $line . "\n" if $debug;
       
   216 			}
       
   217 	  }
       
   218 	  print FILE_HANDLE $line;
       
   219   }	    
       
   220   close(FILE_HANDLE);
       
   221 }
       
   222 
       
   223 ########################################
       
   224 # RemComment
       
   225 #
       
   226 
       
   227 sub RemComment
       
   228 {
       
   229 	my ($file) = @_;
       
   230 	
       
   231 	open(FILE_HANDLE, $file) or die ("Could not read file '$file'\n");
       
   232 	my @lines = <FILE_HANDLE>;
       
   233 	close(FILE_HANDLE);
       
   234 	    
       
   235   open(FILE_HANDLE, ">$file") or die ("Could not write file '$file'\n");
       
   236   foreach my $line ( @lines )
       
   237   {
       
   238 	  if( $line =~ /\.\.\/init\/testframework\.ini/i or $line =~ /\/cccccc00\.cre/i or
       
   239 	      $line =~ /\.\.\\init\\testframework\.ini/i or $line =~ /\\cccccc00\.cre/i )
       
   240 	  {
       
   241 	    if( $line =~ /$comment/ )
       
   242 	    {
       
   243 	    	print $line . "\n" if $debug;
       
   244 	    	$line = substr( $line, length( $comment ) );
       
   245 	    	print $line . "\n" if $debug;
       
   246 	    }
       
   247 	  }
       
   248 	  print FILE_HANDLE $line;
       
   249   }	    
       
   250   close(FILE_HANDLE);
       
   251 }
       
   252 
       
   253 ########################################
       
   254 # CreatePkg
       
   255 #
       
   256 
       
   257 sub CreatePkg
       
   258 {
       
   259 	my ($file, $type) = @_;
       
   260 	
       
   261 	open(FILE_HANDLE, "${file}\.pkg") or die ("Could not read file '${file}\.pkg'\n");
       
   262 	my @lines = <FILE_HANDLE>;
       
   263 	close(FILE_HANDLE);
       
   264 
       
   265 	my $currenttype = "";
       
   266   open(FILE_HANDLE, ">${file}_${type}\.pkg") or die ("Could not write file '${file}_${type}\.pkg'\n");
       
   267   foreach my $line ( @lines )
       
   268   {
       
   269 	  if( $line =~ /\/armv5\/(\w+)\//i )
       
   270 	  {
       
   271 	  	$currenttype = $1;
       
   272 	  	if( $currenttype ne $type )
       
   273 	  	{
       
   274 	  		print $line if $debug;
       
   275 	  		$line =~ s/\/$currenttype\//\/$type\//;
       
   276 	  		print $line if $debug;
       
   277 	  	}
       
   278 	  }
       
   279 	  print FILE_HANDLE $line;
       
   280   }	    
       
   281   close(FILE_HANDLE);
       
   282 }
       
   283 
       
   284 #------------------------------------------------------------------------------------
       
   285 # FindFiles
       
   286 # Parameters:
       
   287 #	$goDir, where to start finding
       
   288 #	$fileSearch, filename search
       
   289 #	$searchType, 0 = fullname search, 1 = filetype search
       
   290 #	$refIncfiles, reference to array which will hold found files
       
   291 #------------------------------------------------------------------------------------
       
   292 sub FindFiles
       
   293 {
       
   294 	my ($godir, $fileSearch, $searchType, $refIncfiles) = @_;
       
   295 
       
   296 	my $startDir = cwd;
       
   297 
       
   298 	chdir($godir) or die("Could not change dir to $godir");
       
   299 
       
   300 	#print("Now in: " . cwd . "\n");
       
   301 
       
   302 	opendir(DIR, ".");
       
   303 	my @filelist = sort(readdir(DIR));
       
   304 	closedir(DIR);
       
   305 
       
   306 	foreach my $file(@filelist)
       
   307 	{
       
   308 		if($file eq "." or $file eq "..") {next};
       
   309 
       
   310 		if (-d $file)
       
   311 		{
       
   312 		 	FindFiles( $file, $fileSearch, $searchType, $refIncfiles);
       
   313 		} else
       
   314 		{
       
   315 			if( ($file =~ m/$fileSearch/i and $searchType == 0 ) or ($file =~ m/$fileSearch$/i and $searchType == 1 ) )
       
   316 			{
       
   317 				$file = cwd . "/" . $file;
       
   318 				push @$refIncfiles, $file;
       
   319 				#print("$file\n");
       
   320 				;
       
   321 			}
       
   322 		}
       
   323 	}
       
   324 
       
   325 	chdir ($startDir) or die("Could not change dir to $startDir");
       
   326 }
       
   327 
       
   328 #------------------------------------------------------------------------------------
       
   329 # ShowHelp
       
   330 #------------------------------------------------------------------------------------
       
   331 sub ShowHelp {
       
   332 
       
   333 print <<USAGE_EOF;
       
   334 siscreator.pl
       
   335 
       
   336 This script will search the VideoApp_Domain root folder from current path.
       
   337 if the root folder is not found, the script will exit. In any other case,
       
   338 it creates sis packages for components. 
       
   339 
       
   340 Default path for sis-files is /videoplayer/tsrc/testing/sis.
       
   341 
       
   342 Options:
       
   343 
       
   344 -sispath    path under videoapp_domain to copy sis files
       
   345 -type       wanted sisx type, urel or udeb
       
   346 -debug      show debug message
       
   347 -norun      do not run, for debugging purposes
       
   348 -help       You're reading it.
       
   349 
       
   350 USAGE_EOF
       
   351 
       
   352 	exit();
       
   353 
       
   354 };