Commit 21ba1c00 authored by Michael Pyne's avatar Michael Pyne

mojo: Refine debug flags implementations (--list-build, --print-modules)

This also removes some needless TTY spam like the trivial dependencies
message and the notation about where your logs are stored. The latter is
simply confusing since we don't actually generate logs with these debug
flags.
parent 23b3baaa
Pipeline #7597 passed with stage
in 1 minute and 26 seconds
......@@ -412,6 +412,7 @@ eval
@atexit_subs = (); # Clear exit handlers
# env driver is just the ~/.config/kde-env-*.sh, session driver is that + ~/.xsession
# TODO: Move to Backend or UserInterface as appropriate.
my $ctx = $app->context;
if ($ctx->getOption('install-environment-driver') ||
$ctx->getOption('install-session-driver'))
......@@ -420,8 +421,6 @@ eval
}
# Exits the script
my $logdir = $app->context()->getLogDir();
note ("Your logs are saved in y[$logdir]");
exit $result;
};
......
......@@ -312,13 +312,16 @@ DONE
'reconfigure', 'colorful-output|color!',
'src-only|svn-only', 'build-only', 'install-only', 'build-system-only',
'rc-file=s', 'prefix=s', 'niceness|nice:10', 'ignore-modules=s{,}',
'print-modules', 'pretend|dry-run|p', 'refresh-build',
'pretend|dry-run|p', 'refresh-build',
'query=s', 'start-program|run=s{,}',
'launch-browser',
'revision=i', 'resume-from=s', 'resume-after=s',
'rebuild-failures', 'resume',
'stop-after=s', 'stop-before=s', 'set-module-option-value=s',
'metadata-only', 'list-build', 'dependency-tree',
'metadata-only',
# Debug-only flags
'print-modules', 'list-build', 'dependency-tree',
# Special sub used (see above), but have to tell Getopt::Long to look
# for negatable boolean flags
......@@ -387,7 +390,7 @@ sub establishContext
# Set aside debug-related and other short-circuit cmdline options
# for kdesrc-build CLI driver to handle
my @debugFlags = qw(dependency-tree list-build metadata-only);
my @debugFlags = qw(dependency-tree list-build print-modules);
$self->{debugFlags} = {
map { ($_, 1) }
grep { defined $cmdlineGlobalOptions->{$_} }
......@@ -565,23 +568,16 @@ sub modulesFromSelectors
# resolveSelectorsIntoModules) in that event.
@modules = _applyModuleFilters($ctx, @modules);
# TODO: Implement 'list-build' option
if(exists $self->{debugFlags}->{'list-build'}) {
my $result = {
dependencyInfo => $moduleGraph,
modulesFromCommand => \@modulesFromCommand,
selectedModules => [],
build => 0
};
return $result;
}
my $result = {
dependencyInfo => $moduleGraph,
modulesFromCommand => \@modulesFromCommand,
selectedModules => \@modules,
build => 1
build => 1,
};
# If debugging then don't build
$result->{build} = 0 if exists $self->{debugFlags}->{'list-build'};
return $result;
}
......
......@@ -271,7 +271,7 @@ sub _lookupDirectDependencies
}
my $depItem = _shortenModuleName($depPath);
if ($depItem eq $item) {
debug("\tBreaking trivial cycle of b[$depItem] -> b[$item]");
debug("\tBreaking trivial cycle of b[$depItem] to itself");
++($result->{trivialCycles});
next;
}
......@@ -653,10 +653,6 @@ sub resolveToModuleGraph
my $trivialCycles = $errors->{trivialCycles};
if ($trivialCycles) {
warning("Total of 'trivial' dependency cycles detected & eliminated: $trivialCycles");
}
my $cycles = _checkDependencyCycles($moduleGraph);
if ($cycles) {
......
......@@ -36,6 +36,7 @@ use Mojo::Server::Daemon;
use Mojo::IOLoop;
use Mojo::UserAgent;
use Mojo::JSON qw(to_json);
use Mojo::Util qw(dumper);
use ksb::BuildException;
use ksb::StatusView;
......@@ -139,18 +140,19 @@ sub _runModeDebug
my %debugFlags = %{$app->ksb->{debugFlags}};
$app->log->debug("Run mode: DEBUG");
if ($debugFlags{'dependency-tree'}) {
$app->log->debug("Dumping dependency tree (in a later release...)");
$app->log->debug("Dumping dependency tree");
return $ua->get_p('/moduleGraph')->then(sub {
my $tx = _check_error(shift);
return $tx->result->json;
})->then(sub {
my $tree = shift;
my $tree = $tx->result->json;
return dumpDependencyTree($ua, $tree);
});
}
elsif ($debugFlags{'list-build'}) {
elsif ($debugFlags{'list-build'} || $debugFlags{'print-modules'}) {
$app->log->debug("Listing modules to build");
return $ua->get_p('/modules')->then(sub {
my $tx = _check_error(shift);
my @modules = @{$tx->result->json};
......@@ -159,7 +161,8 @@ sub _runModeDebug
});
}
return 0; # Bail early
# Bail early
return Mojo::Promise->new->reject('Told to debug for no reason');
}
# Returns a promise chain to handle the normal build case.
......@@ -246,6 +249,9 @@ sub _runModeBuild
})->finally(sub {
$event_stream->say("]");
$event_stream->close();
my $logdir = $ctx->getLogDir();
note ("Your logs are saved in y[$logdir]");
});
}
......@@ -290,9 +296,9 @@ sub start
# build the requested modules, so proceed as appropriate based on the run mode
# the user has requested.
$app->ksb->{debugFlags} //= {};
return $self->_runModeDebug()
if (%{$app->ksb->{debugFlags}});
if (%{$app->ksb->{debugFlags} // 0});
return $self->_runModeBuild(\@module_failures);
})->then(sub {
# Build done, value comes from runMode promise above
......@@ -302,12 +308,17 @@ sub start
# Catches all errors in any of the prior promises
my $err = shift;
say "Error: ", $err->{code}, " ", $err->{message};
if (ref $err) {
say STDERR "Caught an error: ", dumper($err);
}
else {
say STDERR "Caught an error: $err";
}
# See if we made it to an rc-file
my $ctx = $app->ksb->context();
my $rcFile = $ctx ? $ctx->rcFile() // 'Unknown' : undef;
say "Using configuration file found at $rcFile" if $rcFile;
say STDERR "Using configuration file found at $rcFile" if $rcFile;
$result = 1; # error
})->wait;
......
......@@ -5,6 +5,7 @@ use Mojo::Base 'Mojolicious';
use Mojo::Util qw(trim);
use ksb::Application;
use ksb::Debug qw(pretending);
use ksb::dto::ModuleGraph;
use ksb::dto::ModuleInfo;
use ksb::DependencyResolver;
......@@ -43,9 +44,15 @@ sub make_new_ksb
# Reset log handler
my $ctx = $app->context();
$c->app->log(Mojo::Log->new(
path => $ctx->getLogDirFor($ctx) . "/mojo-backend.log"
));
if (pretending()) {
# Mojolicious will install a file watch on the log path so it has to exist
# if we set it. Instead just de-spam the output to TTY for now.
$c->app->log->level('error');
} else {
$c->app->log(Mojo::Log->new(
path => $ctx->getLogDirFor($ctx) . "/mojo-backend.log"
));
}
if(@selectors) {
$c->app->log->info("Module selectors requested:" . join(', ', @selectors));
......@@ -135,7 +142,13 @@ sub _generateRoutes {
$r->get('/modules' => sub {
my $c = shift;
$c->render(json => $c->ksb->modules());
eval {
$c->render(json => [$c->ksb->modules()]);
};
if ($@) {
return $c->render(text => $@->{message}, status => 400);
}
} => 'module_lookup');
$r->get('/known_modules' => sub {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment