|
1 #! perl |
|
2 |
|
3 # Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 # All rights reserved. |
|
5 # This component and the accompanying materials are made available |
|
6 # under the terms of "Eclipse Public License v1.0" |
|
7 # which accompanies this distribution, and is available |
|
8 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 # |
|
10 # Initial Contributors: |
|
11 # Nokia Corporation - initial contribution. |
|
12 # |
|
13 # Contributors: |
|
14 # |
|
15 # Description: |
|
16 # Compare the sdkpkg lists for corresponding packages in two kits. |
|
17 # |
|
18 # |
|
19 |
|
20 use strict; |
|
21 use Getopt::Long; |
|
22 |
|
23 my $toolVersion = "0.1"; |
|
24 |
|
25 sub usage($) |
|
26 { |
|
27 my ($errmsg) = @_; |
|
28 print STDERR "\ncompare_kit_content.pl - Version $toolVersion\n"; |
|
29 |
|
30 print "$errmsg\n" if ($errmsg); |
|
31 |
|
32 print STDERR << 'END_OF_HELP'; |
|
33 |
|
34 Usage: compare_kit_content [-subset exp] [-temp dir] [-123] kit1 kit2 |
|
35 |
|
36 Compare the two kits, by matching the sdkpkg files in each kit and comparing the |
|
37 list of contents for each package. Each kit can be specified either as a zip file |
|
38 or an unpacked directory. |
|
39 |
|
40 Options: |
|
41 -subset exp Compare only packages with names matching exp |
|
42 -temp dir Use dir as the location for temporary files |
|
43 -123 Controls the output: 1 = left only, 2= right only, 3= both (default 12) |
|
44 |
|
45 END_OF_HELP |
|
46 |
|
47 exit(1); |
|
48 } |
|
49 |
|
50 |
|
51 my $subset = ""; |
|
52 my $temp = ""; |
|
53 my $verbose = 0; |
|
54 my $help = 0; |
|
55 my $leftonly = 0; |
|
56 my $rightonly = 0; |
|
57 my $both = 0; |
|
58 |
|
59 # 1. Check arguments, output help etc. |
|
60 |
|
61 GetOptions ( |
|
62 'h|help' => \$help, # print help message |
|
63 'v+' => \$verbose, # print extra diagnostic info |
|
64 's|subset=s' => \$subset, # pattern to match |
|
65 't|temp=s' => \$temp, # temporary directory |
|
66 '1' => \$leftonly, # display files only in kit1 |
|
67 '2' => \$rightonly, # display files only in kit2 |
|
68 '3' => \$both, # display files present in both kits |
|
69 ); |
|
70 |
|
71 usage("") if ($help); |
|
72 usage("must specify two kits") if (@ARGV != 2); |
|
73 |
|
74 usage ("temp directory $temp does not exist") if ($temp ne "" && ! -d $temp); |
|
75 |
|
76 if ($leftonly==0 && $rightonly==0 && $both==0) |
|
77 { |
|
78 $leftonly = 1; |
|
79 $rightonly = 1; |
|
80 } |
|
81 |
|
82 sub leftfiles(@) |
|
83 { |
|
84 return if ($leftonly == 0 || scalar @_ == 0); |
|
85 print "left:\t",join("\nleft:\t",sort @_), "\n"; |
|
86 } |
|
87 sub rightfiles(@) |
|
88 { |
|
89 return if ($rightonly == 0 || scalar @_ == 0); |
|
90 print "right:\t",join("\nright:\t",sort @_), "\n"; |
|
91 } |
|
92 sub bothfiles(@) |
|
93 { |
|
94 return if ($both == 0 || scalar @_ == 0); |
|
95 print "both:\t",join("\nboth:\t",sort @_), "\n"; |
|
96 } |
|
97 |
|
98 my ($kit1, $kit2) = @ARGV; |
|
99 |
|
100 # 2. Get the kit content list for both kits |
|
101 |
|
102 sub kit_content($) |
|
103 { |
|
104 my ($kit) = @_; |
|
105 |
|
106 if (-f "$kit\\package-list.xml.zip") |
|
107 { |
|
108 opendir DIR, $kit or usage("cannot read $kit directory: $!"); |
|
109 my @contents = grep /\.sdkpkg$/, readdir DIR; |
|
110 closedir DIR; |
|
111 |
|
112 return "dir", @contents; |
|
113 } |
|
114 |
|
115 usage("$kit is not a valid kit directory") if (!-f $kit); |
|
116 |
|
117 open UNZIP, "unzip -l $kit |" or usage("cannot read $kit as zip archive"); |
|
118 my @lines = <UNZIP>; |
|
119 close UNZIP; |
|
120 |
|
121 # 36836436 07-12-08 02:59 com.symbian.api.GT-arm_0_0_M04604_Symbian_OS_v9.5.sdkpkg |
|
122 my @contents; |
|
123 foreach my $line (@lines) |
|
124 { |
|
125 if ($line =~ /\s(\S+\.sdkpkg)$/) |
|
126 { |
|
127 push @contents, $1; |
|
128 } |
|
129 } |
|
130 return "zip", @contents; |
|
131 } |
|
132 |
|
133 my ($kit1_type,@kit1_contents) = kit_content($kit1); |
|
134 my ($kit2_type,@kit2_contents) = kit_content($kit2); |
|
135 |
|
136 sub compare_package_files($$) |
|
137 { |
|
138 my ($zip1,$zip2) = @_; |
|
139 |
|
140 open UNZIP, "unzip -l $zip1 |" or usage("cannot read $zip1 as zip archive"); |
|
141 my @lines1 = <UNZIP>; |
|
142 close UNZIP; |
|
143 |
|
144 open UNZIP, "unzip -l $zip2 |" or usage("cannot read $zip2 as zip archive"); |
|
145 my @lines2 = <UNZIP>; |
|
146 close UNZIP; |
|
147 |
|
148 # 699790 12-20-07 00:14 [emul]/epoc32/release/ARMV5/LIB/SipCodec.lib |
|
149 my %zip1_files; |
|
150 foreach my $line (@lines1) |
|
151 { |
|
152 next if ($line !~ /\s\d\d:\d\d\s+(\S.*)$/); |
|
153 $zip1_files{$1} = 1; |
|
154 } |
|
155 |
|
156 my @mismatches; |
|
157 my @bothlist; |
|
158 foreach my $line (@lines2) |
|
159 { |
|
160 next if ($line !~ /\s\d\d:\d\d\s+(\S.*)$/); |
|
161 my $file = $1; |
|
162 |
|
163 if (!defined $zip1_files{$file}) |
|
164 { |
|
165 push @mismatches, $file; |
|
166 next; |
|
167 } |
|
168 push @bothlist, $file; |
|
169 delete $zip1_files{$file}; # matched - remove from the hash |
|
170 } |
|
171 |
|
172 bothfiles(@bothlist); |
|
173 rightfiles(@mismatches); |
|
174 leftfiles(keys %zip1_files); |
|
175 } |
|
176 |
|
177 sub compare_packages($$$$) |
|
178 { |
|
179 my ($type1,$package1,$type2,$package2) = @_; |
|
180 my @unzip = ("unzip", "-j"); |
|
181 my $tempdir = ".\\"; |
|
182 if ($temp ne "") |
|
183 { |
|
184 push @unzip, ("-d", "$temp"); |
|
185 $tempdir = "$temp\\"; |
|
186 } |
|
187 |
|
188 my @unlink_temporaries = (); |
|
189 if ($type1 eq "zip") |
|
190 { |
|
191 my $expected_file = $tempdir.$package1; |
|
192 system @unzip,$kit1,$package1; |
|
193 usage ("failed to read $package1 from $kit1") if (! -f $expected_file); |
|
194 push @unlink_temporaries, $expected_file; |
|
195 $package1 = $expected_file; |
|
196 } |
|
197 else |
|
198 { |
|
199 $package1 = $kit1."\\".$package1; |
|
200 } |
|
201 if ($type2 eq "zip") |
|
202 { |
|
203 my $expected_file = $tempdir.$package2; |
|
204 system @unzip,$kit2,$package2; |
|
205 usage ("failed to read $package2 from $kit2") if (! -f $expected_file); |
|
206 push @unlink_temporaries, $expected_file; |
|
207 $package2 = $expected_file; |
|
208 } |
|
209 else |
|
210 { |
|
211 $package2 = $kit2."\\".$package2; |
|
212 } |
|
213 compare_package_files($package1, $package2); |
|
214 |
|
215 unlink @unlink_temporaries if (scalar @unlink_temporaries != 0); |
|
216 } |
|
217 |
|
218 # 3. sort the lists, eliminating the version information |
|
219 |
|
220 print "left ($kit1_type) = $kit1\n"; |
|
221 print "right ($kit2_type) = $kit2\n"; |
|
222 |
|
223 my %kit1_lookup; |
|
224 foreach my $package (sort @kit1_contents) |
|
225 { |
|
226 my $rootname = $package; |
|
227 if ($package =~ /^([^_]*_)\d+_\d+_\S+\.sdkpkg$/) |
|
228 { |
|
229 $rootname = $1; |
|
230 next if ($subset ne "" && $rootname !~ /$subset/i); |
|
231 } |
|
232 $kit1_lookup{$rootname} = $package; |
|
233 } |
|
234 |
|
235 my @missing_packages; |
|
236 |
|
237 foreach my $package (sort @kit2_contents) |
|
238 { |
|
239 my $rootname = $package; |
|
240 if ($package =~ /^([^_]*_)\d+_\d+_\S+\.sdkpkg$/) |
|
241 { |
|
242 $rootname = $1; |
|
243 next if ($subset ne "" && $rootname !~ /$subset/i); |
|
244 } |
|
245 my $kit1_package = $kit1_lookup{$rootname}; |
|
246 |
|
247 if (!defined $kit1_package) |
|
248 { |
|
249 push @missing_packages, "* $package is only in $kit2\n" if ($rightonly); |
|
250 next; |
|
251 } |
|
252 |
|
253 print "Comparing $rootname...\n"; |
|
254 compare_packages($kit1_type, $kit1_package, $kit2_type, $package); |
|
255 delete $kit1_lookup{$rootname}; |
|
256 } |
|
257 |
|
258 foreach my $rootname (sort keys %kit1_lookup) |
|
259 { |
|
260 my $kit1_package = $kit1_lookup{$rootname}; |
|
261 push @missing_packages, "* $kit1_package is only in $kit1\n" if ($leftonly); |
|
262 } |
|
263 |
|
264 print sort @missing_packages; |