Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/bin/createpackage.pl

    r769 r846  
    22#############################################################################
    33##
    4 ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4## Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    55## All rights reserved.
    66## Contact: Nokia Corporation (qt-info@nokia.com)
     
    6969Usage: createpackage.pl [options] templatepkg [target]-[platform] [certificate key [passphrase]]
    7070
    71 Where supported optiobns are as follows:
    72      [-i|install]            = Install the package right away using PC suite
     71Where supported options are as follows:
     72     [-i|install]            = Install the package right away using PC suite.
    7373     [-p|preprocess]         = Only preprocess the template .pkg file.
    74      [-c|certfile=<file>]    = The file containing certificate information for signing.
     74     [-c|certfile <file>]    = The file containing certificate information for signing.
    7575                               The file can have several certificates, each specified in
    7676                               separate line. The certificate, key and passphrase in line
     
    7878                               as a comments. Also empty lines are ignored. The paths in
    7979                               <file> can be absolute or relative to <file>.
    80      [-u|unsigned]           = Preserves the unsigned package
     80     [-u|unsigned]           = Preserves the unsigned package.
     81     [-o|only-unsigned]      = Creates only unsigned package.
     82     [-s|stub]               = Generates stub sis for ROM.
     83     [-n|sisname <name>]     = Specifies the final sis name.
     84     [-g|gcce-is-armv5]      = Convert gcce platform to armv5.
     85     [-d|dont-patch]         = Skip automatic patching of capabilities and pkg file if default certificate
     86                               is used. Instead non-self-signable capabilities just cause warnings.
    8187Where parameters are as follows:
    8288     templatepkg             = Name of .pkg file template
     
    8490     platform                = One of the supported platform
    8591                               winscw | gcce | armv5 | armv6 | armv7
     92                               Note that when packaging binaries built using gcce and symbian-sbsv2
     93                               mkspec, armv5 must be used for platform instead of gcce.
    8694     certificate             = The certificate file used for signing
    8795     key                     = The certificate's private key file
    88      passphrase              = The certificate's private key file's passphrase
     96     passphrase              = The passphrase of the certificate's private key file
    8997
    9098Example:
     
    102110If no certificate and key files are provided, either a RnD certificate or
    103111a self-signed certificate from QtDir\\src\\s60installs directory is used.
     112In the latter case the resulting package will also be automatically patched
     113using patch_capabilities.pl script, which makes it unsuitable for distribution.
     114Always specify certificates explicitly if you wish to distribute your package.
     115
    104116==============================================================================================
    105117
     
    115127my $preserveUnsigned = "";
    116128my $stub = "";
     129my $signed_sis_name = "";
     130my $onlyUnsigned = "";
     131my $convertGcce = "";
     132my $dontPatchCaps = "";
    117133
    118134unless (GetOptions('i|install' => \$install,
     
    120136                   'c|certfile=s' => \$certfile,
    121137                   'u|unsigned' => \$preserveUnsigned,
    122                    's|stub' => \$stub,)){
     138                   'o|only-unsigned' => \$onlyUnsigned,
     139                   's|stub' => \$stub,
     140                   'n|sisname=s' => \$signed_sis_name,
     141                   'g|gcce-is-armv5' => \$convertGcce,
     142                   'd|dont-patch' => \$dontPatchCaps,)) {
    123143    Usage();
     144}
     145
     146my $epocroot = $ENV{EPOCROOT};
     147my $epocToolsDir = "";
     148if ($epocroot ne "") {
     149    $epocroot =~ s,\\,/,g;
     150    if ($epocroot =~ m,[^/]$,) {
     151        $epocroot = $epocroot."/";
     152    }
     153    $epocToolsDir = "${epocroot}epoc32/tools/";
    124154}
    125155
     
    130160my $targetplatform = lc $ARGV[1];
    131161
     162if ($targetplatform eq "") {
     163    $targetplatform = "-";
     164}
     165
    132166my @tmpvalues = split('-', $targetplatform);
    133 my $target = $tmpvalues[0];
    134 my $platform = $tmpvalues[1];;
     167my $target;
     168$target = $tmpvalues[0] or $target = "";
     169my $platform;
     170$platform = $tmpvalues[1] or $platform = "";
     171
     172if ($platform =~ m/^gcce$/i) {
     173    if (($convertGcce ne "")) {
     174        $platform = "armv5";
     175    } elsif ($ENV{SBS_HOME}) {
     176        # Print a informative note in case suspected misuse is detected.
     177        print "\nNote: You should use armv5 as platform or specify -g parameter to convert platform\n";
     178        print "      when packaging gcce binaries built using symbian-sbsv2 mkspec.\n\n";
     179    }
     180}
    135181
    136182# Convert visual target to real target (debug->udeb and release->urel)
     
    138184$target =~ s/release/urel/i;
    139185
    140 my $certificate = $ARGV[2];
    141 my $key = $ARGV[3];
    142 my $passphrase = $ARGV[4];
     186my $certificate;
     187$certificate = $ARGV[2] or $certificate = "";
     188my $key;
     189$key = $ARGV[3] or $key = "";
     190my $passphrase;
     191$passphrase = $ARGV[4] or $passphrase = "";
    143192
    144193# Generate output pkg basename (i.e. file name without extension)
     
    146195my $preservePkgOutput = "";
    147196$pkgoutputbasename =~ s/_template/_$targetplatform/g;
     197$pkgoutputbasename =~ s/_installer\.pkg/_installer___temp\.pkg/g;
    148198if ($pkgoutputbasename eq $templatepkg) {
    149199    $preservePkgOutput = "1";
    150200}
    151201$pkgoutputbasename =~ s/\.pkg//g;
    152 $pkgoutputbasename = lc($pkgoutputbasename);
    153202
    154203# Store output file names to variables
    155 my $pkgoutput = lc($pkgoutputbasename.".pkg");
    156 my $sisoutputbasename = lc($pkgoutputbasename);
    157 $sisoutputbasename =~ s/_$targetplatform//g;
     204my $pkgoutput = $pkgoutputbasename.".pkg";
     205my $sisoutputbasename;
     206if ($signed_sis_name eq "") {
     207    $sisoutputbasename = $pkgoutputbasename;
     208    $sisoutputbasename =~ s/_$targetplatform//g;
     209    $sisoutputbasename =~ s/_installer___temp/_installer/g;
     210    $signed_sis_name = $sisoutputbasename.".sis";
     211} else {
     212    $sisoutputbasename = $signed_sis_name;
     213    if ($sisoutputbasename =~ m/(\.sis$|\.sisx$)/i) {
     214        $sisoutputbasename =~ s/$1//i;
     215    } else {
     216        $signed_sis_name = $signed_sis_name.".sis";
     217    }
     218}
     219
     220my $installer_unsigned_app_sis_name = "";
     221my $installer_app_sis_name = "";
     222
     223if ($templatepkg =~ m/_installer\.pkg$/i && $onlyUnsigned) {
     224    $installer_unsigned_app_sis_name = $templatepkg;
     225    $installer_unsigned_app_sis_name =~ s/_installer.pkg$/_unsigned.sis/i;
     226    $installer_app_sis_name = $installer_unsigned_app_sis_name;
     227    $installer_app_sis_name =~ s/_unsigned.sis$/.sis/;
     228}
     229
    158230my $unsigned_sis_name = $sisoutputbasename."_unsigned.sis";
    159 my $signed_sis_name = $sisoutputbasename.".sis";
    160 my $stub_sis_name = $sisoutputbasename."_stub.sis";
     231my $stub_sis_name = $sisoutputbasename.".sis";
    161232
    162233# Store some utility variables
    163234my $scriptpath = dirname(__FILE__);
    164235my $certtext = $certificate;
    165 my $certpath = $scriptpath;
    166 $certpath =~ s-^(.*[^\\])$-$1\\-o;          # ensure path ends with a backslash
    167 $certpath =~ s-/-\\-go;                     # for those working with UNIX shells
    168 $certpath =~ s-bin\\$-src\\s60installs\\-;  # certificates are one step up in hierarcy
     236# certificates are one step up in hierarchy
     237my $certpath = File::Spec->catdir($scriptpath, File::Spec->updir(), "src/s60installs/");
    169238
    170239# Check some pre-conditions and print error messages if needed.
    171240unless (length($templatepkg)) {
    172     print "\nError: Template PKG filename is not defined!\n";
     241    print "\nERROR: Template PKG filename is not defined!\n";
    173242    Usage();
    174 }
    175 
    176 # If the pkg file is not actually a template, there is no need for plaform or target.
    177 if ($templatepkg =~ m/_template\.pkg/i) {
    178     unless (length($platform) && length($target)) {
    179         print "\nError: Platform or target is not defined!\n";
    180         Usage();
    181     }
    182243}
    183244
     
    185246stat($templatepkg);
    186247unless( -e _ ) {
    187     print "\nError: Package description file '$templatepkg' does not exist!\n";
     248    print "\nERROR: Package description file '$templatepkg' does not exist!\n";
    188249    Usage();
    189250}
     
    192253if (length($certificate)) {
    193254    unless(length($key)) {
    194         print "\nError: Custom certificate key file parameter missing.!\n";
     255        print "\nERROR: Custom certificate key file parameter missing.!\n";
    195256        Usage();
    196257    }
     
    198259    #If no certificate is given, check default options
    199260    $certtext = "RnD";
    200     $certificate = $certpath."rd.cer";
    201     $key = $certpath."rd-key.pem";
     261    $certificate = File::Spec->catfile($certpath, "rd.cer");
     262    $key = File::Spec->catfile($certpath, "rd-key.pem");
    202263
    203264    stat($certificate);
    204265    unless( -e _ ) {
    205266        $certtext = "Self Signed";
    206         $certificate = $certpath."selfsigned.cer";
    207         $key = $certpath."selfsigned.key";
     267        $certificate = File::Spec->catfile($certpath, "selfsigned.cer");
     268        $key = File::Spec->catfile($certpath, "selfsigned.key");
    208269    }
    209270}
     
    227288        # Do some validation
    228289        unless(scalar(@certinfo) >= 2 && scalar(@certinfo) <= 3 && length($certinfo[0]) && length($certinfo[1]) ) {
    229             print "\nError: $certfile line '$_' does not contain valid information!\n";
     290            print "\nERROR: $certfile line '$_' does not contain valid information!\n";
    230291            Usage();
    231292        }
     
    237298# Remove any existing .sis packages
    238299unlink $unsigned_sis_name;
    239 unlink $signed_sis_name;
     300if (!$onlyUnsigned) {
     301    unlink $signed_sis_name;
     302}
    240303if (!$preservePkgOutput) {
    241304    unlink $pkgoutput;
     
    243306
    244307# Preprocess PKG
     308
    245309local $/;
    246310# read template file
    247 open( TEMPLATE, $templatepkg) or die "Error '$templatepkg': $!\n";
     311open( TEMPLATE, $templatepkg) or die "ERROR: '$templatepkg': $!";
    248312$_=<TEMPLATE>;
    249313close (TEMPLATE);
     314
     315# If the pkg file does not contain macros, there is no need for platform or target.
     316if (m/\$\(PLATFORM\)/) {
     317    unless (length($platform) && length($target)) {
     318        print "\nERROR: Platform or target is not defined!\n";
     319        Usage();
     320    }
     321}
    250322
    251323# replace the PKG variables
     
    253325s/\$\(TARGET\)/$target/gm;
    254326
     327if ($installer_unsigned_app_sis_name ne "") {
     328    s/$installer_app_sis_name\"/$installer_unsigned_app_sis_name\"/;
     329}
     330
    255331#write the output
    256 open( OUTPUT, ">$pkgoutput" ) or die "Error '$pkgoutput' $!\n";
     332open( OUTPUT, ">$pkgoutput" ) or die "ERROR: '$pkgoutput' $!";
    257333print OUTPUT $_;
    258334close OUTPUT;
     
    263339
    264340if($stub) {
    265     if(!($ENV{EPOCROOT})) { die("EPOCROOT must be set to create stub sis files"); }
    266     my $systeminstall = "$ENV{EPOCROOT}epoc32/data/z/system/install";
     341    if(!($epocroot)) { die("ERROR: EPOCROOT must be set to create stub sis files"); }
     342    my $systeminstall = "${epocroot}epoc32/data/z/system/install";
    267343    mkpath($systeminstall);
    268344    my $stub_sis_name = $systeminstall."/".$stub_sis_name;
    269345    # Create stub SIS.
    270     system ("makesis -s $pkgoutput $stub_sis_name");
     346    system ("${epocToolsDir}makesis -s $pkgoutput $stub_sis_name");
    271347} else {
     348    if ($certtext eq "Self Signed"
     349        && !@certificates
     350        && $templatepkg !~ m/_installer\.pkg$/i
     351        && !$onlyUnsigned) {
     352        my $patch_capabilities = File::Spec->catfile(dirname($0), "patch_capabilities");
     353        if ($dontPatchCaps) {
     354            system ("$patch_capabilities -c $pkgoutput") and print ("Warning: Package check for self-signing viability failed. Installing the package on a device will most likely fail!\n\n");
     355        } else {
     356            print("Auto-patching self-signed package.\n");
     357            system ("$patch_capabilities $pkgoutput") and die ("ERROR: Automatic patching failed");
     358        }
     359    }
     360
    272361    # Create SIS.
    273     system ("makesis $pkgoutput $unsigned_sis_name");
     362    # The 'and' is because system uses 0 to indicate success.
     363    system ("${epocToolsDir}makesis $pkgoutput $unsigned_sis_name") and die ("ERROR: makesis failed");
     364
    274365    print("\n");
    275366
     367    my $targetInsert = "";
     368    if ($targetplatform ne "-") {
     369        $targetInsert = " for $targetplatform";
     370    }
     371
     372    if ($onlyUnsigned) {
     373        stat($unsigned_sis_name);
     374        if( -e _ ) {
     375            print ("Successfully created unsigned package ${unsigned_sis_name}${targetInsert}!\n");
     376        } else {
     377            print ("\nUnsigned package creation failed!\n");
     378        }
     379
     380        if (!$preservePkgOutput) {
     381            unlink $pkgoutput;
     382        }
     383        print ("\n");
     384        exit;
     385    }
     386
    276387    # Sign SIS with certificate info given as an argument.
    277     system ("signsis $unsigned_sis_name $signed_sis_name $certificate $key $passphrase");
     388    my $relcert = File::Spec->abs2rel($certificate);
     389    my $relkey = File::Spec->abs2rel($key);
     390    # The 'and' is because system uses 0 to indicate success.
     391    system ("${epocToolsDir}signsis $unsigned_sis_name $signed_sis_name $relcert $relkey $passphrase") and die ("ERROR: signsis failed");
    278392
    279393    # Check if creating signed SIS Succeeded
    280394    stat($signed_sis_name);
    281395    if( -e _ ) {
    282         my $targetInsert = "";
    283         if ($targetplatform ne "-") {
    284             $targetInsert = "for $targetplatform ";
    285         }
    286         print ("Successfully created $signed_sis_name ${targetInsert}using certificate: $certtext!\n");
     396        print ("Successfully created signed package ${signed_sis_name}${targetInsert} using certificate: $certtext!\n");
    287397
    288398        # Sign with additional certificates & keys
    289399        for my $row ( @certificates ) {
    290400            # Get certificate absolute file names, relative paths are relative to certfilepath
    291             my $abscert = File::Spec->rel2abs( $row->[0], $certfilepath);
    292             my $abskey = File::Spec->rel2abs( $row->[1], $certfilepath);
    293 
    294             system ("signsis $signed_sis_name $signed_sis_name $abscert $abskey $row->[2]");
     401            my $relcert = File::Spec->abs2rel(File::Spec->rel2abs( $row->[0], $certfilepath));
     402            my $relkey = File::Spec->abs2rel(File::Spec->rel2abs( $row->[1], $certfilepath));
     403
     404            system ("${epocToolsDir}signsis $signed_sis_name $signed_sis_name $relcert $relkey $row->[2]");
    295405            print ("\tAdditionally signed the SIS with certificate: $row->[0]!\n");
    296406        }
     
    313423        print ("\nSIS creation failed!\n");
    314424    }
     425    print ("\n");
    315426}
    316427
Note: See TracChangeset for help on using the changeset viewer.