[csw-devel] SF.net SVN: gar:[3286] csw/mgar/gar/v2
dmichelsen at users.sourceforge.net
dmichelsen at users.sourceforge.net
Fri Feb 20 15:10:47 CET 2009
Revision: 3286
http://gar.svn.sourceforge.net/gar/?rev=3286&view=rev
Author: dmichelsen
Date: 2009-02-20 14:10:46 +0000 (Fri, 20 Feb 2009)
Log Message:
-----------
mGAR v2: Enhance pathfilter so that licenses are safely included
Modified Paths:
--------------
csw/mgar/gar/v2/bin/pathfilter
csw/mgar/gar/v2/gar.pkg.mk
Modified: csw/mgar/gar/v2/bin/pathfilter
===================================================================
--- csw/mgar/gar/v2/bin/pathfilter 2009-02-20 13:54:44 UTC (rev 3285)
+++ csw/mgar/gar/v2/bin/pathfilter 2009-02-20 14:10:46 UTC (rev 3286)
@@ -5,6 +5,9 @@
# Please note:
# - If no options are given the input is not changed
# - A path must match include and not exclude to pass the filter
+# - The include and exclude directives are matched in order. The path is
+# short-cut included or excluded when there is match. Only the first match
+# is considered.
# - Empty directories are preserved if the incoming prototype doesn't
# contained files in them. Directories which contained files which
# were excluded and which would be empty after exclusion are
@@ -16,26 +19,26 @@
my $help = 0;
-my @exclude;
-my @include;
+my ($hasinclude, $hasexclude);
my @isaexec;
+my @selection;
my $result = GetOptions(
'h|help' => \$help,
'e|isaexec=s' => \@isaexec,
- 'i|include=s' => \@include,
- 'x|exclude=s' => \@exclude) or pod2usage( 1 );
+ 'i|include=s' => sub { push @selection, [ 'i', $_[1] ]; $hasinclude = 1 },
+ 'x|exclude=s' => sub { push @selection, [ 'x', $_[1] ]; $hasexclude = 1 },
+) or pod2usage( 1 );
+# Exclude everything by default if there are only include rules
+push @selection, [ 'x', '.*' ] if( $hasinclude && !$hasexclude );
+
pod2usage(-verbose => 2) if $help;
-my ($exclude, $include) = ('', '');
-$exclude = '^(' . join( '|', @exclude ) . ')$' if( @exclude );
-$exclude = qr#$exclude# if( $exclude );
-$include = '^(' . join( '|', @include ) . ')$' if( @include );
-$include = qr#$include# if( $include );
-
my %p;
my %skipped; # key=path, Contains directories which may be skipped
my %wasntempty; # Same key, =1 iff there is a file in it or a subdirectory
+
+NEXTLINE:
while( <STDIN> ) {
my @line = split /\s+/;
my $ftype = $line[0];
@@ -58,8 +61,17 @@
}
}
- next if( $include ne '' && $path !~ /$include/ );
- next if( $exclude ne '' && $path =~ /$exclude/ );
+ SELECTION:
+ foreach my $selector (@selection) {
+ my ($type, $regex) = @$selector;
+ if( $type eq 'i' ) {
+ last SELECTION if( $path =~ /^$regex$/ );
+ } elsif( $type eq 'x' ) {
+ next NEXTLINE if( $path =~ /^$regex$/ );
+ } else {
+ croak( "The type '$type' is unknown (either 'x' or 'i' is allowed)." );
+ }
+ }
$p{$path} = \@line;
}
@@ -77,11 +89,20 @@
}
# Re-add directories which where empty
+NEXTPATH:
foreach my $path (keys %skipped) {
next if( exists $wasntempty{$path} );
- next if( $include ne '' && $path !~ /$include/ );
- next if( $exclude ne '' && $path =~ /$exclude/ );
+ SELECTION:
+ foreach my $selector (@selection) {
+ my ($type, $regex) = @$selector;
+ if( $type eq 'i' ) {
+ last SELECTION if( $path =~ /^$regex$/ );
+ } elsif( $type eq 'x' ) {
+ next NEXTPATH if( $path =~ /^$regex$/ );
+ }
+ }
+
my @c = split( m!/!, $path );
my @pa = map { join( '/', @c[0..$_] ) } 1..$#c;
@@ -98,10 +119,10 @@
# f none /opt/csw/bin/sparcv8/mytool=/opt/csw/bin/mytool
foreach my $e (@isaexec) {
my ($isaexec_path, $new_path) = split( /=/, $e );
-# if( !exists $p{$isaexec_path} ) {
-# warn "Could not find path '$e' to be replaced by isaexec";
-# next;
-# }
+
+ # Don't do isaexec replacement if the path has not been selected.
+ next if( !exists $p{$isaexec_path} );
+
$p{$new_path} = [ @{$p{$isaexec_path}} ];
$p{$new_path}->[2] = $new_path . '=' . $isaexec_path;
$p{$isaexec_path}->[0] = 'l';
@@ -131,7 +152,6 @@
=item B<-x | --exclude <path>>
Excludes the path from the resulting prototype.
-If -i is given this option is ignored.
=item B<-i | --include <path>>
Modified: csw/mgar/gar/v2/gar.pkg.mk
===================================================================
--- csw/mgar/gar/v2/gar.pkg.mk 2009-02-20 13:54:44 UTC (rev 3285)
+++ csw/mgar/gar/v2/gar.pkg.mk 2009-02-20 14:10:46 UTC (rev 3286)
@@ -190,7 +190,6 @@
$(strip
$(foreach S,$(filter-out $(1),$(_PKG_SPECS)),
$(PKGFILES_$(S))
- $(call licensedir,$(S))/.*
$(EXTRA_PKGFILES_EXCLUDED)
$(EXTRA_PKGFILES_EXCLUDED_$(1))
$(_EXTRA_PKGFILES_EXCLUDED)
@@ -200,7 +199,8 @@
define _pkgfiles_include
$(strip
- $(call licensedir,$(1))/.*
+ $(PKGFILES_$(1)_SHARED)
+ $(PKGFILES_$(1))
)
endef
@@ -226,6 +226,12 @@
$(PROTOTYPE): $(WORKDIR) merge
$(_DBG)cswproto -r $(PKGROOT) $(PKGROOT)=/ >$@
+# The pathfilter rules are as follows:
+# - include license for current package
+# - exclude licenses for all other packages
+# - if other includes are given, only include these files
+# - if no include is given ("catch all packages") include everything except what
+# is put in other packages
.PRECIOUS: $(WORKDIR)/%.prototype $(WORKDIR)/%.prototype-$(GARCH)
$(WORKDIR)/%.prototype: _PKGFILES_EXCLUDE=$(call _pkgfiles_exclude,$*)
$(WORKDIR)/%.prototype: _PKGFILES_INCLUDE=$(call _pkgfiles_include,$*)
@@ -235,9 +241,10 @@
-n "$(_PKGFILES_EXCLUDE)" -o \
-n "$(ISAEXEC_FILES_$*)" -o \
-n "$(ISAEXEC_FILES)" ]; then \
- (pathfilter $(foreach FILE,$(if $(or $(PKGFILES_$*_SHARED),$(PKGFILES_$*)),$(_PKGFILES_INCLUDE)) \
- $(PKGFILES_$*_SHARED) $(PKGFILES_$*),-i '$(FILE)') \
- $(foreach FILE,$(_PKGFILES_EXCLUDE), -x '$(FILE)') \
+ (pathfilter -i $(call licensedir,$*)/license \
+ $(foreach S,$(filter-out $*,$(SPKG_SPECS)),-x $(call licensedir,$S)/license) \
+ $(foreach FILE,$(_PKGFILES_INCLUDE),-i '$(FILE)') \
+ $(if $(_PKGFILES_INCLUDE),-x '.*',$(foreach FILE,$(_PKGFILES_EXCLUDE),-x '$(FILE)')) \
$(foreach IE,$(abspath $(ISAEXEC_FILES_$*) $(ISAEXEC_FILES)), \
-e '$(IE)=$(dir $(IE))$(ISA_DEFAULT)/$(notdir $(IE))' \
) \
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the devel
mailing list