releasing/cbrtools/perl/CheckRls
author Zheng Shen <zheng.shen@nokia.com>
Tue, 20 Jul 2010 15:02:28 +0800
changeset 617 3a747a240983
parent 602 3145852acc89
permissions -rw-r--r--
ROM Tools 12.2.0.4 Postlinker 2.2.5 Revert package_definition.xml to changeset 360bd6b35136
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
602
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     1
#!perl
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     2
# Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     3
# All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     4
# This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     6
# which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     8
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
     9
# Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    11
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    12
# Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    13
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    14
# Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    15
# 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    16
#
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    17
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    18
use strict;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    19
use File::Find;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    20
use File::Basename;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    21
use Cwd 'abs_path';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    22
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    23
$|++;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    24
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    25
my $dir1 = shift @ARGV;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    26
my $dir2 = shift @ARGV;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    27
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    28
unless ($dir1 and -d $dir1 and $dir2 and -d $dir2) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    29
  die "Error: Invalid arguments\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    30
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    31
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    32
$dir1 = AbsoluteFileName($dir1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    33
$dir2 = AbsoluteFileName($dir2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    34
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    35
my $rlsFiles = FindRlsFiles($dir1, $dir2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    36
DiffRlsFiles($dir1, $dir2, $rlsFiles);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    37
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    38
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    39
sub FindRlsFiles {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    40
  my $dir1 = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    41
  my $dir2 = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    42
  my %rlsFiles;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    43
  my $whichDir = $dir1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    44
  my $processFileSub = sub {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    45
    if (/\.rls$/i) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    46
      print '.';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    47
      my $thisFile = $File::Find::name;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    48
      $thisFile =~ s/^\Q$whichDir\E//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    49
      $thisFile =~ s/^\///;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    50
      $thisFile =~ s/\//\\/g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    51
      $rlsFiles{$thisFile} = 1;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    52
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    53
  };
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    54
  print 'Scanning for rls files';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    55
  find($processFileSub, $dir1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    56
  $whichDir = $dir2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    57
  find($processFileSub, $dir2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    58
  print "\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    59
  return \%rlsFiles;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    60
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    61
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    62
sub DiffRlsFiles {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    63
  my $dir1 = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    64
  my $dir2 = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    65
  my $rlsFiles = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    66
  foreach my $thisFile (sort keys %$rlsFiles) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    67
    my $file1 = ConcatenatePaths($dir1, $thisFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    68
    my $file2 = ConcatenatePaths($dir2, $thisFile);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    69
    if (-e $file1 and -e $file2) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    70
      CompareFiles($file1, $file2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    71
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    72
    elsif (-e $file1) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    73
      print "Warning: $file2 does not exist\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    74
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    75
    else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    76
      print "Warning: $file1 does not exist\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    77
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    78
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    79
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    80
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    81
sub CompareFiles {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    82
  my $file1 = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    83
  my $file2 = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    84
  open(IN1, "cpp $file1 2>NUL|") or die "Error: Unable to open \"$file1\": $!";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    85
  open(IN2, "cpp $file2 2>NUL|") or die "Error: Unable to open \"$file2\": $!";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    86
  my $result = 'identical';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    87
  while (my $file1Line = <IN1>) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    88
    my $file2Line = <IN2>;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    89
    unless ($file2Line) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    90
      # file2 has been fully read, so file1 must be longer.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    91
      $result = 'different';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    92
      last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    93
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    94
    if ($file1Line =~ /^\#/ and $file2Line =~ /^\#/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    95
      # Ignore stuff put in by cpp.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    96
      next;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    97
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    98
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
    99
    # Remove whitespace from the ends of lines.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   100
    chomp $file1Line;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   101
    chomp $file2Line;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   102
    $file1Line =~ s/\s*$//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   103
    $file2Line =~ s/\s*$//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   104
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   105
    # Do the comparison.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   106
    if ($file1Line ne $file2Line) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   107
      $result = 'different';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   108
      last;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   109
    }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   110
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   111
  if (<IN2>) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   112
    # We've compared all lines in file1. Need to check to see if file2 has been fully read.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   113
    $result = 'different';
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   114
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   115
  close(IN1);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   116
  close(IN2);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   117
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   118
  if ($result eq 'identical') {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   119
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   120
  else {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   121
    print "Different: $file1 $file2\n";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   122
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   123
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   124
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   125
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   126
sub AbsoluteFileName {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   127
  my $fileName = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   128
  (my $base, my $path) = fileparse($fileName);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   129
  my $absPath = abs_path($path);
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   130
  unless ($absPath =~ /[\\\/]$/) {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   131
    $absPath .= "\\";
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   132
  }
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   133
  $fileName = $absPath . $base;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   134
  $fileName =~ s/\//\\/g;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   135
  return $fileName;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   136
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   137
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   138
sub ConcatenatePaths {
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   139
  my $path1 = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   140
  my $path2 = shift;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   141
  $path1 =~ s/([^\\]$)/$1\\/;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   142
  $path2 =~ s/^\\//;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   143
  return $path1.$path2;
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   144
}
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   145
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   146
=head1 NAME
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   147
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   148
CheckRls - Compares all rls files found in a pair of directory trees
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   149
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   150
=head1 SYNOPSIS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   151
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   152
  checkrls <dir1> <dir2>
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   153
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   154
=head1 DESCRIPTION
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   155
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   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.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   157
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   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.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   159
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   160
=head1 KNOWN BUGS
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   161
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   162
None.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   163
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   164
=head1 COPYRIGHT
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   165
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   166
 Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   167
 All rights reserved.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   168
 This component and the accompanying materials are made available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   169
 under the terms of the License "Eclipse Public License v1.0"
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   170
 which accompanies this distribution, and is available
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   171
 at the URL "http://www.eclipse.org/legal/epl-v10.html".
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   172
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   173
 Initial Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   174
 Nokia Corporation - initial contribution.
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   175
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   176
 Contributors:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   177
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   178
 Description:
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   179
 
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   180
3145852acc89 add releasing to new structure
jjkang
parents:
diff changeset
   181
=cut