1 | #!/usr/bin/perl -w |
---|
2 | |
---|
3 | # ***** BEGIN LICENSE BLOCK ***** |
---|
4 | # Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
---|
5 | # |
---|
6 | # The contents of this file are subject to the Mozilla Public License Version |
---|
7 | # 1.1 (the "License"); you may not use this file except in compliance with |
---|
8 | # the License. You may obtain a copy of the License at |
---|
9 | # http://www.mozilla.org/MPL/ |
---|
10 | # |
---|
11 | # Software distributed under the License is distributed on an "AS IS" basis, |
---|
12 | # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
---|
13 | # for the specific language governing rights and limitations under the |
---|
14 | # License. |
---|
15 | # |
---|
16 | # The Original Code is the Chrome/CVS Location Matcher. |
---|
17 | # |
---|
18 | # The Initial Developer of the Original Code is |
---|
19 | # Gervase Markham. |
---|
20 | # Portions created by the Initial Developer are Copyright (C) 2001 |
---|
21 | # the Initial Developer. All Rights Reserved. |
---|
22 | # |
---|
23 | # Contributor(s): |
---|
24 | # |
---|
25 | # Alternatively, the contents of this file may be used under the terms of |
---|
26 | # either the GNU General Public License Version 2 or later (the "GPL"), or |
---|
27 | # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
---|
28 | # in which case the provisions of the GPL or the LGPL are applicable instead |
---|
29 | # of those above. If you wish to allow use of your version of this file only |
---|
30 | # under the terms of either the GPL or the LGPL, and not to allow others to |
---|
31 | # use your version of this file under the terms of the MPL, indicate your |
---|
32 | # decision by deleting the provisions above and replace them with the notice |
---|
33 | # and other provisions required by the GPL or the LGPL. If you do not delete |
---|
34 | # the provisions above, a recipient may use your version of this file under |
---|
35 | # the terms of any one of the MPL, the GPL or the LGPL. |
---|
36 | # |
---|
37 | # ***** END LICENSE BLOCK ***** |
---|
38 | |
---|
39 | # Version 0.5 |
---|
40 | # |
---|
41 | # This file creates a large list of the mappings between chrome path and CVS |
---|
42 | # paths which are recorded in the jar.mn files throughout the tree. This list |
---|
43 | # is shipped with builds to make it easier for people to create chrome patches |
---|
44 | # using them. |
---|
45 | |
---|
46 | use Fcntl qw(:DEFAULT :flock); |
---|
47 | use File::Basename; |
---|
48 | use Cwd; |
---|
49 | use mozLock; |
---|
50 | |
---|
51 | # This is necessary because this module is not present in Perl versions less |
---|
52 | # than 5.004_05. |
---|
53 | eval q{use File::Spec}; |
---|
54 | exit if $@; |
---|
55 | |
---|
56 | # This file takes two parameters - the jar file to process, and the chrome |
---|
57 | # directory we are compiling into. |
---|
58 | my ($chrome, $jar, $flock) = @ARGV; |
---|
59 | |
---|
60 | my $nofilelocks = $flock ? ($flock eq "-l") : 0; |
---|
61 | |
---|
62 | # OS setup - which chrome does your OS use? |
---|
63 | # |
---|
64 | # The $^O variable contains some representation of what OS you are on. |
---|
65 | # Find its value on your platform by running the following command: |
---|
66 | # perl -e 'print $^O . "\n";' |
---|
67 | # and set the relevant booleans accordingly depending on what |
---|
68 | # chrome your platform uses. There are currently three sorts of chrome: |
---|
69 | # win, mac, and unix. |
---|
70 | |
---|
71 | my $win32 = ($^O =~ /((MS)?win32)|cygwin|os2/i) ? 1 : 0; |
---|
72 | my $macos = ($^O =~ /MacOS|darwin/i) ? 1 : 0; |
---|
73 | my $unix = !($win32 || $macos) ? 1 : 0; |
---|
74 | |
---|
75 | # Testing only - generate chromelist.txt for other platforms |
---|
76 | # $macos = 1; |
---|
77 | # $unix = 0; |
---|
78 | |
---|
79 | my $chromelist = File::Spec->catfile($chrome, "chromelist.txt"); |
---|
80 | my $lockfile = $chromelist . ".lck"; |
---|
81 | |
---|
82 | mozLock($lockfile) unless $nofilelocks; |
---|
83 | |
---|
84 | open(BIGLIST, ">>" . $chromelist) or die "Can't open chromelist.txt"; |
---|
85 | open(JARFILE, "<$jar"); |
---|
86 | |
---|
87 | # Find the absolute directory the jar.mn file is in |
---|
88 | my $stub = File::Spec->catdir(getcwd(), dirname($jar)); |
---|
89 | |
---|
90 | # Convert back to Unix-style directory names for the CVS version |
---|
91 | if ($macos) { $stub =~ tr|:|/|; } |
---|
92 | if ($win32) { $stub =~ tr|\\|/|; } |
---|
93 | |
---|
94 | # Turn the absolute path into a relative path inside the CVS tree |
---|
95 | $stub =~ s|.*mozilla/?||; |
---|
96 | |
---|
97 | my $jarfilename = ""; |
---|
98 | |
---|
99 | while (<JARFILE>) |
---|
100 | { |
---|
101 | # Tidy up the line |
---|
102 | chomp; |
---|
103 | s/^[\s|\+]+//; # Some lines have a + sign before them |
---|
104 | s/\s+$//; |
---|
105 | |
---|
106 | # There's loads of things we aren't interested in |
---|
107 | next if m/^\s*#/; # Comments |
---|
108 | next if m/^$/; # Blank lines |
---|
109 | next if m/\.gif\)\s*$/i; # Graphics |
---|
110 | next if m/\.png\)\s*$/i; |
---|
111 | next if m/\.jpe?g\)\s*$/i; |
---|
112 | next if ($stub =~ m|/win/|) and !$win32; |
---|
113 | next if ($stub =~ m|/unix/|) and !$unix; |
---|
114 | next if ($stub =~ m|/mac/|) and !$macos; |
---|
115 | |
---|
116 | if (m/\s*(.*)\.jar:/) # e.g. "comm.jar:" |
---|
117 | { |
---|
118 | $jarfilename = $1; |
---|
119 | next; |
---|
120 | } |
---|
121 | |
---|
122 | # Split up the common format, which is e.g.: |
---|
123 | # messenger/skin/fred/foo.xul (xpfe/barney/wilma/foo.xul) |
---|
124 | m/(.*)\s+\((.*)\)/; |
---|
125 | my $chromefile = $1; |
---|
126 | my $cvsfile = $2; |
---|
127 | |
---|
128 | # Deal with those jar.mns which have just a single line, |
---|
129 | # implying that the file is in the current directory. |
---|
130 | if (!$1 || $1 eq "") |
---|
131 | { |
---|
132 | $chromefile = File::Spec::Unix->canonpath("$jarfilename/$_"); |
---|
133 | $_ =~ /.*\/(.*?)$/; |
---|
134 | $cvsfile = File::Spec::Unix->canonpath($1); |
---|
135 | } else { |
---|
136 | $chromefile = File::Spec::Unix->canonpath("$jarfilename/$chromefile"); |
---|
137 | $cvsfile = File::Spec::Unix->canonpath($cvsfile); |
---|
138 | } |
---|
139 | |
---|
140 | # Convert to platform-specific separator for the chrome version. |
---|
141 | # This permits easy grepping of the file for a given path. |
---|
142 | if ($macos) { $chromefile =~ tr|/|:|; } |
---|
143 | if ($win32) { $chromefile =~ tr|/|\\|; } |
---|
144 | |
---|
145 | $cvsfile = File::Spec::Unix->catfile($stub, $cvsfile); |
---|
146 | |
---|
147 | print BIGLIST "$chromefile ($cvsfile)\n"; |
---|
148 | } |
---|
149 | |
---|
150 | mozUnlock($lockfile) unless $nofilelocks; |
---|
151 | |
---|
152 | exit(0); |
---|
153 | |
---|