rev 10527 - branches/kde4/cdbs

Modestas Vainius modax-guest at alioth.debian.org
Sat May 10 16:26:09 UTC 2008


Author: modax-guest
Date: 2008-05-10 16:26:08 +0000 (Sat, 10 May 2008)
New Revision: 10527

Added:
   branches/kde4/cdbs/dh_sameversiondeps
Modified:
   branches/kde4/cdbs/kde.mk
Log:
dh_sameversiondeps: a helper untility which expands appropriately formatted substvar to the dependency which versioning is based on the versioning of other dependency (which most likely were generated by dpkg-shlibdeps).

E.g. in kdepimlibs5-dev case, it needs a pretty tightly (e.g. the shlibs version of kde4libs it was built against) versioned dependency on kdelibs5-dev. Therefore, the idea is to automatically add such kdelibs5-dev depencency that it is versioned in the same way as kdelibs5 dep is versioned for the package kdepimlibs5. Hence the  substvar ${sameVersionDep:kdelibs5-dev:kdepimlibs5-Depends-kdelibs5} on kdepimlibs5-dev  tells dh_sameversiondeps to:

* Get Depends field of the kdepimlibs5 package from debian/control, expand other substvars in that field based on the contents of debian/$package.substvars and debian/substvars.
* Find all kdelibs5 occurenciers (versioning included).
* s/kdelibs5/kdelibs5-dev/ and set the value of sameVersionDep:kdelibs5-dev:kdepimlibs5-Depends-kdelibs5 substvar to the resulting string dependency string. substvar is written to debian/$package.substvars by default.


