Skip to content

Commit

Permalink
Support for template PKG file.
Browse files Browse the repository at this point in the history
This commit changes qmake to generate only one template pkg file,
instead of one for each supported platform and build.

Due to this change createpackage.bat script now need to be called with
two additional parameters - platform and target. Example of needed changes:

Instead of old way:
	>createpackage.bat [-i] pkgfile [certificate key [passphrase]]
The new implementation works as:
	>createpackage.bat [-i] pkgfile platform build [certificate key [passphrase]]

In addition createpackage.bat backend is replaced by createpackage.pl,
it takes care of preprocesing the pkg file, i.e. expanding the variables with
their values and calling the makesis and signsis with right parameters.

Perl is used to make implementation more cross-platform.

Task: 259037
RevBy: Miikka Heikkinen
  • Loading branch information
Janne Anttila committed Aug 27, 2009
1 parent 8c71456 commit f189e00
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 123 deletions.
105 changes: 1 addition & 104 deletions bin/createpackage.bat
Original file line number Diff line number Diff line change
@@ -1,106 +1,3 @@
@echo off

set installsigned_old=%installsigned%
set pkgfile_old=%pkgfile%
set basename_old=%basename%
set signsis1_old=%signsis1%
set signsis2_old=%signsis2%
set signsis3_old=%signsis3%
set unsigned_sis_name_old=%unsigned_sis_name%
set signed_sis_name_old=%signed_sis_name%
set scriptpath_old=%scriptpath%
set certificate_old=%certificate%

rem Help text
if "%1"=="" (
echo Convenience script for creating signed packages you can install on your phone.
echo Usage: createpackage.bat [-i] myexample_armv5_udeb.pkg [certificate key [passphrase]]
echo.
echo If no certificate and key files are provided, either a RnD certificate or
echo a self-signed certificate from Qt installation root directory is used.
echo.
echo To install the package right away using PC suite, use -i argument.
goto done
)

if "%1"=="-i" (
set installsigned=true
set pkgfile=%2
set basename=%~n2
set signsis1=%3
set signsis2=%4
set signsis3=%5
) else (
set installsigned=false
set pkgfile=%1
set basename=%~n1
set signsis1=%2
set signsis2=%3
set signsis3=%4
)

set unsigned_sis_name=%basename%_unsigned.sis
set signed_sis_name=%basename%.sis

rem Get absolute path to this script
set scriptpath=%~dp0

rem Check the .pkg actually exists.
if not exist %pkgfile% (
echo Error: Package description file '%pkgfile%' does not exist.
goto done
)

rem Remove any existing .sis packages
if exist %signed_sis_name% del %signed_sis_name%
if exist %unsigned_sis_name% del %unsigned_sis_name%

rem Create .sis package
makesis %pkgfile% %unsigned_sis_name%

rem If no certificate is given, check default options
if x%signsis1% == x (
rem If RnD certificate is not found, sign with self signed certificate
if not exist %scriptpath%..\rd.cer (
set certificate=Self signed
signsis %unsigned_sis_name% %signed_sis_name% %scriptpath%..\selfsigned.cer %scriptpath%..\selfsigned.key
goto install
)

rem Sign with RnD certificate
set certificate=RnD
signsis %unsigned_sis_name% %signed_sis_name% %scriptpath%..\rd.cer %scriptpath%..\rd-key.pem
) else (
if x%signsis2% == x (
echo Custom certificate key file parameter missing.
goto cleanup
)

set certificate=%signsis1%
signsis %unsigned_sis_name% %signed_sis_name% %signsis1% %signsis2% %signsis3%
)

:install
if exist %signed_sis_name% (
echo Successfully created %signed_sis_name% using certificate %certificate%
if "%installsigned%" == "true" (
echo Installing %signed_sis_name%...
call %signed_sis_name%
)
)

:cleanup
if exist %unsigned_sis_name% del %unsigned_sis_name%

:done

set installsigned=%installsigned_old%
set pkgfile=%pkgfile_old%
set basename=%basename_old%
set signsis1=%signsis1_old%
set signsis2=%signsis2_old%
set signsis3=%signsis3_old%
set unsigned_sis_name=%unsigned_sis_name_old%
set signed_sis_name=%signed_sis_name_old%
set scriptpath=%scriptpath_old%
set certificate=%certificate_old%
perl %scriptpath%createpackage.pl %*
156 changes: 156 additions & 0 deletions bin/createpackage.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#!\usr\bin\perl
############################################################################################
#
# Convenience script for creating signed packages you can install on your phone.
#
# Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
# Contact: Qt Software Information (qt-info@nokia.com)
#
############################################################################################

