[Bio] / FigCommon / bootstrap.pl Repository:
ViewVC logotype

Diff of /FigCommon/bootstrap.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Fri Dec 19 22:57:48 2003 UTC revision 1.28, Mon Dec 5 19:10:06 2005 UTC
# Line 1  Line 1 
1  #  #
2    # Copyright (c) 2003-2006 University of Chicago and Fellowship
3    # for Interpretations of Genomes. All Rights Reserved.
4    #
5    # This file is part of the SEED Toolkit.
6    #
7    # The SEED Toolkit is free software. You can redistribute
8    # it and/or modify it under the terms of the SEED Toolkit
9    # Public License.
10    #
11    # You should have received a copy of the SEED Toolkit Public License
12    # along with this program; if not write to the University of Chicago
13    # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14    # Genomes at veronika@thefig.info or download a copy from
15    # http://www.theseed.org/LICENSE.TXT.
16    #
17    
18    #
19  # FIG bootstrap script.  # FIG bootstrap script.
20  #  #
21  # Control is passed here from the toplevel configure (or dists/releases/install depending  # Control is passed here from the toplevel configure (or dists/releases/install depending
# Line 34  Line 51 
51    
52  BEGIN {  BEGIN {
53    
54      # print "Here in the perl bootstrap. inc is:\n" . join("\n", @INC), "\n";      print "Here in the perl bootstrap. inc is:\n" . join("\n", @INC), "\n";
55    
56      my $my_prefix, $prefix, $inc, @newInc;      my $my_prefix, $prefix, $inc, @newInc;
57    
# Line 56  Line 73 
73          }          }
74    
75          $::perlenv_override = 1;          $::perlenv_override = 1;
     }  
   
     # print "New inc is:\n" . join("\n", @newInc), "\n";  
   
