Browse Source

Building blocks for vendor-specific build of Debian packages

* scripts/Dpkg/Vendor.pm: Provide simple parser for vendor-specific
information stored in /etc/dpkg/origins/. The current vendor can
be identified through get_current_vendor() and get_vendor_info()
retrieves the information stores within those files.
* scripts/dpkg-buildpackage.pl: Setup the DEB_VENDOR environment
variable if possible.
* man/dpkg-buildpackage.1: Document the above changes.
* scripts/Dpkg/Source/Package/V3/quilt.pm (get_series_file): Use
get_current_vendor() to decide the name of the vendor-specific
series file that should be used in priority.
Raphael Hertzog 18 years ago
parent
commit
322153b6e8

+ 13 - 0
ChangeLog

@@ -1,3 +1,16 @@
+2008-06-21  Raphael Hertzog  <hertzog@debian.org>
+
+	* scripts/Dpkg/Vendor.pm: Provide simple parser for vendor-specific
+	information stored in /etc/dpkg/origins/. The current vendor can
+	be identified through get_current_vendor() and get_vendor_info()
+	retrieves the information stores within those files.
+	* scripts/dpkg-buildpackage.pl: Setup the DEB_VENDOR environment
+	variable if possible.
+	* man/dpkg-buildpackage.1: Document the above changes.
+	* scripts/Dpkg/Source/Package/V3/quilt.pm (get_series_file): Use
+	get_current_vendor() to decide the name of the vendor-specific
+	series file that should be used.
+
 2008-06-19  Guillem Jover  <guillem@debian.org>
 2008-06-19  Guillem Jover  <guillem@debian.org>
 
 
 	* lib/varbuf.c (varbufdupc): Store the old used size instead of the
 	* lib/varbuf.c (varbufdupc): Store the old used size instead of the

+ 4 - 0
debian/changelog

