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