1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
#!/usr/bin/perl -w
# Copyright © 2010 Piotr Ożarowski <piotr@debian.org>
# Copyright © 2012 Jakub Wilk <jwilk@debian.org>
#
# 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 (<FILE>) {
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
|