Git commit eb2ae2ec1fa6f1435f26036e5567f5f36501b599 by Michael Pyne. Committed on 15/02/2021 at 22:26. Pushed by mpyne into branch 'make_it_mojo'.
backend-mode: Touch up backend mode to work again after recent changes. M +18 -0 doc/man-kdesrc-build.1.docbook M +1 -1 kdesrc-build M +3 -0 modules/ksb/Application.pm M +25 -7 modules/web/BackendServer.pm https://invent.kde.org/sdk/kdesrc-build/commit/eb2ae2ec1fa6f1435f26036e5567f5f36501b599 diff --git a/doc/man-kdesrc-build.1.docbook b/doc/man-kdesrc-build.1.docbook index 973e65d..9a5cba5 100644 --- a/doc/man-kdesrc-build.1.docbook +++ b/doc/man-kdesrc-build.1.docbook @@ -51,6 +51,7 @@ <arg choice='req'><replaceable>VALUE TO QUERY</replaceable></arg> <arg rep="repeat"><replaceable>Module name</replaceable></arg> </cmdsynopsis> +</refsynopsisdiv> <refsect1> <title>DESCRIPTION</title> @@ -1124,6 +1125,23 @@ kdepim: master </listitem> </varlistentry> +<varlistentry> +<term> +<envar>KDESRC_BUILD_DEBUG</envar> +</term> + +<listitem> +<para> + If set, this variable will cause the kdesrc-build internal backend server + to provide extra debugging information at the console when used in "backend + mode" (that is, <command>kdesrc-build --backend</command>) and also for the + internal Web server to provide extra server logs in the + <symbol>mojo-backend.log</symbol> log file held in the log directory for + this execution. +</para> +</listitem> +</varlistentry> + <varlistentry> <term> <envar>KDESRC_BUILD_DUMP_CONTEXT</envar> diff --git a/kdesrc-build b/kdesrc-build index 2309f8e..babf7bf 100755 --- a/kdesrc-build +++ b/kdesrc-build @@ -182,7 +182,7 @@ sub launchBackend my $daemon = Mojo::Server::Daemon->new( app => web::BackendServer->new, listen => ['http://localhost'], - silent => 1, + silent => !exists $ENV{KDESRC_BUILD_DEBUG}, ); $daemon->start; # Grabs the socket to listen on diff --git a/modules/ksb/Application.pm b/modules/ksb/Application.pm index 9332c7e..c44555c 100644 --- a/modules/ksb/Application.pm +++ b/modules/ksb/Application.pm @@ -691,6 +691,9 @@ sub establishContext my $cmdlineOptions = $optsAndSelectors->{options}; my $cmdlineGlobalOptions = $cmdlineOptions->{global}; + $cmdlineGlobalOptions->{'start-program'} //= [ ]; + $cmdlineGlobalOptions->{'ignore-modules'} //= [ ]; + # Must precede loading the rc-file as the module sets and modules default # to the phasing of the global build context. $self->_applyBuildContextPhasesFromCmdline($ctx, $optsAndSelectors); diff --git a/modules/web/BackendServer.pm b/modules/web/BackendServer.pm index 5a5ea85..0a6d3bd 100644 --- a/modules/web/BackendServer.pm +++ b/modules/web/BackendServer.pm @@ -23,6 +23,9 @@ has 'selectors'; sub new { my ($class, $optsAndSelectors) = @_; + $optsAndSelectors->{options} //= {}; + $optsAndSelectors->{selectors} //= []; + return $class->SUPER::new( opts_and_selectors => $optsAndSelectors, options => $optsAndSelectors->{options}, @@ -55,7 +58,7 @@ sub make_new_ksb } else { $c->app->log(Mojo::Log->new( path => $ctx->getLogDirFor($ctx) . "/mojo-backend.log", - level => 'info', + level => (exists $ENV{KDESRC_BUILD_DEBUG} ? 'debug' : 'info'), )); } @@ -124,7 +127,7 @@ sub _renderException { my $out = { }; - if (ref $err eq 'STRING') { + if (!ref $err || ref $err eq 'STRING') { $out->{message} = $err; $out->{exception_type} = 'Runtime'; } else { @@ -145,8 +148,7 @@ sub _generateRoutes { my $c = shift; if ($c->in_build || !defined $LAST_RESULT) { - $c->res->code(400); - return $c->render; + return $c->render(status => 400, json => { error => "Not ready to reset" }); } my $old_result = $LAST_RESULT; @@ -365,15 +367,31 @@ sub _generateRoutes { $IN_PROGRESS = 1; - $BUILD_PROMISE = $c->ksb->startHeadlessBuild->finally(sub { + $BUILD_PROMISE = $c->ksb->startHeadlessBuild->then(sub{ my ($result) = @_; - $c->app->log->debug("Build done"); + $c->app->log->debug("Build done, result $result"); + $LAST_RESULT = $result; + })->catch(sub { + my @reason = @_; + $c->app->log->error("Exception during build @reason"); + })->finally(sub { $IN_PROGRESS = 0; - return $LAST_RESULT = $result; }); $c->render(text => $c->url_for('event_viewer')->to_abs->to_string); }); + + $r->post('/shutdown' => sub { + my $c = shift; + + # Shutdown the server once the transaction completes + # by invoking ksb::Application::finish + $c->tx->on(finish => sub { + $c->app->ksb->finish(0); + }); + + $c->render(text => "Shutting down.\n", status => 200); + }); } 1;