76      @INC = @newInc;      @INC = @newInc;
77  }  }
78    }
79    
80    
81  use FileHandle;  use FileHandle;
# Line 105  Line 119 
119    
120  our $fig_disk = $ENV{FIG_HOME};  our $fig_disk = $ENV{FIG_HOME};
121  our $env_name = $ENV{FIGCONFIG_ENV};  our $env_name = $ENV{FIGCONFIG_ENV};
122    our $env_dir = "$ENV{FIGCONFIG_ENV_DIR}";
123  our $env_bin = "$ENV{FIGCONFIG_ENV_DIR}/bin";  our $env_bin = "$ENV{FIGCONFIG_ENV_DIR}/bin";
124  our $env_lib = "$ENV{FIGCONFIG_ENV_DIR}/lib";  our $env_lib = "$ENV{FIGCONFIG_ENV_DIR}/lib";
125  our $dist_bin = "$ENV{FIGCONFIG_RELEASE_DIR}/bin/$ENV{FIGCONFIG_ENV}";  #
126  our $dist_lib = "$ENV{FIGCONFIG_RELEASE_DIR}/lib/$ENV{FIGCONFIG_ENV}";  # We are moving to use a symlink in dist/releases/current for these.
127    # This symlink is managed by switch_to_release.
128    #
129    #our $release_bin = "$ENV{FIGCONFIG_RELEASE_DIR}/bin/$ENV{FIGCONFIG_ENV}";
130    #our $release_lib = "$ENV{FIGCONFIG_RELEASE_DIR}/lib/$ENV{FIGCONFIG_ENV}";
131    
132    our $release_bin = "$fig_disk/dist/releases/current/$ENV{FIGCONFIG_ENV}/bin";
133    our $release_lib = "$fig_disk/dist/releases/current/$ENV{FIGCONFIG_ENV}/lib";
134    
135    our $fig_bin = "$fig_disk/FIG/bin";
136    
137  #  #
138  # Location of start/stop servers scripts.  # Location of start/stop servers scripts.
# Line 124  Line 148 
148    
149      my $fig = "$fig_disk/FIG";      my $fig = "$fig_disk/FIG";
150      my $data = "$fig/Data";      my $data = "$fig/Data";
151        my $sproutData = "$fig/SproutData";
152    
153      my $hostname = `hostname`;      my $hostname = `hostname`;
154      chomp $hostname;      chomp $hostname;
155    
156      push(@$Config, ["fig_disk", $fig_disk, 1]);      push(@$Config, ["fig_disk", $fig_disk, 1]);
157      push(@$Config, ["blastmast", "$fig_disk/BLASTMAT", 1]);      push(@$Config, ["blastmat", "$fig_disk/BLASTMAT", 1]);
158      push(@$Config, ["fig", $fig, 1]);      push(@$Config, ["fig", $fig, 1]);
159      push(@$Config, ["bin", $dist_bin, 1]);      push(@$Config, ["bin", $fig_bin, 1]);
160      push(@$Config, ["ext_bin", $env_bin, 1]);      push(@$Config, ["ext_bin", $env_bin, 1]);
161        push(@$Config, ["common_runtime", $env_dir, 1]);
162        push(@$Config, ["arch", $ENV{FIGCONFIG_ENV}, 1]);
163        push(@$Config, ["var", "$fig/var", 1]);
164      push(@$Config, ["data", $data, 1]);      push(@$Config, ["data", $data, 1]);
165      push(@$Config, ["global", "$data/Global", 1]);      push(@$Config, ["global", "$data/Global", 1]);
166      push(@$Config, ["organisms", "$data/Organisms", 1]);      push(@$Config, ["organisms", "$data/Organisms", 1]);
167      push(@$Config, ["RC", "$fig_disk/FIG/ResolutionCenter", 1]);      push(@$Config, ["RC", "$fig_disk/FIG/ResolutionCenter", 1]);
168      push(@$Config, ["NR", "$fig_disk/FIG/NR", 1]);      push(@$Config, ["NR", "$fig_disk/FIG/NR", 1]);
169      push(@$Config, ["temp", "$fig_disk/FIG/Tmp", 1]);      push(@$Config, ["temp", "$fig_disk/FIG/Tmp", 1]);
170      push(@$Config, ["temp_url", "http://$hostname/FIG-Tmp", 1]);      push(@$Config, ["sproutData", $sproutData, 1]);
171      push(@$Config, ["cgi_url", "http://$hostname/FIG", 1]);  
172        my $sandbox;
173        if ($ENV{FIGCONFIG_SANDBOX})
174        {
175            $sandbox = "/$ENV{FIGCONFIG_SANDBOX}";
176        }
177    
178        push(@$Config, ["temp_url", "http://$hostname$sandbox/FIG-Tmp", 1]);
179        push(@$Config, ["cgi_url", "http://$hostname$sandbox/FIG", 1]);
180    
181        #
182        # Add values for a relative base href of temp and CGI pages.  The latter
183        # is used by HHTP.pm to write common page start.  It would make the most
184        # sense to derive the above 2 values from these.  -- GJO
185        #
186    
187        push(@$Config, ["temp_base", "$sandbox/FIG-Tmp/", 1]);
188        push(@$Config, ["cgi_base", "$sandbox/FIG/", 1]);
189  }  }
190    
191  sub compute_environment  sub compute_environment
# Line 151  Line 196 
196    
197      push(@$Env, ["RTROOT", $ENV{FIG_HOME}, 0]);      push(@$Env, ["RTROOT", $ENV{FIG_HOME}, 0]);
198      push(@$Env, ["RTDIST", "\$RTROOT/dist", 0]);      push(@$Env, ["RTDIST", "\$RTROOT/dist", 0]);
199        push(@$Env, ["RTSITECONFIGDIR", "\$RTROOT/config", 0]);
200      push(@$Env, ["RTARCH", $ENV{FIGCONFIG_ENV}, 0]);      push(@$Env, ["RTARCH", $ENV{FIGCONFIG_ENV}, 0]);
201      push(@$Env, ["RTCURRENT", $ENV{FIGCONFIG_RELEASE}, 0]);      push(@$Env, ["RTCURRENT", "`cat \$RTROOT/CURRENT_RELEASE`", 0]);
202      push(@$Env, ["FIG_HOME", $ENV{FIG_HOME}, 0]);      push(@$Env, ["FIG_HOME", $ENV{FIG_HOME}, 0]);
203    
204      push(@$Env, ["BLASTMAT", "$ENV{FIG_HOME}/BLASTMAT", 0]);      push(@$Env, ["BLASTMAT", "$ENV{FIG_HOME}/BLASTMAT", 0]);
# Line 165  Line 211 
211      #      #
212    
213      my @path = ();      my @path = ();
214        push(@path, $fig_bin);
215      push(@path, $env_bin);      push(@path, $env_bin);
     push(@path, $dist_bin);  
