]> err.no Git - dpkg/commitdiff
Create Dpkg::Path with some functions needed for dpkg-shlibdeps
authorRaphael Hertzog <hertzog@debian.org>
Wed, 26 Sep 2007 20:59:55 +0000 (22:59 +0200)
committerRaphael Hertzog <hertzog@debian.org>
Wed, 26 Sep 2007 20:59:55 +0000 (22:59 +0200)
The two first function in this module are used to:
- find out the package's root directory (or build tree) using any of its
file as input
- find out the relative filename of a file inside a package's build tree

debian/dpkg-dev.install
scripts/Dpkg/Path.pm [new file with mode: 0644]
scripts/Makefile.am

index 52c2b90509269c9ecf463750312b1c2b42c48a7f..df13a81e1da6f2e159410ad07a4a9128069296c2 100644 (file)
@@ -17,6 +17,7 @@ usr/bin/dpkg-shlibdeps
 usr/bin/dpkg-source
 usr/lib/dpkg/controllib.pl
 usr/lib/dpkg/parsechangelog
+usr/share/perl5/Dpkg/Path.pm
 usr/share/perl5/Dpkg/Version.pm
 usr/share/perl5/Dpkg/ErrorHandling.pm
 usr/share/perl5/Dpkg/Shlibs.pm
diff --git a/scripts/Dpkg/Path.pm b/scripts/Dpkg/Path.pm
new file mode 100644 (file)
index 0000000..5422e0f
--- /dev/null
@@ -0,0 +1,82 @@
+# Copyright 2007 RaphaĆ«l Hertzog <hertzog@debian.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+package Dpkg::Path;
+
+use strict;
+use warnings;
+
+use Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT_OK = qw(get_pkg_root_dir relative_to_pkg_root);
+
+=head1 NAME
+
+Dpkg::Path - some common path handling functions
+
+=head1 DESCRIPTION
+
+It provides some functions to handle various path.
+
+=head1 METHODS
+
+=over 8
+
+=item get_pkg_root_dir($file)
+
+This function will scan upwards the hierarchy of directory to find out
+the directory which contains the "DEBIAN" sub-directory and it will return
+its path. This directory is the root directory of a package being built.
+
+=cut
+
+sub get_pkg_root_dir($) {
+    my $file = shift;
+    $file =~ s{/+$}{};
+    $file =~ s{/+[^/]+$}{} if not -d $file;
+    do {
+       return $file if -d "$file/DEBIAN";
+       last if $file !~ m{/};
+       $file =~ s{/+[^/]+$}{};
+    } while ($file);
+    return undef;
+}
+
+=item relative_to_pkg_root($file)
+
+Returns the filename relative to get_pkg_root_dir($file).
+
+=cut
+
+sub relative_to_pkg_root($) {
+    my $file = shift;
+    my $pkg_root = get_pkg_root_dir($file);
+    if (defined $pkg_root) {
+       $pkg_root .= "/";
+       return $file if ($file =~ s/^\Q$pkg_root\E//);
+    }
+    return undef;
+}
+
+=back
+
+=head1 AUTHOR
+
+Raphael Hertzog <hertzog@debian.org>.
+
+=cut
+
+1;
index 9a338fc1334c3fdc5b65701335b879cd3ed7261b..27d8496562bbaf34614a6b0831fd9cbfdaa8d2bb 100644 (file)
@@ -63,6 +63,7 @@ nobase_dist_perllib_DATA = \
        Dpkg/ErrorHandling.pm \
        Dpkg/BuildOptions.pm \
        Dpkg/Gettext.pm \
+       Dpkg/Path.pm \
        Dpkg/Version.pm \
        Dpkg.pm