Ignore:
Timestamp:
2013-05-06T15:23:45+12:00 (11 years ago)
Author:
jmt12
Message:

Replacing hardcoded additions to INC and PATH environment variables with conditional ones - this allows us to use the order of values in these variables for precedence, thus allows better support for extensions that override classifiers, plugins etc. ENV and PATH functions already exists in util, but augmentINC() is a new function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/IncrementalBuildUtils.pm

    r21646 r27303  
    4242    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
    4343    die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
    44     unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
    45     unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
    46     unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
    47     unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
     44
     45    # - ensure we only add perllib paths to INC if they weren't already there
     46    # as otherwise we lose the ability to use order in INC as a guide for
     47    # inheritence/overriding [jmt12]
     48    my $gsdl_perllib_path = $ENV{'GSDLHOME'} . '/perllib';
     49    my $found_path = 0;
     50    foreach my $inc_path (@INC)
     51    {
     52      if ($inc_path eq $gsdl_perllib_path)
     53      {
     54        $found_path = 1;
     55        last;
     56      }
     57    }
     58    if (!$found_path)
     59    {
     60      unshift (@INC, $gsdl_perllib_path);
     61      unshift (@INC, $gsdl_perllib_path . '/cpan');
     62      unshift (@INC, $gsdl_perllib_path . '/plugins');
     63      unshift (@INC, $gsdl_perllib_path . '/classify');
     64    }
    4865}
    4966
     
    6582  $path_separator = ";";
    6683}
    67 $ENV{'PATH'} = &util::filename_cat($ENV{'GSDLHOME'}, "bin", $ENV{'GSDLOS'}) . $path_separator . &util::filename_cat($ENV{'GSDLHOME'}, "bin", "script") . $path_separator.$ENV{'PATH'};
     84# - once again we need to ensure we aren't duplicating paths on the environment
     85# otherwise things like extension executables won't be correctly used in
     86# preference to main Greenstone ones [jmt12]
     87my @env_path = split($path_separator, $ENV{'PATH'});
     88my $os_binary_path = &util::filename_cat($ENV{'GSDLHOME'}, 'bin', $ENV{'GSDLOS'});
     89my $script_path = &util::filename_cat($ENV{'GSDLHOME'}, 'bin', 'script');
     90my $found_os_bin = 0;
     91foreach my $path (@env_path)
     92{
     93  if ($path eq $os_binary_path)
     94  {
     95    $found_os_bin = 1;
     96    last;
     97  }
     98}
     99if (!$found_os_bin)
     100{
     101  $ENV{'PATH'} = $os_binary_path . $path_separator . $script_path . $path_separator . $ENV{'PATH'};
     102}
     103
    68104
    69105# /**
Note: See TracChangeset for help on using the changeset viewer.