From kde-commits Sat Mar 31 20:20:19 2018 From: Michael Pyne Date: Sat, 31 Mar 2018 20:20:19 +0000 To: kde-commits Subject: [kdesrc-build/make_it_mojo] modules/ksb: mojo: Complete promise-ifying Module.pm's build subroutine. Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=152252767404506 Git commit 59b5cf41d5350d0bba3a8b171c3f71818b9af9c8 by Michael Pyne. Committed on 31/03/2018 at 20:17. Pushed by mpyne into branch 'make_it_mojo'. mojo: Complete promise-ifying Module.pm's build subroutine. One somewhat annoying part about this is that the Mojo subprocess stuff has no event loop running at all in portion of code that actually runs in the forked child. So if you want to use promise-based code within a subprocess block (to allow for doing build/test/install in a single subprocess), you need to break up each chunk into its own subprocess. There is probably a way to do this (Mojo::Reactor->next_tick?) but it's hard to tell what's a documented 'feature' in the Mojo API or whether I'd be using an undocumented behavior that can break in the future. M +41 -20 modules/ksb/Module.pm https://commits.kde.org/kdesrc-build/59b5cf41d5350d0bba3a8b171c3f71818b9af9= c8 diff --git a/modules/ksb/Module.pm b/modules/ksb/Module.pm index ed204b8..6fb9590 100644 --- a/modules/ksb/Module.pm +++ b/modules/ksb/Module.pm @@ -419,35 +419,56 @@ sub build super_mkdir($pathinfo{'path'}); p_chdir($pathinfo{'path'}); = - # TODO: Turn this into a promise too - return Mojo::Promise->new->reject('Unable to setup build system') - if !$self->setupBuildSystem(); - return Mojo::Promise->new->resolve - if $self->getOption('build-system-only'); - - my $promise =3D Mojo::Promise->new; - return $self->runPhase_p('build', + my $buildSystemPromise =3D $self->runPhase_p('buildsystem', sub { - # called in child process, can block - return $buildSystem->buildInternal(); + return $self->setupBuildSystem(); }, sub { - # called in this process, with results my $was_successful =3D shift; - $self->setPersistentOption('last-build-rev', $self->currentScm= Revision()); = - return $promise->resolve(1) if $was_successful; - return $promise->reject('Build failed'); - } - )->then(sub { - return $self->runPhase_p('install', + return Mojo::Promise->new->reject('Unable to setup build syste= m') + unless $was_successful; + + return $was_successful; + }); + + return $buildSystemPromise if $self->getOption('build-system-only'); + + # If we don't stop with the build system only, then keep extending that + # promise chain to complete the build, test, and install + + return $buildSystemPromise->then(sub { + return $self->runPhase_p('build', + sub { + # called in child process, can block + return $buildSystem->buildInternal(); + }, + sub { + # called in this process, with results + my $was_successful =3D shift; + $self->setPersistentOption('last-build-rev', $self->curren= tScmRevision()); + + return 1 if $was_successful; + return Mojo::Promise->new->reject('Build failed'); + } + ); + })->then(sub { + return $self->runPhase_p('test', sub { - # TODO: This should be a simple phase to run. if ($self->getOption('run-tests')) { + # TODO: Make test failure a blocker for install? $self->buildSystem()->runTestsuite(); } - - # TODO: Likewise this should be a phase to run. + return 1; + }, + sub { + my $was_successful =3D shift; + return $was_successful; + } + ); + })->then(sub { + return $self->runPhase_p('install', + sub { if ($self->getOption('install-after-build')) { return 0 if !$self->install(); }