sbsv1_os/e32toolp/platform/lockit_info.pm
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 # Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 #
       
    15 
       
    16 package lockit_info;
       
    17 use File::Copy;
       
    18 use File::Path;
       
    19 use File::Basename;
       
    20 
       
    21 require Exporter;
       
    22 @ISA=qw(Exporter);
       
    23 @EXPORT=qw(
       
    24 	Check_Epocroot
       
    25 	Setup_LockitPath
       
    26 	Lockit_Releasables
       
    27 	Copy_Files
       
    28 	WriteTo_Info
       
    29 	LineExists
       
    30 	Lockit_SrcFile
       
    31 	Open_InfoFile
       
    32 	Close_InfoFile
       
    33 );
       
    34 
       
    35 use strict;
       
    36 use Pathutl;
       
    37 my $epocroot;
       
    38 my $epocPath;
       
    39 
       
    40 sub Check_Epocroot 
       
    41 	{
       
    42 	$epocroot = $ENV{EPOCROOT};
       
    43 	die "ERROR: Must set the EPOCROOT environment variable\n" if (!defined($epocroot));
       
    44 	$epocroot =~ s-/-\\-go;	# for those working with UNIX shells
       
    45 	die "ERROR: EPOCROOT must not include a drive letter\n" if ($epocroot =~ /^.:/);
       
    46 	die "ERROR: EPOCROOT must be an absolute path without a drive letter\n" if ($epocroot !~ /^\\/);
       
    47 	die "ERROR: EPOCROOT must not be a UNC path\n" if ($epocroot =~ /^\\\\/);
       
    48 	die "ERROR: EPOCROOT must end with a backslash\n" if ($epocroot !~ /\\$/);
       
    49 	die "ERROR: EPOCROOT must specify an existing directory\n" if (!-d $epocroot);
       
    50 
       
    51 	$epocroot=~ s-\\$--;		# chop trailing \\
       
    52 	$epocPath = "$epocroot\\epoc32\\localisation";
       
    53 	}
       
    54 
       
    55 
       
    56 ## main function which handles all lockit-related function
       
    57 sub Lockit_SrcFile()
       
    58 {
       
    59 	my ($ResrcFile, $RppFile,$Resrc_Options, $FileType, $Bitmaps, $RscTarget, $lang);
       
    60 	
       
    61 	if (defined $ENV{ABLD_TOOLSMOD_COMPATIBILITY_MODE} &&  ($ENV{ABLD_TOOLSMOD_COMPATIBILITY_MODE} eq 'alpha')) {
       
    62 		($ResrcFile, $RppFile,$Resrc_Options, $FileType, $Bitmaps, $RscTarget, $lang)= @_;
       
    63 	}
       
    64 	else {
       
    65 
       
    66 		($ResrcFile, $RppFile,$Resrc_Options, $FileType, $Bitmaps, $RscTarget)= @_;
       
    67 	}
       
    68 	$RscTarget=Path_Split('File', $RscTarget);
       
    69 	my ($Tgtdir, $CWDir) = split(/:/, $Resrc_Options);
       
    70 	$Tgtdir =~s-^(.*)\\$-$1-o; # remove terminating backslash
       
    71 	$Tgtdir=~s-^\\--o; # remove leading backslash
       
    72 	
       
    73 	Check_Epocroot();
       
    74 	my $FilePath;
       
    75 
       
    76 	if (defined $ENV{ABLD_TOOLSMOD_COMPATIBILITY_MODE} &&  ($ENV{ABLD_TOOLSMOD_COMPATIBILITY_MODE} eq 'alpha')) {
       
    77 		$FilePath = Setup_LockitPath($CWDir, $ResrcFile, $FileType, $lang);
       
    78 
       
    79 		# update rppfile in epoc32\localisation if -l option specified and generating resource
       
    80 			
       
    81 		copy("$RppFile", "$FilePath\\");
       
    82 	}
       
    83 	else {
       
    84 		$FilePath = Setup_LockitPath($CWDir, $ResrcFile, $FileType);
       
    85 
       
    86 		# update rppfile in epoc32\localisation if -l option specified and generating resource
       
    87 		copy("$RppFile", "$FilePath\\$ResrcFile.rpp");
       
    88 	}
       
    89 
       
    90 	# update bitmaps in epoc32\localisation if -l option and bitmaps specified
       
    91 	if ($CWDir && ($Bitmaps ne ""))
       
    92 	{
       
    93 		my $BmpRef;
       
    94 		$Bitmaps =~ s/ +|\t/ /g; # replace tabs and more spaces with single space
       
    95 		$Bitmaps =~s/^ //g; # remove leading space
       
    96 		$Bitmaps =~s/ $//g; # remove trailing space
       
    97 
       
    98 		my (@AifBitmaps) = split(/ /, $Bitmaps);
       
    99 		foreach $BmpRef (@AifBitmaps) {
       
   100 			$BmpRef =~ /^([^\\]+)(\\.*)$/;
       
   101 			my $CDepth = $1;
       
   102 			my $bmp = $2;
       
   103 			Copy_Files($bmp, $FilePath);
       
   104 			my $file_base= basename($bmp);
       
   105 			chmod (0666,"$FilePath\\$file_base");
       
   106 		}
       
   107 	}
       
   108 
       
   109 	if (defined $ENV{ABLD_TOOLSMOD_COMPATIBILITY_MODE} &&  ($ENV{ABLD_TOOLSMOD_COMPATIBILITY_MODE} eq 'alpha')) {
       
   110 		if (LineExists($ResrcFile.$lang, $RscTarget) == 0)
       
   111 		{
       
   112 			Open_InfoFile($ResrcFile . $lang);
       
   113 
       
   114 			WriteTo_Info ( "\n\\$Tgtdir\\$RscTarget :" );
       
   115 
       
   116 			if($FileType =~ /RSC/i && $RppFile ne "") {
       
   117 				WriteTo_Info (
       
   118 					 " $ResrcFile$lang.rpp"
       
   119 				)
       
   120 			}
       
   121 
       
   122 			elsif ($RppFile ne "") {
       
   123 				WriteTo_Info (
       
   124 					 " $ResrcFile$lang.text $ResrcFile$lang.struct"
       
   125 				)
       
   126 			}
       
   127 
       
   128 			if($Bitmaps ne "")
       
   129 			{
       
   130 				my $BmpRef;
       
   131 				my (@AifBitmaps) = split(/ /, $Bitmaps);
       
   132 				foreach $BmpRef (@AifBitmaps) {
       
   133 					$BmpRef =~ /^([^\\]+)(\\.*)$/;
       
   134 					my $CDepth = $1;
       
   135 					my $bmp = $2;
       
   136 					my $file_base= basename($bmp);
       
   137 					WriteTo_Info (
       
   138 						 " $CDepth\\$file_base"
       
   139 					);
       
   140 				}
       
   141 			}
       
   142 
       
   143 			Close_InfoFile($ResrcFile . $lang);
       
   144 		}
       
   145 	}
       
   146 	else {
       
   147 		if (LineExists($ResrcFile, $RscTarget) == 0)
       
   148 		{
       
   149 			Open_InfoFile($ResrcFile);
       
   150 
       
   151 			WriteTo_Info ( "\n\\$Tgtdir\\$RscTarget :" );
       
   152 
       
   153 			if($FileType =~ /RSC/i && $RppFile ne "") {
       
   154 				WriteTo_Info (
       
   155 					 " $ResrcFile.rpp"
       
   156 				)
       
   157 			}
       
   158 
       
   159 			elsif ($RppFile ne "") {
       
   160 				WriteTo_Info (
       
   161 					 " $ResrcFile.text $ResrcFile.struct"
       
   162 				)
       
   163 			}
       
   164 
       
   165 			if($Bitmaps ne "")
       
   166 			{
       
   167 				my $BmpRef;
       
   168 				my (@AifBitmaps) = split(/ /, $Bitmaps);
       
   169 				foreach $BmpRef (@AifBitmaps) {
       
   170 					$BmpRef =~ /^([^\\]+)(\\.*)$/;
       
   171 					my $CDepth = $1;
       
   172 					my $bmp = $2;
       
   173 					my $file_base= basename($bmp);
       
   174 					WriteTo_Info (
       
   175 						 " $CDepth\\$file_base"
       
   176 					);
       
   177 				}
       
   178 			}
       
   179 
       
   180 			Close_InfoFile($ResrcFile);
       
   181 
       
   182 		}
       
   183 	}
       
   184 }
       
   185 
       
   186 
       
   187 ## copy source files
       
   188 sub Copy_Files ()
       
   189 	{
       
   190 	my ($SourceName, $TargetName) = @_;
       
   191 
       
   192 	copy($SourceName, $TargetName);
       
   193 	}
       
   194 
       
   195 ## create necessary directories
       
   196 sub Create_InfoFile ()
       
   197 	{
       
   198 	my ($CreateLockitPath, $CreateInfoFile, $Datadir) = @_;
       
   199 	if ( !-e "$CreateLockitPath") { mkpath($CreateLockitPath); }
       
   200 	if ( !-e "$epocPath\\group") { mkpath("$epocPath\\group"); }
       
   201 	if ( !-e "$epocPath\\group\\$CreateInfoFile.info") {	
       
   202 		open INFO,">$epocPath\\group\\$CreateInfoFile.info" or die "ERROR: Can not create file \"$CreateInfoFile\"\n"; 
       
   203 		print INFO "DATADIR: $Datadir\n";
       
   204 		close INFO;
       
   205 	}
       
   206 }
       
   207 
       
   208 ## open INFO file to write source information
       
   209 sub Open_InfoFile ($)
       
   210 	{
       
   211 	my $FileToOpen = $_[0];
       
   212 	open INFO,">>$epocPath\\group\\$FileToOpen.INFO" or die "ERROR: Can not open  \"$epocPath\\group\\$FileToOpen\"\n";
       
   213 	}
       
   214 
       
   215 
       
   216 ## write source filename to INFO file
       
   217 sub WriteTo_Info ($) 
       
   218 	{
       
   219 	my $Text = $_[0];
       
   220 	print INFO "$Text";
       
   221 	}
       
   222 
       
   223 
       
   224 ## check whether source filename is written to INFO file
       
   225 sub LineExists ()
       
   226 	{
       
   227 	my $FileToOpen = $_[0];
       
   228 	my $LineCheck = $_[1];
       
   229 	my $exists = 0;
       
   230 
       
   231 	open INFO,"$epocPath\\group\\$FileToOpen.info" or die "ERROR: Can not open \"$FileToOpen\"\n";
       
   232 		while(<INFO>) {
       
   233 			if (/$LineCheck/i) { $exists = 1; return $exists; } 
       
   234 		}
       
   235 		close INFO;
       
   236 	return $exists;
       
   237 	}
       
   238 	
       
   239 
       
   240 #determine Components pathname and create INFO files
       
   241 sub Setup_LockitPath
       
   242 	{
       
   243 	my ($ComponentSrcPath, $Resrc, $FileType, $lang);
       
   244 
       
   245 	if (defined $ENV{ABLD_TOOLSMOD_COMPATIBILITY_MODE} &&  ($ENV{ABLD_TOOLSMOD_COMPATIBILITY_MODE} eq 'alpha')) {
       
   246 		($ComponentSrcPath, $Resrc, $FileType, $lang) = @_;
       
   247 	}
       
   248 	else {
       
   249 		($ComponentSrcPath, $Resrc, $FileType) = @_;
       
   250 	}
       
   251 	my ($temp, $CWDir) = split(/\\/, $ComponentSrcPath);
       
   252 	my $FilePath = $epocPath;
       
   253 
       
   254 	if($FileType =~ /RSS/i) { $FileType = "rsc"; }
       
   255 	if($FileType =~ /^acl|abw|aif|a[0-9]/i) {
       
   256 		$FilePath .= "\\aif";
       
   257 	}
       
   258 	
       
   259 ## change added to support cnf file generation
       
   260 	if ($FileType =~ /CNF/i) { 
       
   261 		$FilePath .= "\\cnf"; 
       
   262 	}
       
   263 
       
   264 	my $WorkPath = ""; 
       
   265 
       
   266 	if($Resrc !~ /^$CWDir$/i) {
       
   267 		$WorkPath = "$Resrc"; 
       
   268 	}
       
   269 
       
   270 	$FilePath .= "\\$WorkPath\\$FileType";
       
   271 
       
   272 	if (defined $ENV{ABLD_TOOLSMOD_COMPATIBILITY_MODE} &&  ($ENV{ABLD_TOOLSMOD_COMPATIBILITY_MODE} eq 'alpha')) {
       
   273 		&Create_InfoFile("$FilePath", "$Resrc$lang", "\\$WorkPath");
       
   274 	}
       
   275 	else {
       
   276 		&Create_InfoFile("$FilePath", "$Resrc", "\\$WorkPath");
       
   277 	}
       
   278 
       
   279 	return $FilePath;
       
   280 	}
       
   281 
       
   282 
       
   283 ## accumulate list of Lockit releasables
       
   284 sub Lockit_Releasables
       
   285 {
       
   286 	my ($ComponentSrcPath, $ResrcFile, $href, $Bitmaps, $lang);
       
   287 	my $Resrc;
       
   288 	my ($BaseResrc,$FileType);
       
   289 	my $LockitInfoPath;
       
   290 	my $LockitPath;
       
   291 	my %Files;
       
   292 
       
   293 	if (defined $ENV{ABLD_TOOLSMOD_COMPATIBILITY_MODE} &&  ($ENV{ABLD_TOOLSMOD_COMPATIBILITY_MODE} eq 'alpha')) {
       
   294 		($ComponentSrcPath, $ResrcFile, $href, $Bitmaps, $lang) = @_;
       
   295 
       
   296 		$Resrc = basename($ResrcFile);
       
   297 		($BaseResrc,$FileType) = split(/\./, $Resrc);
       
   298 		Check_Epocroot();
       
   299 	
       
   300 		$LockitInfoPath = "$epocPath\\group\\$BaseResrc$lang.info";
       
   301 
       
   302 		$LockitPath = Setup_LockitPath($ComponentSrcPath, $BaseResrc, $FileType, "");
       
   303 		%Files = %$href;
       
   304 
       
   305 		if($FileType =~ /RSS|ACL|ABW|AIF|A[0-9]/i && $Bitmaps eq ""){
       
   306 			$LockitPath .= "\\$BaseResrc$lang.rpp";
       
   307 		}
       
   308 		else {
       
   309 			$LockitPath .= "\\$Bitmaps";
       
   310 		}
       
   311 
       
   312 	}
       
   313 	else {
       
   314 		($ComponentSrcPath, $ResrcFile, $href, $Bitmaps) = @_;
       
   315 
       
   316 		$Resrc = basename($ResrcFile);
       
   317 		($BaseResrc,$FileType) = split(/\./, $Resrc);
       
   318 		Check_Epocroot();
       
   319 		$LockitInfoPath = "$epocPath\\group\\$BaseResrc.info";
       
   320 
       
   321 		$LockitPath = Setup_LockitPath($ComponentSrcPath, $BaseResrc, $FileType);
       
   322 		%Files = %$href;
       
   323 
       
   324 		if($FileType =~ /RSS|ACL|ABW|AIF|A[0-9]/i && $Bitmaps eq ""){
       
   325 			$LockitPath .= "\\$BaseResrc.rpp";
       
   326 		}
       
   327 		else {
       
   328 			$LockitPath .= "\\$Bitmaps";
       
   329 		}
       
   330 	}
       
   331 
       
   332 	my %loggedFiles;
       
   333 	$loggedFiles{lc($_)} = 1 foreach keys (%Files);
       
   334 	
       
   335 	$Files{$LockitPath} = 1 if !($loggedFiles{lc($LockitPath)});
       
   336 	$Files{$LockitInfoPath} = 1 if !($loggedFiles{lc($LockitInfoPath)});
       
   337 	
       
   338 	return %Files;
       
   339 }
       
   340 
       
   341 sub Close_InfoFile ($)
       
   342 	{
       
   343 	my $FileToClose = $_[0];
       
   344 	close INFO;
       
   345 	}
       
   346 
       
   347 1;