[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: systemd / cross-building / failure in dpkg-gencontrol



Hi,

Quoting Michael Biebl (2015-08-24 09:56:02)
> Am 24.08.2015 um 08:21 schrieb Johannes Schauer:
> > Quoting Helmut Grohne (2015-08-24 07:32:16)
> >> It is not clear how to implement :native for mk-build-deps, because it does
> >> not differentiate between build architecture and host architecture. Maybe the
> >> simplest fix would be to s/:native// in mk-build-deps and declare cross
> >> support unfixably broken. Dima Kogan already observed that it does not work
> >> at all in #794538.
> > 
> > This is fixable. It has to be because building a binary package to satisfy
> > dependencies already works in other situations while still being cross-aware,
> > most notably in sbuild.
> > 
> > Namely, what mk-build-deps should do is to copy the sbuild behaviour:
> > 
> >  - use libdpkg-perl to parse and process the Build-{Depends,Conflicts}* fields
> >    and filter architecture and profile restrictions correctly
> >  - change the meaning of its --arch option (this currently does some magic
> >    depending on whether the source package has architecture specific build
> >    dependencies or not):
> >       - this option should specify the HOST architecture
> >       - the generated binary package should be of this architecture (this is
> >         already the case)
> >       - foo:native dependencies should be converted to foo:$build
> >       - the dependency on build-essential should be build-essential:$build
> >       - if host != build, then an additional build dependency on
> >         crossbuild-essential-$host:$build should be added
> >       - change the created binary package name to have "cross" or a similar
> >         identifier in its name so that it can be installed at the same time
> >         with a package for a native build for the same source package
> > 
> > Doing all this is not very hard and the code even already exists in perl in the
> > function setup_apt_archive() in the sbuild source code at
> > lib/Sbuild/ResolverBase.pm:
> > 
> >       http://sources.debian.net/src/sbuild/0.65.2-1.1/lib/Sbuild/ResolverBase.pm/#L692
> > [...]
> [...]
> It would be great if one of you can follow up on #794538 (or file a new bug
> report against devscripts), since you obviously are in a much better position
> to explain any details to the maintainer of mk-build-deps.

the attached patch addresses all the issues listed above and should now follow
closer the working behaviour of sbuild. I CC-ed the bug report you mentioned.

Thanks for bringing this up!

cheers, josch
From d5b29c75033e7c49e1b117bbdde0e48d7bb13110 Mon Sep 17 00:00:00 2001
From: Johannes 'josch' Schauer <josch@mister-muffin.de>
Date: Mon, 24 Aug 2015 12:45:57 +0200
Subject: [PATCH] scripts/mk-build-deps.pl: support crossbuild dependencies

---
 scripts/mk-build-deps.pl | 71 +++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 55 insertions(+), 16 deletions(-)

diff --git a/scripts/mk-build-deps.pl b/scripts/mk-build-deps.pl
index a17be2b..68690cb 100755
--- a/scripts/mk-build-deps.pl
+++ b/scripts/mk-build-deps.pl
@@ -61,10 +61,9 @@ the B<--install> switch.
 
 =item B<-a> I<foo>, B<--arch> I<foo>
 
-If the source package has architecture-specific build dependencies, produce
-a package for architecture I<foo>, not for the system architecture. (If the
-source package does not have architecture-specific build dependencies,
-the package produced is always for the pseudo-architecture B<all>.)
+Set the host architecture the binary package is built for. This defaults to
+the native architecture. Use this option to create a binary package that is
+able to satisfy crossbuild dependencies.
 
 =item B<-B>, B<--build-dep>
 
@@ -110,6 +109,7 @@ use Pod::Usage;
 use Dpkg::Control;
 use Dpkg::Version;
 use Dpkg::IPC;
+use Dpkg::Deps;
 use FileHandle;
 use Text::ParseWords;
 
@@ -412,17 +412,56 @@ sub build_equiv
 {
     my ($opts) = @_;
     my $args = '';
-    my $arch = 'all';
+
+    chomp(my $native_arch = readpipe("dpkg --print-architecture"));
+    my $hostarch = $native_arch;
 
     if (defined $opt_arch) {
 	$args = "--arch=$opt_arch ";
-	$arch = $opt_arch;
+	$hostarch = $opt_arch;
     }
-    elsif ($opts->{depends} =~ m/\[|\]/) {
-	spawn(exec => ['dpkg-architecture', '-qDEB_HOST_ARCH'],
-	      to_string => \$arch,
-	      wait_child => 1);
-	chomp($arch);
+
+    my $build_profiles = [ split /\s+/, ($ENV{'DEB_BUILD_PROFILES'} // "") ];
+
+    my $positive = deps_parse($opts->{depends} // "",
+	reduce_arch => 1,
+	host_arch => $hostarch,
+	build_arch => $native_arch,
+	build_dep => 1,
+	reduce_profiles => 1,
+	build_profiles => $build_profiles);
+    my $negative = deps_parse($opts->{conflicts} // "",
+	reduce_arch => 1,
+	host_arch => $hostarch,
+	build_arch => $native_arch,
+	build_dep => 1,
+	union => 1,
+	reduce_profiles => 1,
+	build_profiles => $build_profiles);
+
+    # either remove :native for native builds or replace it by the build
+    # architecture
+    my $handle_native_archqual = sub {
+        my ($dep) = @_;
+        if ($dep->{archqual} && $dep->{archqual} eq "native") {
+            if ($hostarch eq $native_arch) {
+                $dep->{archqual} = undef;
+            } else {
+                $dep->{archqual} = $native_arch;
+            }
+        }
+        return 1;
+    };
+    deps_iterate($positive, $handle_native_archqual);
+    deps_iterate($negative, $handle_native_archqual);
+
+    my $pkgname;
+    my $buildess = "build-essential:$native_arch";
+    if ($native_arch eq $hostarch) {
+	$pkgname = "$opts->{name}-$opts->{type}";
+    } else {
+	$pkgname = "$opts->{name}-cross-$opts->{type}";
+	$buildess .= ", crossbuild-essential-$hostarch:$native_arch";
     }
 
     my $readme = '/usr/share/devscripts/README.mk-build-deps';
@@ -431,11 +470,11 @@ sub build_equiv
     print EQUIVS "Section: devel\n" .
     "Priority: optional\n".
     "Standards-Version: 3.7.3\n\n".
-    "Package: $opts->{name}-$opts->{type}\n".
-    "Architecture: $arch\n".
-    "Depends: build-essential, $opts->{depends}\n";
+    "Package: $pkgname\n".
+    "Architecture: $hostarch\n".
+    "Depends: $buildess, $positive\n";
 
-    print EQUIVS "Conflicts: $opts->{conflicts}\n" if $opts->{conflicts};
+    print EQUIVS "Conflicts: $negative\n" if $negative;
 
     # Allow the file not to exist to ease testing
     print EQUIVS "Readme: $readme\n" if -r $readme;
@@ -452,7 +491,7 @@ sub build_equiv
     # The version in the .deb filename will not contain the epoch
     $version = $v->as_string(omit_epoch => 1);
     my $package = "$opts->{name}-$opts->{type}";
-    my $deb_file = "${package}_${version}_${arch}.deb";
+    my $deb_file = "${package}_${version}_${hostarch}.deb";
     return {
 	package => $package,
 	deb_file => $deb_file
-- 
2.1.4

Attachment: signature.asc
Description: signature


Reply to: