Michal Čihař wrote:
> I know it would be hard to find some solution which would help in most
> cases. But I hate to put the logic to compile for all python versions
> to all debian/rules. It would be great if this logic can be somehow
> separated and reused independently of build system.

That logic follows below. 

If this were say, rewritten in python :) and factored out into a standalone
program with a name like python-multibuild, and included in some python
development package, then debhelper and rules files could just call it,
and pass it the setup.py to run and the action to do.

I'd love to remove this code from debhelper, if we can find someplace
else to put it.

sub dbg_build_needed {
        my $this=shift;
        my $act=shift;

        # Return a list of python-dbg package which are listed
        # in the build-dependencies. This is kinda ugly, but building
        # dbg extensions without checking if they're supposed to be
        # built may result in various FTBFS if the package is not
        # built in a clean chroot.

        my @dbg;
        open (CONTROL, 'debian/control') ||
                error("cannot read debian/control: $!\n");
        foreach my $builddeps (join('', <CONTROL>) =~
                        /^Build-Depends[^:]*:.*\n(?:^[^\w\n].*\n)*/gmi) {
                while ($builddeps =~ /(python[^, ]*-dbg)/g) {
                        push @dbg, $1;
                }
        }

        close CONTROL;
        return @dbg;

}

sub setup_py {
        my $this=shift;
        my $act=shift;

        # We need to to run setup.py with the default python first
        # as distutils/setuptools modifies the shebang lines of scripts.
        # This ensures that #!/usr/bin/python is used and not pythonX.Y
        # Take into account that the default Python must not be in
        # the requested Python versions.
        # Then, run setup.py with each available python, to build
        # extensions for each.
        
        my $python_default = `pyversions -d`;
        $python_default =~ s/^\s+//;
        $python_default =~ s/\s+$//;
        my @python_requested = split ' ', `pyversions -r 2>/dev/null`;
        if (grep /^\Q$python_default\E/, @python_requested) {
                @python_requested = ("python", grep(!/^\Q$python_default\E/,
                                        @python_requested));
        }
                
        my @python_dbg;                 
        my @dbg_build_needed = $this->dbg_build_needed();
        foreach my $python (map { $_."-dbg" } @python_requested) {
                if (grep /^(python-all-dbg|\Q$python\E)/, @dbg_build_needed) {
                        push @python_dbg, $python;
                }
                elsif (($python eq "python-dbg")
                       and (grep /^\Q$python_default\E/, @dbg_build_needed)) {
                        push @python_dbg, $python_default."-dbg";
                }
        }              

        foreach my $python (@python_requested, @python_dbg) {
                if (-x "/usr/bin/".$python) {
                        # effectively this runs system($python, "setup.py", 
$act, @_);
                        $this->doit_in_sourcedir($python, "setup.py", $act, @_);
                }
        }
}


-- 
see shy jo

Attachment: signature.asc
Description: Digital signature

Reply via email to