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

[PATCH/RFC] dpkg-shlibdeps: ignore shell scripts



It can be convenient in debian/rules to simply run

  dpkg-shlibdeps debian/tmp/usr/bin/*

to set the ${shlibs:Depends} substvar according to the needs of
binaries that would be installed.  Unfortunately, if some of the
commands to be installed are implemented as scripts for the shell,
perl, python, or some other interpreter, the output will be somewhat
ugly:

| objdump: debian/tmp/usr/bin/some-script: File format not recognized
| objdump: debian/tmp/usr/bin/other-script: File format not recognized
[...]

Teach dpkg-shlibdeps to recognize this situation and avoid the
warning.

The heuristic used to detect scripts here is very simple: any file
starting with the two bytes #! is assumed to be a script.  Maybe in
the future the rule will change to be more sophisticated.  It is a
public function so other packages can make use of it.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Yes, the debian/rules could check for such files itself, but that
would be wasteful in two ways:

 - checking for binaries right before running objdump instead of
   earlier saves a little time on buildds, since it keeps the file
   in the cache

 - more importantly, including this code in dpkg-shlibdeps avoids
   the complication of including such code in all the various
   build systems

So I would be happy to see something like this go in.  What do you
think?

If the implementation seems okay, I’d be glad to add a couple of tests
and try it out with some real packages.

 debian/changelog               |    5 ++++-
 scripts/Dpkg/Shlibs/Objdump.pm |   11 +++++++++++
 scripts/dpkg-shlibdeps.pl      |    4 ++++
 3 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index cd98bb9..903609b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,9 @@
 dpkg (1.15.8) UNRELEASED; urgency=low
 
-  *
+  [ Jonathan Nieder ]
+  * Let dpkg-shlibdeps ignore files with a #! line specifying an
+    interpreter.  The new Dpkg::Shlibs::Objdump::is_script() function
+    is used to identify these files.
 
  -- Guillem Jover <guillem@debian.org>  Wed, 21 Apr 2010 04:40:12 +0200
 
diff --git a/scripts/Dpkg/Shlibs/Objdump.pm b/scripts/Dpkg/Shlibs/Objdump.pm
index aa52a8a..3f33ebe 100644
--- a/scripts/Dpkg/Shlibs/Objdump.pm
+++ b/scripts/Dpkg/Shlibs/Objdump.pm
@@ -105,6 +105,17 @@ sub is_elf {
     return $result;
 }
 
+sub is_script {
+    my ($file) = @_;
+    open(FILE, "<", $file) || syserr(_g("cannot read %s"), $file);
+    my ($header, $result) = ("", 0);
+    if (read(FILE, $header, 2) == 2) {
+	$result = 1 if ($header =~ /^#!$/);
+    }
+    close(FILE)
+    return $result;
+}
+
 package Dpkg::Shlibs::Objdump::Object;
 
 use Dpkg::Gettext;
diff --git a/scripts/dpkg-shlibdeps.pl b/scripts/dpkg-shlibdeps.pl
index 554cae6..27eed49 100755
--- a/scripts/dpkg-shlibdeps.pl
+++ b/scripts/dpkg-shlibdeps.pl
@@ -155,6 +155,10 @@ foreach my $file (keys %exec) {
     $cur_field = $exec{$file};
     print ">> Scanning $file (for $cur_field field)\n" if $debug;
 
+    if (Dpkg::Shlibs::Objdump::is_script($file)) {
+	print "Not a binary\n" if $debug;
+	continue;
+    }
     my $obj = Dpkg::Shlibs::Objdump::Object->new($file);
     my @sonames = $obj->get_needed_libraries;
 
-- 
1.7.1.rc1


Reply to: