common/tools/ats/hlm_prep_package.pl
changeset 1209 10d9bc494ce9
parent 1155 1bd0e92dbd45
equal deleted inserted replaced
1208:86025b85795b 1209:10d9bc494ce9
    12 #
    12 #
    13 # Description:
    13 # Description:
    14 #   This is a script for fixing pkg and ini files.
    14 #   This is a script for fixing pkg and ini files.
    15 
    15 
    16 use strict;
    16 use strict;
       
    17 use Getopt::Long;
    17 use File::Copy;
    18 use File::Copy;
    18 use Tie::File;
    19 use Tie::File;
    19 use File::Find;
    20 use File::Find;
    20 
    21 
       
    22 my $package_path;
       
    23 my @pkg_paths; # Array needed as csv file may contain more than one.
       
    24 my $pkg_path_num = 1; # By default at least one needs to be provided.
       
    25 my $csv_file;
       
    26 my $bld_drive;
       
    27 my $line;
       
    28 my $help;
       
    29 my $repo;
       
    30 my $destination;
    21 my @files;
    31 my @files;
    22 my @ini_files;
    32 my @ini_files;
    23 my @lines;
    33 my @lines;
    24 my $file;
    34 my $file;
    25 my $n;
    35 my $n;
       
    36 my $current_iteration;
    26 my $file_fixed;
    37 my $file_fixed;
    27 sub Wanted;
    38 sub Wanted;
    28 sub Parse_ini;
    39 sub Parse_ini;
    29 
    40 
    30 my $package_path;
    41 sub usage($);
    31 if ($ARGV[0]) {
    42 sub help();
    32   $package_path = $ARGV[0];
    43 sub usage_error();
    33  }
       
    34 else { die "Missing parameter \"package path\". For example: D:\\sf\\app\\musicplayer"; }
       
    35 
    44 
    36 find(\&Wanted, $package_path);
    45 my %optmap = (  'package-path' => \$package_path,
       
    46 			    'csv-file' => \$csv_file,
       
    47 				'bld-drive' => \$bld_drive,
       
    48 				'help' => \$help);
    37 
    49 
    38 #Copy a pkg file and replace \armv5\urel with $(platform)\$(target)
    50 GetOptions(\%optmap,
    39 foreach $file (@files) { #Replace "//v800020/Publish" with "http://cdn.symbian,org"
    51           'package-path=s',
    40 	copy($file,$file . ".orig") or die ("Cannot copy file \"$file\". $!\n");
    52           'csv-file=s',
    41 	tie (@lines, 'Tie::File', $file, recsep => "\n") or die ("Cannot tie file \"$file\". $!\n");
    53 		  'bld-drive=s',
    42 	$n = 0;
    54 		  'help!') 
    43 	$file_fixed = 0;
    55           or usage_error();
    44 	print @lines[49] . "\n";
    56 
    45 	foreach (@lines) {
    57 if ($help) {
    46 		if (lc(@lines[$n]) =~ m/epoc32\\release\\armv5\\urel\\/) {
    58 	help();
    47 			@lines[$n] = lc(@lines[$n]);
       
    48 			@lines[$n] =~ s/\\armv5\\urel\\/\\\$(platform)\\\$(target)\\/;
       
    49 			$file_fixed = 1;
       
    50 		}
       
    51 		if (lc(@lines[$n]) =~ m/epoc32\/release\/armv5\/urel\//) {
       
    52 			@lines[$n] = lc(@lines[$n]);
       
    53 			@lines[$n] =~ s/\/armv5\/urel\//\/\$(platform)\/\$(target)\//;
       
    54 			$file_fixed = 1;
       
    55 		}
       
    56 		if (lc(@lines[$n]) =~ m/epoc32\\release\\armv5\\udeb\\/) {
       
    57 			@lines[$n] = lc(@lines[$n]);
       
    58 			@lines[$n] =~ s/\\armv5\\udeb\\/\\\$(platform)\\\$(target)\\/;
       
    59 			$file_fixed = 1;
       
    60 		}
       
    61 #		if (lc(@lines[$n]) =~ m/e:\\/) { # Replace e: with c:
       
    62 #			@lines[$n] = lc(@lines[$n]);
       
    63 #			@lines[$n] =~ s/e:\\/c:\\/;
       
    64 #			$file_fixed = 1;
       
    65 #		}
       
    66 		$n++;
       
    67 	}
       
    68 	if ($file_fixed) { print $file . " fixed.\n"; }
       
    69 	untie @lines;
       
    70 }
    59 }
    71 
    60 
    72 find(\&Parse_ini, $package_path);
    61 usage_error(), unless ((defined($package_path)) || ((defined($csv_file)) && (defined($bld_drive))));
    73 
    62 
    74 foreach $file (@ini_files) {
    63 if (defined($csv_file)) {
    75 	if ((lc($file) =~ m/\/init\//) || (lc($file) =~ m/\/group\//)) { # Only operate on files from /init/ directories
    64 	$pkg_path_num = 0;
       
    65 	open FILE, "<$csv_file" or die("Failed to read $csv_file: $!\n");
       
    66 	while ($line = <FILE>)
       
    67 	{
       
    68 		chomp $line;
       
    69 		($repo,$destination) = split /,/,$line;
       
    70 		if ((lc($destination) ne "dst") && (lc($destination) ne "")) { 
       
    71 #			$package_path = $bld_drive . $destination;
       
    72 			push @pkg_paths, $bld_drive . $destination;
       
    73 			$pkg_path_num++;
       
    74 #			last; 
       
    75 		}
       
    76 		
       
    77 	}
       
    78 	close FILE;
       
    79 }
       
    80 
       
    81 $current_iteration = 0;
       
    82 while ($current_iteration < $pkg_path_num) {
       
    83 	if (defined($csv_file)) {
       
    84 		$package_path = @pkg_paths[$current_iteration];
       
    85 	}
       
    86 	print "Processing: $package_path \n";
       
    87 
       
    88 	find(\&Wanted, $package_path);
       
    89 
       
    90 	#Copy a pkg file and replace \armv5\urel with $(platform)\$(target)
       
    91 	foreach $file (@files) { #Replace "//v800020/Publish" with "http://cdn.symbian,org"
    76 		copy($file,$file . ".orig") or die ("Cannot copy file \"$file\". $!\n");
    92 		copy($file,$file . ".orig") or die ("Cannot copy file \"$file\". $!\n");
    77 		tie (@lines, 'Tie::File', $file, recsep => "\n") or die ("Cannot tie file \"$file\". $!\n");
    93 		tie (@lines, 'Tie::File', $file, recsep => "\n") or die ("Cannot tie file \"$file\". $!\n");
    78 		$n = 0;
    94 		$n = 0;
    79 		$file_fixed = 0;
    95 		$file_fixed = 0;
    80 		foreach (@lines) {
    96 		foreach (@lines) {
    81 			if (lc(@lines[$n]) =~ m/^separateprocesses/) {
    97 			if (lc(@lines[$n]) =~ m/epoc32\\release\\armv5\\urel\\/) {
    82 				@lines[$n] = '#' . @lines[$n];
    98 				@lines[$n] = lc(@lines[$n]);
       
    99 				@lines[$n] =~ s/\\armv5\\urel\\/\\\$(platform)\\\$(target)\\/;
    83 				$file_fixed = 1;
   100 				$file_fixed = 1;
    84 			}
   101 			}
    85 			if (lc(@lines[$n]) =~ m/^uitestingsupport/) {
   102 			if (lc(@lines[$n]) =~ m/epoc32\/release\/armv5\/urel\//) {
    86 				@lines[$n] = '#' . @lines[$n];
   103 				@lines[$n] = lc(@lines[$n]);
       
   104 				@lines[$n] =~ s/\/armv5\/urel\//\/\$(platform)\/\$(target)\//;
    87 				$file_fixed = 1;
   105 				$file_fixed = 1;
    88 			}
   106 			}
       
   107 			if (lc(@lines[$n]) =~ m/epoc32\\release\\armv5\\udeb\\/) {
       
   108 				@lines[$n] = lc(@lines[$n]);
       
   109 				@lines[$n] =~ s/\\armv5\\udeb\\/\\\$(platform)\\\$(target)\\/;
       
   110 				$file_fixed = 1;
       
   111 			}
       
   112 #			if (lc(@lines[$n]) =~ m/e:\\/) { # Replace e: with c:
       
   113 #				@lines[$n] = lc(@lines[$n]);
       
   114 #				@lines[$n] =~ s/e:\\/c:\\/;
       
   115 #				$file_fixed = 1;
       
   116 #			}
    89 			$n++;
   117 			$n++;
    90 		}
   118 		}
    91 		if ($file_fixed) { print $file . " fixed.\n"; }
   119 		if ($file_fixed) { print $file . " fixed.\n"; }
    92 		untie @lines;
   120 		untie @lines;
    93 	}
   121 	}
       
   122 
       
   123 	find(\&Parse_ini, $package_path);
       
   124 
       
   125 	foreach $file (@ini_files) {
       
   126 		if ((lc($file) =~ m/\/init\//) || (lc($file) =~ m/\/group\//)) { # Only operate on files from /init/ directories
       
   127 			copy($file,$file . ".orig") or die ("Cannot copy file \"$file\". $!\n");
       
   128 			tie (@lines, 'Tie::File', $file, recsep => "\n") or die ("Cannot tie file \"$file\". $!\n");
       
   129 			$n = 0;
       
   130 			$file_fixed = 0;
       
   131 			foreach (@lines) {
       
   132 				if (lc(@lines[$n]) =~ m/^separateprocesses/) {
       
   133 					@lines[$n] = '#' . @lines[$n];
       
   134 					$file_fixed = 1;
       
   135 				}
       
   136 				if (lc(@lines[$n]) =~ m/^uitestingsupport/) {
       
   137 					@lines[$n] = '#' . @lines[$n];
       
   138 					$file_fixed = 1;
       
   139 				}
       
   140 				$n++;
       
   141 			}
       
   142 			if ($file_fixed) { print $file . " fixed.\n"; }
       
   143 			untie @lines;
       
   144 		}
       
   145 	}
       
   146 
       
   147 	$current_iteration++;
    94 }
   148 }
       
   149 
       
   150 print "OK\n";
       
   151 exit 0;
    95 
   152 
    96 sub Wanted {
   153 sub Wanted {
    97     # only operate on .pkg files
   154     # only operate on .pkg files
    98 	/.pkg$/ or return;
   155 	/.pkg$/ or return;
    99     push (@files, $File::Find::name);
   156     push (@files, $File::Find::name);
   102 sub Parse_ini {
   159 sub Parse_ini {
   103     # only operate on .ini files
   160     # only operate on .ini files
   104 	/\.ini$/ or return;
   161 	/\.ini$/ or return;
   105     push (@ini_files, $File::Find::name);
   162     push (@ini_files, $File::Find::name);
   106 }
   163 }
       
   164 
       
   165 sub usage($)
       
   166 {
       
   167     my $error = shift;
       
   168     my $fh = $error == 0 ? *STDOUT : *STDERR;
       
   169     print $fh "hlm_prep_package.pl\n" .
       
   170             "Specify package path or csv file\n" .
       
   171             "synopsis:\n" .
       
   172             "  hlm_prep_package.pl --help\n" .
       
   173             "  hlm_prep_package.pl [--package-path=DIR] [--csv-file=FILE] [--bld-drive=DRIVE] \n" .
       
   174             "options:\n" .
       
   175             "  --help                        Display this help and exit.\n" .
       
   176             "  --package-path=DIR            DIR is the package location, e.g. H:\\sf\\app\\musicplayer.\n" .
       
   177             "  --csv-file=FILE               FILE is the full path to the csv file.\n" .
       
   178             "  --bld-drive=DRIVE             DRIVE is the subst'd drive on which the build is stored.\n";
       
   179     exit $error;            
       
   180 }
       
   181 
       
   182 sub help()
       
   183 {
       
   184     usage(0);
       
   185 }
       
   186 
       
   187 sub usage_error()
       
   188 {
       
   189     usage(1);
       
   190 }