source: trunk/bin/patch_capabilities.pl@ 1106

Last change on this file since 1106 was 846, checked in by Dmitry A. Kuminov, 14 years ago

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

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 15.5 KB
Line 
1#!/usr/bin/perl
2#############################################################################
3##
4## Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5## All rights reserved.
6## Contact: Nokia Corporation ([email protected])
7##
8## This file is part of the S60 port of the Qt Toolkit.
9##
10## $QT_BEGIN_LICENSE:LGPL$
11## Commercial Usage
12## Licensees holding valid Qt Commercial licenses may use this file in
13## accordance with the Qt Commercial License Agreement provided with the
14## Software or, alternatively, in accordance with the terms contained in
15## a written agreement between you and Nokia.
16##
17## GNU Lesser General Public License Usage
18## Alternatively, this file may be used under the terms of the GNU Lesser
19## General Public License version 2.1 as published by the Free Software
20## Foundation and appearing in the file LICENSE.LGPL included in the
21## packaging of this file. Please review the following information to
22## ensure the GNU Lesser General Public License version 2.1 requirements
23## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24##
25## In addition, as a special exception, Nokia gives you certain additional
26## rights. These rights are described in the Nokia Qt LGPL Exception
27## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28##
29## GNU General Public License Usage
30## Alternatively, this file may be used under the terms of the GNU
31## General Public License version 3.0 as published by the Free Software
32## Foundation and appearing in the file LICENSE.GPL included in the
33## packaging of this file. Please review the following information to
34## ensure the GNU General Public License version 3.0 requirements will be
35## met: http://www.gnu.org/copyleft/gpl.html.
36##
37## If you have questions regarding the use of this file, please contact
38## Nokia at [email protected].
39## $QT_END_LICENSE$
40##
41#############################################################################
42
43#######################################################################
44#
45# A script for setting binary capabilities based on .pkg file contents.
46#
47#######################################################################
48
49#
50# Note: Please make sure to output all changes done to the pkg file in a print statements
51# starting with "Patching: " to ease integration into IDEs!
52#
53
54use File::Copy;
55use File::Spec;
56
57sub Usage() {
58 print("This script can be used to set capabilities of all binaries\n");
59 print("specified for deployment in a .pkg file.\n");
60 print("If no capabilities are given, the binaries will be given the\n");
61 print("capabilities supported by self-signed certificates.\n\n");
62 print(" *** NOTE: If *_template.pkg file is given and one is using symbian-abld or\n");
63 print(" symbian-sbsv2 platform, 'target-platform' is REQUIRED. ***\n\n");
64 print(" *** NOTE2: When patching gcce binaries built with symbian-sbsv2 toolchain,\n");
65 print(" armv5 must be specified as platform.\n");
66 print("\nUsage: patch_capabilities.pl [-c] pkg_filename [target-platform [capability list]]\n");
67 print("\nE.g. patch_capabilities.pl myapp_template.pkg release-armv5 \"All -TCB\"\n");
68 print("\nThe parameter -c can be used to just check if package is compatible with self-signing\n");
69 print("without actually doing any patching.\n");
70 print("Explicit capability list cannot be used with -c parameter.\n");
71 exit();
72}
73
74sub trim($) {
75 my $string = shift;
76 $string =~ s/^\s+//;
77 $string =~ s/\s+$//;
78 return $string;
79}
80
81my $epocroot = $ENV{EPOCROOT};
82my $epocToolsDir = "";
83if ($epocroot ne "") {
84 $epocroot =~ s,\\,/,g;
85 if ($epocroot =~ m,[^/]$,) {
86 $epocroot = $epocroot."/";
87 }
88 $epocToolsDir = "${epocroot}epoc32/tools/";
89}
90
91my $nullDevice = "/dev/null";
92$nullDevice = "NUL" if ($^O =~ /MSWin/);
93
94my @capabilitiesToAllow = ("LocalServices", "NetworkServices", "ReadUserData", "UserEnvironment", "WriteUserData", "Location");
95my @capabilitiesSpecified = ();
96
97# If arguments were given to the script,
98if (@ARGV)
99{
100 # Parse the first given script argument as a ".pkg" file name.
101 my $pkgFileName = shift(@ARGV);
102 my $justCheck = "";
103 my $msgPrefix = "Patching:";
104
105 if ($pkgFileName eq "-c") {
106 $pkgFileName = shift(@ARGV);
107 $justCheck = true;
108 $msgPrefix = "Warning:";
109 }
110
111 # These variables will only be set for template .pkg files.
112 my $target;
113 my $platform;
114
115 # Check if using template .pkg and set target/platform variables
116 if (($pkgFileName =~ m|_template\.pkg$|i) && -r($pkgFileName))
117 {
118 my $targetplatform;
119 my $templateFile;
120 my $templateContents;
121 open($templateFile, "< $pkgFileName") or die ("Could not open $pkgFileName");
122 $templateContents = <$templateFile>;
123 close($templateFile);
124 unless (($targetplatform = shift(@ARGV)) || $templateContents !~ /\$\(PLATFORM\)/)
125 {
126 Usage();
127 }
128 $targetplatform = "-" if (!$targetplatform);
129 my @tmpvalues = split('-', $targetplatform);
130 $target = $tmpvalues[0];
131 $platform = $tmpvalues[1];
132
133 # Convert visual target to real target (debug->udeb and release->urel)
134 $target =~ s/debug/udeb/i;
135 $target =~ s/release/urel/i;
136
137 if (($platform =~ m/^gcce$/i) && ($ENV{SBS_HOME})) {
138 # Print a informative note in case suspected misuse is detected.
139 print "\nNote: You must use armv5 as platform when packaging gcce binaries built using symbian-sbsv2 mkspec.\n";
140 }
141 }
142
143 # If the specified ".pkg" file exists (and can be read),
144 if (($pkgFileName =~ m|\.pkg$|i) && -r($pkgFileName))
145 {
146 print ("\n");
147 if ($justCheck) {
148 print ("Checking");
149 } else {
150 print ("Patching");
151 }
152 print (" package file and relevant binaries...\n");
153
154 if (!$justCheck) {
155 # If there are more arguments given, parse them as capabilities.
156 if (@ARGV)
157 {
158 @capabilitiesSpecified = ();
159 while (@ARGV)
160 {
161 push (@capabilitiesSpecified, pop(@ARGV));
162 }
163 }
164 }
165
166 # Start with no binaries listed.
167 my @binaries = ();
168
169 my $tempPkgFileName = $pkgFileName."_@@TEMP@@";
170
171 if (!$justCheck) {
172 unlink($tempPkgFileName);
173 open (NEW_PKG, ">>".$tempPkgFileName);
174 }
175 open (PKG, "<".$pkgFileName);
176
177 my $checkFailed = "";
178 my $somethingPatched = "";
179
180 # Parse each line.
181 while (<PKG>)