Przeglądaj źródła

Create Dpkg::Path with some functions needed for dpkg-shlibdeps

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
Raphael Hertzog 19 lat temu
rodzic
commit
435c9a0bfe
3 zmienionych plików z 84 dodań i 0 usunięć
  1. 1 0
      debian/dpkg-dev.install
  2. 82 0
      scripts/Dpkg/Path.pm
  3. 1 0
      scripts/Makefile.am

+ 1 - 0
debian/dpkg-dev.install

@@ -17,6 +17,7 @@ usr/bin/dpkg-shlibdeps
 usr/bin/dpkg-source
 usr/bin/dpkg-source
 usr/lib/dpkg/controllib.pl
 usr/lib/dpkg/controllib.pl
 usr/lib/dpkg/parsechangelog
 usr/lib/dpkg/parsechangelog
+usr/share/perl5/Dpkg/Path.pm
 usr/share/perl5/Dpkg/Version.pm
 usr/share/perl5/Dpkg/Version.pm
 usr/share/perl5/Dpkg/ErrorHandling.pm
 usr/share/perl5/Dpkg/ErrorHandling.pm
 usr/share/perl5/Dpkg/Shlibs.pm
 usr/share/perl5/Dpkg/Shlibs.pm

+ 82 - 0
scripts/Dpkg/Path.pm

@@ -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;

+ 1 - 0
scripts/Makefile.am

@@ -63,6 +63,7 @@ nobase_dist_perllib_DATA = \
 	Dpkg/ErrorHandling.pm \
 	Dpkg/ErrorHandling.pm \
 	Dpkg/BuildOptions.pm \
 	Dpkg/BuildOptions.pm \
 	Dpkg/Gettext.pm \
 	Dpkg/Gettext.pm \
+	Dpkg/Path.pm \
 	Dpkg/Version.pm \
 	Dpkg/Version.pm \
 	Dpkg.pm
 	Dpkg.pm