This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=36a7770f03e9e4d1865d25ad74b27d82c07b6f84 commit 36a7770f03e9e4d1865d25ad74b27d82c07b6f84 Author: Johannes Schauer Marin Rodrigues <[email protected]> AuthorDate: Fri May 27 01:33:19 2022 +0200 dpkg-genbuildinfo: Add new can-execute-cross-built-programs tainted flag Whether we can execute a cross-built program depends on whether the CPU and the operating system have such capability, including in some cases doing so via emulation, such as qemu hooked via something like binfmt on Linux. If the system is or not capable of running such programs, might affect the built artifacts and what tests run or not. [[email protected]: - Use File::Temp instead of tmpnam() and push_exit_handler(). - Set a taint flag instead of a new field. - Pass -w to gcc to avoid warnings. - Refactor into a function. - Style fixes. ] Closes: #1011191 --- man/deb-buildinfo.pod | 7 ++++++ scripts/dpkg-genbuildinfo.pl | 51 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/man/deb-buildinfo.pod b/man/deb-buildinfo.pod index fff6a03e2..626d12cb4 100644 --- a/man/deb-buildinfo.pod +++ b/man/deb-buildinfo.pod @@ -211,6 +211,13 @@ The system has programs under I</usr/local/bin> or I</usr/local/sbin>. The system has libraries, either static or shared under I</usr/local/lib>. +=item B<can-execute-cross-built-programs> + +The system can execute cross built programs, either directly or via some +emulation layer. + +Since dpkg 1.21.10. + =back =item B<Installed-Build-Depends:> (required) diff --git a/scripts/dpkg-genbuildinfo.pl b/scripts/dpkg-genbuildinfo.pl index 29d6c3a8c..a142cc1b3 100755 --- a/scripts/dpkg-genbuildinfo.pl +++ b/scripts/dpkg-genbuildinfo.pl @@ -28,13 +28,19 @@ use warnings; use List::Util qw(any); use Cwd; use File::Basename; +use File::Temp; use POSIX qw(:fcntl_h :locale_h strftime); use Dpkg (); use Dpkg::Gettext; use Dpkg::Checksums; use Dpkg::ErrorHandling; -use Dpkg::Arch qw(get_build_arch get_host_arch debarch_eq); +use Dpkg::IPC; +use Dpkg::Arch qw( + get_build_arch + get_host_arch + debarch_eq debarch_to_gnutriplet +); use Dpkg::Build::Types; use Dpkg::Build::Info qw(get_build_env_allowed); use Dpkg::BuildOptions; @@ -247,9 +253,52 @@ sub collect_installed_builddeps { return $installed_deps; } +sub is_cross_executable { + my $host_arch = get_host_arch(); + my $build_arch = get_build_arch(); + + return if $host_arch eq $build_arch; + + # If we are cross-compiling, record whether it was possible to execute + # the host architecture by cross-compiling and executing a small + # host-arch binary. + my $CC = debarch_to_gnutriplet($host_arch) . '-gcc'; + my $crossprog = 'int main() { write(1, "ok", 2); return 0; }'; + my ($stdout, $stderr) = ('', ''); + my $tmpfh = File::Temp->new(); + spawn( + exec => [ $CC, '-w', '-x', 'c', '-o', $tmpfh->filename, '-' ], + from_string => \$crossprog, + to_string => \$stdout, + error_to_string => \$stderr, + wait_child => 1, + nocheck => 1, + ); + if ($?) { + print { *STDOUT } $stdout; + print { *STDERR } $stderr; + subprocerr("$CC -w -x c -"); + } + close $tmpfh; + spawn( + exec => [ $tmpfh->filename ], + error_to_file => '/dev/null', + to_string => \$stdout, + wait_child => 1, + nocheck => 1, + ); + + return 1 if $? == 0 && $stdout eq 'ok'; + return 0; +} + sub get_build_tainted_by { my @tainted = run_vendor_hook('build-tainted-by'); + if (is_cross_executable()) { + push @tainted, 'can-execute-cross-built-programs'; + } + return @tainted; } -- Dpkg.Org's dpkg

