|
1 #!perl |
|
2 |
|
3 # InstallSupplementaryKit.pl - Source Code Integration Script |
|
4 |
|
5 # Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
6 # All rights reserved. |
|
7 # This component and the accompanying materials are made available |
|
8 # under the terms of "Eclipse Public License v1.0" |
|
9 # which accompanies this distribution, and is available |
|
10 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
11 # |
|
12 # Initial Contributors: |
|
13 # Nokia Corporation - initial contribution. |
|
14 # |
|
15 # Contributors: |
|
16 # |
|
17 # Description: |
|
18 # Versions: |
|
19 # 1.0 Initial |
|
20 # 1.1 No warnings about pre-existing directories |
|
21 # 1.2 MCL version, adds -buildfromclean flag to move epoc32 directory and -platform flag |
|
22 # |
|
23 # |
|
24 |
|
25 |
|
26 use Getopt::Long; |
|
27 use File::Path; |
|
28 use File::CheckTree; |
|
29 |
|
30 |
|
31 # ---------------------------- Global variables ------------------------------- |
|
32 |
|
33 my $JarFile = ""; |
|
34 my $TargetDirectory = ""; |
|
35 my $BuildFromClean = 0; |
|
36 my $Platform = ""; |
|
37 my $Options = ""; |
|
38 |
|
39 # start the program |
|
40 main(); |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 # ---------------------------- Start of Main() -------------------------------- |
|
46 sub main() |
|
47 { |
|
48 if (@ARGV) |
|
49 { |
|
50 CommandLineInterface(); |
|
51 } |
|
52 else |
|
53 { |
|
54 UserInterface(); |
|
55 } |
|
56 |
|
57 |
|
58 # extract any *.sdkpkg files from the Jar file into the target directory |
|
59 system("unzip -o \"$JarFile\" \"*.sdkpkg\" -d \"$TargetDirectory\""); |
|
60 |
|
61 print "\n"; |
|
62 |
|
63 # install each Jar file and delete it when done |
|
64 foreach my $Package (<$TargetDirectory\\*.sdkpkg>) |
|
65 { |
|
66 # if -o specified, only install the required options |
|
67 # (if -b specified, combine up into \bin\generic and \bin\techview) |
|
68 |
|
69 if ( ($Options ne "") ) |
|
70 { |
|
71 if ( ($Package =~ /bin\.GT-/i) && ($Options =~ /G/i) ) |
|
72 { |
|
73 # GT binaries |
|
74 print " installing $Package\n"; |
|
75 if ($BuildFromClean == 1) |
|
76 { |
|
77 system("unzip -o -q \"$Package\" -x \"package.xml\" -d \"$TargetDirectory\""); |
|
78 } |
|
79 else |
|
80 { |
|
81 # install to temporary location then move |
|
82 system("unzip -o -q \"$Package\" -x \"package.xml\" -d \"$TargetDirectory\\tmp\""); |
|
83 MoveDirectory("$TargetDirectory\\tmp\\bin\\techview", "$TargetDirectory\\bin\\TechView\\generic"); |
|
84 rmtree "$TargetDirectory\\tmp" or print "Unable to remove \"$TargetDirectory\\tmp\" - $!\n"; |
|
85 } |
|
86 } |
|
87 elsif ( ($Package =~ /bin\.GT-/i) && ($Options !~ /G/i) ) |
|
88 { |
|
89 print " excluded $Package\n"; |
|
90 } |
|
91 |
|
92 elsif ( ($Package =~ /bin\.TechView-/i) && ($Options =~ /U/i) ) |
|
93 { |
|
94 # TechView binaries |
|
95 print " installing $Package\n"; |
|
96 if ($BuildFromClean == 1) |
|
97 { |
|
98 system("unzip -o -q \"$Package\" -x \"package.xml\" -d \"$TargetDirectory\""); |
|
99 } |
|
100 else |
|
101 { |
|
102 # install to temporary location then move |
|
103 system("unzip -o -q \"$Package\" -x \"package.xml\" -d \"$TargetDirectory\\tmp\""); |
|
104 MoveDirectory("$TargetDirectory\\tmp\\bin\\techview", "$TargetDirectory\\bin\\TechView\\TechView"); |
|
105 rmtree "$TargetDirectory\\tmp" or print "Unable to remove \"$TargetDirectory\\tmp\" - $!\n"; |
|
106 } |
|
107 } |
|
108 elsif ( ($Package =~ /bin\.TechView-/i) && ($Options !~ /U/i) ) |
|
109 { |
|
110 print " excluded $Package\n"; |
|
111 } |
|
112 |
|
113 elsif ( ($Package =~ /doc\./i) && ($Options =~ /D/i) ) |
|
114 { |
|
115 # documentation - install to 'doc' location then move |
|
116 print " installing $Package\n"; |
|
117 system("unzip -o -q \"$Package\" -x \"package.xml\" -d \"$TargetDirectory\""); |
|
118 } |
|
119 elsif ( ($Package =~ /doc/i) && ($Options !~ /D/i) ) |
|
120 { |
|
121 print " excluded $Package\n"; |
|
122 } |
|
123 |
|
124 elsif ( ( ($Package =~ /\.bin\./i) && ($Options =~ /(G|U)/i) ) || |
|
125 ( ($Package =~ /\.src\./i) && ($Options =~ /S/i) ) || |
|
126 ( ($Package !~ /\.src\./i) && ($Package !~ /\.bin\./i) ) ) |
|
127 { |
|
128 # non-specific binaries or sources or non-binaries, non-sources |
|
129 system("unzip -o -q \"$Package\" -x \"package.xml\" -d \"$TargetDirectory\""); |
|
130 print " installing $Package\n"; |
|
131 } |
|
132 elsif ( ( ($Package =~ /\.src\./i) && ($Options !~ /S/i) ) || |
|
133 ( ($Package =~ /\.bin\./i) && ($Options !~ /(G|U)/i) ) ) |
|
134 { |
|
135 print " excluded $Package\n"; |
|
136 } |
|
137 else |
|
138 { |
|
139 print "Failed to install $Package\n"; |
|
140 } |
|
141 } |
|
142 |
|
143 # otherwise install everything else regardless (non-BFC or no options specified) |
|
144 else |
|
145 { |
|
146 # sources in BuildFromClean installation, everything if BFC with no options, or non-BFC |
|
147 print " installing $Package\n"; |
|
148 system("unzip -o -q \"$Package\" -x \"package.xml\" -d \"$TargetDirectory\""); |
|
149 } |
|
150 unlink $Package or print "Unable to delete $Package file from \"$TargetDirectory\"\n"; |
|
151 } |
|
152 |
|
153 |
|
154 # move files from [sdkroot]\src to src\, delete [sdkroot] directory |
|
155 if ( -e "$TargetDirectory\\\[sdkroot\]" ) |
|
156 { |
|
157 MoveDirectory("$TargetDirectory\\\[sdkroot\]", "$TargetDirectory"); |
|
158 rmdir "$TargetDirectory\\\[sdkroot\]" or print "Unable to remove \"$TargetDirectory\\\[sdkroot\]\" - $!\n"; |
|
159 } |
|
160 |
|
161 |
|
162 # rename 'doc' directory to 'documentation' |
|
163 if ( -e "$TargetDirectory\\doc") |
|
164 { |
|
165 MoveDirectory("$TargetDirectory\\doc", "$TargetDirectory\\documentation"); |
|
166 rmdir "$TargetDirectory\\doc" or print "Unable to remove \"$TargetDirectory\\doc\" - $!\n"; |
|
167 } |
|
168 |
|
169 |
|
170 # move binary directories if platform defined for BuildFromClean - moves epoc32 tree from bin\TechView to \bin\%platform% |
|
171 if ( ($BuildFromClean == 1) && (-e "$TargetDirectory\\bin\\TechView") && ($Platform ne "") ) |
|
172 { |
|
173 MoveDirectory("$TargetDirectory\\bin\\TechView", "$TargetDirectory\\bin\\$Platform"); |
|
174 rmdir "$TargetDirectory\\bin\\TechView" or print "Unable to remove \"$TargetDirectory\\bin\\TechView\" - $!\n"; |
|
175 } |
|
176 |
|
177 |
|
178 # remove the [meta] tree (usually only contains licence text) |
|
179 rmtree ("$TargetDirectory\\\[meta\]", 0, 1); |
|
180 } |
|
181 |
|
182 # ------------------- Start ofCommandLineInterface() ------------------------- |
|
183 |
|
184 |
|
185 sub CommandLineInterface() |
|
186 { |
|
187 %CmdLineOptions = (); |
|
188 my $help; |
|
189 if ( (GetOptions( \%CmdLineOptions, "jarfile|j=s" => \$JarFile, "target|t=s" => \$TargetDirectory, "help|h|?" => \$help, "buildfromclean|b" => \$BuildFromClean, "platform|p=s" => \$Platform, "options|o=s" => \$Options) == 0) || ($JarFile eq "") || ($TargetDirectory eq "") || ($help == 1) ) |
|
190 { |
|
191 Usage(); |
|
192 exit; |
|
193 } |
|
194 |
|
195 |
|
196 if ( ($BuildFromClean == 1) && ($Platform eq "") && ($ENV{'Platform'} eq "") ) |
|
197 { |
|
198 Usage(); |
|
199 print "\nN.B. -platform required if -b specified\n"; |
|
200 exit; |
|
201 } |
|
202 elsif ( ($BuildFromClean == 1) && ($Platform eq "") ) |
|
203 { |
|
204 $Platform = $ENV{'Platform'} ; |
|
205 } |
|
206 |
|
207 # NAHEED --- Prevent stopping of the scripts if the Suplementary |
|
208 # product is not present. Rather than die just display a |
|
209 # WARNING .... |
|
210 # check that Kit zips are in stated directory |
|
211 if (! -e $JarFile) |
|
212 { |
|
213 print "Warning: Jar file $JarFile not found.\n"; |
|
214 exit; |
|
215 } |
|
216 |
|
217 |
|
218 # ensure target directory exists or can be created |
|
219 if (! -d $TargetDirectory) |
|
220 { |
|
221 mkpath ($TargetDirectory) or die "Could not find or create $TargetDirectory\n"; |
|
222 } |
|
223 |
|
224 } |
|
225 |
|
226 |
|
227 # ------------------------ Start of UserInterface() --------------------------- |
|
228 |
|
229 |
|
230 sub UserInterface() |
|
231 { |
|
232 # get name of Supplementary Kit to install |
|
233 do # ensure file exists |
|
234 { |
|
235 print "Enter name of Supplementary Kit (*.jar) : "; |
|
236 chomp( $JarFile = <STDIN> ); |
|
237 } while (! -e $JarFile) ; |
|
238 |
|
239 |
|
240 # get location to write extracted files to |
|
241 do # ensure directory exists or can be created |
|
242 { |
|
243 print "Enter directory to extract files to : "; |
|
244 chomp( $TargetDirectory = <STDIN> ); |
|
245 } while ( (! -d $TargetDirectory) and (! mkpath ($TargetDirectory)) ) ; |
|
246 |
|
247 |
|
248 # get Platform name - try environment, else ask user |
|
249 if ($ENV{'Platform'} eq "") |
|
250 { |
|
251 print "Enter platform name : "; |
|
252 chomp( $Platform = <STDIN> ); |
|
253 } |
|
254 else |
|
255 { |
|
256 $Platform = $ENV{'Platform'} ; |
|
257 } |
|
258 |
|
259 |
|
260 # get build from clean flag |
|
261 my $answer = ""; |
|
262 do |
|
263 { |
|
264 print "Build from clean (epoc32 tree combination) (Y/N) ? "; |
|
265 chomp ($answer = <STDIN>); |
|
266 } while ($answer !~ /[YN]/i); |
|
267 if ($answer =~ /Y/i) |
|
268 { |
|
269 $BuildFromClean = 1; |
|
270 } |
|
271 |
|
272 |
|
273 # get installation options |
|
274 print "Enter installation options : "; |
|
275 chomp($Options = <STDIN>); |
|
276 } |
|
277 |
|
278 |
|
279 # ------------------------ Start of MoveDirectory() --------------------------- |
|
280 |
|
281 |
|
282 # Recursively moves directory tree |
|
283 |
|
284 sub MoveDirectory($$) |
|
285 { |
|
286 my ($aFrom, $aTo) = @_; |
|
287 |
|
288 opendir(DIR, $aFrom) or die "Path $aFrom not found!\n"; |
|
289 |
|
290 foreach my $entry (readdir(DIR)) |
|
291 { |
|
292 if (($entry ne ".") and ($entry ne "..")) |
|
293 { |
|
294 if (-d $aFrom."/".$entry) |
|
295 { |
|
296 if (!(makepath ($aTo."/".$entry))) |
|
297 { |
|
298 print "Warning: Could not create $aTo/$entry - $!\n"; |
|
299 } |
|
300 MoveDirectory($aFrom."/".$entry, $aTo."/".$entry); |
|
301 rmdir $aFrom."/".$entry or print "Warning: Unable to remove $aFrom/$entry - $!\n"; |
|
302 } |
|
303 else |
|
304 { |
|
305 rename $aFrom."/".$entry, $aTo."/".$entry or print "Warning: Unable to move $aFrom/$entry - $!\n"; |
|
306 } |
|
307 } |
|
308 } |
|
309 |
|
310 closedir(DIR); |
|
311 } |
|
312 |
|
313 # -------------------------- Start of makepath() ------------------------------ |
|
314 |
|
315 sub makepath($) |
|
316 { |
|
317 my ($path) = @_; |
|
318 |
|
319 if (-d $path) |
|
320 { |
|
321 return -1; |
|
322 } |
|
323 else |
|
324 { |
|
325 return mkpath($path); |
|
326 } |
|
327 } |
|
328 |
|
329 # ---------------------------- Start of Usage() ------------------------------- |
|
330 |
|
331 sub Usage() |
|
332 { |
|
333 print <<ENDOFUSAGETEXT; |
|
334 |
|
335 INSTALLSUPPLEMENTARYKIT.PL Version 1.2 Copyright (c) 2003 Symbian Ltd |
|
336 All Rights Reserved |
|
337 |
|
338 Usage: |
|
339 perl InstallSupplementaryKit.pl [options] |
|
340 |
|
341 where options are: |
|
342 -b[uildfromclean] combines unpacked files into build from clean locations |
|
343 -j[arfile] <path> fully qualified file name of Kit's .jar |
|
344 -o[ptions] DGUS installation options ( D=documentation, G=GT, U=UI(TechView), S=source ) |
|
345 -p[latform] <platform> build platform - used with -b to create binaries installation directory path |
|
346 (moves epoc32 tree from \\bin\TechView into \\bin\\<platform>) |
|
347 -t[arget] <path> path to directory to unpack Kit into |
|
348 |
|
349 ENDOFUSAGETEXT |
|
350 } |