123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- # ex:ts=8 sw=4:
- # $OpenBSD: PortBuilder.pm,v 1.77 2017/05/07 14:50:14 espie Exp $
- #
- # Copyright (c) 2010-2013 Marc Espie <espie@openbsd.org>
- #
- # Permission to use, copy, modify, and distribute this software for any
- # purpose with or without fee is hereby granted, provided that the above
- # copyright notice and this permission notice appear in all copies.
- #
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- use strict;
- use warnings;
- # this object is responsible for launching the build of ports
- # which mostly includes starting the right jobs
- package DPB::PortBuilder;
- use File::Path;
- use DPB::Util;
- use DPB::Job::Port;
- use DPB::Serialize;
- sub new
- {
- my ($class, $state) = @_;
- if ($state->opt('R')) {
- require DPB::PortBuilder::Rebuild;
- $class = $class->rebuild_class;
- }
- my $self = bless {
- state => $state,
- clean => $state->opt('c'),
- dontclean => $state->{dontclean},
- fetch => $state->opt('f'),
- wantsize => $state->{wantsize},
- fullrepo => $state->fullrepo,
- realfullrepo => $state->anchor($state->fullrepo),
- sizer => $state->sizer,
- heuristics => $state->heuristics}, $class;
- if ($state->opt('u') || $state->opt('U')) {
- $self->{update} = 1;
- }
- if ($state->opt('U')) {
- $self->{forceupdate} = 1;
- }
- if ($self->{fetch} && $state->defines('NO_CHECKSUM')) {
- $self->{nochecksum} = 1;
- }
- $self->init;
- return $self;
- }
- sub want_size
- {
- my ($self, $v, $core) = @_;
- if (!$self->{wantsize}) {
- return 0;
- }
- # always show for inmem
- if ($core->{inmem}) {
- return 1;
- }
- # do we already have this stats ? don't run it every time
- if ($self->{sizer}->match_pkgname($v)) {
- return rand(10) < 1;
- } else {
- return 1;
- }
- }
- sub rebuild_class
- { 'DPB::PortBuilder::Rebuild' }
- sub ports
- {
- my $self = shift;
- return $self->{state}->ports;
- }
- sub logger
- {
- my $self = shift;
- return $self->{state}->logger;
- }
- sub locker
- {
- my $self = shift;
- return $self->{state}->locker;
- }
- sub dontjunk
- {
- my ($self, $v) = @_;
- $self->{dontjunk}{$v->fullpkgname} = 1;
- }
- sub make
- {
- my $self = shift;
- return $self->{state}->make;
- }
- sub make_args
- {
- my $self = shift;
- return $self->{state}->make_args;
- }
- sub init
- {
- my $self = shift;
- $self->{state}{build_user}->make_path($self->{realfullrepo});
- $self->{global} = $self->logger->append("build");
- $self->{lockperf} =
- DPB::Util->make_hot($self->logger->append("awaiting-locks"));
- if ($self->{wantsize}) {
- $self->{logsize} =
- DPB::Util->make_hot($self->logger->append("size"));
- }
- if ($self->{state}->defines("WRAP_MAKE")) {
- $self->{rsslog} = $self->logger->logfile("rss");
- $self->{wrapper} = $self->{state}->defines("WRAP_MAKE");
- }
- }
- sub pkgfile
- {
- my ($self, $v) = @_;
- my $name = $v->fullpkgname;
- return "$self->{realfullrepo}/$name.tgz";
- }
- sub check
- {
- my ($self, $v) = @_;
- return $self->{state}{build_user}->run_as(
- sub {
- return -f $self->pkgfile($v);
- });
- }
- sub end_check
- {
- ✓
- }
- sub checks_rebuild
- {
- }
- sub register_package
- {
- }
- sub report
- {
- my ($self, $v, $job, $core) = @_;
- return if $job->{signature_only};
- my $pkgpath = $v->fullpkgpath;
- my $host = $core->fullhostname;
- if ($core->{realjobs}) {
- $host .= '*'.$core->{realjobs};
- }
- my $log = $self->{global};
- my $sz = $self->logger->run_as(
- sub {
- return (stat $self->logger->log_pkgpath($v))[7];
- });
- if (defined $job->{offset}) {
- $sz -= $job->{offset};
- }
- print $log "$pkgpath $host ", $job->totaltime, " ", $sz, " ",
- $job->timings;
- if ($job->{failed}) {
- my $fh = $self->logger->open('>>', $job->{log});
- print $fh "Error: job failed with $job->{failed} on ",
- $core->hostname, "\n";
- print $log "!\n";
- } else {
- print $log "\n";
- return unless defined $self->{state}{permanent_log};
- my $fh = $self->logger->open('>>',
- $self->{state}{permanent_log});
- return unless defined $fh;
- print $fh DPB::Serialize::Build->write({
- pkgpath => $pkgpath,
- host => $host,
- time => $job->totaltime,
- size => $sz,
- ts => CORE::time }), "\n";
- }
- }
- sub get
- {
- my $self = shift;
- return DPB::Core->get;
- }
- sub end_lock
- {
- my ($self, $lock, $core, $job) = @_;
- my $end = time();
- print $lock "status=$core->{status}\n";
- print $lock "todo=", $job->current_task, "\n";
- print $lock "end=$end (", DPB::Util->time2string($end), ")\n";
- close $lock;
- }
- sub build
- {
- my ($self, $v, $core, $lock, $final_sub) = @_;
- my $start = time();
- my ($log, $fh) = $self->logger->make_logs($v);
- my $memsize = $self->{sizer}->build_in_memory($fh, $core, $v);
- my $meminfo;
- if ($memsize) {
- print $lock "mem=$memsize\n";
- $meminfo = " in memory";
- $core->{inmem} = $memsize;
- } else {
- $meminfo = "";
- $core->{inmem} = 0;
- }
- if ($v->{info}->has_property('tag')) {
- print $lock "tag=".$v->{info}->has_property('tag')."\n";
- }
- print $fh ">>> Building on ", $core->hostname;
- print $fh $meminfo, " under ";
- $v->quick_dump($fh);
- my $job;
- $job = DPB::Job::Port->new($log, $fh, $v, $lock, $self, $memsize, $core,
- sub {
- close($fh);
- $self->end_lock($lock, $core, $job);
- $self->report($v, $job, $core);
- &$final_sub($job->{failed});
- });
- $core->start_job($job, $v);
- if ($job->{parallel}) {
- $core->can_swallow($job->{parallel}-1);
- }
- print $lock "host=", $core->hostname, "\n",
- "pid=$core->{pid}\n",
- "start=$start (", DPB::Util->time2string($start), ")\n";
- $job->set_watch($self->logger, $v);
- }
- sub force_junk
- {
- my ($self, $v, $core, $final_sub) = @_;
- my $start = time();
- my $log = $self->logger->log_pkgpath($v);
- my $fh = $self->logger->open('>>', $log);
- print $fh ">>> Force junking on ", $core->hostname;
- my $job;
- $job = DPB::Job::Port->new_junk_only($log, $fh, $v, undef, $self,
- 0,$core,
- sub {
- close($fh);
- &$final_sub($job->{failed});
- $core->mark_ready;
- });
- $core->start_job($job, $v);
- }
- sub test
- {
- my ($self, $v, $core, $lock, $final_sub) = @_;
- my $start = time();
- my $log = $self->logger->make_test_logs($v);
- my $memsize = $self->{sizer}->build_in_memory($core, $v);
- open my $fh, ">>", $log or DPB::Util->die_bang("can't open $log");
- if ($memsize) {
- print $lock "mem=$memsize\n";
- print $fh ">>> Building in memory under ";
- $core->{inmem} = $memsize;
- } else {
- print $fh ">>> Building under ";
- $core->{inmem} = 0;
- }
- if ($v->{info}->has_property('tag')) {
- print $lock "tag=".$v->{info}->has_property('tag')."\n";
- }
- $v->quick_dump($fh);
- my $job;
- $job = DPB::Job::Port::Test->new($log, $fh, $v, $lock, $self,
- $memsize, $core,
- sub {
- close($fh);
- $self->end_lock($lock, $core, $job);
- $self->report($v, $job, $core);
- &$final_sub($job->{failed});
- });
- $core->start_job($job, $v);
- print $lock "host=", $core->hostname, "\n",
- "pid=$core->{pid}\n",
- "start=$start (", DPB::Util->time2string($start), ")\n";
- }
- sub install
- {
- my ($self, $v, $core) = @_;
- my ($log, $fh) = $self->logger->make_logs($v);
- print $fh ">>> Installing under ";
- $v->quick_dump($fh);
- my $job = DPB::Job::Port::Install->new($log, $fh, $v, $self,
- sub {
- close($fh);
- $core->mark_ready;
- });
- $core->start_job($job, $v);
- return $core;
- }
- 1;
|