Lift get_paths into its own module

Fixes #752
This commit is contained in:
Derek Bankieris 2019-04-09 13:28:16 -05:00
parent 4611db2e92
commit bde2ec5158
3 changed files with 17 additions and 19 deletions

View File

@ -14,6 +14,7 @@ use trick_version ;
use Digest::MD5 qw(md5_hex) ;
use File::Path qw(make_path) ;
use html ;
use get_paths ;
##
## ================================================================================
@ -127,10 +128,6 @@ if ( $help ) {
@include_dirs = $ENV{"TRICK_CFLAGS"} =~ /-I\s*(\S+)/g ; # get include paths from TRICK_CFLAGS
# Get environment variables, split on colons, strip leading/trailing whitespace, remove empty elements, get absolute paths then remove more empty elements
sub get_paths {
return grep { $_ ne ''} map abs_path($_), grep { $_ ne '' } map { s/(^\s+|\s+$)//g ; $_ } split /:/, $ENV{$_[0]} ;
}
@exclude_paths = get_paths( "TRICK_EXCLUDE") ;
@swig_exclude_paths = get_paths( "TRICK_SWIG_EXCLUDE") ;
@ext_lib_paths = get_paths( "TRICK_EXT_LIB_DIRS") ;

View File

@ -10,6 +10,7 @@ use gte ;
use Digest::MD5 qw(md5_hex) ;
use trick_version ;
use html ;
use get_paths ;
use strict ;
my @exclude_paths ;
@ -24,21 +25,6 @@ my %trick_headers ;
my %python_modules ;
my %python_module_dirs ;
sub get_paths {
my @paths = split /:/ , $ENV{$_[0]} ;
if (scalar @paths) {
@paths = sort(@paths ) ;
# trim whitespace
@paths = map { s/(^\s+|\s+$)//g ; $_ } @paths ;
# Remove empty elements. Sort forced all blank names to the front.
while ( scalar @paths and not length @paths[0] ) {
shift @paths ;
}
@paths = map { (-e $_) ? abs_path($_) : $_ } @paths ;
}
return @paths ;
}
sub read_files_to_process() {
my @include_paths ;
my $cc ;

View File

@ -0,0 +1,15 @@
package get_paths ;
use Exporter ();
use Cwd 'abs_path' ;
@ISA = qw(Exporter);
@EXPORT = qw(get_paths);
use strict ;
# Get environment variables, split on colons, strip leading/trailing whitespace, remove empty elements, get absolute paths then remove more empty elements
sub get_paths {
return grep { $_ ne ''} map abs_path($_), grep { $_ ne '' } map { s/(^\s+|\s+$)//g ; $_ } split /:/, $ENV{$_[0]} ;
}
1;