~ubuntu-branches/ubuntu/oneiric/sbuild/oneiric

« back to all changes in this revision

Viewing changes to lib/Sbuild/ResolverBase.pm

  • Committer: Bazaar Package Importer
  • Author(s): Lorenzo De Liso
  • Date: 2011-05-01 16:55:16 UTC
  • mfrom: (8.1.19 upstream) (3.3.17 sid)
  • Revision ID: james.westby@ubuntu.com-20110501165516-8g3uwrnhv2bzjt8y
Tags: 0.62.2-1ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/patches/do-not-install-debfoster-into-chroots.patch: 
    do not install debfoster into the chroots because it is in universe and 
    not needed for package building itself.
  - debian/patches/run-pre-build-hooks-as-root.patch: 
    run pre-build hooks as root (Closes: #607228)
* Now that the package uses a patch system, don't modify the files directly;
  instead, put the changes in the respective patches and add the DEP-3
  patch tagging guidelines to them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
use POSIX;
27
27
use Fcntl;
28
28
use File::Temp qw(tempdir tempfile);
29
 
use File::Path qw(remove_tree);
30
29
use File::Copy;
31
30
 
32
31
use Dpkg::Deps;
353
352
 
354
353
    my $arch = $self->get('Arch');
355
354
    my ($sysname, $nodename, $release, $version, $machine) = POSIX::uname();
 
355
    $self->log_subsection("Build environment");
356
356
    $self->log("Kernel: $sysname $release $arch ($machine)\n");
357
357
 
358
358
    $self->log("Toolchain package versions:");
514
514
                   tempdir('resolver' . '-XXXXXX',
515
515
                           DIR => $self->get('Chroot Build Dir')));
516
516
    }
 
517
    $session->run_command(
 
518
        { COMMAND => ['chown', 'sbuild:sbuild', $session->strip_chroot_path($self->get('Dummy package path'))],
 
519
          USER => 'root',
 
520
          DIR => '/' });
 
521
    if ($?) {
 
522
        $self->log_error("E: Failed to set sbuild:sbuild ownership on dummy package dir\n");
 
523
        return 0;
 
524
    }
 
525
    $session->run_command(
 
526
        { COMMAND => ['chmod', '0770', $session->strip_chroot_path($self->get('Dummy package path'))],
 
527
          USER => 'root',
 
528
          DIR => '/' });
 
529
    if ($?) {
 
530
        $self->log_error("E: Failed to set 0770 permissions on dummy package dir\n");
 
531
        return 0;
 
532
    }
517
533
    my $dummy_dir = $self->get('Dummy package path');
518
534
    my $dummy_gpghome = $dummy_dir . '/gpg';
519
535
    my $dummy_archive_dir = $dummy_dir . '/apt_archive';
535
551
        $self->cleanup_apt_archive();
536
552
        return 0;
537
553
    }
538
 
    if (!(-d $dummy_archive_dir || mkdir $dummy_archive_dir, 0755)) {
 
554
    $session->run_command(
 
555
        { COMMAND => ['chown', 'sbuild:sbuild',
 
556
                      $session->strip_chroot_path($dummy_gpghome)],
 
557
          USER => 'root',
 
558
          DIR => '/' });
 
559
    if ($?) {
 
560
        $self->log_error("E: Failed to set sbuild:sbuild ownership on $dummy_gpghome\n");
 
561
        return 0;
 
562
    }
 
563
    if (!(-d $dummy_archive_dir || mkdir $dummy_archive_dir, 0775)) {
539
564
        $self->log_warning('Could not create build-depends dummy archive dir ' . $dummy_archive_dir . ': ' . $!);
540
565
        $self->cleanup_apt_archive();
541
566
        return 0;
603
628
                              host_arch => $self->get('Arch'));
604
629
    }
605
630
 
 
631
    $self->log("Merged Build-Depends: $positive\n") if $positive;
 
632
    $self->log("Merged Build-Conflicts: $negative\n") if $negative;
 
633
 
 
634
    # Filter out all but the first alternative.
 
635
    if (!$self->get_conf('RESOLVE_ALTERNATIVES')) {
 
636
        my $positive_filtered = Dpkg::Deps::AND->new();
 
637
        foreach my $item ($positive->get_deps()) {
 
638
            my ($first) = $item->get_deps();
 
639
            $positive_filtered->add($first) if defined $first;
 
640
        }
 
641
        $positive = $positive_filtered;
 
642
    }
 
643
 
606
644
    if ($positive ne "") {
607
645
        print DUMMY_CONTROL 'Depends: ' . $positive . "\n";
608
646
    }
610
648
        print DUMMY_CONTROL 'Conflicts: ' . $negative . "\n";
