Arepa::Builder - Arepa builder base "class"


Arepa documentation Contained in the Arepa distribution.

Index


Code Index:

NAME

Top

Arepa::Builder - Arepa builder base "class"

SYNOPSIS

Top

 my $module = Arepa::Builder->ui_module;
 Arepa::Builder->ui_module($new_ui_module);

 Arepa::Builder->init($builder_name);

 Arepa::Builder->compile_package_from_dsc($builder_name, $dsc_file);
 Arepa::Builder->compile_package_from_dsc($builder_name, $dsc_file,
                                          output_dir => 1);
 Arepa::Builder->compile_package_from_repository($builder_name,
                                                 $dsc_file);
 Arepa::Builder->compile_package_from_repository($builder_name,
                                                 $dsc_file,
                                                 output_dir => 1,
                                                 bin_nmu    => 1);

 my $log = Arepa::Builder->last_build_log;

 Arepa::Builder->create($builder_dir, $mirror, $distribution);

DESCRIPTION

Top

This module contains the interface for an Arepa builder. It should be the "subclass" for any builder module. Every Arepa builder type must have a module implementing this API. Arepa::BuilderFarm, when manipulating the builders, will use the correct builder module according to the builder type (e.g. for type 'sbuild', Arepa::Builder::Sbuild).

This module is never used directly, but through "subclasses" in Arepa::BuilderFarm.

METHODS

Top

ui_module
ui_module($ui_module)

Returns the UI module being used (by default, Arepa::UI::Text. If a parameter is passed, the UI module is changed to that, and the new value is returned.

init($builder_name)

Initialises the given $builder_name to be able to use it. This should be done once per machine boot (e.g. in an init script).

compile_package_from_dsc($builder_name, $dsc_file)
compile_package_from_dsc($builder_name, $dsc_file, %opts)

Compiles the source package described by the given $dsc_file using the given $builder_name. The resulting .deb files are put in the current directory by default. Valid options are output_dir and bin_nmu (see compile_package_from_repository documentation).

compile_package_from_repository($builder_name, $name, $version)
compile_package_from_repository($builder_name, $name, $version, %opts)

Compiles the source package with the given $name and $version using the given $builder_name. By default, the resulting .deb files are put in the current directory. The only valid options are output_dir (to specify the directory where the resulting .deb files should end up in) and bin_nmu (to specify if the compilation should be considered a binNMU).

last_build_log

Returns the log text of the last build.

create($builder_dir, $mirror, $distribution);

Creates a new builder in the given directory $builder_dir, using the Debian mirror $mirror and the distribution $distribution.

SEE ALSO

Top

Arepa::BuilderFarm, Arepa::Config.

AUTHOR

Top

Esteban Manchado Velázquez <estebanm@opera.com>.

LICENSE AND COPYRIGHT

Top

DISCLAIMER OF WARRANTY

Top

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Arepa documentation Contained in the Arepa distribution.

package Arepa::Builder;

use strict;
use warnings;

use Carp;
use Cwd;
use File::chmod;
use File::Temp;
use File::Basename;
use File::Path;
use File::Find;
use File::Copy;
use Config::Tiny;
use YAML::Syck;

use Arepa;

my $ui_module = 'Arepa::UI::Text';

sub ui_module {
    my ($self, $module) = @_;
    if (defined $module) {
        $ui_module = $module;
    }
    eval qq(use $ui_module;);
    die $@ if $@;
    return $ui_module;
}

sub type {
    my ($self) = @_;
    my $class = ref($self) || $self;
    $class =~ s/.+:://;
    if (!$class) {
        croak "You should use a proper builder class, not ".ref($self);
    }
    return lc($class);
}

sub new {
    my ($class, %attrs) = @_;

    return bless {
                    %attrs,
                 },
                 $class;
}

sub name { $_[0]->{name} }
sub last_build_log { $_[0]->{last_build_log} }

sub config {
    my ($self, $key) = @_;
    return $self->{$key};
}


# To be implemented by each type

sub do_init {
    my ($self, $builder) = @_;
    croak "Not implemented";
}

sub init {
    my ($self, $builder) = @_;
    $self->do_init($builder);
}

sub do_uninit {
    my ($self, $builder) = @_;
    croak "Not implemented";
}

sub uninit {
    my ($self, $builder) = @_;
    $self->do_uninit($builder);
}

sub do_compile_package_from_dsc {
    my ($self, $dsc_file, %user_opts) = @_;
    croak "Not implemented";
}

sub compile_package_from_dsc {
    my ($self, $dsc_file, %user_opts) = @_;
    $self->do_compile_package_from_dsc($dsc_file, %user_opts);
}

sub do_compile_package_from_repository {
    my ($self, $pkg_name, $pkg_version, %user_opts) = @_;
    croak "Not implemented";
}

sub compile_package_from_repository {
    my ($self, $pkg_name, $pkg_version, %user_opts) = @_;
    $self->do_compile_package_from_repository($pkg_name,
                                              $pkg_version,
                                              %user_opts);
}

sub do_create {
    my ($self, $builder_dir, $mirror, $distribution, %opts) = @_;
    croak "Not implemented";
}

sub create {
    my ($self, $builder_dir, $mirror, $distribution, %user_opts) = @_;
    my %opts = (builder_config_dir => '/etc/arepa/builders',
                arch               => `dpkg-architecture -qDEB_BUILD_ARCH`,
                %user_opts);
    chomp($opts{arch});

    $self->do_create($builder_dir, $mirror, $distribution, %opts);

    $self->ui_module->print_title("Configuration for config.yml");

    my $type = $self->type;

    my $config_string = <<EOD;
type: $type
architecture: $opts{arch}
# Compile "Architecture: all" packages with this builder?
architecture_all: 0
# This is the distribution the packages compiled by this builder go to. For a
# package to be compiled by this builder, it has to have the correct
# architecture and this distribution (or an alias or similar, see below) in
# its *.changes file.
distribution: $distribution
# Other names for this distribution (if the distribution name is
# mycompany-squeeze, you might want 'squeeze' and 'testing' as aliases)
distribution_aliases: []
# Recompile packages (binNMU or Binary-only Non-Maintainer Upload; see
# http://www.debian.org/doc/developers-reference/pkgs.html#nmu-binnmu)
# originally uploaded for other distributions in this builder. This option is
# an easy way to get "for free" packages compiled for several distributions.
# Typical values for this list would be 'unstable' or 'lenny'
bin_nmu_for: []
EOD

    my $builder_name = basename($builder_dir);
    my $path = File::Spec->catfile($opts{builder_config_dir},
                                   "$builder_name.yml");
    open F, ">$path" or croak "Can't write builder configuration in $path";
    print F $config_string;
    close F;
    print "You can tweak the builder configuration in $path\n";

    my $sources_list_path = File::Spec->catfile($builder_dir, "etc", "apt",
                                                "sources.list");
    print "You should also review $sources_list_path\n";
}

1;

__END__