[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.10-201-gdb61869



The following commit has been merged in the master branch:
commit 1ec035b3f7c60c7e412c794bd43a5d2137b12f60
Author: Niels Thykier <niels@thykier.net>
Date:   Fri Sep 14 17:34:39 2012 +0200

    L::Profile: Turn "profile-path" into "include-path"
    
    Generalize the profile-path member into an include-path that lists
    "Lintian roots" rather than just "profile dirs".  As a consequence,
    there is no longer a "single root" for a Profile and accordingly
    the "root" member is removed.
    
    Two important side-effects are that Lintian::Data can now query and
    use the include-path and checks can now be loaded from
    $ENV{'HOME'}/.lintian/checks or even /etc/lintian/checks.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/frontend/lintian b/frontend/lintian
index 63eb193..7a9e2b1 100755
--- a/frontend/lintian
+++ b/frontend/lintian
@@ -93,14 +93,13 @@ my %conf_opt;                   #names of options set in the cfg file
 my %group_cache = ();           # Cache to store groups in case of group
                                 # queries
 
-# The profile search path except LINTIAN_ROOT/profiles
-#  which will be added later (we dont know LINTIAN_ROOT
-#  at this point)
+# The search path except $ENV{'LINTIAN_ROOT'}/--root LINTIAN_ROOT
+# which will be added later.
 my @prof_inc;
 # In some (rare) cases, $ENV{HOME} will not be available.
 # - Handle that gracefully by not emitting "Uninitialized ...".
-push @prof_inc, "$ENV{HOME}/.lintian/profiles" if defined $ENV{HOME};
-push @prof_inc, '/etc/lintian/profiles';
+push @prof_inc, "$ENV{HOME}/.lintian" if defined $ENV{HOME};
+push @prof_inc, '/etc/lintian';
 
 
 my $experimental_output_opts = undef;
@@ -820,8 +819,8 @@ $TAGS->show_experimental($opt{'display-experimental'});
 $TAGS->show_overrides($opt{'show-overrides'});
 $TAGS->sources(keys %display_source) if %display_source;
 
-$PROFILE = Lintian::Profile->new ($opt{'LINTIAN_PROFILE'}, $opt{'LINTIAN_ROOT'},
-                                  [@prof_inc, "$opt{'LINTIAN_ROOT'}/profiles"]);
+$PROFILE = Lintian::Profile->new ($opt{'LINTIAN_PROFILE'},
+                                  [@prof_inc, $opt{'LINTIAN_ROOT'}]);
 # Ensure $opt{'LINTIAN_PROFILE'} is defined
 $opt{'LINTIAN_PROFILE'} = $PROFILE->name unless defined $opt{'LINTIAN_PROFILE'};
 v_msg('Using profile ' . $PROFILE->name . '.');
diff --git a/frontend/lintian-info b/frontend/lintian-info
index db657e9..865f715 100755
--- a/frontend/lintian-info
+++ b/frontend/lintian-info
@@ -67,7 +67,7 @@ EOT
     exit 0;
 }
 
-$profile = Lintian::Profile->new ($prof, $ENV{'LINTIAN_ROOT'});
+$profile = Lintian::Profile->new ($prof);
 
 Lintian::Data->set_vendor ($profile);
 
