#!/usr/bin/perl
use strict;
use warnings;
use Fedora::Rebuild;
use Config::Tiny;
use File::Spec;

my $cfgfile = File::Spec->catfile($ENV{HOME}, '.rebuildperlrc');

my %config = (
    all => 'all',
    done => 'done',
    failed => 'failed',
    workdir => 'workdir',
    repodir => 'testrepo',
    repourls => [
        'http://download.englab.brq.redhat.com/pub/fedora/linux/development/rawhide/x86_64/os/' ], 
    mock_install_group => 'buildsys-build',
    architecture => 'x86_64',
    anonymous => 0,
    dist => 'rawhide',
    target => 'rawhide',
    message => 'Perl mass rebuild',
    buildrequiresfilter => sub { $_[0] !~ /^\s*perl\(/ },
    mode => 'koji',
    threads => 16,
    loadthreads => 4,
    selectthreads => 1,
    failurelimit => 8,
    ordered => 1,
    verbosesolver => 1
);

if (-f $cfgfile) {
    my $cfg = Config::Tiny->new->read($cfgfile);
    if (! defined $cfg) {
        print STDERR "Could not parse `" . $cfgfile .
            "' configuration file: " . $Config::Tiny::errstr . "\n";
        exit 1;
    }
    foreach (keys %{$cfg->{_}}) {
        $config{$_} = $cfg->{_}->{$_};
        $config{$_} = eval $config{$_} if $_ eq 'buildrequiresfilter';
        $config{$_} = eval $config{$_} if $_ eq 'repourls';
    }
}

my $builder = Fedora::Rebuild->new(%config);
exit !$builder->run;


__END__
=encoding utf8

=head1 NAME

rebuild - Rebuilds perl packages from scratch

=head1 DESCRIPTION

Main goal is to rebuild perl modules packages for Fedora. The rebuild is
driven from bottom to top, i.e. from perl interpreter to modules depending on
intermediate modules. This way, it's possible to upgrade perl interpreter to
incompatible version and to rebuild all modules against the new interpreter.


=head1 AUTHOR

Petr Písař <ppisar@redhat.com>

=head1 COPYING

Copyright (C) 2011, 2012, 2013, 2014  Petr Písař <ppisar@redhat.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

=cut
