Blame nss/coreconf/import.pl

Packit 40b132
#! /usr/local/bin/perl
Packit 40b132
#
Packit 40b132
# This Source Code Form is subject to the terms of the Mozilla Public
Packit 40b132
# License, v. 2.0. If a copy of the MPL was not distributed with this
Packit 40b132
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
Packit 40b132
Packit 40b132
print STDERR "import.pl\n";
Packit 40b132
Packit 40b132
require('coreconf.pl');
Packit 40b132
Packit 40b132
Packit 40b132
$returncode =0;
Packit 40b132
Packit 40b132
Packit 40b132
#######-- read in variables on command line into %var
Packit 40b132
Packit 40b132
$var{UNZIP} = "unzip -o";
Packit 40b132
Packit 40b132
&parse_argv;
Packit 40b132
Packit 40b132
if (! ($var{IMPORTS} =~ /\w/)) {
Packit 40b132
    print STDERR "nothing to import\n";
Packit 40b132
}
Packit 40b132
Packit 40b132
######-- Do the import!
Packit 40b132
Packit 40b132
foreach $import (split(/ /,$var{IMPORTS}) ) {
Packit 40b132
Packit 40b132
    print STDERR "\n\nIMPORTING .... $import\n-----------------------------\n";
Packit 40b132
Packit 40b132
Packit 40b132
# if a specific version specified in IMPORT variable
Packit 40b132
# (if $import has a slash in it)
Packit 40b132
Packit 40b132
    if ($import =~ /\//) {
Packit 40b132
        # $component=everything before the first slash of $import
Packit 40b132
Packit 40b132
	$import =~ m|^([^/]*)/|; 
Packit 40b132
	$component = $1;
Packit 40b132
Packit 40b132
	$import =~ m|^(.*)/([^/]*)$|;
Packit 40b132
Packit 40b132
	# $path=everything before the last slash of $import
Packit 40b132
	$path = $1;
Packit 40b132
Packit 40b132
	# $version=everything after the last slash of $import
Packit 40b132
	$version = $2;
Packit 40b132
Packit 40b132
	if ($var{VERSION} ne "current") {
Packit 40b132
	    $version = $var{VERSION};
Packit 40b132
	}
Packit 40b132
    }
Packit 40b132
    else {
Packit 40b132
	$component = $import;
Packit 40b132
	$path = $import;
Packit 40b132
	$version = $var{VERSION};
Packit 40b132
    }
Packit 40b132
Packit 40b132
    $releasejardir = "$var{RELEASE_TREE}/$path";
Packit 40b132
    if ($version eq "current") {
Packit 40b132
	print STDERR "Current version specified. Reading 'current' file ... \n";
Packit 40b132
	
Packit 40b132
	open(CURRENT,"$releasejardir/current") || die "NO CURRENT FILE\n";
Packit 40b132
	$version = <CURRENT>;
Packit 40b132
	$version =~ s/(\r?\n)*$//; # remove any trailing [CR/]LF's
Packit 40b132
	close(CURRENT);
Packit 40b132
	print STDERR "Using version $version\n";
Packit 40b132
	if ( $version eq "") {
Packit 40b132
	    die "Current version file empty. Stopping\n";
Packit 40b132
	}
Packit 40b132
    }
Packit 40b132
    
Packit 40b132
    $releasejardir = "$releasejardir/$version";
Packit 40b132
    if ( ! -d $releasejardir) {
Packit 40b132
	die "$releasejardir doesn't exist (Invalid Version?)\n";
Packit 40b132
    }
Packit 40b132
    foreach $jarfile (split(/ /,$var{FILES})) {
Packit 40b132
Packit 40b132
	($relpath,$distpath,$options) = split(/\|/, $var{$jarfile});
Packit 40b132
Packit 40b132
	if ($var{'OVERRIDE_IMPORT_CHECK'} eq 'YES') {
Packit 40b132
	    $options =~ s/v//g;
Packit 40b132
	}
Packit 40b132
Packit 40b132
	if ( $relpath ne "") { $releasejarpathname = "$releasejardir/$relpath";}
Packit 40b132
	else { $releasejarpathname = $releasejardir; }
Packit 40b132
Packit 40b132
# If a component doesn't have IDG versions, import the DBG ones
Packit 40b132
    if( ! -e "$releasejarpathname/$jarfile" ) {
Packit 40b132
        if( $relpath =~ /IDG\.OBJ$/ ) {
Packit 40b132
            $relpath =~ s/IDG.OBJ/DBG.OBJ/;
Packit 40b132
            $releasejarpathname = "$releasejardir/$relpath";
Packit 40b132
        } elsif( $relpath =~ /IDG\.OBJD$/ ) {
Packit 40b132
            $relpath =~ s/IDG.OBJD/DBG.OBJD/;
Packit 40b132
            $releasejarpathname = "$releasejardir/$relpath";
Packit 40b132
        }
Packit 40b132
    }
Packit 40b132
Packit 40b132
	if (-e "$releasejarpathname/$jarfile") {
Packit 40b132
	    print STDERR "\nWorking on jarfile: $jarfile\n";
Packit 40b132
	    
Packit 40b132
	    if ($distpath =~ m|/$|) {
Packit 40b132
		$distpathname = "$distpath$component";
Packit 40b132
	    }
Packit 40b132
	    else {
Packit 40b132
		$distpathname = "$distpath"; 
Packit 40b132
	    }
Packit 40b132
	  
Packit 40b132
	  
Packit 40b132
#the block below is used to determine whether or not the xp headers have
Packit 40b132
#already been imported for this component
Packit 40b132
Packit 40b132
	    $doimport = 1;
Packit 40b132
	  if ($options =~ /v/) {   # if we should check the imported version
Packit 40b132
	      print STDERR "Checking if version file exists $distpathname/version\n";
Packit 40b132
	      if (-e "$distpathname/version") {
Packit 40b132
		  open( VFILE, "<$distpathname/version") ||
Packit 40b132
		      die "Cannot open $distpathname/version for reading. Permissions?\n";
Packit 40b132
		  $importversion = <VFILE>;
Packit 40b132
		  close (VFILE);
Packit 40b132
		  $importversion =~ s/\r?\n$//;   # Strip off any trailing CR/LF
Packit 40b132
		  if ($version eq $importversion) {
Packit 40b132
		      print STDERR "$distpathname version '$importversion' already imported. Skipping...\n";
Packit 40b132
		      $doimport =0;
Packit 40b132
		  }
Packit 40b132
	      }
Packit 40b132
	  }
Packit 40b132
	  
Packit 40b132
	  if ($doimport == 1) {
Packit 40b132
	      if (! -d "$distpathname") {
Packit 40b132
		  &rec_mkdir("$distpathname");
Packit 40b132
	      }
Packit 40b132
	      # delete the stuff in there already.
Packit 40b132
	      # (this should really be recursive delete.)
Packit 40b132
	      
Packit 40b132
	      if ($options =~ /v/) {
Packit 40b132
		  $remheader = "\nREMOVING files in '$distpathname/' :";
Packit 40b132
		  opendir(DIR,"$distpathname") ||
Packit 40b132
		      die ("Cannot read directory $distpathname\n");
Packit 40b132
		  @filelist = readdir(DIR);
Packit 40b132
		  closedir(DIR);
Packit 40b132
		  foreach $file ( @filelist ) {
Packit 40b132
		      if (! ($file =~ m!/.?.$!) ) {
Packit 40b132
			  if (! (-d $file)) {
Packit 40b132
			      $file =~ m!([^/]*)$!;
Packit 40b132
			      print STDERR "$remheader $1";
Packit 40b132
			      $remheader = " ";
Packit 40b132
			      unlink "$distpathname/$file";
Packit 40b132
			  }
Packit 40b132
		      }
Packit 40b132
		  }
Packit 40b132
	      }
Packit 40b132
Packit 40b132
Packit 40b132
	      print STDERR "\n\n";
Packit 40b132
Packit 40b132
	      print STDERR "\nExtracting jarfile '$jarfile' to local directory $distpathname/\n";
Packit 40b132
	      
Packit 40b132
	      print STDERR "$var{UNZIP} $releasejarpathname/$jarfile -d $distpathname\n";
Packit 40b132
	      system("$var{UNZIP} $releasejarpathname/$jarfile -d $distpathname");
Packit 40b132
	      
Packit 40b132
	      $r = $?;
Packit 40b132
Packit 40b132
	      if ($options =~ /v/) {
Packit 40b132
		  if ($r == 0) {
Packit 40b132
		      unlink ("$distpathname/version");
Packit 40b132
		      if (open(VFILE,">$distpathname/version")) {
Packit 40b132
			  print VFILE "$version\n";
Packit 40b132
			  close(VFILE);
Packit 40b132
		      }
Packit 40b132
		  }
Packit 40b132
		  else {
Packit 40b132
		      print STDERR "Could not create '$distpathname/version'. Permissions?\n";
Packit 40b132
		      $returncode ++;
Packit 40b132
		  }
Packit 40b132
	      }
Packit 40b132
	  }  # if (doimport)
Packit 40b132
	} # if (-e releasejarpathname/jarfile)
Packit 40b132
    } # foreach jarfile)
Packit 40b132
} # foreach IMPORT
Packit 40b132
Packit 40b132
Packit 40b132
Packit 40b132
exit($returncode);
Packit 40b132
Packit 40b132
Packit 40b132
Packit 40b132
Packit 40b132