3
# The contents of this file are subject to the Netscape Public
4
# License Version 1.1 (the "License"); you may not use this file
5
# except in compliance with the License. You may obtain a copy of
6
# the License at http://www.mozilla.org/NPL/
8
# Software distributed under the License is distributed on an "AS
9
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
# implied. See the License for the specific language governing
11
# rights and limitations under the License.
13
# The Original Code is Mozilla Communicator client code, released
16
# The Initial Developer of the Original Code is Netscape
17
# Communications Corporation. Portions created by Netscape are
18
# Copyright (C) 1998-1999 Netscape Communications Corporation. All
22
# Sean Su <ssu@netscape.com>
26
# This perl script parses the input file for special variables
27
# in the format of $Variable$ and replace it with the appropriate
30
# Input: .jst file - which is a .js template
31
# default version - a date in the form of:
32
# major.minor.release.yyyymmdyhr
33
# ie: 5.0.0.1999120910
34
# component staging path - path to where the components are staged at
36
# ie: perl makejs.pl xpcom.jst 5.0.0.99256
43
# Make sure there are at least three arguments
46
die "usage: $0 <.jst file> <default version> <staging path>
48
.jst file : .js template input file
49
default version : default julian base version number to use in the
50
form of: major.minor.release.yydoy
52
component staging path : path to where this component is staged at
53
ie: z:/stage/windows/32bit/en/5.0/xpcom
58
$topsrcdir = GetTopSrcDir();
59
$inJstFile = $ARGV[0];
60
$inVersion = $ARGV[1];
61
$inStagePath = $ARGV[2];
63
# get environment vars
64
$userAgent = $ENV{WIZ_userAgent};
65
$userAgentShort = $ENV{WIZ_userAgentShort};
66
$xpinstallVersion = $ENV{WIZ_xpinstallVersion};
67
$nameCompany = $ENV{WIZ_nameCompany};
68
$nameProduct = $ENV{WIZ_nameProduct};
69
$nameProductInternal = $ENV{WIZ_nameProductInternal};
70
$shortNameProduct = $ENV{WIZ_shortNameProduct};
71
$fileMainExe = $ENV{WIZ_fileMainExe};
72
$fileUninstall = $ENV{WIZ_fileUninstall};
73
$greBuildID = $ENV{WIZ_greBuildID};
74
$greFileVersion = $ENV{WIZ_greFileVersion};
75
$greUniqueID = $ENV{WIZ_greUniqueID};
76
$greVersion = $ENV{WIZ_greVersion};
78
# Get the name of the file replacing the .jst extension with a .js extension
79
$inJstFileBase = $inJstFile;
80
$inJstFileBase =~ s/\.jst//;
81
$outJsFile = "$inJstFileBase.js";
82
$outTempFile = "$inJstFileBase.template";
85
print " copy \"$topsrcdir/xpinstall/packager/common/share.t\" $outTempFile\n";
86
copy("$topsrcdir/xpinstall/packager/common/share.t", "$outTempFile");
87
system("cat $inJstFile >> $outTempFile");
89
# Open the input .template file
90
open(fpInTemplate, $outTempFile) || die "\ncould not open $outTempFile: $!\n";
92
# Open the output .js file
93
open(fpOutJs, ">$outJsFile") || die "\nCould not open $outJsFile: $!\n";
95
# While loop to read each line from input file
96
while($line = <fpInTemplate>)
98
if($line =~ /\$SpaceRequired\$/i) # For each line read, search and replace $SpaceRequired$ with the calculated size
102
# split read line by ":" deliminator
103
@colonSplit = split(/:/, $line);
106
@semiColonSplit = split(/;/, $colonSplit[1]);
107
$subDir = $semiColonSplit[0];
108
$spaceRequired = GetSpaceRequired("$inStagePath/$subDir");
109
$line =~ s/\$SpaceRequired\$:$subDir/$spaceRequired/i;
113
$spaceRequired = GetSpaceRequired("$inStagePath");
114
$line =~ s/\$SpaceRequired\$/$spaceRequired/i;
119
$line =~ s/\$Version\$/$inVersion/i;
120
$line =~ s/\$UserAgent\$/$userAgent/i;
121
$line =~ s/\$UserAgentShort\$/$userAgentShort/i;
122
$line =~ s/\$XPInstallVersion\$/$xpinstallVersion/i;
123
$line =~ s/\$CompanyName\$/$nameCompany/i;
124
$line =~ s/\$ProductName\$/$nameProduct/i;
125
$line =~ s/\$ProductShortName\$/$shortNameProduct/i;
126
$line =~ s/\$ProductNameInternal\$/$nameProductInternal/gi;
127
$line =~ s/\$MainExeFile\$/$fileMainExe/i;
128
$line =~ s/\$UninstallFile\$/$fileUninstall/i;
129
$line =~ s/\$GreBuildID\$/$greBuildID/gi;
130
$line =~ s/\$GreFileVersion\$/$greFileVersion/gi;
131
$line =~ s/\$GreUniqueID\$/$greUniqueID/gi;
132
$line =~ s/\$GreVersion\$/$greVersion/gi;
142
sub GetSpaceRequired()
145
my($spaceRequired) = 0;
147
print " calculating size for $inPath\n";
149
$spaceRequired = `\"$ENV{WIZ_distInstallPath}/ds32.exe\" /D /L0 /A /S /C 32768 $inPath`;
151
@dirEntries = <$inPath/*>;
153
# iterate over all dir entries
154
foreach $item ( @dirEntries )
156
# if dir entry is dir
159
# add GetSpaceRequired(<dirEntry>) to space used
160
$spaceRequired += GetSpaceRequired($item);
162
# else if dir entry is file
165
# add size of file to space used
166
$spaceRequired += (-s $item);
171
$spaceRequired = int($spaceRequired / 1024);
173
return($spaceRequired);
176
sub ParseUserAgentShort()
178
my($aUserAgent) = @_;
179
my($aUserAgentShort);
181
@spaceSplit = split(/ /, $aUserAgent);
182
if($#spaceSplit >= 0)
184
$aUserAgentShort = $spaceSplit[0];
187
return($aUserAgentShort);
192
my($rootDir) = dirname($0) . "/$DEPTH";
193
my($savedCwdDir) = cwd();