use strict;

# use a command-line parsing module
use Getopt::Long;
# Use file name parsing module
use File::Basename;

sub Usage() {
print "\n";
print "==========================================================================================\n";
print "Convenience script for creating signed packages you can install on your phone.\n";
print "\n";
print "Usage: createpackage.pl [-i] templatepkg platform target [certificate key [passphrase]]\n";
print "\n";
print "Where parameters are as follows:\n";
print " [-i|install] = Install the package right away using PC suite\n";
print " templatepkg = Name of .pkg file template\n";
print " platform = One of the supported platform\n";
print " GCCE | ARMV5 | ARMV6 | ARMV7\n";
print " target = Either UDEB or UREL\n";
print " certificate = The certificate file used for signing\n";
print " key = The certificate's private key file\n";
print " passphrase = The certificate's private key file's passphrase\n";
print "\n";
print "If no certificate and key files are provided, either a RnD certificate or\n";
print "a self-signed certificate from Qt installation root directory is used.\n";
print "\n";
print "==========================================================================================\n";
exit();
}

# Read given options
my $install = "";
unless (GetOptions('i|install' => \$install)){
Usage();
}

# Read params to variables
my $templatepkg = $ARGV[0];
my $platform = uc $ARGV[1];
my $target = uc $ARGV[2];
my $visualtarget = $target;
$visualtarget =~ s/udeb/debug/i;
$visualtarget =~ s/urel/release/i;

my $certificate = $ARGV[3];
my $key = $ARGV[4];
my $passphrase = $ARGV[5];

# Generate output pkg basename (i.e. file name without extension)
my $pkgoutputbasename = $templatepkg;
$pkgoutputbasename =~ s/_template\.pkg/_$visualtarget-$platform/g;
$pkgoutputbasename = lc($pkgoutputbasename);

# Store output file names to variables
my $pkgoutput = lc($pkgoutputbasename.".pkg");
my $unsigned_sis_name = $pkgoutputbasename."_unsigned.sis";
my $signed_sis_name = $pkgoutputbasename.".sis";

# Store some utility variables
my $scriptpath = dirname(__FILE__);
my $certtext = $certificate;
my $certpath = $scriptpath;
$certpath =~ s-^(.*[^\\])$-$1\\-o; # ensure path ends with a backslash
$certpath = $certpath."../"; # certificates are one step up in hierarcy
$certpath =~ s-/-\\-go; # for those working with UNIX shells

# Check some pre-conditions and print error messages if needed
unless (length($templatepkg) && length($platform) && length($target)) {
print "\nError: Template PKG filename, platform or target is not defined!\n";
Usage();
}

# Check template exist
stat($templatepkg);
unless( -e _ ) {
print "\nError: Package description file '$templatepkg' does not exist!\n";
Usage();
}

# Check certifcate preconditions and set default certificate variables if needed
if (length($certificate)) {
unless(length($key)) {
print "\nError: Custom certificate key file parameter missing.!\n";
Usage();
}
} else {
#If no certificate is given, check default options
$certtext = "RnD";
$certificate = $certpath."rd.cer";
$key = $certpath."rd-key.pem";

stat($certificate);
unless( -e _ ) {
$certtext = "Self Signed";
$certificate = $certpath."selfsigned.cer";
$key = $certpath."selfsigned.key";
}
}

# Remove any existing .sis packages
unlink $unsigned_sis_name;
unlink $signed_sis_name;
unlink $pkgoutput;

# Preprocess PKG
local $/;
# read template file
open( TEMPLATE, $templatepkg) or die "Error '$templatepkg': $!\n";
$_=<TEMPLATE>;
close (TEMPLATE);

# replace the PKG variables
s/\$\(PLATFORM\)/$platform/gm;
s/\$\(TARGET\)/$target/gm;

#write the output
open( OUTPUT, ">$pkgoutput" ) or die "Error '$pkgoutput' $!\n";
print OUTPUT $_;
close OUTPUT;

# Create and sign SIS
system ("makesis $pkgoutput $unsigned_sis_name");
system ("signsis $unsigned_sis_name $signed_sis_name $certificate $key $passphrase");

