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

[SCM] Debian package checker branch, master, updated. 2.5.12-130-geec546d



The following commit has been merged in the master branch:
commit 73923b30979dba6e52b44f0a2aa9df4369d146fb
Author: Niels Thykier <niels@thykier.net>
Date:   Mon May 27 17:10:11 2013 +0200

    L::Util: Add locate_helper_tool
    
    Add new utility function to locate helper code.  This will allow
    others to write tools and easily find them without having to set paths
    or ENV variables themselves before calling lintian.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/debian/changelog b/debian/changelog
index 3cca257..1ccc52c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -124,6 +124,10 @@ lintian (2.5.13) UNRELEASED; urgency=low
 
   * frontend/lintian:
     + [NT] Ignore LINTIAN_ROOT/locale and /var/lib/lintian/locale.
+    + [NT] Export LINTIAN_INCLUDE_DIRS and LINTIAN_HELPERS_DIR to
+      subprocesses.  These are ":"-separated lists of dirs used by
+      Lintian.  The first being a list of raw include dirs and the
+      second being a list of helpers dirs in these include dirs.
 
   * lib/*:
     + [NT] Fix a number of spelling mistakes in the POD.
@@ -157,6 +161,8 @@ lintian (2.5.13) UNRELEASED; urgency=low
       cases.
     + [NT] Avoid the LOCPATH dance to find the path to an UTF-8
       locale now that stable's libc-bin provides C.UTF-8 for us.
+    + [NT] Add new function, locate_helper_tool, to find helper
+      tools.
 
   * private/refresh-perl-provides:
     + [NT] Apply patch from Niko Tyni to improve Lintian's
diff --git a/frontend/lintian b/frontend/lintian
index f4aecd7..9ce0e8a 100755
--- a/frontend/lintian
+++ b/frontend/lintian
@@ -655,7 +655,11 @@ $opt{'LINTIAN_PROFILE'} = 'debian/ftp-master-auto-reject' if $ftpmaster_tags;
 # {{{ Loading lintian's own libraries, parse config file and setup output
 
 # Include (only existsing) lib directories from @search_dirs in @INC
+# and LINTIAN_{INCLUDE,HELPER}_DIRS.
 
+$ENV{'LINTIAN_INCLUDE_DIRS'} = join(':', grep { -d } @search_dirs);
+$ENV{'LINTIAN_HELPER_DIRS'} = join(':',
+                                   grep { -d } map { "$_/helpers" } @search_dirs);
 unshift @INC, grep { -d } map { "$_/lib" } @search_dirs;
 
 require Lintian::Lab;
diff --git a/lib/Lintian/Util.pm b/lib/Lintian/Util.pm
index 6fb67ba..1eb7b55 100644
--- a/lib/Lintian/Util.pm
+++ b/lib/Lintian/Util.pm
@@ -76,6 +76,7 @@ BEGIN {
                  normalize_pkg_path
                  parse_boolean
                  is_ancestor_of
+                 locate_helper_tool
                  $PKGNAME_REGEX),
                  @{ $EXPORT_TAGS{constants} }
     );
@@ -962,6 +963,47 @@ sub fail {
     croak $str;
 }
 
+=item locate_helper_tool(TOOLNAME)
+
+Given the name of a helper tool, returns the path to it.  The tool
+must be available in the "helpers" subdir of one of the "lintian root"
+directories used by Lintian.
+
+The tool name should follow the same rules as check names.
+Particularly, third-party checks should namespace their tools in the
+same way they namespace their checks.  E.g. "python/some-helper".
+
+If the tool cannot be found, this sub will cause a trappable error.
+
+=cut
+
+{
+    my %_CACHE = ();
+    sub locate_helper_tool {
+        my ($toolname) = @_;
+        if ($toolname =~ m{(?:\A|/) \.\. (?:\Z|/)}xsm) {
+            fail("$toolname is not a valid tool name");
+        }
+        return $_CACHE{$toolname} if exists $_CACHE{$toolname};
+
+        my $toolpath_str = $ENV{'LINTIAN_HELPER_DIRS'};
+        if (defined($toolpath_str)) {
+            # NB: We rely on LINTIAN_HELPER_DIRS to contain only
+            # absolute paths.  Otherwise we may return relative
+            # paths.
+            for my $dir (split(':', $toolpath_str)) {
+                my $tool = "$dir/$toolname";
+                next unless -f -x $tool;
+                $_CACHE{$toolname} = $tool;
+                return $tool;
+            }
+        }
+        $toolpath_str //= '<N/A>';
+        fail(sprintf('Cannot locate %s (search dirs: %s)',
+                     $toolname, $toolpath_str));
+    }
+}
+
 =item strip ([LINE])
 
 Strips whitespace from the beginning and the end of LINE and returns
diff --git a/lib/Test/Lintian.pm b/lib/Test/Lintian.pm
index bc6014a..14850c9 100644
--- a/lib/Test/Lintian.pm
+++ b/lib/Test/Lintian.pm
@@ -612,6 +612,8 @@ sub load_profile_for_test {
 
     $PROFILE = Lintian::Profile->new ($profname, \@inc);
     Lintian::Data->set_vendor ($PROFILE);
+    $ENV{'LINTIAN_HELPER_DIRS'} = join(':', map { "$_/helpers" } @inc);
+    $ENV{'LINTIAN_INCLUDE_DIRS'} = join(':', @inc);
 }
 
 

-- 
Debian package checker


Reply to: