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

[SCM] Debian package checker branch, master, updated. 2.5.11-159-ge891392



The following commit has been merged in the master branch:
commit e891392032fe8180932f2fb4b2ee0e48f3052745
Author: Niels Thykier <niels@thykier.net>
Date:   Fri Feb 15 17:10:40 2013 +0100

    L::Profile: Allow and subst {VENDOR} in the profile name
    
    Allow {VENDOR} to appear in the profile name - it can be used with the
    "--profile" (or LINTIAN_PROFILE) to request the "most specific vendor
    specific" for a profile.  As an example, Lintian's default choice for
    a profile can now be described via:
    
      --profile {VENDOR}/main
    
    With this, it is possible to create application specific profiles that
    have vendor specific cases (without having to do the vendor mapping
    manually).
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/debian/changelog b/debian/changelog
index ee3bfcf..3c9bc13 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -170,6 +170,8 @@ lintian (2.5.12) UNRELEASED; urgency=low
     + [NT] Make --suppress-tags{,--from-file} do something when used
       with --check-part and document that --tags causes the option
       to be ignored.
+    + [NT] Accept the magic token "{VENDOR}" as a part of the value
+      to --profile.
 
   * lib/Lintian/Collect.pm:
     + [NT] Add "is_non_free" method to easily check of a given
diff --git a/lib/Lintian/Profile.pm b/lib/Lintian/Profile.pm
index 1c905af..01afd49 100644
--- a/lib/Lintian/Profile.pm
+++ b/lib/Lintian/Profile.pm
@@ -26,6 +26,8 @@ use warnings;
 
 use Carp qw(croak);
 
+use Dpkg::Vendor qw(get_current_vendor get_vendor_info);
+
 use Lintian::CheckScript;
 use Lintian::Util qw(parse_boolean read_dpkg_control);
 
@@ -118,7 +120,7 @@ sub new {
     } else {
         croak "Illegal profile name \"$name\""
             if $name =~ m,^/,o or $name =~ m/\./o;
-        $profile = $self->_find_profile ($name);
+        ($profile, undef) = $self->_find_vendor_profile ($name);
     }
     croak "Cannot find profile $name (in " . join(', ', map { "$_/profiles" } @$ipath).")"
         unless $profile;
@@ -336,7 +338,7 @@ sub _read_profile {
         my $parentf;
         croak "Invalid Extends field in $pfile"
             unless $parent && $parent !~ m/\./o;
-        $parentf = $self->_find_profile ($parent);
+        ($parentf, undef) = $self->_find_vendor_profile ($parent);
         croak "Cannot find $parent, which $pname extends"
             unless $parentf;
         $self->_read_profile($parentf);
@@ -583,23 +585,51 @@ sub _default_inc_path {
 }
 
 sub _find_vendor_profile {
-    my ($self) = @_;
-    require Dpkg::Vendor;
-    my $vendor = Dpkg::Vendor::get_current_vendor ();
-    croak "Could not determine the current vendor"
-        unless $vendor;
-    my $orig = $vendor; # copy
-    while ($vendor) {
-        my $file = $self->_find_profile (lc $vendor);
-        return ($file, $vendor) if $file;
-        my $info = Dpkg::Vendor::get_vendor_info ($vendor);
-        # Cannot happen atm, but in case Dpkg::Vendor changes its internals
-        #  or our code changes
-        croak "Could not look up the parent vendor of $vendor"
-            unless $info;
-        $vendor = $info->{'Parent'};
+    my ($self, $prof) = @_;
+    my @vendors;
+
+    if (defined $prof and $prof !~ m/[{}]/) {
+        # no substitution required...
+        return ($self->_find_profile ($prof), $prof);
+    } elsif (defined $prof) {
+        my $cpy = $prof;
+        # Check for unknown (or broken) subst.
+        $cpy =~ s/\Q{VENDOR}\E//g;
+        croak "Unknown substitution \"$1\" (in \"$prof\")"
+            if $cpy =~ m/\{([^ \}]+)\}/;
+        croak "Bad, broken or empty subtitution marker in \"$prof\""
+            if $cpy =~ m/[{}]/;
+    }
+
+    $prof //= '{VENDOR}/main';
+
+    @vendors = @{ $self->{'_vendor_cache'} } if exists $self->{'_vendor_cache'};
+    unless (@vendors) {
+        my $vendor = Dpkg::Vendor::get_current_vendor ();
+        croak "Could not determine the current vendor"
+            unless $vendor;
+        push @vendors, lc $vendor;
+        while ($vendor) {
+            my $info = Dpkg::Vendor::get_vendor_info ($vendor);
+            # Cannot happen atm, but in case Dpkg::Vendor changes its internals
+            #  or our code changes
+            croak "Could not look up the parent vendor of $vendor"
+                unless $info;
+            $vendor = $info->{'Parent'};
+            push @vendors, lc $vendor if $vendor;
+        }
+        $self->{'_vendor_cache'} = \@vendors;
+    }
+    foreach my $vendor (@vendors) {
+        my $file;
+        my $profname = $prof;
+        $profname =~ s/\Q{VENDOR}\E/$vendor/g;
+
+        $file = $self->_find_profile ($profname);
+
+        return ($file, $profname) if $file;
     }
-    croak "Could not find a profile for vendor $orig";
+    croak "Could not find a profile matching \"$prof\" for vendor $vendors[0]";
 }
 
 =back
diff --git a/man/lintian.pod.in b/man/lintian.pod.in
index 87cf7c7..0f77870 100644
--- a/man/lintian.pod.in
+++ b/man/lintian.pod.in
@@ -312,8 +312,21 @@ Use the profile from vendor (or the profile with that name).  If the
 profile name does not contain a slash, the default profile for than
 vendor is chosen.
 
-If not specified, B<lintian> loads the best profile for the current
-vendor.
+As an example, if you are on Ubuntu and want to use Lintian's Debian
+checks, you can use:
+
+  --profile debian
+
+Likewise, on a Debian machine you can use this to request the Ubuntu
+checks.
+
+If the token I<{VENDOR}> appears in the profile name, B<lintian> will
+substitute the token with a vendor name to find the profile.
+B<lintian> uses L<Dpkg::Vendor> to determine the best vendor to use
+(the closer to the current vendor, the better).  This is mostly useful
+for people implementing their own checks ontop of Lintian.
+
+If not specified, the default value is I<{VENDOR}/main>.
 
 Please Refer to the Lintian User Manual for the full documentation of
 profiles.

-- 
Debian package checker


Reply to: