From 435c9a0bfeda19e1d6991eefba4735775c444f73 Mon Sep 17 00:00:00 2001 From: Raphael Hertzog Date: Wed, 26 Sep 2007 22:59:55 +0200 Subject: [PATCH] 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 --- debian/dpkg-dev.install | 1 + scripts/Dpkg/Path.pm | 82 +++++++++++++++++++++++++++++++++++++++++ scripts/Makefile.am | 1 + 3 files changed, 84 insertions(+) create mode 100644 scripts/Dpkg/Path.pm diff --git a/debian/dpkg-dev.install b/debian/dpkg-dev.install index 52c2b905..df13a81e 100644 --- a/debian/dpkg-dev.install +++ b/debian/dpkg-dev.install @@ -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 index 00000000..5422e0f7 --- /dev/null +++ b/scripts/Dpkg/Path.pm @@ -0,0 +1,82 @@ +# Copyright 2007 Raphaël Hertzog + +# 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 . + +=cut + +1; diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 9a338fc1..27d84965 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -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 -- 2.39.5