2000-10-18 21:15:17 +04:00
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Netscape Public
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at http://www.mozilla.org/NPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
# rights and limitations under the License.
|
|
|
|
#
|
|
|
|
# The Original Code is mozilla.org code.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Netscape
|
|
|
|
# Communications Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998-2000 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
|
|
|
#
|
|
|
|
|
|
|
|
package mozBDate;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use IO::File;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
use Exporter ();
|
|
|
|
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
|
|
|
|
|
|
|
|
$VERSION = 1.00;
|
|
|
|
@ISA = qw(Exporter);
|
|
|
|
@EXPORT = qw(&UpdateBuildNumber &SubstituteBuildNumber);
|
|
|
|
%EXPORT_TAGS = ( );
|
|
|
|
@EXPORT_OK = qw();
|
|
|
|
}
|
|
|
|
|
|
|
|
sub write_number($) {
|
|
|
|
my ($file, $num) = @_;
|
|
|
|
unlink($file);
|
|
|
|
open(OUT, ">$file") || die "$file: $!\n";
|
|
|
|
print OUT "$num\n";
|
|
|
|
close(OUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub UpdateBuildNumber($$) {
|
|
|
|
|
|
|
|
my ($outfile, $official) = @_;
|
2002-02-20 09:21:10 +03:00
|
|
|
my $given_date = $ENV{"MOZ_BUILD_DATE"};
|
|
|
|
my $build_number;
|
2000-10-18 21:15:17 +04:00
|
|
|
|
2002-02-20 09:21:10 +03:00
|
|
|
if ($given_date eq "") {
|
|
|
|
# XP way of doing the build date.
|
|
|
|
# 1998091509 = 1998, September, 15th, 9am local time zone
|
|
|
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
|
|
|
|
localtime(time);
|
2000-10-18 21:15:17 +04:00
|
|
|
|
2002-02-20 09:21:10 +03:00
|
|
|
# localtime returns year minus 1900
|
|
|
|
$year = $year + 1900;
|
|
|
|
$build_number = sprintf("%04d%02d%02d%02d", $year, 1+$mon,
|
|
|
|
$mday, $hour);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$build_number = $given_date;
|
|
|
|
}
|
2000-10-18 21:15:17 +04:00
|
|
|
|
|
|
|
if ("$outfile" eq "") {
|
2000-10-21 03:14:12 +04:00
|
|
|
print "$build_number\n";
|
|
|
|
return;
|
2000-10-18 21:15:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($official) {
|
2000-10-21 03:14:12 +04:00
|
|
|
&write_number($outfile, $build_number);
|
2000-10-18 21:15:17 +04:00
|
|
|
} else {
|
|
|
|
|
2000-10-21 03:14:12 +04:00
|
|
|
my $old_num = -1;
|
|
|
|
|
|
|
|
# Only overwrite file if contents are not already set to 0
|
|
|
|
if ( -e $outfile ) {
|
|
|
|
open(OLD, "<$outfile") || die "$outfile: $!\n";
|
|
|
|
$old_num = <OLD>;
|
|
|
|
chomp($old_num);
|
|
|
|
close(OLD);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($old_num != 0) {
|
|
|
|
&write_number($outfile, "0000000000");
|
|
|
|
}
|
2000-10-18 21:15:17 +04:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub SubstituteBuildNumber($$$) {
|
|
|
|
|
|
|
|
my ($outfile, $build_num, $infile) = @_;
|
|
|
|
my $INFILE = new IO::File;
|
|
|
|
my $OUTFILE = new IO::File;
|
2000-10-21 03:14:12 +04:00
|
|
|
|
2000-10-18 21:15:17 +04:00
|
|
|
open $INFILE, "<$build_num";
|
|
|
|
my $build = <$INFILE>;
|
|
|
|
close $INFILE;
|
|
|
|
chomp $build;
|
|
|
|
|
2000-10-21 03:14:12 +04:00
|
|
|
if ($infile ne "") {
|
|
|
|
open($INFILE, "< $infile") || die "$infile: $!\n";
|
2000-10-18 21:15:17 +04:00
|
|
|
} else {
|
2000-10-21 03:14:12 +04:00
|
|
|
open($INFILE, "< $outfile") || die "$outfile: $!\n";
|
2000-10-18 21:15:17 +04:00
|
|
|
}
|
|
|
|
open $OUTFILE, ">${outfile}.old" || die;
|
|
|
|
|
|
|
|
while (<$INFILE>) {
|
2000-10-21 03:14:12 +04:00
|
|
|
|
|
|
|
my $id = $_;
|
|
|
|
my $temp;
|
|
|
|
if ($id =~ "Build ID:") {
|
|
|
|
$temp = "Build ID: " . $build;
|
|
|
|
$id =~ s/Build ID:\s\d+/$temp/;
|
|
|
|
print $OUTFILE $id;
|
|
|
|
}
|
|
|
|
elsif ($id =~ "NS_BUILD_ID") {
|
|
|
|
$temp = "NS_BUILD_ID " . $build;
|
|
|
|
$id =~ s/NS_BUILD_ID\s\d+/$temp/;
|
|
|
|
print $OUTFILE $id;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print $OUTFILE $_;
|
|
|
|
}
|
2000-10-18 21:15:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
close $INFILE;
|
|
|
|
close $OUTFILE;
|
|
|
|
|
|
|
|
unlink $outfile;
|
|
|
|
rename "${outfile}.old", "$outfile";
|
|
|
|
}
|
|
|
|
|
|
|
|
END {};
|
|
|
|
|
|
|
|
1;
|
|
|
|
|