Bug 459878, fix up errors for 3.0.5 -> 3.1b2 MU test
[mozilla-1.9.git] / config / zipcfunc.pl
blobabb7531ea184db740c1e600e5f4b4ebf33eadafa
1 #!perl
2 #
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
16 # The Original Code is Mozilla Communicator client code, released
17 # March 31, 1998.
19 # The Initial Developer of the Original Code is
20 # Netscape Communications Corporation.
21 # Portions created by the Initial Developer are Copyright (C) 1998-1999
22 # the Initial Developer. All Rights Reserved.
24 # Contributor(s):
25 # Sean Su <ssu@netscape.com>
27 # Alternatively, the contents of this file may be used under the terms of
28 # either of the GNU General Public License Version 2 or later (the "GPL"),
29 # or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 # in which case the provisions of the GPL or the LGPL are applicable instead
31 # of those above. If you wish to allow use of your version of this file only
32 # under the terms of either the GPL or the LGPL, and not to allow others to
33 # use your version of this file under the terms of the MPL, indicate your
34 # decision by deleting the provisions above and replace them with the notice
35 # and other provisions required by the GPL or the LGPL. If you do not delete
36 # the provisions above, a recipient may use your version of this file under
37 # the terms of any one of the MPL, the GPL or the LGPL.
39 # ***** END LICENSE BLOCK *****
41 use Cwd;
42 return(1);
44 sub ZipChrome()
46 # inOsType - Os type
47 # inUpdate - update or noupdate
48 # update - enables time/date compare file update of chrome archives
49 # noupdate - disables time/date compare file update of chrome archives.
50 # it will always update chrome files regardless of time/date stamp.
51 # inSourcePath - path to where the tmpchrome dir
52 # inTargetPath - path to where the bin\chrome dir
53 ($inOsType, $inUpdate, $inSourcePath, $inTargetPath) = @_;
55 # check Os type
56 if($inOsType =~ /win32/i)
58 $gPathDelimiter="\\";
60 elsif($inOsType =~ /mac/i)
62 $gPathDelimiter=":";
64 elsif($inOsType =~ /unix/i)
66 $gPathDelimiter="/";
68 else
70 return(2);
73 # Verify Update
74 if(!($inUpdate =~ /update/i) &&
75 !($inUpdate =~ /noupdate/i))
77 return(2);
80 if($inOsType =~ /win32/i)
82 # Convert all '/' to '\\' or else win32 will have problems
83 $inSourcePath =~ s/\//\\/g;
84 $inTargetPath =~ s/\//\\/g;
87 # Make sure $inSourcePath exists
88 if(!(-e "$inSourcePath"))
90 return(1);
93 # Make sure $inTargetPath exists
94 if(!(-e "$inTargetPath"))
96 mkdir("$inTargetPath", 0775);
99 # Call CreateArchive() on locales, packages, and skins
100 # CreateArchive("loc", $inSourcePath . $gPathDelimiter . "locales", "$inTargetPath");
101 # CreateArchive("pkg", $inSourcePath . $gPathDelimiter . "packages", "$inTargetPath");
102 # CreateArchive("skn", $inSourcePath . $gPathDelimiter . "skins", "$inTargetPath");
103 CreateArchive("jar", $inSourcePath . $gPathDelimiter, "$inTargetPath");
104 return(0);
107 sub CreateArchive()
109 my($inExtension, $inSrc, $inDest) = @_;
110 my($dir);
111 my(@dirList);
112 my(@dirItem);
113 my($dirName);
114 my($saveCwdir);
115 my($mZipParam);
117 # Make sure $inSrc exists
118 if(!(-e "$inSrc"))
120 return(0);
123 # Make sure $inSrc is a directory
124 if(!(-d "$inSrc"))
126 return(0);
129 # Make sure $inDest exists
130 if(!(-e "$inDest"))
132 mkdir("$inDest", 0775);
135 # Check for extension, if none is passed, use .jar as default
136 if($inExtension eq "")
138 $inExtension = "jar";
141 # Save current working directory
142 $saveCwdir = cwd();
143 chdir($inSrc);
145 # For all the subdirectories within $inSrc, create an archive
146 # using the name of the subdirectory, but with the extension passed
147 # in as a parameter.
148 @dirList = <*>;
149 foreach $dir (@dirList)
151 if($inOsType =~ /win32/i)
153 # Convert all '/' to '\\' or else win32 will have problems
154 $dir =~ s/\//\\/g;
157 # Get the leaf dir name of full path
158 # Get the leaf dir name from full path
159 if($inOsType =~ /win32/i)
161 @dirItem = split(/\\/, $dir);
163 elsif($inOsType =~ /mac/i)
165 @dirItem = split(/:/, $dir);
167 elsif($inOsType =~ /unix/i)
169 @dirItem = split(/\//, $dir);
171 $dirName = $dirItem[$#dirItem];
173 if(-d "$dir")
175 # Zip only works for win32 and unix systems
176 if(($inOsType =~ /win32/i) || ($inOsType =~ /unix/i))
178 if($inUpdate =~ /noupdate/i)
180 print "\n";
181 if(-e "$dirName.$inExtension")
183 # Delete archive is one already exists in target location
184 print " Removing $dirName.$inExtension\n";
185 unlink "$dirName.$inExtension";
188 print " Creating $dirName.$inExtension\n";
189 $mZipParam = "";
191 elsif($inUpdate =~ /update/i)
193 if(!(-e "$dirName.$inExtension"))
195 print "\n";
196 print " Creating $dirName.$inExtension\n";
197 $mZipParam = "";
199 else
201 print " Updating $dirName.$inExtension\n";
202 $mZipParam = "-u";
206 # Create the archive in $inDest
207 chdir("$dirName");
208 if(system("zip $mZipParam -r ..$gPathDelimiter$dirName.$inExtension *") != 0)
210 print "Error: zip $mZipParam -r ..$gPathDelimiter$dirName.$inExtension *\n";
211 chdir("..");
212 return(1);
214 chdir("..");
219 # Restore to the current working dir
220 chdir($saveCwdir);
221 return(0);