# Check if creating signed SIS Succeeded
stat($signed_sis_name);
if( -e _ ) {
print ("\nSuccessfully created $signed_sis_name using certificate $certtext!\n");

# remove temporary pkg and unsigned sis
unlink $pkgoutput;
unlink $unsigned_sis_name;

# Install the sis if requested
if ($install) {
print ("\nInstalling $signed_sis_name...\n");
system ("$signed_sis_name");
}
} else {
# Lets leave the generated PKG for problem solving purposes
print ("\nSIS creation failed!\n");
}


#end of file
2 changes: 1 addition & 1 deletion qmake/generators/symbian/initprojectdeploy_symbian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void initProjectDeploySymbian(QMakeProject* project,
if (deployBinaries) {
// Executables and libraries are deployed to \sys\bin
QFileInfo releasePath(epocRoot() + "epoc32\\release\\" + platform + "\\" + build + "\\");
deploymentList.append(CopyItem(Option::fixPathToLocalOS(releasePath.absolutePath() + "\\" + info.fileName()),
deploymentList.append(CopyItem(Option::fixPathToLocalOS(releasePath.absolutePath() + "\\" + info.fileName(), false, true),
Option::fixPathToLocalOS(deploymentDrive + QLatin1String(SYSBIN_DIR "\\") + info.fileName())));
}
if (isPlugin(info, devicePath)) {
Expand Down
23 changes: 6 additions & 17 deletions qmake/generators/symbian/symmake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,7 @@ bool SymbianMakefileGenerator::writeMakefile(QTextStream &t)
}

if (generatePkg) {
QStringList platformList = project->values("SYMBIAN_PLATFORMS");
foreach(QString platform, platformList) {
if (platform.compare("WINSCW", Qt::CaseInsensitive)) {
generatePkgFile(platform.toLower(), "udeb", iconFile);
generatePkgFile(platform.toLower(), "urel", iconFile);
}
}
generatePkgFile(iconFile);
}

writeBldInfContent(t, generatePkg);
Expand Down Expand Up @@ -258,13 +252,10 @@ bool SymbianMakefileGenerator::writeMakefile(QTextStream &t)
return true;
}

void SymbianMakefileGenerator::generatePkgFile(const QString &compiler, const QString &config, const QString &iconFile)
void SymbianMakefileGenerator::generatePkgFile(const QString &iconFile)
{
QString build = (config == "udeb") ? "debug" : "release";
QString pkgFilename = QString("%1_%2-%3.%4")
QString pkgFilename = QString("%1_template.%2")
.arg(fileInfo(project->projectFile()).completeBaseName())
.arg(build)
.arg(compiler)
.arg("pkg");
QFile pkgFile(pkgFilename);
if (!pkgFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
Expand Down Expand Up @@ -344,10 +335,8 @@ void SymbianMakefileGenerator::generatePkgFile(const QString &compiler, const QS
QString installPathRegResource = "!:\\private\\10003a3f\\import\\apps";

// Find location of builds
QString epocReleasePath = QString("%1epoc32/release/%2/%3")
.arg(epocRoot())
.arg(compiler)
.arg(config);
QString epocReleasePath = QString("%1epoc32/release/$(PLATFORM)/$(TARGET)")
.arg(epocRoot());


if (targetType == TypeExe) {
Expand Down Expand Up @@ -391,7 +380,7 @@ void SymbianMakefileGenerator::generatePkgFile(const QString &compiler, const QS
QString remoteTestPath;
remoteTestPath = QString("!:\\private\\%1").arg(privateDirUid);

initProjectDeploySymbian(project, depList, remoteTestPath, true, compiler, config, generatedDirs, generatedFiles);
initProjectDeploySymbian(project, depList, remoteTestPath, true, "$(PLATFORM)", "$(TARGET)", generatedDirs, generatedFiles);
if (depList.size())
t << "; DEPLOYMENT" << endl;
for (int i = 0; i < depList.size(); ++i) {
Expand Down
2 changes: 1 addition & 1 deletion qmake/generators/symbian/symmake.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class SymbianMakefileGenerator : public MakefileGenerator
QString canonizePath(const QString& origPath);

virtual bool writeMakefile(QTextStream &t);
void generatePkgFile(const QString &compiler, const QString &config, const QString &iconFile);
void generatePkgFile(const QString &iconFile);
bool containsStartWithItem(const QChar &c, const QStringList& src);

virtual void init();
Expand Down

0 comments on commit f189e00

Please sign in to comment.