os/ossrv/lowlevellibsandfws/pluginfw/TestExecute/EComSWITests/data/tem_dosis.pl
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/pluginfw/TestExecute/EComSWITests/data/tem_dosis.pl	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,207 @@
     1.4 +#!perl
     1.5 +
     1.6 +# Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.7 +# All rights reserved.
     1.8 +# This component and the accompanying materials are made available
     1.9 +# under the terms of "Eclipse Public License v1.0"
    1.10 +# which accompanies this distribution, and is available
    1.11 +# at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.12 +#
    1.13 +# Initial Contributors:
    1.14 +# Nokia Corporation - initial contribution.
    1.15 +#
    1.16 +# Contributors:
    1.17 +#
    1.18 +# Description:
    1.19 +#
    1.20 +
    1.21 +use strict;
    1.22 +use File::Copy;
    1.23 +use Getopt::Long;
    1.24 +use File::Basename;
    1.25 +use File::Spec;
    1.26 +
    1.27 +my $basedir;
    1.28 +my $platform;
    1.29 +my $cfg;
    1.30 +my $certpem;
    1.31 +my $certkey;
    1.32 +my $outdir;
    1.33 +my $maketrgt;
    1.34 +my $sources;
    1.35 +my $stublist;
    1.36 +
    1.37 +GetOptions(
    1.38 +  'basedir=s' => \$basedir,
    1.39 +  'platform=s' => \$platform,
    1.40 +  'cfg=s' => \$cfg,
    1.41 +  'certpem=s' => \$certpem,
    1.42 +  'certkey=s' => \$certkey,
    1.43 +  'outdir=s' => \$outdir,
    1.44 +  'maketrgt=s' => \$maketrgt,
    1.45 +  'sources=s' => \$sources,
    1.46 +  'stublist=s' => \$stublist,
    1.47 +);
    1.48 +
    1.49 +my $ROOT = $ENV{EPOCROOT};
    1.50 +$ROOT =~ s#\\#/#g;
    1.51 +
    1.52 +if ($maketrgt =~ /RELEASABLES/i or $maketrgt =~ /EXTRATARGET/i)
    1.53 +{
    1.54 +  my @targets = ();
    1.55 +  my @extra = ();
    1.56 +  my $s;
    1.57 +  my @a = split(/\s+/,  $sources);
    1.58 +  foreach my $pkg (@a)
    1.59 +  {
    1.60 +	my $isStub = $stublist =~ /\b$pkg\b/i;
    1.61 +	my $destdir = GetTargetDir($isStub);
    1.62 +	my $trgtname = PkgToSis($pkg, $isStub);
    1.63 +	$s =  "$destdir/$trgtname";
    1.64 +    GetExternalForm(\$s);
    1.65 +   	push(@targets, $s);
    1.66 +
    1.67 +    if ($destdir =~ /epoc32\/data\/z\/.*\/udeb/ || $isStub)
    1.68 +	{
    1.69 +	  my $extratrgt = $destdir;
    1.70 +	  $extratrgt =~ s/\/udeb//;
    1.71 +	  $s = "$extratrgt/$trgtname";
    1.72 +      GetExternalForm(\$s);
    1.73 +	  push(@extra, $s);
    1.74 +	}
    1.75 +  }
    1.76 +
    1.77 +  $s = join(' ', @targets);
    1.78 +  $s = join(' ', @extra) if ($maketrgt =~ /EXTRATARGET/i);
    1.79 +  print "$s";
    1.80 +  exit(0);
    1.81 +}
    1.82 +
    1.83 +# Getting here is build final. The pkg file must be in basedir.
    1.84 +chdir($basedir);
    1.85 +
    1.86 +# $ARGV[0] is one of the targets generated in RELEASABLES above.
    1.87 +my $arg = $ARGV[0];
    1.88 +my $filename = basename($arg);
    1.89 +my $trgtdir = dirname($arg);
    1.90 +RecursiveMkDir($trgtdir);
    1.91 +
    1.92 +my $isStub;
    1.93 +($filename, $isStub) = SisToPkg($filename);
    1.94 +die "Pkg $filename does not exist!\n" if (! -f $filename);
    1.95 +
    1.96 +my $cmd;
    1.97 +if ($isStub)
    1.98 +{
    1.99 +  $cmd = "makesis -s $filename $arg";
   1.100 +  system($cmd);
   1.101 +}
   1.102 +else
   1.103 +{
   1.104 +  # change the source locations in pkg file
   1.105 +  my $generatedpkg = "generated.pkg";
   1.106 +  EditPkgFile($filename, $generatedpkg);
   1.107 +
   1.108 +  my $generatedsis = "generated.sis";
   1.109 +  $cmd = "makesis $generatedpkg $generatedsis";
   1.110 +  system($cmd);
   1.111 +
   1.112 +  $cmd = "signsis -S $generatedsis $arg $certpem $certkey";
   1.113 +  system($cmd);
   1.114 +
   1.115 +  # make an extra copy in /epoc32/data/z/tef_ecomswi.
   1.116 +  # iby files normally do not expect files in udeb or urel
   1.117 +  # under /epoc32/data/z.
   1.118 +  if ($trgtdir =~ /\bepoc32\b.\bdata\b.\bz\b.*\budeb\b/)
   1.119 +  {
   1.120 +	my $extratrgt = $arg;
   1.121 +	$extratrgt =~ s/[\/\\]udeb//;
   1.122 +	copy($arg, $extratrgt);
   1.123 +  }
   1.124 +
   1.125 +  unlink($generatedsis);
   1.126 +  unlink($generatedpkg);
   1.127 +}
   1.128 +
   1.129 +###################################################
   1.130 +# subroutines
   1.131 +###################################################
   1.132 +sub GetTargetDir
   1.133 +{
   1.134 +  my $isStub = shift;
   1.135 +
   1.136 +  # for armv5, store all artefacts in data/z.
   1.137 +  my $d = "${ROOT}epoc32/data/z/$outdir/$cfg";
   1.138 +  $d =~ s#/$cfg## if ($isStub);
   1.139 +
   1.140 +  if ($platform =~ /winscw/i)
   1.141 +  {
   1.142 +    $d = "${ROOT}epoc32/release/$platform/$cfg/z/$outdir";
   1.143 +    $d = "${ROOT}epoc32/release/$platform/$cfg/z/system/install" if ($isStub);
   1.144 +  }
   1.145 +  return $d;
   1.146 +}
   1.147 +
   1.148 +sub PkgToSis
   1.149 +{
   1.150 +  my $f = shift;
   1.151 +  my $isStub = shift;
   1.152 +  $f =~ s/\.pkg$//i;
   1.153 +  my $suffix = ($isStub) ? ".sis" : "signed.sis";
   1.154 +  $f .= $suffix;
   1.155 +  return $f;
   1.156 +}
   1.157 +
   1.158 +sub SisToPkg
   1.159 +{
   1.160 +  my $f = shift;
   1.161 +  my $isStub = 1;
   1.162 +  $isStub = 0 if ($f =~ s/signed.sis$//);
   1.163 +  $f =~ s/\.sis$//;
   1.164 +  $f .= ".pkg";
   1.165 +  return ($f, $isStub);
   1.166 +}
   1.167 +
   1.168 +sub EditPkgFile
   1.169 +{
   1.170 +  my $inf = shift;
   1.171 +  my $outf = shift;
   1.172 +
   1.173 +  open(FIN, $inf) or die "fail to read $inf $!\n";
   1.174 +  open(FOUT, ">$outf") or die "fail to write $outf $!\n";
   1.175 +  local $/ = undef;
   1.176 +  my $data = <FIN>;
   1.177 +  close(FIN);
   1.178 +
   1.179 +  $data =~ s/_PLATFORM_/$platform/g;
   1.180 +  $data =~ s/_CFG_/$cfg/g;
   1.181 +  print FOUT $data;
   1.182 +  close(FOUT);
   1.183 +}
   1.184 +
   1.185 +# simple one, cannot handle cases like \\londata04\somedir
   1.186 +sub RecursiveMkDir
   1.187 +{
   1.188 +  my $path = shift;
   1.189 +  $path =~ s#\\#/#g;
   1.190 +
   1.191 +  my $i = 1;
   1.192 +  my $s;
   1.193 +  do {
   1.194 +	$i = index($path, "/", $i);
   1.195 +	if ($i != -1)
   1.196 +	{
   1.197 +	  $s = substr($path, 0, $i++);
   1.198 +	  mkdir($s, 0777) if (! -d $s);
   1.199 +	}
   1.200 +  } while ($i != -1);
   1.201 +
   1.202 +  mkdir($path, 0777) if (! -d $path);
   1.203 +}
   1.204 +
   1.205 +sub GetExternalForm
   1.206 +{
   1.207 +  my $refs = shift;
   1.208 +  my @a = split(/[\/\\]/, $$refs);
   1.209 +  $$refs = File::Spec->catfile(@a);
   1.210 +}