1
/* This file is part of KDevelop
2
Copyright 2012 Aleix Pol Gonzalez <aleixpol@kde.org>
4
This library is free software; you can redistribute it and/or
5
modify it under the terms of the GNU Library General Public
6
License version 2 as published by the Free Software Foundation.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
23
#include <KLocalizedString>
24
#include <KConfigGroup>
25
#include <interfaces/iproject.h>
26
#include <outputview/outputmodel.h>
27
#include <project/interfaces/ibuildsystemmanager.h>
28
#include <project/projectmodel.h>
29
#include <interfaces/iproject.h>
30
#include <interfaces/icore.h>
31
#include <interfaces/iprojectcontroller.h>
34
NinjaJob::NinjaJob(KDevelop::ProjectBaseItem* item, const QStringList& arguments, const QByteArray& signal, QObject* parent)
35
: OutputExecuteJob(parent)
36
, m_isInstalling(false)
37
, m_idx(item->index())
40
setToolTitle(i18n("Ninja"));
41
setCapabilities(Killable);
42
setStandardToolView( KDevelop::IOutputView::BuildView );
43
setBehaviours(KDevelop::IOutputView::AllowUserClose | KDevelop::IOutputView::AutoScroll );
44
setFilteringStrategy( KDevelop::OutputModel::CompilerFilter );
45
setProperties( NeedWorkingDirectory | PortableMessages | DisplayStderr | IsBuilderHint | PostProcessOutput );
51
foreach( const QString& arg, arguments ) {
52
if( !arg.startsWith( '-' ) ) {
57
if( !targets.isEmpty() )
58
title = i18n("Ninja (%1): %2", item->text(), targets.join(" "));
60
title = i18n("Ninja (%1)", item->text());
63
connect(this, SIGNAL(finished(KJob*)), SLOT(emitProjectBuilderSignal(KJob*)));
66
void NinjaJob::setIsInstalling( bool isInstalling )
68
m_isInstalling = isInstalling;
71
KUrl NinjaJob::workingDirectory() const
73
KDevelop::ProjectBaseItem* it = item();
76
KDevelop::IBuildSystemManager* bsm = it->project()->buildSystemManager();
77
KUrl workingDir = bsm->buildDirectory( it );
78
while( !QFile::exists( workingDir.toLocalFile( KUrl::AddTrailingSlash ) + "build.ninja" ) ) {
79
KUrl upWorkingDir = workingDir.upUrl();
80
if( upWorkingDir.isEmpty() || upWorkingDir == workingDir ) {
81
return bsm->buildDirectory( it->project()->projectItem() );
83
workingDir = upWorkingDir;
88
QStringList NinjaJob::privilegedExecutionCommand() const
90
KDevelop::ProjectBaseItem* it = item();
93
KSharedConfig::Ptr configPtr = it->project()->projectConfiguration();
94
KConfigGroup builderGroup( configPtr, "NinjaBuilder" );
96
bool runAsRoot = builderGroup.readEntry( "Install As Root", false );
97
if ( runAsRoot && m_isInstalling )
99
int suCommand = builderGroup.readEntry( "Su Command", 0 );
100
QStringList arguments;
101
QString suCommandName;
102
switch( suCommand ) {
104
return QStringList() << "kdesudo" << "-t";
107
return QStringList() << "sudo";
110
return QStringList() << "kdesu" << "-t";
113
return QStringList();
116
void NinjaJob::emitProjectBuilderSignal(KJob* job)
118
Q_ASSERT(!m_signal.isEmpty());
120
KDevelop::ProjectBaseItem* it = item();
124
QMetaObject::invokeMethod(parent(), m_signal, Q_ARG(KDevelop::ProjectBaseItem*, it));
126
QMetaObject::invokeMethod(parent(), "failed", Q_ARG(KDevelop::ProjectBaseItem*, it));
129
void NinjaJob::postProcessStderr( const QStringList& lines )
131
appendLines( lines );
134
void NinjaJob::postProcessStdout( const QStringList& lines )
136
appendLines( lines );
139
void NinjaJob::appendLines(const QStringList& lines)
144
QStringList ret(lines);
146
for(QStringList::iterator it=ret.end(); it!=ret.begin(); ) {
148
bool curr = it->startsWith('[');
149
if((prev && curr) || it->endsWith("] "))
154
model()->appendLines(ret);
157
KDevelop::ProjectBaseItem* NinjaJob::item() const
159
return KDevelop::ICore::self()->projectController()->projectModel()->itemFromIndex(m_idx);