Selaa lähdekoodia

dpkg-gensymbols: replace #PACKAGE# in dependency templates

To better support packages of libraries that have different names
between architectures, offer the possibility to not hardcode the package
name in the symbols file by using #PACKAGE#. This marker is then
substituted by dpkg-gensymbols when the symbols files are installed inside
the binary package.
Raphael Hertzog 17 vuotta sitten
vanhempi
commit
52e96c75e2

+ 11 - 0
ChangeLog

@@ -1,3 +1,14 @@
+2009-02-27  Raphael Hertzog  <hertzog@debian.org>
+
+	* scripts/Dpkg/Shlibs/SymbolFile.pm (save, dump): Add new
+	parameter asking that #PACKAGE# be replaced on the fly.
+	* scripts/dpkg-gensymbols.pl: Replace #PACKAGE# while outputting
+	symbols files.
+	* man/dpkg-gensymbols.1: Document the new feature.
+	* scripts/t/200_Dpkg_Shlibs.t,
+	scripts/t/200_Dpkg_Shlibs/symbols.fake-2: Add test-case for
+	replacement of #PACKAGE# on the fly (together with test of dump).
+
 2009-02-27  Raphael Hertzog  <hertzog@debian.org>
 2009-02-27  Raphael Hertzog  <hertzog@debian.org>
 
 
 	* scripts/update-alternatives.pl: Add one more sanity check
 	* scripts/update-alternatives.pl: Add one more sanity check

+ 3 - 0
debian/changelog

@@ -170,6 +170,9 @@ dpkg (1.15.0) UNRELEASED; urgency=low
       a single command.
       a single command.
   * Document in update-alternatives(8) how one can repair all broken
   * Document in update-alternatives(8) how one can repair all broken
     alternatives with a single command. Closes: #250258, #395556
     alternatives with a single command. Closes: #250258, #395556
+  * Modify dpkg-gensymbols to replace #PACKAGE# on the fly while installing
+    symbols files so that package having libraries whose name varies between
+    architectures do not need to hardcode the package name. Closes: #517264
 
 
   [ Pierre Habouzit ]
   [ Pierre Habouzit ]
   * Add a --query option to update-alternatives. Closes: #336091, #441904
   * Add a --query option to update-alternatives. Closes: #336091, #441904

+ 9 - 1
man/dpkg-gensymbols.1

@@ -56,6 +56,14 @@ with "~".
 Before applying any patch to the symbols file, the maintainer should
 Before applying any patch to the symbols file, the maintainer should
 double-check that it's sane. Public symbols are not supposed to disappear,
 double-check that it's sane. Public symbols are not supposed to disappear,
 so the patch should ideally only add new lines.
 so the patch should ideally only add new lines.
+.SS Using #PACKAGE# substitution
+.P
+In some rare cases, the name of the library varies between architectures.
+To avoid hardcoding the name of the package in the symbols file, you can
+use the marker \fI#PACKAGE#\fR. It will be replaced by the real package
+name during installation of the symbols files. Contrary to the
+\fI#MINVER#\fR marker, \fI#PACKAGE#\fR will never appear in a symbols file
+inside a binary package.
 .SS Using includes
 .SS Using includes
 .P 
 .P 
 When the set of exported symbols differ between architectures, it's no
 When the set of exported symbols differ between architectures, it's no
@@ -190,7 +198,7 @@ Show the version and exit.
 .BR dpkg\-shlibdeps (1).
 .BR dpkg\-shlibdeps (1).
 .
 .
 .SH AUTHORS
 .SH AUTHORS
