Skip to content

Commit

Permalink
--no-retry option to not retry building already failed packages
Browse files Browse the repository at this point in the history
  • Loading branch information
jozef committed Feb 24, 2010
1 parent 018c401 commit 5c5ac4d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,4 +12,5 @@
/tmp/*
/Debian-Apt-PM-*
/cache/apt/apt-pm/*
/sharedstate/dh-make-pm/*

1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -15,6 +15,7 @@ README
script/apt-pm
script/dh-make-pm
script/dpkg-scanpmpackages
sharedstate/dh-make-pm/.exists
t/00_compile.t
t/01_Debian-Apt-PM.t
t/distribution.t
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.SKIP
Expand Up @@ -35,4 +35,5 @@
cache/apt/apt-pm/[^d]
cache/apt/apt-pm/deb/[^.]
cache/apt/apt-pm/deb-src/[^.]
sharedstate/dh-make-pm/[^.]

6 changes: 6 additions & 0 deletions lib/Debian/Apt/PM/SPc.pm
Expand Up @@ -15,6 +15,7 @@ use File::Spec;

sub _path_types {qw(
cachedir
sharedstatedir
)};

=head1 PATHS
Expand All @@ -25,10 +26,15 @@ sub _path_types {qw(
The Perl modules indexes are stored in F</var/cache/apt/apt-pm/> folder.
=head2 sharedstatedir
Used to store status of a tarball builds. (pass/fail)
=cut

sub prefix { use Sys::Path; Sys::Path->find_distribution_root(__PACKAGE__); };
sub cachedir { File::Spec->catdir(__PACKAGE__->prefix, 'cache') };
sub sharedstatedir { File::Spec->catdir(__PACKAGE__->prefix, 'sharedstate') };

1;

Expand Down
38 changes: 32 additions & 6 deletions script/dh-make-pm
Expand Up @@ -7,6 +7,8 @@ dh-make-pm - build Debian packages (dh-make-perl on pbuilder+cowdancer steroids
=head1 SYNOPSIS
dh-make-pm --cpan Debian::Apt::PM
--no-retry will skip packaging modules that already failed to package
=head1 DESCRIPTION
Expand Down Expand Up @@ -84,6 +86,8 @@ use File::Path 2.01 'make_path', 'remove_tree';
use CPAN;
use File::Basename 'basename';
use File::Copy 'copy';
use JSON::Util;
use Debian::Apt::PM::SPc;

use Debian::Apt::PM;
our $aptpm = Debian::Apt::PM->new();
Expand All @@ -95,11 +99,13 @@ sub main {
my $module_name;
my $repository_folder = '/var/cache/pbuilder/result';
my $build_folder = File::Spec->catdir(File::HomeDir->my_home, '.dh-make-pm', 'build');
my $no_build_retry = 0;
GetOptions(
'help|h' => \$help,
'cpan=s' => \$module_name,
'repo=s' => \$repository_folder,
'build=s' => \$build_folder,
'no-retry' => \$no_build_retry,
) or pod2usage;
pod2usage if $help;
pod2usage if not $module_name;
Expand All @@ -113,6 +119,11 @@ sub main {
die $build_folder.' folder does not exists'
if not -d $build_folder;

my $build_history_filename = Debian::Apt::PM::SPc->sharedstatedir.'/dh-make-pm/build-history.json';
JSON::Util->encode({}, [$build_history_filename])
if not -f $build_history_filename;
my %build_history = %{JSON::Util->decode([$build_history_filename])};

my %all_prereq;
my @to_make = ($module_name);

Expand All @@ -133,12 +144,6 @@ sub main {
print STDERR 'going to build deb from ', join(', ', @to_make), "\n";

while (my $build = pop @to_make) {
# refresh the repository
chdir($repository_folder);
system('make', 'all') and die $!;
system('apt-pm', 'update') and die $!;
system('sudo', 'cowbuilder', '--update', '--bindmounts', '/var/cache/pbuilder/result/') and die $!;

# clean-up build directory
remove_tree( $build_folder, {keep_root => 1} );

Expand All @@ -149,6 +154,22 @@ sub main {
copy($dist_tarball, $build_folder) or die "Copy failed: $!";;
$dist_tarball = basename($dist_tarball);

# don't retry to build a tarball that failed build before
if ($no_build_retry and $build_history{$dist_tarball}->{'fail'}) {
print STDERR 'SKIP ', $dist_tarball,' previous build failed', "\n";
next;
}

# refresh the repository
chdir($repository_folder);
system('make', 'all') and die $!;
system('apt-pm', 'update') and die $!;
system('sudo', 'cowbuilder', '--update', '--bindmounts', '/var/cache/pbuilder/result/') and die $!;

# mark current tarball as fail
$build_history{$dist_tarball}->{'fail'} = time();
JSON::Util->encode(\%build_history, [$build_history_filename], { 'atomic' => 1 });

chdir($build_folder) or die $!;

extract_dist_tarball($dist_tarball);
Expand Down Expand Up @@ -191,6 +212,11 @@ sub main {
my $deb_basename = $1;

system('mv', glob($deb_basename.'*'), '/var/cache/pbuilder/result/unstable') and die $!;

# mark current tarball as pass
delete $build_history{$dist_tarball}->{'fail'};
$build_history{$dist_tarball}->{'pass'} = time();
JSON::Util->encode(\%build_history, [$build_history_filename], { 'atomic' => 1 });
}


Expand Down
Empty file added sharedstate/dh-make-pm/.exists
Empty file.

0 comments on commit 5c5ac4d

Please sign in to comment.