1 |
#!/usr/bin/perl -w |
2 |
# ***** BEGIN LICENSE BLOCK ***** |
3 |
# Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
4 |
# |
5 |
# The contents of this file are subject to the Mozilla Public License Version |
6 |
# 1.1 (the "License"); you may not use this file except in compliance with |
7 |
# the License. You may obtain a copy of the License at |
8 |
# http://www.mozilla.org/MPL/ |
9 |
# |
10 |
# Software distributed under the License is distributed on an "AS IS" basis, |
11 |
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
12 |
# for the specific language governing rights and limitations under the |
13 |
# License. |
14 |
# |
15 |
# The Original Code is the Win32 Version System. |
16 |
# |
17 |
# The Initial Developer of the Original Code is Netscape Communications Corporation |
18 |
# Portions created by the Initial Developer are Copyright (C) 2002 |
19 |
# the Initial Developer. All Rights Reserved. |
20 |
# |
21 |
# Contributor(s): |
22 |
# |
23 |
# Alternatively, the contents of this file may be used under the terms of |
24 |
# either the GNU General Public License Version 2 or later (the "GPL"), or |
25 |
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
26 |
# in which case the provisions of the GPL or the LGPL are applicable instead |
27 |
# of those above. If you wish to allow use of your version of this file only |
28 |
# under the terms of either the GPL or the LGPL, and not to allow others to |
29 |
# use your version of this file under the terms of the MPL, indicate your |
30 |
# decision by deleting the provisions above and replace them with the notice |
31 |
# and other provisions required by the GPL or the LGPL. If you do not delete |
32 |
# the provisions above, a recipient may use your version of this file under |
33 |
# the terms of any one of the MPL, the GPL or the LGPL. |
34 |
# |
35 |
# ***** END LICENSE BLOCK ***** |
36 |
|
37 |
package Moz::Milestone; |
38 |
use strict; |
39 |
|
40 |
use vars qw($officialMilestone |
41 |
$milestone); |
42 |
|
43 |
local $Moz::Milestone::milestone; |
44 |
local $Moz::Milestone::officialMilestone; |
45 |
|
46 |
# |
47 |
# Usage: getOfficialMilestone($milestoneFile) |
48 |
# Returns full milestone (x.x.x.x[ab12pre+]) |
49 |
# |
50 |
sub getOfficialMilestone($) { |
51 |
my $mfile = $_[0]; |
52 |
open(FILE,"$mfile") || |
53 |
die ("Can't open $mfile for reading!"); |
54 |
|
55 |
my $num = <FILE>; |
56 |
while($num =~ /^\s*#/ || $num !~ /^\d/) { |
57 |
$num = <FILE>; |
58 |
} |
59 |
|
60 |
close(FILE); |
61 |
if ($num !~ /^\d/) { return; } |
62 |
chomp($num); |
63 |
# Remove extra ^M caused by using dos-mode line-endings |
64 |
chop $num if (substr($num, -1, 1) eq "\r"); |
65 |
$Moz::Milestone::officialMilestone = $num; |
66 |
$Moz::Milestone::milestone = &getMilestoneNum; |
67 |
return $num; |
68 |
} |
69 |
|
70 |
# |
71 |
# Usage: getMilestoneNum($num) |
72 |
# Returns: milestone without a + if it exists. |
73 |
# |
74 |
sub getMilestoneNum { |
75 |
if (defined($Moz::Milestone::milestone)) { |
76 |
return $Moz::Milestone::milestone; |
77 |
} |
78 |
|
79 |
if (defined($Moz::Milestone::officialMilestone)) { |
80 |
$Moz::Milestone::milestone = $Moz::Milestone::officialMilestone; |
81 |
} else { |
82 |
$Moz::Milestone::milestone = $_[0]; |
83 |
} |
84 |
|
85 |
if ($Moz::Milestone::milestone =~ /\+$/) { # for x.x.x+, strip off the + |
86 |
$Moz::Milestone::milestone =~ s/\+$//; |
87 |
} |
88 |
|
89 |
return $Moz::Milestone::milestone; |
90 |
} |
91 |
|
92 |
# |
93 |
# Usage: getMilestoneQualifier($num) |
94 |
# Returns: + if it exists. |
95 |
# |
96 |
sub getMilestoneQualifier { |
97 |
my $milestoneQualifier; |
98 |
if (defined($Moz::Milestone::officialMilestone)) { |
99 |
$milestoneQualifier = $Moz::Milestone::officialMilestone; |
100 |
} else { |
101 |
$milestoneQualifier = $_[0]; |
102 |
} |
103 |
|
104 |
if ($milestoneQualifier =~ /\+$/) { |
105 |
return "+"; |
106 |
} |
107 |
} |
108 |
|
109 |
sub getMilestoneMajor { |
110 |
my $milestoneMajor; |
111 |
if (defined($Moz::Milestone::milestone)) { |
112 |
$milestoneMajor = $Moz::Milestone::milestone; |
113 |
} else { |
114 |
$milestoneMajor = $_[0]; |
115 |
} |
116 |
my @parts = split(/\./,$milestoneMajor); |
117 |
return $parts[0]; |
118 |
} |
119 |
|
120 |
sub getMilestoneMinor { |
121 |
my $milestoneMinor; |
122 |
if (defined($Moz::Milestone::milestone)) { |
123 |
$milestoneMinor = $Moz::Milestone::milestone; |
124 |
} else { |
125 |
$milestoneMinor = $_[0]; |
126 |
} |
127 |
my @parts = split(/\./,$milestoneMinor); |
128 |
|
129 |
if ($#parts < 1 ) { return 0; } |
130 |
return $parts[1]; |
131 |
} |
132 |
|
133 |
sub getMilestoneMini { |
134 |
my $milestoneMini; |
135 |
if (defined($Moz::Milestone::milestone)) { |
136 |
$milestoneMini = $Moz::Milestone::milestone; |
137 |
} else { |
138 |
$milestoneMini = $_[0]; |
139 |
} |
140 |
my @parts = split(/\./,$milestoneMini); |
141 |
|
142 |
if ($#parts < 2 ) { return 0; } |
143 |
return $parts[2]; |
144 |
} |
145 |
|
146 |
sub getMilestoneMicro { |
147 |
my $milestoneMicro; |
148 |
if (defined($Moz::Milestone::milestone)) { |
149 |
$milestoneMicro = $Moz::Milestone::milestone; |
150 |
} else { |
151 |
$milestoneMicro = $_[0]; |
152 |
} |
153 |
my @parts = split(/\./,$milestoneMicro); |
154 |
|
155 |
if ($#parts < 3 ) { return 0; } |
156 |
return $parts[3]; |
157 |
} |
158 |
|
159 |
sub getMilestoneAB { |
160 |
my $milestoneAB; |
161 |
if (defined($Moz::Milestone::milestone)) { |
162 |
$milestoneAB = $Moz::Milestone::milestone; |
163 |
} else { |
164 |
$milestoneAB = $_[0]; |
165 |
} |
166 |
|
167 |
if ($milestoneAB =~ /a/) { return "alpha"; } |
168 |
if ($milestoneAB =~ /b/) { return "beta"; } |
169 |
return "final"; |
170 |
} |
171 |
|
172 |
# |
173 |
# build_file($template_file,$output_file) |
174 |
# |
175 |
sub build_file($$) { |
176 |
my @FILE; |
177 |
my @MILESTONE_PARTS; |
178 |
my $MINI_VERSION = 0; |
179 |
my $MICRO_VERSION = 0; |
180 |
my $OFFICIAL = 0; |
181 |
my $QUALIFIER = ""; |
182 |
|
183 |
if (!defined($Moz::Milestone::milestone)) { die("$0: no milestone file set!\n"); } |
184 |
@MILESTONE_PARTS = split(/\./, &getMilestoneNum); |
185 |
if ($#MILESTONE_PARTS >= 2) { |
186 |
$MINI_VERSION = 1; |
187 |
} else { |
188 |
$MILESTONE_PARTS[2] = 0; |
189 |
} |
190 |
if ($#MILESTONE_PARTS >= 3) { |
191 |
$MICRO_VERSION = 1; |
192 |
} else { |
193 |
$MILESTONE_PARTS[3] = 0; |
194 |
} |
195 |
if (! &getMilestoneQualifier) { |
196 |
$OFFICIAL = 1; |
197 |
} else { |
198 |
$QUALIFIER = "+"; |
199 |
} |
200 |
|
201 |
if (-e $_[0]) { |
202 |
open(FILE, "$_[0]") || die("$0: Can't open $_[0] for reading!\n"); |
203 |
@FILE = <FILE>; |
204 |
close(FILE); |
205 |
|
206 |
open(FILE, ">$_[1]") || die("$0: Can't open $_[1] for writing!\n"); |
207 |
|
208 |
# |
209 |
# There will be more of these based on what we need for files. |
210 |
# |
211 |
foreach(@FILE) { |
212 |
s/__MOZ_MAJOR_VERSION__/$MILESTONE_PARTS[0]/g; |
213 |
s/__MOZ_MINOR_VERSION__/$MILESTONE_PARTS[1]/g; |
214 |
s/__MOZ_MINI_VERSION__/$MILESTONE_PARTS[2]/g; |
215 |
s/__MOZ_MICRO_VERSION__/$MILESTONE_PARTS[3]/g; |
216 |
if ($MINI_VERSION) { |
217 |
s/__MOZ_OPTIONAL_MINI_VERSION__/.$MILESTONE_PARTS[2]/g; |
218 |
} |
219 |
if ($MICRO_VERSION) { |
220 |
s/__MOZ_OPTIONAL_MICRO_VERSION__/.$MILESTONE_PARTS[3]/g; |
221 |
} |
222 |
|
223 |
print FILE $_; |
224 |
} |
225 |
close(FILE); |
226 |
} else { |
227 |
die("$0: $_[0] doesn't exist for autoversioning!\n"); |
228 |
} |
229 |
|
230 |
} |
231 |
|
232 |
1; |