@@ -39,6 +39,10 @@ dpkg (1.15.0) UNRELEASED; urgency=low
   * Modified Dpkg::BuildOptions to recognize and use spaces as separator
   * Modified Dpkg::BuildOptions to recognize and use spaces as separator
     in DEB_BUILD_OPTIONS (in order to conform with the Debian policy
     in DEB_BUILD_OPTIONS (in order to conform with the Debian policy
     ruling estasblished in #430649). Closes: #486937
     ruling estasblished in #430649). Closes: #486937
+  * Add DEB_VENDOR environment variable in the build environment to be able to
+    change behaviour dynamically depending on the vendor of the current system
+    (or target system when the user overrides DEB_VENDOR by setting it himself).
+    Closes: #457371
 
 
   [ Pierre Habouzit ]
   [ Pierre Habouzit ]
   * Add a --query option to update-alternatives. Closes: #336091, #441904
   * Add a --query option to update-alternatives. Closes: #336091, #441904

+ 7 - 1
man/dpkg-buildpackage.1

@@ -216,6 +216,12 @@ Show the usage message and exit.
 Show the version and exit.
 Show the version and exit.
 .
 .
 .SH ENVIRONMENT
 .SH ENVIRONMENT
+The variable \fBDEB_VENDOR\fR will be set to the name of the current vendor
+if \fI/etc/dpkg/origins/default\fR exists and can be used to look up the vendor
+name. If the variable already exists, and contains the name of an existing
+vendor in \fI/etc/dpkg/origins\fR, it will be kept; otherwise the variable is
+unset.
+.P
 A set of environment variables for setting compiler and linker options are
 A set of environment variables for setting compiler and linker options are
 set to default values unless already set in the environment. Note that
 set to default values unless already set in the environment. Note that
 this mechanism was only introduced in dpkg-dev, version 1.14.17 and
 this mechanism was only introduced in dpkg-dev, version 1.14.17 and
@@ -279,7 +285,7 @@ objects (if the linker is called directly, then
 .B -Wl
 .B -Wl
 and
 and
 .B ,
 .B ,
-have to be stripped from these options. Default value: empty.
+have to be stripped from these options). Default value: empty.
 .TP
 .TP
 .B LDFLAGS_APPEND
 .B LDFLAGS_APPEND
 Optimization options appended to the compiler flags when linking code,
 Optimization options appended to the compiler flags when linking code,

+ 3 - 3
scripts/Dpkg/Source/Package/V3/quilt.pm

@@ -27,6 +27,7 @@ use Dpkg::Gettext;
 use Dpkg::ErrorHandling qw(error syserr warning usageerr subprocerr info);
 use Dpkg::ErrorHandling qw(error syserr warning usageerr subprocerr info);
 use Dpkg::Source::Patch;
 use Dpkg::Source::Patch;
 use Dpkg::IPC;
 use Dpkg::IPC;
+use Dpkg::Vendor qw(get_current_vendor);
 
 
 use POSIX;
 use POSIX;
 use File::Basename;
 use File::Basename;
@@ -61,9 +62,8 @@ sub get_autopatch_name {
 sub get_series_file {
 sub get_series_file {
     my ($self, $dir) = @_;
     my ($self, $dir) = @_;
     my $pd = File::Spec->catdir($dir, "debian", "patches");
     my $pd = File::Spec->catdir($dir, "debian", "patches");
-    # TODO: replace "debian" with the current distro name once we have a
-    # way to figure it out
-    foreach (File::Spec->catfile($pd, "debian.series"),
+    my $vendor = lc(get_current_vendor() || "debian");
+    foreach (File::Spec->catfile($pd, "$vendor.series"),
              File::Spec->catfile($pd, "series")) {
              File::Spec->catfile($pd, "series")) {
         return $_ if -e $_;
         return $_ if -e $_;
     }
     }

+ 102 - 0
scripts/Dpkg/Vendor.pm

@@ -0,0 +1,102 @@
+# Copyright 2008 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::Vendor;
+
+use strict;
+use warnings;
+
+use Dpkg::ErrorHandling qw(syserr);
+use Dpkg::Gettext;
+use Dpkg::Cdata;
+
+use Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT_OK = qw(get_vendor_info get_current_vendor get_vendor_file);
+
+=head1 NAME
+
+Dpkg::Vendor - get access to some vendor specific information
+
+=head1 DESCRIPTION
+
+The files in /etc/dpkg/origins/ can provide information about various
+vendors who are providing Debian packages. Currently those files look like
+this:
+
+  Vendor: Debian
+  Vendor-URL: http://www.debian.org/
+  Bugs: debbugs://bugs.debian.org
+
+The file should be named according to the vendor name.
+
+=head1 FUNCTIONS
+
+=over 4
+
+=item $fields = Dpkg::Vendor::get_vendor_info($name)
+
+Returns a Dpkg::Fields object with the information parsed from the
+corresponding vendor file in /etc/dpkg/origins/. If $name is omitted,
+it will use /etc/dpkg/origins/default which is supposed to be a symlink
+to the vendor of the currently installed operating system. Returns undef
+if there's no file for the given vendor.
+
+=cut
+sub get_vendor_info(;$) {
+    my $vendor = shift || "default";
+    my $file = get_vendor_file($vendor);
+    return undef unless $file;
+    open(my $fh, "<", $file) || syserr(_g("cannot read %s"), $file);
+    my $fields = parsecdata($fh, $file);
+    close($fh);
+    return $fields;
+}
+
+=item $name = Dpkg::Vendor::get_vendor_file($name)
+
+Check if there's a file for the given vendor and returns its
+name.
+
+=cut
+sub get_vendor_file(;$) {
+    my $vendor = shift || "default";
+    my $file;
+    foreach my $name ($vendor, lc($vendor), ucfirst($vendor)) {
+        $file = "/etc/dpkg/origins/$name" if -e "/etc/dpkg/origins/$name";
+    }
+    return $file;
+}
+
+=item $name = Dpkg::Vendor::get_current_vendor()
+
+Returns the name of the current vendor. If DEB_VENDOR is set, it uses
+that first, otherwise it falls back to parsing /etc/dpkg/origins/default.
+If that file doesn't exist, it returns undef.
+
+=cut
+sub get_current_vendor() {
+    my $f;
+    if ($ENV{'DEB_VENDOR'}) {
+        $f = get_vendor_info($ENV{'DEB_VENDOR'});
+        return $f->{'Vendor'} if defined $f;
+    }
+    $f = get_vendor_info();
+    return $f->{'Vendor'} if defined $f;
+    return undef;
+}
+
+1;

+ 8 - 0
scripts/dpkg-buildpackage.pl

@@ -15,6 +15,7 @@ use Dpkg::Compression;
 use Dpkg::Version qw(check_version);
 use Dpkg::Version qw(check_version);
 use Dpkg::Changelog qw(parse_changelog);
 use Dpkg::Changelog qw(parse_changelog);
 use Dpkg::Arch qw(get_build_arch debarch_to_gnutriplet);
 use Dpkg::Arch qw(get_build_arch debarch_to_gnutriplet);
+use Dpkg::Vendor qw(get_current_vendor);
 
 
 textdomain("dpkg-dev");
 textdomain("dpkg-dev");
 
 
@@ -319,6 +320,13 @@ if ($targetgnusystem and
                                "/usr/share/pkgconfig/";
                                "/usr/share/pkgconfig/";
 }
 }
 
 
+my $vendor = get_current_vendor();
+if (defined $vendor) {
+    $ENV{'DEB_VENDOR'} = $vendor;
+} else {
+    delete $ENV{'DEB_VENDOR'};
+}
+
 my $arch;
 my $arch;
 unless ($sourceonly) {
 unless ($sourceonly) {
     $arch = mustsetvar($ENV{'DEB_HOST_ARCH'}, _g('host architecture'));
     $arch = mustsetvar($ENV{'DEB_HOST_ARCH'}, _g('host architecture'));