import.pl 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #! /usr/local/bin/perl
  2. #
  3. # This Source Code Form is subject to the terms of the Mozilla Public
  4. # License, v. 2.0. If a copy of the MPL was not distributed with this
  5. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. print STDERR "import.pl\n";
  7. require('coreconf.pl');
  8. $returncode =0;
  9. #######-- read in variables on command line into %var
  10. $var{UNZIP} = "unzip -o";
  11. &parse_argv;
  12. if (! ($var{IMPORTS} =~ /\w/)) {
  13. print STDERR "nothing to import\n";
  14. }
  15. ######-- Do the import!
  16. foreach $import (split(/ /,$var{IMPORTS}) ) {
  17. print STDERR "\n\nIMPORTING .... $import\n-----------------------------\n";
  18. # if a specific version specified in IMPORT variable
  19. # (if $import has a slash in it)
  20. if ($import =~ /\//) {
  21. # $component=everything before the first slash of $import
  22. $import =~ m|^([^/]*)/|;
  23. $component = $1;
  24. $import =~ m|^(.*)/([^/]*)$|;
  25. # $path=everything before the last slash of $import
  26. $path = $1;
  27. # $version=everything after the last slash of $import
  28. $version = $2;
  29. if ($var{VERSION} ne "current") {
  30. $version = $var{VERSION};
  31. }
  32. }
  33. else {
  34. $component = $import;
  35. $path = $import;
  36. $version = $var{VERSION};
  37. }
  38. $releasejardir = "$var{RELEASE_TREE}/$path";
  39. if ($version eq "current") {
  40. print STDERR "Current version specified. Reading 'current' file ... \n";
  41. open(CURRENT,"$releasejardir/current") || die "NO CURRENT FILE\n";
  42. $version = <CURRENT>;
  43. $version =~ s/(\r?\n)*$//; # remove any trailing [CR/]LF's
  44. close(CURRENT);
  45. print STDERR "Using version $version\n";
  46. if ( $version eq "") {
  47. die "Current version file empty. Stopping\n";
  48. }
  49. }
  50. $releasejardir = "$releasejardir/$version";
  51. if ( ! -d $releasejardir) {
  52. die "$releasejardir doesn't exist (Invalid Version?)\n";
  53. }
  54. foreach $jarfile (split(/ /,$var{FILES})) {
  55. ($relpath,$distpath,$options) = split(/\|/, $var{$jarfile});
  56. if ($var{'OVERRIDE_IMPORT_CHECK'} eq 'YES') {
  57. $options =~ s/v//g;
  58. }
  59. if ( $relpath ne "") { $releasejarpathname = "$releasejardir/$relpath";}
  60. else { $releasejarpathname = $releasejardir; }
  61. # If a component doesn't have IDG versions, import the DBG ones
  62. if( ! -e "$releasejarpathname/$jarfile" ) {
  63. if( $relpath =~ /IDG\.OBJ$/ ) {
  64. $relpath =~ s/IDG.OBJ/DBG.OBJ/;
  65. $releasejarpathname = "$releasejardir/$relpath";
  66. } elsif( $relpath =~ /IDG\.OBJD$/ ) {
  67. $relpath =~ s/IDG.OBJD/DBG.OBJD/;
  68. $releasejarpathname = "$releasejardir/$relpath";
  69. }
  70. }
  71. if (-e "$releasejarpathname/$jarfile") {
  72. print STDERR "\nWorking on jarfile: $jarfile\n";
  73. if ($distpath =~ m|/$|) {
  74. $distpathname = "$distpath$component";
  75. }
  76. else {
  77. $distpathname = "$distpath";
  78. }
  79. #the block below is used to determine whether or not the xp headers have
  80. #already been imported for this component
  81. $doimport = 1;
  82. if ($options =~ /v/) { # if we should check the imported version
  83. print STDERR "Checking if version file exists $distpathname/version\n";
  84. if (-e "$distpathname/version") {
  85. open( VFILE, "<$distpathname/version") ||
  86. die "Cannot open $distpathname/version for reading. Permissions?\n";
  87. $importversion = <VFILE>;
  88. close (VFILE);
  89. $importversion =~ s/\r?\n$//; # Strip off any trailing CR/LF
  90. if ($version eq $importversion) {
  91. print STDERR "$distpathname version '$importversion' already imported. Skipping...\n";
  92. $doimport =0;
  93. }
  94. }
  95. }
  96. if ($doimport == 1) {
  97. if (! -d "$distpathname") {
  98. &rec_mkdir("$distpathname");
  99. }
  100. # delete the stuff in there already.
  101. # (this should really be recursive delete.)
  102. if ($options =~ /v/) {
  103. $remheader = "\nREMOVING files in '$distpathname/' :";
  104. opendir(DIR,"$distpathname") ||
  105. die ("Cannot read directory $distpathname\n");
  106. @filelist = readdir(DIR);
  107. closedir(DIR);
  108. foreach $file ( @filelist ) {
  109. if (! ($file =~ m!/.?.$!) ) {
  110. if (! (-d $file)) {
  111. $file =~ m!([^/]*)$!;
  112. print STDERR "$remheader $1";
  113. $remheader = " ";
  114. unlink "$distpathname/$file";
  115. }
  116. }
  117. }
  118. }
  119. print STDERR "\n\n";
  120. print STDERR "\nExtracting jarfile '$jarfile' to local directory $distpathname/\n";
  121. print STDERR "$var{UNZIP} $releasejarpathname/$jarfile -d $distpathname\n";
  122. system("$var{UNZIP} $releasejarpathname/$jarfile -d $distpathname");
  123. $r = $?;
  124. if ($options =~ /v/) {
  125. if ($r == 0) {
  126. unlink ("$distpathname/version");
  127. if (open(VFILE,">$distpathname/version")) {
  128. print VFILE "$version\n";
  129. close(VFILE);
  130. }
  131. }
  132. else {
  133. print STDERR "Could not create '$distpathname/version'. Permissions?\n";
  134. $returncode ++;
  135. }
  136. }
  137. } # if (doimport)
  138. } # if (-e releasejarpathname/jarfile)
  139. } # foreach jarfile)
  140. } # foreach IMPORT
  141. exit($returncode);