#!/usr/bin/perl -w # Copyright © 2010 Piotr Ożarowski # Copyright © 2012 Jakub Wilk # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. use strict; use Debian::Debhelper::Dh_Lib; use File::Find; init(options => { "strict" => \$dh{STRICT}, "force" => \$dh{FORCE}, }); my %data; open(FILE, '<', '/usr/share/numpy3/versions') or error("cannot read version data: $!\n"); while () { chomp; next unless /^[^#]/; my ($key, $value) = split; $data{$key} = $value; } close FILE; unless (exists $data{'abi'} and exists $data{'api'} and exists $data{'api-min-version'}) { error("cannot parse version data file"); } sub has_numpy_capi_reference { # NumPy has no discernable ELF dependencies but tries to import a particular # module to initialize an array of API entry points. We just look for that # module name being referenced by the binary module. my ($file) = @_; open(my $fd, '<:raw', $file) or error("open $file: $!"); local $/ = undef; my $content = <$fd>; close($fd); return $content =~ /numpy\._?core\._multiarray_umath\x00/ and $content =~ /_(?:ARRAY|UFUNC)_API\x00/; } foreach my $package (@{$dh{DOPACKAGES}}) { if (package_binary_arch($package) ne "all") { my $tmp = tmpdir($package); my $uses_numpy_capi = 0; my $check_python_modules = sub { my $fn = $_; return if $uses_numpy_capi; return if ! $fn =~ /\.so(?:\.|$)?/; return if -l $fn; # Ignore symlinks if (excludefile($fn)) { $File::Find::prune = 1 if -d _; return; } if (-d _) { if ($fn =~ m!^\Q$tmp\E/usr/lib/debug!) { $File::Find::prune = 1; } return; } return if ! -f _; return if ! is_so_or_exec_elf_file($fn); if (has_numpy_capi_reference($fn)) { $uses_numpy_capi = 1; } }; find({wanted => $check_python_modules, no_chdir => 1}, $tmp); if ($dh{FORCE} && !$uses_numpy_capi) { $uses_numpy_capi = 1; warning("binary package $package does not depend on the NumPy C ABI, but --force was given"); } if ($uses_numpy_capi) { my $numpy_dep = "python3-numpy2-abi$data{'abi'}"; # The first NumPy 2.x ABI release is binary compatible with the last NumPy 1.x ABI release $numpy_dep .= " | python3-numpy-abi9" if ($data{'abi'} eq '0'); if ($dh{STRICT}) { # For strict dependencies, we require the same API version as well $numpy_dep .= ", python3-numpy-api$data{'api'}"; } addsubstvar($package, "python3:Depends", $numpy_dep); } else { warning("skipping binary package $package which does not depend on the NumPy C ABI"); } } } exit 0