Added: branches/kde4/cdbs/dh_sameversiondeps
===================================================================
--- branches/kde4/cdbs/dh_sameversiondeps	                        (rev 0)
+++ branches/kde4/cdbs/dh_sameversiondeps	2008-05-10 16:26:08 UTC (rev 10527)
@@ -0,0 +1,140 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Dpkg::Control;
+use Dpkg::Substvars;
+use Dpkg::ErrorHandling;
+use File::Copy;
+
+use Debian::Debhelper::Dh_Lib;
+
+my $namespace = "sameVersionDep";
+my @fields = qw(Depends Recommends Suggests Enhances Pre-Depends);
+my $re_fields = join("|", @fields);
+my $re_pkgname = qr/[a-z0-9][a-z0-9+.-]*/;
+my $re_oursubstvar = qr/\$\{($namespace:($re_pkgname):($re_pkgname)-($re_fields)-($re_pkgname))\}/;
+
+# Global substvars file
+my $g_substvars = new Dpkg::Substvars;
+$g_substvars->parse("debian/substvars") if (-r "debian/substvars");
+
+sub Shlibsvars::new {
+    my ($cls, $package, $control, $substvars_file) = @_;
+    my $self = bless ( {
+        "package" => $package,
+        "control" => $control,
+        "file" => $substvars_file,
+        }, $cls);
+    $self->{substvars} = new Dpkg::Substvars;
+    if (-r $self->{file}) {
+        $self->{substvars}->parse($self->{file});
+    }
+    return $self;
+}
+
+sub Shlibsvars::get_fieldval {
+    my ($self, $field) = @_;
+
+    my $pkg = $self->{control}->get_pkg_by_name($self->{package});
+    return undef if (!defined $pkg || !exists $pkg->{$field});
+
+    # Turn of warnings for substvars runs
+    my $save_quiet = $Dpkg::ErrorHandling::quiet_warnings;
+    $Dpkg::ErrorHandling::quiet_warnings = 1;
+
+    my $val = $pkg->{$field};
+    $val = $self->{substvars}->substvars($val);
+    $val = $g_substvars->substvars($val);
+
+    $Dpkg::ErrorHandling::quiet_warnings = $save_quiet;
+    return $val;
+}
+
+sub Shlibsvars::extract_deps {
+    my ($self, $field, $deppkg) = @_;
+
+    my $val = $self->get_fieldval($field);
+    return undef() unless defined $val;
+
+    # Extract dependency fields we need
+    my @matched_deps;
+    for my $dep (split(/\s*,\s*/, $val)) {
+        if ($dep =~ /^\Q$deppkg\E(?:$|[\W])/) {
+            push @matched_deps, $dep;
+        }
+    }
+    return join(",", @matched_deps);
+}
+
+sub write_substvar($$$$) {
+    my ($pkgname, $varname, $value, $substvars) = @_;
+    my @contents;
+    my $varset = 0;
+
+    my $file = (-r $substvars) ? $substvars : "debian/substvars";
+    if (-r $file) {
+        open(FILE, "<$file") or die "Unable to open substvars file '$file' for reading\n";
+        while (<FILE>) {
+            if (!$varset && /^\s*\Q$varname=\E/) {
+                push @contents, "$varname=$value\n";
+                $varset = 1;
+            } else {
+                push @contents, $_;
+            }
+        }
+        close(FILE);
+    } else {
+        # Fallback to default
+        $file = $substvars;
+    }
+
+    open(FILE, ">$file.tmp") or die "Unable to open substvars file '$file.tmp' for writing\n";
+    for (@contents) {
+        print FILE $_;
+    }
+    if (!$varset) {
+        print FILE "$varname=$value", "\n";
+    }
+    close(FILE);
+
+    File::Copy::move("$file.tmp", "$file");
+}
+
+init();
+
+my $control = new Dpkg::Control;
+my %shlibsvars;
+
+foreach my $package (@{$dh{DOPACKAGES}}) {
+    my $pkg_substvars = sprintf("debian/%ssubstvars", pkgext($package));
+    my $pkg = $control->get_pkg_by_name($package);
+
+    for my $fieldname (@fields) {
+        if (exists $pkg->{$fieldname}) {
+            my $fieldval = $pkg->{$fieldname};
+            my $pkgname = $pkg->{Package};
+
+            while ($fieldval =~ m/\G.*?$re_oursubstvar/g) {
+                my $varname = $1;
+                my $dep2add = $2;
+                my $basepkg = $3;
+                my $deptype = $4;
+                my $deppkg  = $5;
+
+                if (!exists $shlibsvars{$basepkg}) {
+                    my $base_substvars = sprintf("debian/%ssubstvars", pkgext($basepkg));
+                    $shlibsvars{$basepkg} = new Shlibsvars($basepkg, $control, $base_substvars);
+                }
+                my $vars = $shlibsvars{$basepkg};
+                my $deps = $vars->extract_deps($deptype, $deppkg);
+                $deps = "" unless($deps);
+                $deps =~ s/\b\Q$deppkg\E\b/$dep2add/g;
+
+                # Write substvar for the package
+                write_substvar($pkgname, $varname, $deps, $pkg_substvars);
+            }
+        }
+    }
+}
+
+exit 0


Property changes on: branches/kde4/cdbs/dh_sameversiondeps
___________________________________________________________________
Name: svn:executable
   + *

Modified: branches/kde4/cdbs/kde.mk
===================================================================
--- branches/kde4/cdbs/kde.mk	2008-05-10 10:29:57 UTC (rev 10526)
+++ branches/kde4/cdbs/kde.mk	2008-05-10 16:26:08 UTC (rev 10527)
@@ -73,6 +73,7 @@
 	rm -rf debian/man/out
 	-rmdir debian/man
 	rm -f debian/stamp-man-pages
+	rm -f debian/stamp-sameversiondeps
 	rm -f CMakeCache.txt
 
 
@@ -100,3 +101,7 @@
 		rm -rf debian/$(DEB_SOURCE_PACKAGE)-doc-html/usr/share/doc/kde/HTML/en/$$pkg; \
 	done
 
+
+# Generate "sameVersionDep" substvars
+$(patsubst %,binary-predeb/%,$(DEB_PACKAGES)) :: binary-predeb/%:
+	debian/cdbs/dh_sameversiondeps -p$(cdbs_curpkg)




More information about the pkg-kde-commits mailing list