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

[SCM] Debian package checker branch, master, updated. 2.5.11-69-g59d96e3



The following commit has been merged in the master branch:
commit 59d96e3c2602325651d42c6682a57da357af38fc
Author: Niels Thykier <niels@thykier.net>
Date:   Wed Jan 16 22:34:12 2013 +0100

    lintian{,-info}: Add --include-dir cmd-line option
    
    Add a new command-line option, --include-dir DIR, to have Lintian look
    for checks, profiles or even data files in DIR on top of the current
    search path.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/debian/changelog b/debian/changelog
index deefc13..113f4bc 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -62,6 +62,10 @@ lintian (2.5.12) UNRELEASED; urgency=low
   * doc/tutorial/Lintian/Tutorial{/WritingChecks}.pod:
     + [NT] Add POD tutorial on writing checks.
 
+  * frontend/lintian{,-info}:
+    + [NT] Add --include-dir command line option.  This can be used
+      to load additional Lintian checks, profiles, libraries or data.
+      (Closes: #359059)
   * frontend/lintian:
     + [NT] Remove "make-shift" lab-query support now that
       Lintian::Lab supports it.
diff --git a/frontend/lintian b/frontend/lintian
index 1b211f3..c23ec6e 100755
--- a/frontend/lintian
+++ b/frontend/lintian
@@ -25,6 +25,8 @@
 use strict;
 use warnings;
 
+use Cwd qw(abs_path);
+
 use Getopt::Long;
 use POSIX qw(:sys_wait_h);
 
@@ -97,14 +99,10 @@ my %opt = (                     #hash of some flags from cmd or cfg
     'user-dirs' => 1,
 );
 
-# The search path except $ENV{'LINTIAN_ROOT'}/--root LINTIAN_ROOT
-# which will be added later.
+# The search path - affected by --include-dir X, --[no-]user-dirs
+# The LINTIAN_ROOT will be appended last and the user dirs will be
+# pre-appended (depending --[no-]user-dirs).
 my @search_dirs;
-# In some (rare) cases, $ENV{HOME} will not be available.
-# - Handle that gracefully by not emitting "Uninitialized ...".
-push @search_dirs, "$ENV{HOME}/.lintian" if defined $ENV{HOME};
-push @search_dirs, '/etc/lintian';
-
 
 my $experimental_output_opts = undef;
 
@@ -208,6 +206,7 @@ Behaviour options:
 Configuration options:
     --cfg CONFIGFILE          read CONFIGFILE for configuration
     --no-cfg                  do not read any config files
+    --include-dir DIR         include checks, libraries (etc.) from DIR
     -j X, --jobs X            limit the number of parallel unpacking jobs to X
     --lab LABDIR              use LABDIR as permanent laboratory
     --root ROOTDIR            use ROOTDIR instead of /usr/share/lintian
@@ -506,6 +505,7 @@ my %opthash = (                 # ------------------ actions
                'root=s' => \$opt{'LINTIAN_ROOT'},
 
                'jobs|j:i' => \$opt{'jobs'},
+               'include-dir=s' => \@search_dirs,
                'user-dirs!' => \$opt{'user-dirs'},
 
                # ------------------ package selection options
@@ -556,17 +556,42 @@ if ($> == 0 and not $allow_root) {
 $opt{'LINTIAN_ROOT'} = $ENV{'LINTIAN_ROOT'} unless (defined($opt{'LINTIAN_ROOT'}));
 if (defined $opt{'LINTIAN_ROOT'}) {
     unless ($opt{'LINTIAN_ROOT'} =~ m,^/,) {
-        require Cwd;
-        my $cwd = Cwd::getcwd();
-        $opt{'LINTIAN_ROOT'} = "$cwd/$opt{'LINTIAN_ROOT'}";
+        my $resolved = abs_path ($opt{'LINTIAN_ROOT'});
+        unless (defined $resolved) {
+            print STDERR "Cannot resolve $opt{'LINTIAN_ROOT'}: $!\n";
+            exit 2;
+        }
+        $opt{'LINTIAN_ROOT'} = $resolved;
     }
 } else {
     $opt{'LINTIAN_ROOT'} = '/usr/share/lintian';
 }
 
-if (!$opt{'user-dirs'} or $ENV{'LINTIAN_INTERNAL_TESTSUITE'}){
-    # Remove the user part of the search dirs.
-    @search_dirs = ();
+# Filter out non-existent paths and resolve the rest.
+# - as we will add them to @INC, make sure they are resolved
+#   so a check doing a chdir will not suddently load anything
+#   differently.
+@search_dirs = map {
+    if (-d $_) {
+        my $resolved = abs_path ($_);
+        unless (defined $resolved) {
+            print STDERR "Cannot resolve $_: $!\n";
+            exit 2;
+        }
+        ($resolved);
+    } else {
+        ();
+    }
+} @search_dirs;
+
+if ($opt{'user-dirs'} and not $ENV{'LINTIAN_INTERNAL_TESTSUITE'}){
+    # Pre-append the user part of the search dirs.
+
+    unshift @search_dirs, '/etc/lintian';
+
+    # In some (rare) cases, $ENV{HOME} will not be available.
+    # - Handle that gracefully by not emitting "Uninitialized ...".
+    unshift @search_dirs, "$ENV{HOME}/.lintian" if defined $ENV{HOME};
 }
 
 push @search_dirs, $opt{'LINTIAN_ROOT'};
@@ -617,9 +642,9 @@ $opt{'LINTIAN_PROFILE'} = 'debian/ftp-master-auto-reject' if $ftpmaster_tags;
 
 # {{{ Loading lintian's own libraries, parse config file and setup output
 
-# Only update @INC if the LINTIAN_ROOT actually contains any libraries...
-unshift @INC, "$opt{'LINTIAN_ROOT'}/lib"
-    if -d "$opt{'LINTIAN_ROOT'}/lib";
+# Include (only existsing) lib directories from @search_dirs in @INC
+
+unshift @INC, grep { -d } map { "$_/lib" } @search_dirs;
 
 require Lintian::Lab;
 
diff --git a/frontend/lintian-info b/frontend/lintian-info
index 0b2a805..6afa1c7 100755
--- a/frontend/lintian-info
+++ b/frontend/lintian-info
@@ -54,6 +54,7 @@ GetOptions(
     'help|h' => \$help,
     'profile=s' => \$prof,
     'user-dirs!' => \$user_dirs,
+    'include-dir=s' => \@dirs,
 ) or die("error parsing options\n");
 
 # help
@@ -67,6 +68,7 @@ Options:
     -a, --annotate    display descriptions of tags in Lintian overrides
     -t, --tags        display tag descriptions
     --profile X       use vendor profile X to determine severities
+    --include-dir DIR check for Lintian data in DIR
     --[no-]user-dirs  whether to include profiles from user directories
 EOT
 
@@ -74,9 +76,9 @@ EOT
 }
 
 if ($user_dirs) {
-    # If requested, include user dirs
-    push @dirs, "$ENV{'HOME'}/.lintian" if exists $ENV{'HOME'};
-    push @dirs, '/etc/lintian';
+    # If requested, pre-append user dirs
+    unshift @dirs, '/etc/lintian';
+    unshift @dirs, "$ENV{'HOME'}/.lintian" if exists $ENV{'HOME'};
 }
 # Add the Lintian root in the end...
 push @dirs, $ENV{'LINTIAN_ROOT'} if exists $ENV{'LINTIAN_ROOT'};
diff --git a/man/lintian-info.pod b/man/lintian-info.pod
index 92df654..8b6bd50 100644
--- a/man/lintian-info.pod
+++ b/man/lintian-info.pod
@@ -60,6 +60,18 @@ about that tag.
 
 Display usage information and exit.
 
+=item B<--include-dir> dir
+
+Use dir as an additional "Lintian root".  The directory is expected
+have a similar layout to the LINTIAN_ROOT (if it exists), but does not
+need to be a full self-contained root.
+
+Unlike B<lintian>, B<lintian-info> will I<not> load any code from
+these additional directories.
+
+This option may appear more than once; each time adding an additional
+directory.
+
 =item B<--profile> prof
 
 Use the severities from the vendor profile prof when displaying tags.
diff --git a/man/lintian.pod.in b/man/lintian.pod.in
index 348a69b..f676952 100644
--- a/man/lintian.pod.in
+++ b/man/lintian.pod.in
@@ -379,6 +379,27 @@ information about the packages it checks.  This option overrides the
 B<LINTIAN_LAB> environment variable and the configuration file entry
 of the same name.
 
+=item B<--include-dir> dir
+
+Use dir as an additional "LINTIAN_ROOT".  The directory is expected
+have a similar layout to the LINTIAN_ROOT (if it exists), but does not
+need to be a full self-contained root.
+
+B<lintian> will check this directory for (additional) profiles, data
+files, support libraries and checks.  The latter two implies that
+Lintian may attempt to I<load and execute code> from this directory.
+
+Unlike with the B<--root> option, B<lintian> will I<not> load
+collections from this directory.
+
+This option may appear more than once; each time adding an additional
+directory.  Directories are searched in the order they appear on the
+command line.
+
+The additional directories will be checked I<after> the user
+directories (though see B<--no-user-dirs>) and I<before> the core
+LINTIAN_ROOT (e.g. B<--root>).
+
 =item B<-j> [X], B<--jobs>[=X]
 
 Set the limit for how many unpacking jobs Lintian will run in
@@ -396,6 +417,10 @@ Look for B<lintian>'s support files (such as check scripts and
 collection scripts) in rootdir.  This overrides the B<LINTIAN_ROOT>
 environment variable.  The default location is I</usr/share/lintian>.
 
+This option is mostly useful for development or testing of B<lintian>.
+To add additional support files (e.g. extra checks), consider using
+B<--include-dir> instead.
+
 =item B<--user-dirs>, B<--no-user-dirs>
 
 By default, B<lintian> will check I<$HOME> and I</etc> for files

-- 
Debian package checker


Reply to: