|
1 #!perl |
|
2 # Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 # |
|
17 |
|
18 use strict; |
|
19 use File::Find; |
|
20 use File::Basename; |
|
21 use Cwd 'abs_path'; |
|
22 |
|
23 $|++; |
|
24 |
|
25 my $dir1 = shift @ARGV; |
|
26 my $dir2 = shift @ARGV; |
|
27 |
|
28 unless ($dir1 and -d $dir1 and $dir2 and -d $dir2) { |
|
29 die "Error: Invalid arguments\n"; |
|
30 } |
|
31 |
|
32 $dir1 = AbsoluteFileName($dir1); |
|
33 $dir2 = AbsoluteFileName($dir2); |
|
34 |
|
35 my $rlsFiles = FindRlsFiles($dir1, $dir2); |
|
36 DiffRlsFiles($dir1, $dir2, $rlsFiles); |
|
37 |
|
38 |
|
39 sub FindRlsFiles { |
|
40 my $dir1 = shift; |
|
41 my $dir2 = shift; |
|
42 my %rlsFiles; |
|
43 my $whichDir = $dir1; |
|
44 my $processFileSub = sub { |
|
45 if (/\.rls$/i) { |
|
46 print '.'; |
|
47 my $thisFile = $File::Find::name; |
|
48 $thisFile =~ s/^\Q$whichDir\E//; |
|
49 $thisFile =~ s/^\///; |
|
50 $thisFile =~ s/\//\\/g; |
|
51 $rlsFiles{$thisFile} = 1; |
|
52 } |
|
53 }; |
|
54 print 'Scanning for rls files'; |
|
55 find($processFileSub, $dir1); |
|
56 $whichDir = $dir2; |
|
57 find($processFileSub, $dir2); |
|
58 print "\n"; |
|
59 return \%rlsFiles; |
|
60 } |
|
61 |
|
62 sub DiffRlsFiles { |
|
63 my $dir1 = shift; |
|
64 my $dir2 = shift; |
|
65 my $rlsFiles = shift; |
|
66 foreach my $thisFile (sort keys %$rlsFiles) { |
|
67 my $file1 = ConcatenatePaths($dir1, $thisFile); |
|
68 my $file2 = ConcatenatePaths($dir2, $thisFile); |
|
69 if (-e $file1 and -e $file2) { |
|
70 CompareFiles($file1, $file2); |
|
71 } |
|
72 elsif (-e $file1) { |
|
73 print "Warning: $file2 does not exist\n"; |
|
74 } |
|
75 else { |
|
76 print "Warning: $file1 does not exist\n"; |
|
77 } |
|
78 } |
|
79 } |
|
80 |
|
81 sub CompareFiles { |
|
82 my $file1 = shift; |
|
83 my $file2 = shift; |
|
84 open(IN1, "cpp $file1 2>NUL|") or die "Error: Unable to open \"$file1\": $!"; |
|
85 open(IN2, "cpp $file2 2>NUL|") or die "Error: Unable to open \"$file2\": $!"; |
|
86 my $result = 'identical'; |
|
87 while (my $file1Line = <IN1>) { |
|
88 my $file2Line = <IN2>; |
|
89 unless ($file2Line) { |
|
90 # file2 has been fully read, so file1 must be longer. |
|
91 $result = 'different'; |
|
92 last; |
|
93 } |
|
94 if ($file1Line =~ /^\#/ and $file2Line =~ /^\#/) { |
|
95 # Ignore stuff put in by cpp. |
|
96 next; |
|
97 } |
|
98 |
|
99 # Remove whitespace from the ends of lines. |
|
100 chomp $file1Line; |
|
101 chomp $file2Line; |
|
102 $file1Line =~ s/\s*$//; |
|
103 $file2Line =~ s/\s*$//; |
|
104 |
|
105 # Do the comparison. |
|
106 if ($file1Line ne $file2Line) { |
|
107 $result = 'different'; |
|
108 last; |
|
109 } |
|
110 } |
|
111 if (<IN2>) { |
|
112 # We've compared all lines in file1. Need to check to see if file2 has been fully read. |
|
113 $result = 'different'; |
|
114 } |
|
115 close(IN1); |
|
116 close(IN2); |
|
117 |
|
118 if ($result eq 'identical') { |
|
119 } |
|
120 else { |
|
121 print "Different: $file1 $file2\n"; |
|
122 } |
|
123 } |
|
124 |
|
125 |
|
126 sub AbsoluteFileName { |
|
127 my $fileName = shift; |
|
128 (my $base, my $path) = fileparse($fileName); |
|
129 my $absPath = abs_path($path); |
|
130 unless ($absPath =~ /[\\\/]$/) { |
|
131 $absPath .= "\\"; |
|
132 } |
|
133 $fileName = $absPath . $base; |
|
134 $fileName =~ s/\//\\/g; |
|
135 return $fileName; |
|
136 } |
|
137 |
|
138 sub ConcatenatePaths { |
|
139 my $path1 = shift; |
|
140 my $path2 = shift; |
|
141 $path1 =~ s/([^\\]$)/$1\\/; |
|
142 $path2 =~ s/^\\//; |
|
143 return $path1.$path2; |
|
144 } |
|
145 |
|
146 =head1 NAME |
|
147 |
|
148 CheckRls - Compares all rls files found in a pair of directory trees |
|
149 |
|
150 =head1 SYNOPSIS |
|
151 |
|
152 checkrls <dir1> <dir2> |
|
153 |
|
154 =head1 DESCRIPTION |
|
155 |
|
156 rls files contain the content of resource files that needs to be translated into different languages. Changes made to a particular language variant therefore potentially need to be applied to all other language variants. It is therefore important that changes to rls files are made in a highly controlled way. This tool provides a means of comparing the rls found in a pair of directory trees, and reporting which ones have changed. |
|
157 |
|
158 The rls files are run through the C preprocessor before being compared. This means that changes to comments will be ignored. Also, differences in white space (space and tab characters) at the end of a line are ignored. Each file pair that contains any other kind of difference is reported to C<STDOUT>. Use a conventional differencing tool to get a detailed picture of what the differences are. |
|
159 |
|
160 =head1 KNOWN BUGS |
|
161 |
|
162 None. |
|
163 |
|
164 =head1 COPYRIGHT |
|
165 |
|
166 Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
167 All rights reserved. |
|
168 This component and the accompanying materials are made available |
|
169 under the terms of the License "Eclipse Public License v1.0" |
|
170 which accompanies this distribution, and is available |
|
171 at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
172 |
|
173 Initial Contributors: |
|
174 Nokia Corporation - initial contribution. |
|
175 |
|
176 Contributors: |
|
177 |
|
178 Description: |
|
179 |
|
180 |
|
181 =cut |