216      push(@path, "$fig_disk/bin");      push(@path, "$fig_disk/bin");
217    
218      push(@$Env, ["PATH", join(":", @path), 1]);      push(@$Env, ["PATH", join(":", @path), 1]);
219    
220      push(@$Env, ["LD_LIBRARY_PATH", "${env_lib}:${dist_lib}", 1]);      #
221        # Compute  LD_LIBRARY_PATH.
222        #
223        # Some packages, like mysql, place their shared libs in subdirectories
224        # of the libdir.
225        #
226    
227        my @ld_path = ($env_lib);
228    
229        my $dh;
230        if (!opendir($dh, $env_lib))
231        {
232            warn "Could not opendir $env_lib: $!";
233        }
234    
235        while ($_ = readdir($dh))
236        {
237            next if /^\./;
238    
239            my $path = "$env_lib/$_";
240            next unless -d $path;
241    
242            #
243            # See if there are any .so's in here.
244            #
245    
246            my @solist = <$path/*.so*>;
247            if (@solist > 0)
248            {
249                push(@ld_path, $path);
250            }
251        }
252        closedir($dh);
253    
254        #
255        # And if perl is dynamically linked, we need to add the perl core directory
256        # to the path too.
257        #
258    
259        my @coredir = <$env_lib/perl5/*/*/CORE>;
260        if (@coredir)
261        {
262            if ( -f "$coredir[0]/libperl.so" )
263            {
264                print "Found libperl in $coredir[0]\n";
265                push(@ld_path, $coredir[0]);
266            }
267        }
268    
269        my $ld_path = join(":", @ld_path);
270        $OtherConfig->{ld_library_path} = $ld_path;
271    
272        push(@$Env, ["LD_LIBRARY_PATH", $ld_path, 1]);
273    
274        my @perllib = grep({ $_ ne "." } @INC,
275                           $release_lib,
276                           "$release_lib/FigKernelPackages",
277                           "$fig_disk/config");
278    
279        push(@$Env, ["PERL5LIB", join(":", @perllib), 1]);
280  }  }
281    
282  sub configure_python  sub configure_python
# Line 194  Line 299 
299      chomp $py_version;      chomp $py_version;
300      print "Python version $py_version\n";      print "Python version $py_version\n";
301    
302        #
303        # Python figures this out for us.
304        #$OtherConfig->{python_site_path} = "$ENV{FIGCONFIG_ENV_DIR}/lib/python$py_version/site-packages";
305    
306      my @path = ();      my @path = ();
307      push(@path, "$ENV{FIGCONFIG_ENV_DIR}/lib/python$py_version/site-packages");      #push(@path, $OtherConfig->{python_site_path});
308      push(@path, "$ENV{FIGCONFIG_RELEASE_DIR}/lib/$ENV{FIGCONFIG_ENV}");      push(@path, "$release_lib");
309      push(@path, "$fig_disk/config");      push(@path, "$fig_disk/config");
310      push(@$Env, ["PYTHONPATH", join(":", @path), 1]);      push(@$Env, ["PYTHONPATH", join(":", @path), 1]);
311    
# Line 205  Line 314 
314    
315  sub find_in_path  sub find_in_path
316  {  {
317      my($file) = @_;      my($file, @extra) = @_;
318      my(@path) = split(":", $ENV{PATH});      my(@path) = split(":", $ENV{PATH});
319    
320      for my $p (@path)      for my $p (@path, @extra)
321      {      {
322          my $x = "$p/$file";          my $x = "$p/$file";
323          if (-x $x)          if (-x $x)
# Line 229  Line 338 
338      #      #
339      # Special case for the mac.      # Special case for the mac.
340      #      #
341        # RDO 20040603 - don't do this any more; we want to pick up
342        # the python we ship.
343        #
344    
345      if ($ENV{FIGCONFIG_ENV} eq "mac")      if (0 && $ENV{FIGCONFIG_ENV} eq "mac")
346      {      {
347          if ($python = find_in_path("pythonw"))          #
348            # We'd like to use the MacPython that is installed
349            # as pythonw.
350            #
351            if ($python = find_in_path("pythonw", "/usr/local/bin"))
352          {          {
353                $OtherConfig->{python_require_poundbang_env} = 1;
354              return $python;              return $python;
355          }          }
356    
357          #          #
358          # Didn't find it in the path; we require the          # Otherwise, we can live with the regular python.
359          # MacPython build, and that installs into          # Fall thru to the generic case.
         # /usr/local/bin/pythonw by default.  
360          #          #
   
         return "/usr/local/bin/pythonw";  
361      }      }
     else  
     {  
362          #          #
363          # Non-mac, just look in the env dir or the path.          # Non-mac, just look in the env dir or the path.
364          #          #
# Line 254  Line 366 
366          $python = "$ENV{FIGCONFIG_ENV_DIR}/bin/python";          $python = "$ENV{FIGCONFIG_ENV_DIR}/bin/python";
367          if (-x $python)          if (-x $python)
368          {          {
369            #
370            # The mac doesn't seem to like the long #! lines, so we'll use poundbang env.
371            #
372            if ($ENV{FIGCONFIG_ENV} =~ /^mac/)
373            {
374                $OtherConfig->{python_require_poundbang_env} = 1;
375            }
376              return $python;              return $python;
377          }          }
378    
379          return find_in_path("python");          return find_in_path("python");
380      }      }
 }  
381    
382  #  #
383  # Find the name of the perl executable we are to use.  # Find the name of the perl executable we are to use.
# Line 297  Line 415 
415  if [ -n "\$$name" ] ; then  if [ -n "\$$name" ] ; then
416      DELIM=:      DELIM=:
417  fi  fi
418  $name=\${$name}\${DELIM}$value  $name=$value\${DELIM}\${$name}
419  export $name  export $name
420  END  END
421          }          }
# Line 307  Line 425 
425              print $fh "export $name\n";              print $fh "export $name\n";
426          }          }
427      }      }
428        print $fh "alias rtpath='source \$RTDIST/releases/\$RTCURRENT/ReleaseTools/RTPath.sh'\n";
429  }  }
430    
431  sub write_csh_init  sub write_csh_init
# Line 325  Line 444 
444    
445              print $fh <<END;              print $fh <<END;
446  if (\$?$name) then  if (\$?$name) then
447      setenv $name \${$name}:$value      setenv $name $value:\${$name}
448  else  else
449      setenv $name $value      setenv $name $value
450  endif  endif
# Line 337  Line 456 
456          }          }
457      }      }
458    
459        #
460        # Alias for RT stuff.
461        #
462        print $fh "alias rtpath 'source \$RTDIST/releases/\$RTCURRENT/ReleaseTools/RTPath.csh'\n";
463  }  }
464    
465  sub run_script  sub run_script
# Line 415  Line 538 
538    
539  }  }
540    
541    sub finalize_server_scripts
542    {
543        #
544        # After any environment-specific stuff, call start_services and stop_services.
545        #
546    
547        open(F, ">>$start_servers") or die "Cannot write $start_servers: $!";
548        print F "\n$fig_bin/start_services\n";
549        close(F);
550        chmod(0775, $start_servers);
551    
552        open(F, ">>$stop_servers") or die "Cannot write $stop_servers: $!";
553        print F "\n$fig_bin/stop_services\n";
554        close(F);
555        chmod(0775, $stop_servers);
556    
557    }
558    
559  sub write_config_pm  sub write_config_pm
560  {  {
561      my($fh, $config) = @_;      my($fh, $config) = @_;
# Line 473  Line 614 
614              next if $inc eq '.';              next if $inc eq '.';
615              print $fh "\t$inc\n";              print $fh "\t$inc\n";
616          }          }
617          print $fh ")\n";          print $fh ");\n";
618          print $fh "}\n";          print $fh "}\n";
619      }      }
620    
621      print $fh "use Data::Dumper;\n";      print $fh "use Data::Dumper;\n";
622      print $fh "use Carp;\n";      print $fh "use Carp;\n";
623    
624      print $fh "use lib \"$dist_lib\";\n";      #
625      print $fh "use lib \"$dist_lib/FigKernelPackages\";\n";      # We generate a comment here that gets expanded by switch_to_release
626        # This is part of the effort in making the environment bootstrapping
627        # code independent of releases.
628        #
629    
630        #print $fh "use lib \"$release_lib\";\n";
631        #print $fh "use lib \"$release_lib/FigKernelPackages\";\n";
632    
633        print $fh "# Following block is expanded by switch_to_release to add use lib directives\n";
634        print $fh "# to point at the correct locations in the release directory.\n";
635        print $fh "#BEGIN switch_to_release generated code\n";
636        print $fh "#END switch_to_release generated code\n";
637        print $fh "\n";
638    
639      print $fh "use lib \"$fig_disk/config\";\n";      print $fh "use lib \"$fig_disk/config\";\n";
640    
641      print $fh "use FIG_Config;\n";      print $fh "use FIG_Config;\n";
642      print $fh "\n";      print $fh "\n";
643        print $fh "#### END tool_hdr ####\n\n"
644  }  }
645    
646  sub write_tool_hdr_python  sub write_tool_hdr_python
# Line 494  Line 649 
649    
650      my $python = find_python();      my $python = find_python();
651    
652        if ($OtherConfig->{python_require_poundbang_env})
653        {
654            print $fh "#!/usr/bin/env $python\n";
655        }
656        else
657        {
658      print $fh "#!$python\n";      print $fh "#!$python\n";
659        }
660      print $fh "\n";      print $fh "\n";
661    
662      print $fh "import sys\n";      print $fh "import sys, os\n";
663      my $pp = join(", ", map({ '"' . $_ . '"'} split(":", $OtherConfig->{pythonpath})));  
664      print $fh "sys.path.extend(($pp))\n";  
665        print $fh "sys.path.append('$OtherConfig->{python_site_path}')\n";
666    
667        #
668        # Append the perl path to the environment, for use later with CallPerl.
669        #
670    
671        my $perlpath = join(":", @INC, $release_lib, "$release_lib/FigKernelPackages", "$fig_disk/config");
672        print $fh <<END;
673    if os.getenv("PERL5LIB", "") != "":
674        _delim = ":"
675    else:
676        _delim = ""
677    os.environ["PERL5LIB"] = "$perlpath" + _delim + os.getenv("PERL5LIB", "")
678    
679    END
680    
681        print $fh "# Following block is expanded by switch_to_release to add use lib directives\n";
682        print $fh "# to point at the correct locations in the release directory.\n";
683        print $fh "#BEGIN switch_to_release generated code\n";
684        print $fh "#END switch_to_release generated code\n";
685        print $fh "\n";
686    
687        print $fh "sys.path.append('$fig_disk/config')\n";
688    
689      print $fh "import FIG_Config\n";      print $fh "import FIG_Config\n";
690      print $fh "\n";      print $fh "\n";
691        print $fh "#### END tool_hdr_py ####\n\n"
692    }
693    
694    sub write_rtconfig
695    {
696        my($fh) = @_;
697    
698        my $python = find_python();
699        my $perl = find_perl();
700    
701        print $fh "RTPYTHON=$python\n";
702        print $fh "RTPERL=$perl\n";
703        print $fh "RTPYTHONPATH=$OtherConfig->{pythonpath}\n";
704    
705        my %seen;
706        my @perlpath;
707        for (@INC, "$fig_disk/config")
708        {
709            next if $seen{$_};
710            push(@perlpath, $_);
711            $seen{$_}++;
712        }
713        my $perlpath = join(":", @perlpath);
714    
715        print $fh "RTPERL5LIB=$perlpath\n";
716    
717        print $fh "RTPYTHONIMPORTS=FIG_Config\n";
718        print $fh "RTPERLIMPORTS=FIG_Config\n";
719        print $fh "RTSETENV=BLASTMAT=$fig_disk/BLASTMAT\n";
720        print $fh "RTSETENV=FIG_HOME=$fig_disk\n";
721        print $fh "#RTLD_LDPATH=$OtherConfig->{ld_library_path}\n";
722  }  }
723    
724  setup_directories("$fig_disk/bin",  setup_directories("$fig_disk/bin",
# Line 516  Line 733 
733  configure_std_fig_environment();  configure_std_fig_environment();
734  configure_python();  configure_python();
735  configure_environment_specific();  configure_environment_specific();
736    # configure_database();
737    
738    finalize_server_scripts();
739    
740  #  #
741  # Write the shell startup to the figdisk.  # Write the shell startup to the figdisk.
# Line 544  Line 764 
764  # Write the tool headers  # Write the tool headers
765  #  #
766    
767  open(FH, ">$fig_disk/config/tool_hdr") or die "Cannot write $fig_disk/config/tool_hdr: $!";  open(FH, ">$fig_disk/config/base_tool_hdr") or die "Cannot write $fig_disk/config/tool_hdr: $!";
768  write_tool_hdr_perl(\*FH);  write_tool_hdr_perl(\*FH);
769  close(FH);  close(FH);
770    
771  open(FH, ">$fig_disk/config/tool_hdr_py") or die "Cannot write $fig_disk/config/tool_hdr_py: $!";  open(FH, ">$fig_disk/config/base_tool_hdr_py") or die "Cannot write $fig_disk/config/tool_hdr_py: $!";
772  write_tool_hdr_python(\*FH);  write_tool_hdr_python(\*FH);
773  close(FH);  close(FH);
774    
775    open(FH, ">$fig_disk/config/RTConfig") or die "Cannot write $fig_disk/config/RTConfig: $!";
776    write_rtconfig(\*FH);
777    close(FH);
778    
779    unshift(@INC, "$ENV{FIGCONFIG_RELEASE_DIR}");
780    
781    require FigCommon::SwitchRelease;
782    
783  #  #
784  # We have enough environment configured now to do a make.  # We need to tweak the current path and PERL5LIB environment to get bootstrapping to
785  #  # work correctly.
 # We use system and manually load the environment config so that it will  
 # work properly despite any user settings.  
786  #  #
787    
788  system("source $fig_disk/config/fig-user-env.sh; cd $ENV{FIGCONFIG_RELEASE_DIR}; make clean; make");  $ENV{PATH} = "$ENV{FIGCONFIG_ENVDIR}/bin:$ENV{PATH}";
789    
790    $ENV{PERL5LIB} = (map { $_->[1] } grep { $_->[0] eq "PERL5LIB"} @$Env)[0];
791    
792    &FigCommon::SwitchRelease::switch_to_release($fig_disk, $ENV{FIGCONFIG_ENV}, $ENV{FIGCONFIG_RELEASE});

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.28

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3