611
649
    }
612
650
 
613
 
    debug("DUMMY Depends: $positive \n");
614
 
    debug("DUMMY Conflicts: $negative \n");
 
651
    $self->log("Filtered Build-Depends: $positive\n") if $positive;
 
652
    $self->log("Filtered Build-Conflicts: $negative\n") if $negative;
615
653
 
616
654
    print DUMMY_CONTROL <<"EOF";
617
655
Maintainer: Debian buildd-tools Developers <buildd-tools-devel\@lists.alioth.debian.org>
621
659
EOF
622
660
    close (DUMMY_CONTROL);
623
661
 
 
662
    foreach my $path ($dummy_pkg_dir . '/DEBIAN/control',
 
663
                      $dummy_pkg_dir . '/DEBIAN',
 
664
                      $dummy_pkg_dir,
 
665
                      $dummy_archive_dir) {
 
666
        $session->run_command(
 
667
            { COMMAND => ['chown', 'sbuild:sbuild',
 
668
                          $session->strip_chroot_path($path)],
 
669
              USER => 'root',
 
670
              DIR => '/' });
 
671
        if ($?) {
 
672
            $self->log_error("E: Failed to set sbuild:sbuild ownership on $path\n");
 
673
            return 0;
 
674
        }
 
675
    }
 
676
 
624
677
    #Now build the package:
625
678
    $session->run_command(
626
679
        { COMMAND => ['dpkg-deb', '--build', $session->strip_chroot_path($dummy_pkg_dir), $session->strip_chroot_path($dummy_deb)],
627
 
          USER => $self->get_conf('USER'),
 
680
          USER => $self->get_conf('BUILD_USER'),
628
681
          PRIORITY => 0});
629
682
    if ($?) {
630
683
        $self->log("Dummy package creation failed\n");
692
745
                       $session->strip_chroot_path($dummy_release_file));
693
746
    $session->run_command(
694
747
        { COMMAND => \@gpg_command,
695
 
          USER => $self->get_conf('USER'),
 
748
          USER => $self->get_conf('BUILD_USER'),
696
749
          PRIORITY => 0});
697
750
    if ($?) {
698
751
        $self->log("Failed to sign dummy archive Release file.\n");
708
761
        close($tmpfh);
709
762
        # List file needs to be moved with root.
710
763
        $session->run_command(
 
764
            { COMMAND => ['chmod', '0644', $session->strip_chroot_path($tmpfilename)],
 
765
              USER => 'root',
 
766
              PRIORITY => 0});
 
767
        if ($?) {
 
768
            $self->log("Failed to create apt list file for dummy archive.\n");
 
769
            $self->cleanup_apt_archive();
 
770
            return 0;
 
771
        }
 
772
        $session->run_command(
711
773
            { COMMAND => ['mv', $session->strip_chroot_path($tmpfilename),
712
774
                          $session->strip_chroot_path($dummy_archive_list_file)],
713
775
              USER => 'root',
736
798
# Remove the apt archive.
737
799
sub cleanup_apt_archive {
738
800
    my $self = shift;
 
801
 
739
802
    my $session = $self->get('Session');
 
803
 
740
804
    if (defined $self->get('Dummy package path')) {
741
 
        remove_tree($self->get('Dummy package path'));
 
805
        $session->run_command(
 
806
            { COMMAND => ['rm', '-fr', $session->strip_chroot_path($self->get('Dummy package path'))],
 
807
              USER => $self->get_conf('BUILD_USER'),
 
808
              DIR => '/' });
742
809
    }
 
810
 
743
811
    $session->run_command(
744
812
        { COMMAND => ['rm', '-f', $session->strip_chroot_path($self->get('Dummy archive list file'))],
745
813
          USER => 'root',
812
880
    # Run apt-ftparchive to generate Packages and Sources files.
813
881
    $host->run_command(
814
882
        { COMMAND => ['apt-ftparchive', '-q=2', 'generate', $tmpfilename],
815
 
          USER => $self->get_conf('USER'),
 
883
          USER => $self->get_conf('USERNAME'),
816
884
          PRIORITY => 0,
817
885
          DIR => '/'});
818
886
    if ($?) {
824
892
    # Get output for Release file
825
893
    my $pipe = $host->pipe_command(
826
894
        { COMMAND => ['apt-ftparchive', '-q=2', '-c', $tmpfilename, 'release', $dummy_archive_dir],
827
 
          USER => $self->get_conf('USER'),
 
895
          USER => $self->get_conf('USERNAME'),
828
896
          PRIORITY => 0,
829
897
          DIR => '/'});
830
898
    if (!defined($pipe)) {