diff --git a/lib/Lintian/Data.pm b/lib/Lintian/Data.pm
index ff6a1b5..a0e757f 100644
--- a/lib/Lintian/Data.pm
+++ b/lib/Lintian/Data.pm
@@ -96,20 +96,14 @@ sub new {
     # - $start is an index into $vendors (the first $vendor to try)
     sub _open_data_file {
         my ($self, $type, $vendors, $start) = @_;
-        my $root = $profile->root;
         my $file;
         my $cur = $start;
-        my @basedirs;
-        # Gracefully handle $ENV{'HOME'} being unset
-        push @basedirs, "$ENV{'HOME'}/.lintian/vendors" if defined $ENV{'HOME'};
-        push @basedirs, "$root/vendors", '/etc/lintian/vendors';
 
-        # Do not allow user or system settings to affect the test results.
-        @basedirs = ("$root/vendors") if $ENV{'LINTIAN_INTERNAL_TESTSUITE'};
         OUTER: for (; $cur < scalar @$vendors ; $cur++) {
-            foreach my $basedir (@basedirs) {
-                if ( -f "$basedir/$vendors->[$cur]/data/$type" ) {
-                    $file = "$basedir/$vendors->[$cur]/data/$type";
+            my $vendorpart = "vendors/$vendors->[$cur]/data/$type";
+            foreach my $datafile ($profile->include_path ($vendorpart)) {
+                if ( -f $datafile) {
+                    $file = $datafile;
                     last OUTER;
                 }
             }
diff --git a/lib/Lintian/Profile.pm b/lib/Lintian/Profile.pm
index 59ed808..1b1a6da 100644
--- a/lib/Lintian/Profile.pm
+++ b/lib/Lintian/Profile.pm
@@ -39,7 +39,7 @@ Lintian::Profile - Profile parser for Lintian
  my $profile = Lintian::Profile->new ('debian', $ENV{'LINTIAN_ROOT'});
  # Load the debian profile using an explicit search path
  $profile = Lintian::Profile->new ('debian', $ENV{'LINTIAN_ROOT'},
-    ['/path/to/profiles', "$ENV{'LINTIAN_ROOT'}/profiles"]);
+    ['/path/to/alt/root', $ENV{'LINTIAN_ROOT'}]);
  # Load the "default" profile for the current vendor
  $profile = Lintian::Profile->new (undef, $ENV{'LINTIAN_ROOT'});
  foreach my $tag ($profile->tags) {
@@ -85,36 +85,33 @@ my %SEC_FIELDS = (
     'severity'    => 1,
     );
 
-=item Lintian::Profile->new($profname, $root[, $ppath])
+=item Lintian::Profile->new($profname[, $ipath])
 
-Creates a new profile from the profile located by using
-find_profile($profname, @$ppath).  $profname is the name of the
-profile and $ppath is a list reference containing the directories to
-search for the profile and (if any) its parents.  $root is the
-"LINTIAN_ROOT" and is used for finding checks.
+Creates a new profile from the profile.  $profname is the name of the
+profile and $ipath is a list reference containing containing the path
+to one (or more) Lintian "roots".
 
 If $profname is C<undef>, the default vendor will be loaded based on
 Dpkg::Vendor::get_current_vendor.
 
-If $ppath is not given, a default one will be used.
+If $ipath is not given, a default one will be used.
 
 =cut
 
 sub new {
-    my ($type, $name, $root, $ppath) = @_;
+    my ($type, $name, $ipath) = @_;
     my $profile;
-    $ppath = [_default_inc_path ($root)] unless $ppath;
+    $ipath = [_default_inc_path ()] unless $ipath;
     my $self = {
         'parent-map'           => {},
         'profile_list'         => [],
-        'profile-path'         => $ppath,
+        'include-path'         => $ipath,
         'enabled-tags'         => {}, # "set" of tags enabled (value is largely ignored)
         'enabled-checks'       => {}, # maps script to the number of tags enabled (0 if disabled)
         'non-overridable-tags' => {},
         'severity-changes'     => {},
         'check-scripts'        => {}, # maps script name to Lintian::CheckScript
         'known-tags'           => {}, # maps tag name to Lintian::Tag::Info
-        'root'         => $root,
     };
     $self = bless $self, $type;
     if (not defined $name) {
@@ -124,7 +121,7 @@ sub new {
             if $name =~ m,^/,o or $name =~ m/\./o;
         $profile = $self->_find_profile ($name);
     }
-    croak "Cannot find profile $name (in " . join(', ', @$ppath).")"
+    croak "Cannot find profile $name (in " . join(', ', map { "$_/profiles" } @$ipath).")"
         unless $profile;
     $self->_read_profile($profile);
     return $self;
@@ -143,13 +140,9 @@ Note: This list reference and its contents should not be modified.
 Returns the name of the profile, which may differ from the name used
 to create this instance of the profile (e.g. due to symlinks).
 
-=item $prof->root
-
-Returns the LINTIAN_ROOT associated with the profile.
-
 =cut
 
-Lintian::Profile->mk_ro_accessors (qw(profile_list name root));
+Lintian::Profile->mk_ro_accessors (qw(profile_list name));
 
 =item $prof->tags([$known])
 
@@ -260,6 +253,28 @@ sub disable_tags {
     }
 }
 
+=item $prof->include_path ([$path])
+
+Returns an array of paths to the (partial) Lintian roots, which are
+used by this profile.  The paths are ordered from "highest" to
+"lowest" priority (i.e. items in the earlier paths should shadow those
+in later ones).
+
+If $path is given, the array will contain the paths to the path in
+these roots denoted by $path.
+
+Paths returned are not guaranteed to exists.
+
+=cut
+
+sub include_path {
+    my ($self, $path) = @_;
+    unless (defined $path) {
+        return @{ $self->{'include-path'} };
+    }
+    return map { "$_/$path" } @{ $self->{'include-path'} };
+}
+
 # $prof->_find_profile ($pname)
 #
 # Finds a profile called $pname in the search directories and returns
@@ -276,7 +291,7 @@ sub _find_profile {
     # $vendor is short for $vendor/main
     $pname = "$pname/main" unless $pname =~ m,/,o;
     $pfile = "$pname.profile";
-    foreach my $path (@{ $self->{'profile-path'} }){
+    foreach my $path ($self->include_path ('profiles')) {
         return "$path/$pfile" if -e "$path/$pfile";
     }
     return '';
@@ -392,7 +407,7 @@ sub _read_profile_tags{
     my $tag_sub = sub {
         my ($field, $tag) = @_;
         unless (exists $self->{'known-tags'}->{$tag}) {
-            $self->_load_checks($pname);
+            $self->_load_checks;
             croak "Unknown tag \"$tag\" in profile \"$pname\""
                 unless exists $self->{'known-tags'}->{$tag};
         }
@@ -489,10 +504,21 @@ sub _check_for_invalid_fields {
 
 sub _load_check {
     my ($self, $profile, $check) = @_;
-    my $root = $self->root;
-    my $cf = "$root/checks/${check}.desc";
-    croak "$profile references unknown $check" unless -f $cf;
-    my $c = Lintian::CheckScript->new ($cf);
+    my $desc = undef;
+    foreach my $checkdir ($self->include_path ('checks')) {
+        my $cf = "$checkdir/${check}.desc";
+        if ( -f $cf ) {
+            $desc = $cf;
+            last;
+        }
+    }
+    croak "$profile references unknown $check" unless defined $desc;
+    $self->_parse_check ($desc);
+}
+
+sub _parse_check {
+    my ($self, $desc) = @_;
+    my $c = Lintian::CheckScript->new ($desc);
     return if $self->{'check-scripts'}->{$c->name};
     $self->{'check-scripts'}->{$c->name} = $c;
     for my $tn ($c->tags) {
@@ -505,22 +531,27 @@ sub _load_check {
 }
 
 sub _load_checks {
-    my ($self, $profile) = @_;
-    my $root = $self->root;
-    opendir my $dirfd, "$root/checks" or croak "opendir $root/checks: $!";
-    for my $desc (sort readdir $dirfd) {
-        next unless $desc =~ s/\.desc$//o;
-        $self->_load_check($profile, $desc);
+    my ($self) = @_;
+    foreach my $checkdir ($self->include_path ('checks')) {
+        next unless -d $checkdir;
+        opendir my $dirfd, $checkdir or croak "opendir $checkdir: $!";
+        for my $desc (sort readdir $dirfd) {
+            next unless $desc =~ m/\.desc$/o;
+            # _parse_check ignores duplicates, so we don't have to check for it.
+            $self->_parse_check ("$checkdir/$desc");
+        }
+        closedir $dirfd;
     }
-    closedir $dirfd;
 }
 
 sub _default_inc_path {
-    my ($root) = @_;
     my @path = ();
-    push @path, "$ENV{'HOME'}/.lintian/profiles"
+    push @path, "$ENV{'HOME'}/.lintian"
         if exists $ENV{'HOME'} and defined $ENV{'HOME'};
-    push @path, '/etc/lintian/profiles', "$root/profiles";
+    push @path, '/etc/lintian';
+    # ENV{LINTIAN_ROOT} replaces /usr/share/lintian if present.
+    push @path, $ENV{'LINTIAN_ROOT'} if defined $ENV{'LINTIAN_ROOT'};
+    push @path, '/usr/share/lintian' unless defined $ENV{'LINTIAN_ROOT'};
     return @path;
 }
 
diff --git a/reporting/html_reports b/reporting/html_reports
index 0d25f4f..abb0512 100755
--- a/reporting/html_reports
+++ b/reporting/html_reports
@@ -59,8 +59,7 @@ use Lintian::Profile;
 use Lintian::Util qw(read_dpkg_control slurp_entire_file);
 
 my $profile = Lintian::Profile->new (undef,
-                                     $LINTIAN_ROOT,
-                                     ["$LINTIAN_ROOT/profiles"]);
+                                     [$LINTIAN_ROOT]);
 
 Lintian::Data->set_vendor ($profile);
 
diff --git a/t/scripts/tags.t b/t/scripts/tags.t
index 51e4666..61d6574 100755
--- a/t/scripts/tags.t
+++ b/t/scripts/tags.t
@@ -29,8 +29,8 @@ use Lintian::Profile;
 use Lintian::Tags ();
 use Lintian::Util qw(read_dpkg_control);
 
-my $vendor = Lintian::Profile->new ('debian/main', $ENV{'LINTIAN_ROOT'},
-                                 ["$ENV{'LINTIAN_ROOT'}/profiles"]);
+my $vendor = Lintian::Profile->new ('debian/main',
+                                 [$ENV{'LINTIAN_ROOT'}]);
 my @DESCS = <$ENV{'LINTIAN_ROOT'}/checks/*.desc>;
 
 my %severities = map { $_ => 1 } 'pedantic', @Lintian::Tags::SEVERITIES;
diff --git a/t/tests/binaries-hardening/test_calibration b/t/tests/binaries-hardening/test_calibration
index 7d538aa..529b73b 100755
--- a/t/tests/binaries-hardening/test_calibration
+++ b/t/tests/binaries-hardening/test_calibration
@@ -13,8 +13,8 @@ sub _split_hash {
     map { $hash->{$_} = 1 } split m/\s*,\s*/o, $val;
     return $hash;
 }
-my $PROFILE = Lintian::Profile->new ('debian/main', $ENV{'LINTIAN_ROOT'},
-                                     ["$ENV{'LINTIAN_ROOT'}/profiles"]);
+my $PROFILE = Lintian::Profile->new ('debian/main',
+                                     [$ENV{'LINTIAN_ROOT'}]);
 
 Lintian::Data->set_vendor ($PROFILE);
 

-- 
Debian package checker


Reply to: