Import from 1.9a8 tarball
[mozilla-nss.git] / security / coreconf / import.pl
blobbc50077c9c83cc5866fe6e129d1a695aca8edd04
1 #! /usr/local/bin/perl
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 the Netscape security libraries.
18 # The Initial Developer of the Original Code is
19 # Netscape Communications Corporation.
20 # Portions created by the Initial Developer are Copyright (C) 1994-2000
21 # the Initial Developer. All Rights Reserved.
23 # Contributor(s):
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.
37 # ***** END LICENSE BLOCK *****
39 print STDERR "import.pl\n";
41 require('coreconf.pl');
44 $returncode =0;
47 #######-- read in variables on command line into %var
49 $var{UNZIP} = "unzip -o";
51 &parse_argv;
53 if (! ($var{IMPORTS} =~ /\w/)) {
54 print STDERR "nothing to import\n";
57 ######-- Do the import!
59 foreach $import (split(/ /,$var{IMPORTS}) ) {
61 print STDERR "\n\nIMPORTING .... $import\n-----------------------------\n";
64 # if a specific version specified in IMPORT variable
65 # (if $import has a slash in it)
67 if ($import =~ /\//) {
68 # $component=everything before the first slash of $import
70 $import =~ m|^([^/]*)/|;
71 $component = $1;
73 $import =~ m|^(.*)/([^/]*)$|;
75 # $path=everything before the last slash of $import
76 $path = $1;
78 # $version=everything after the last slash of $import
79 $version = $2;
81 if ($var{VERSION} ne "current") {
82 $version = $var{VERSION};
85 else {
86 $component = $import;
87 $path = $import;
88 $version = $var{VERSION};
91 $releasejardir = "$var{RELEASE_TREE}/$path";
92 if ($version eq "current") {
93 print STDERR "Current version specified. Reading 'current' file ... \n";
95 open(CURRENT,"$releasejardir/current") || die "NO CURRENT FILE\n";
96 $version = <CURRENT>;
97 $version =~ s/(\r?\n)*$//; # remove any trailing [CR/]LF's
98 close(CURRENT);
99 print STDERR "Using version $version\n";
100 if ( $version eq "") {
101 die "Current version file empty. Stopping\n";
105 $releasejardir = "$releasejardir/$version";
106 if ( ! -d $releasejardir) {
107 die "$releasejardir doesn't exist (Invalid Version?)\n";
109 foreach $jarfile (split(/ /,$var{FILES})) {
111 ($relpath,$distpath,$options) = split(/\|/, $var{$jarfile});
113 if ($var{'OVERRIDE_IMPORT_CHECK'} eq 'YES') {
114 $options =~ s/v//g;
117 if ( $relpath ne "") { $releasejarpathname = "$releasejardir/$relpath";}
118 else { $releasejarpathname = $releasejardir; }
120 # If a component doesn't have IDG versions, import the DBG ones
121 if( ! -e "$releasejarpathname/$jarfile" ) {
122 if( $relpath =~ /IDG\.OBJ$/ ) {
123 $relpath =~ s/IDG.OBJ/DBG.OBJ/;
124 $releasejarpathname = "$releasejardir/$relpath";
125 } elsif( $relpath =~ /IDG\.OBJD$/ ) {
126 $relpath =~ s/IDG.OBJD/DBG.OBJD/;
127 $releasejarpathname = "$releasejardir/$relpath";
131 if (-e "$releasejarpathname/$jarfile") {
132 print STDERR "\nWorking on jarfile: $jarfile\n";
134 if ($distpath =~ m|/$|) {
135 $distpathname = "$distpath$component";
137 else {
138 $distpathname = "$distpath";
142 #the block below is used to determine whether or not the xp headers have
143 #already been imported for this component
145 $doimport = 1;
146 if ($options =~ /v/) { # if we should check the imported version
147 print STDERR "Checking if version file exists $distpathname/version\n";
148 if (-e "$distpathname/version") {
149 open( VFILE, "<$distpathname/version") ||
150 die "Cannot open $distpathname/version for reading. Permissions?\n";
151 $importversion = <VFILE>;
152 close (VFILE);
153 $importversion =~ s/\r?\n$//; # Strip off any trailing CR/LF
154 if ($version eq $importversion) {
155 print STDERR "$distpathname version '$importversion' already imported. Skipping...\n";
156 $doimport =0;
161 if ($doimport == 1) {
162 if (! -d "$distpathname") {
163 &rec_mkdir("$distpathname");
165 # delete the stuff in there already.
166 # (this should really be recursive delete.)
168 if ($options =~ /v/) {
169 $remheader = "\nREMOVING files in '$distpathname/' :";
170 opendir(DIR,"$distpathname") ||
171 die ("Cannot read directory $distpathname\n");
172 @filelist = readdir(DIR);
173 closedir(DIR);
174 foreach $file ( @filelist ) {
175 if (! ($file =~ m!/.?.$!) ) {
176 if (! (-d $file)) {
177 $file =~ m!([^/]*)$!;
178 print STDERR "$remheader $1";
179 $remheader = " ";
180 unlink "$distpathname/$file";
187 print STDERR "\n\n";
189 print STDERR "\nExtracting jarfile '$jarfile' to local directory $distpathname/\n";
191 print STDERR "$var{UNZIP} $releasejarpathname/$jarfile -d $distpathname\n";
192 system("$var{UNZIP} $releasejarpathname/$jarfile -d $distpathname");
194 $r = $?;
196 if ($options =~ /v/) {
197 if ($r == 0) {
198 unlink ("$distpathname/version");
199 if (open(VFILE,">$distpathname/version")) {
200 print VFILE "$version\n";
201 close(VFILE);
204 else {
205 print STDERR "Could not create '$distpathname/version'. Permissions?\n";
206 $returncode ++;
209 } # if (doimport)
210 } # if (-e releasejarpathname/jarfile)
211 } # foreach jarfile)
212 } # foreach IMPORT
216 exit($returncode);