[debhelper-devel] [debhelper] 01/01: Add PoC support for building DEB_TARGET during cross builds

Niels Thykier nthykier at moszumanska.debian.org
Tue Oct 17 19:37:40 UTC 2017


This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch dh-cross-target
in repository debhelper.

commit fa000d911225bee49b2dd5ea65670879c6469300
Author: Niels Thykier <niels at thykier.net>
Date:   Tue Oct 17 19:36:25 2017 +0000

    Add PoC support for building DEB_TARGET during cross builds
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 dh_gencontrol                  | 13 ++++++++----
 lib/Debian/Debhelper/Dh_Lib.pm | 48 +++++++++++++++++++++++++++++++++++-------
 2 files changed, 49 insertions(+), 12 deletions(-)

diff --git a/dh_gencontrol b/dh_gencontrol
index bdbf178..8ab4ca3 100755
--- a/dh_gencontrol
+++ b/dh_gencontrol
@@ -102,11 +102,16 @@ on_pkgs_in_parallel {
 		# avoid gratuitous warnings
 		ensure_substvars_are_present($substvars, 'misc:Depends', 'misc:Pre-Depends');
 
-		my (@debug_info_params, $build_ids, @multiarch_params);
+		my (@debug_info_params, $build_ids, @multiarch_params, @arch_reset);
 		if ( -d $dbgsym_info_dir ) {
 			$build_ids = read_dbgsym_build_ids($dbgsym_info_dir);
 		}
 
+		if (Debian::Debhelper::Dh_Lib::package_cross_type($package) eq 'target') {
+			my $target_arch = dpkg_architecture_value('DEB_TARGET_ARCH');
+			push(@arch_reset, 'dpkg-architecture', '--host-arch', $target_arch, '-f', '-c');
+		}
+
 		if ( -d $dbgsym_tmp) {
 			my $multiarch = package_multiarch($package);
 			my $section = package_section($package);
@@ -147,8 +152,8 @@ on_pkgs_in_parallel {
 				push(@dbgsym_options, '-UReplaces', '-UBreaks');
 			}
 			install_dir("${dbgsym_tmp}/DEBIAN");
-			doit("dpkg-gencontrol", "-p${package}", "-l$changelog", "-T$substvars",
-				"-P${dbgsym_tmp}",@{$dh{U_PARAMS}}, @dbgsym_options);
+			doit(@arch_reset, "dpkg-gencontrol", "-p${package}", "-l$changelog", "-T$substvars",
+				"-P${dbgsym_tmp}", @{$dh{U_PARAMS}}, @dbgsym_options);
 
 			reset_perm_and_owner(0644, "${dbgsym_tmp}/DEBIAN/control");
 		} elsif ($build_ids) {
@@ -163,7 +168,7 @@ on_pkgs_in_parallel {
 			if (package_multiarch($package) eq 'no');
 
 		# Generate and install control file.
-		doit("dpkg-gencontrol", "-p$package", "-l$changelog", "-T$substvars",
+		doit(@arch_reset, "dpkg-gencontrol", "-p$package", "-l$changelog", "-T$substvars",
 			"-P$tmp", @debug_info_params, @multiarch_params,
 			@{$dh{U_PARAMS}});
 
diff --git a/lib/Debian/Debhelper/Dh_Lib.pm b/lib/Debian/Debhelper/Dh_Lib.pm
index 167d5d2..e673570 100644
--- a/lib/Debian/Debhelper/Dh_Lib.pm
+++ b/lib/Debian/Debhelper/Dh_Lib.pm
@@ -1311,7 +1311,7 @@ sub sourcepackage {
 # As a side effect, populates %package_arches and %package_types
 # with the types of all packages (not only those returned).
 my (%package_types, %package_arches, %package_multiarches, %packages_by_type,
-    %package_sections);
+    %package_sections, %package_cross_type);
 sub getpackages {
 	my ($type) = @_;
 	error("getpackages: First argument must be one of \"arch\", \"indep\", or \"both\"")
@@ -1328,7 +1328,7 @@ sub getpackages {
 	my $arch="";
 	my $section="";
 	my ($package_type, $multiarch, %seen, @profiles, $source_section,
-		$included_in_build_profile);
+		$included_in_build_profile, $cross_type, $cross_target_arch);
 	if (exists $ENV{'DEB_BUILD_PROFILES'}) {
 		@profiles=split /\s+/, $ENV{'DEB_BUILD_PROFILES'};
 	}
@@ -1361,7 +1361,11 @@ sub getpackages {
 			$package_type=$1;
 		} elsif (/^Multi-Arch:\s*(.*)/i) {
 			$multiarch = $1;
-
+		} elsif (/^Private-Package-Cross-Type:\s*(.*)/i) {
+			$cross_type = $1;
+			if ($cross_type ne 'host' and $cross_type ne 'target') {
+				error("Unknown value of Private-Package-Cross-Type \"$cross_type\" at debian/control:$.");
+			}
 		} elsif (/^Build-Profiles:\s*(.*)/i) {
 			# rely on libdpkg-perl providing the parsing functions
 			# because if we work on a package with a Build-Profiles
@@ -1386,15 +1390,28 @@ sub getpackages {
 				$package_arches{$package}=$arch;
 				$package_multiarches{$package} = $multiarch;
 				$package_sections{$package} = $section || $source_section;
+				$cross_type //= 'host';
+				$package_cross_type{$package} = $cross_type;
 				push(@{$packages_by_type{'all-listed-in-control-file'}}, $package);
 				if ($included_in_build_profile) {
 					if ($arch eq 'all') {
 						push(@{$packages_by_type{'indep'}}, $package);
 						push(@{$packages_by_type{'both'}}, $package);
-					} elsif ($arch eq 'any' ||
-							 ($arch ne 'all' && samearch(buildarch(), $arch))) {
-						push(@{$packages_by_type{'arch'}}, $package);
-						push(@{$packages_by_type{'both'}}, $package);
+					} else {
+						my $included = 0;
+						$included = 1 if $arch eq 'any';
+						if (not $included) {
+							my $desired_arch = buildarch();
+							if ($cross_type eq 'target') {
+								$cross_target_arch //= dpkg_architecture_value('DEB_TARGET_ARCH');
+								$desired_arch = $cross_target_arch;
+							}
+							$included = 1 if samearch($desired_arch, $arch);
+						}
+						if ($included) {
+							push(@{$packages_by_type{'arch'}}, $package);
+							push(@{$packages_by_type{'both'}}, $package);
+						}
 					}
 				}
 			} elsif ($section and not defined($source_section)) {
@@ -1402,6 +1419,7 @@ sub getpackages {
 			}
 			$package='';
 			$package_type=undef;
+			$cross_type = undef;
 			$arch='';
 			$section='';
 		}
@@ -1429,7 +1447,9 @@ sub package_binary_arch {
 		warning "package $package is not in control info";
 		return buildarch();
 	}
-	return $package_arches{$package} eq 'all' ? "all" : buildarch();
+	return 'all' if $package_arches{$package} eq 'all';
+	return dpkg_architecture_value('DEB_TARGET_ARCH') if package_cross_type($package) eq 'target';
+	return buildarch();
 }
 
 # Returns the Architecture: value which the package declared.
@@ -1481,6 +1501,18 @@ sub package_section {
 	return $package_sections{$package} // 'unknown';
 }
 
+sub package_cross_type {
+	my ($package) = @_;
+
+	# Test the architecture field instead, as it is common for a
+	# package to not have a multi-arch value.
+	if (! exists $package_cross_type{$package}) {
+		warning "package $package is not in control info";
+		return 'host';
+	}
+	return $package_cross_type{$package} // 'host';
+}
+
 # Return true if a given package is really a udeb.
 sub is_udeb {
 	my $package=shift;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git




More information about the debhelper-devel mailing list