-Copyright \(co 2007 Rapha\[:e]l Hertzog
+Copyright \(co 2007-2009 Rapha\[:e]l Hertzog
 .sp
 .sp
 This is free software; see the GNU General Public Licence version 2 or later
 This is free software; see the GNU General Public Licence version 2 or later
 for copying conditions. There is NO WARRANTY.
 for copying conditions. There is NO WARRANTY.

+ 17 - 9
scripts/Dpkg/Shlibs/SymbolFile.pm

@@ -188,7 +188,7 @@ sub merge_object_from_symfile {
 }
 }
 
 
 sub save {
 sub save {
-    my ($self, $file, $with_deprecated) = @_;
+    my ($self, $file, %opts) = @_;
     $file = $self->{file} unless defined($file);
     $file = $self->{file} unless defined($file);
     my $fh;
     my $fh;
     if ($file eq "-") {
     if ($file eq "-") {
@@ -197,23 +197,31 @@ sub save {
 	open($fh, ">", $file)
 	open($fh, ">", $file)
 	    || syserr(_g("cannot write %s"), $file);
 	    || syserr(_g("cannot write %s"), $file);
     }
     }
-    $self->dump($fh, $with_deprecated);
+    $self->dump($fh, %opts);
     close($fh) if ($file ne "-");
     close($fh) if ($file ne "-");
 }
 }
 
 
 sub dump {
 sub dump {
-    my ($self, $fh, $with_deprecated) = @_;
-    $with_deprecated = 1 unless defined($with_deprecated);
+    my ($self, $fh, %opts) = @_;
+    $opts{with_deprecated} = 1 unless exists $opts{with_deprecated};
     foreach my $soname (sort keys %{$self->{objects}}) {
     foreach my $soname (sort keys %{$self->{objects}}) {
 	my @deps = @{$self->{objects}{$soname}{deps}};
 	my @deps = @{$self->{objects}{$soname}{deps}};
-	print $fh "$soname $deps[0]\n";
-	shift @deps;
-	print $fh "| $_\n" foreach (@deps);
+        my $dep = shift @deps;
+        $dep =~ s/#PACKAGE#/$opts{package}/g if exists $opts{package};
+	print $fh "$soname $dep\n";
+        foreach $dep (@deps) {
+            $dep =~ s/#PACKAGE#/$opts{package}/g if exists $opts{package};
+	    print $fh "| $dep\n";
+        }
 	my $f = $self->{objects}{$soname}{fields};
 	my $f = $self->{objects}{$soname}{fields};
-	print $fh "* $_: $f->{$_}\n" foreach (sort keys %{$f});
+        foreach my $field (sort keys %{$f}) {
+            my $value = $f->{$field};
+            $value =~ s/#PACKAGE#/$opts{package}/g if exists $opts{package};
+	    print $fh "* $field: $value\n";
+        }
 	foreach my $sym (sort keys %{$self->{objects}{$soname}{syms}}) {
 	foreach my $sym (sort keys %{$self->{objects}{$soname}{syms}}) {
 	    my $info = $self->{objects}{$soname}{syms}{$sym};
 	    my $info = $self->{objects}{$soname}{syms}{$sym};
-	    next if $info->{deprecated} and not $with_deprecated;
+	    next if $info->{deprecated} and not $opts{with_deprecated};
 	    print $fh "#MISSING: $info->{deprecated}#" if $info->{deprecated};
 	    print $fh "#MISSING: $info->{deprecated}#" if $info->{deprecated};
 	    print $fh " $sym $info->{minver}";
 	    print $fh " $sym $info->{minver}";
 	    print $fh " $info->{dep_id}" if $info->{dep_id};
 	    print $fh " $info->{dep_id}" if $info->{dep_id};

+ 4 - 3
scripts/dpkg-gensymbols.pl

@@ -189,7 +189,7 @@ $symfile->clear_except(keys %{$od->{objects}});
 # Write out symbols files
 # Write out symbols files
 if ($stdout) {
 if ($stdout) {
     $output = "standard output";
     $output = "standard output";
-    $symfile->save("-");
+    $symfile->save("-", package => $oppackage);
 } else {
 } else {
     unless (defined($output)) {
     unless (defined($output)) {
 	unless($symfile->is_empty()) {
 	unless($symfile->is_empty()) {
@@ -199,7 +199,7 @@ if ($stdout) {
     }
     }
     if (defined($output)) {
     if (defined($output)) {
 	print "Storing symbols in $output.\n" if $debug;
 	print "Storing symbols in $output.\n" if $debug;
-	$symfile->save($output);
+	$symfile->save($output, package => $oppackage);
     } else {
     } else {
 	print "No symbol information to store.\n" if $debug;
 	print "No symbol information to store.\n" if $debug;
     }
     }
@@ -253,7 +253,8 @@ if ($compare) {
 	# and after
 	# and after
 	my $before = File::Temp->new(TEMPLATE=>'dpkg-gensymbolsXXXXXX');
 	my $before = File::Temp->new(TEMPLATE=>'dpkg-gensymbolsXXXXXX');
 	my $after = File::Temp->new(TEMPLATE=>'dpkg-gensymbolsXXXXXX');
 	my $after = File::Temp->new(TEMPLATE=>'dpkg-gensymbolsXXXXXX');
-	$ref_symfile->dump($before); $symfile->dump($after);
+	$ref_symfile->dump($before, package => $oppackage);
+        $symfile->dump($after, package => $oppackage);
 	seek($before, 0, 0); seek($after, 0, 0);
 	seek($before, 0, 0); seek($after, 0, 0);
 	my ($md5_before, $md5_after) = (Digest::MD5->new(), Digest::MD5->new());
 	my ($md5_before, $md5_after) = (Digest::MD5->new(), Digest::MD5->new());
 	$md5_before->addfile($before);
 	$md5_before->addfile($before);

+ 1 - 1
scripts/t/200_Dpkg_Shlibs.t

@@ -161,7 +161,7 @@ is_deeply($sym, { 'minver' => '1.0', 'dep_id' => 1, 'deprecated' => 0,
 
 
 # Check dump output
 # Check dump output
 my $io = IO::String->new();
 my $io = IO::String->new();
-$sym_file->dump($io);
+$sym_file->dump($io, package => "libfake1");
 is(${$io->string_ref()},
 is(${$io->string_ref()},
 'libfake.so.1 libfake1 #MINVER#
 'libfake.so.1 libfake1 #MINVER#
 | libvirtualfake
 | libvirtualfake

+ 1 - 1
scripts/t/200_Dpkg_Shlibs/symbols.fake-2

@@ -1,6 +1,6 @@
 #include "symbols.include-2"
 #include "symbols.include-2"
 # This is just a comment
 # This is just a comment
-libfake.so.1 libfake1 #MINVER#
+libfake.so.1 #PACKAGE# #MINVER#
 * Build-Depends-Package: libfake-dev
 * Build-Depends-Package: libfake-dev
 # The alternate dependency is below
 # The alternate dependency is below
 | libvirtualfake
 | libvirtualfake