diff options
Diffstat (limited to 'src/lib/Qbs')
-rw-r--r-- | src/lib/Qbs/Qbs.pri | 37 | ||||
-rw-r--r-- | src/lib/Qbs/buildexecutor.cpp | 156 | ||||
-rw-r--r-- | src/lib/Qbs/buildexecutor.h | 94 | ||||
-rw-r--r-- | src/lib/Qbs/buildproduct.cpp | 121 | ||||
-rw-r--r-- | src/lib/Qbs/buildproduct.h | 86 | ||||
-rw-r--r-- | src/lib/Qbs/buildproject.cpp | 139 | ||||
-rw-r--r-- | src/lib/Qbs/buildproject.h | 88 | ||||
-rw-r--r-- | src/lib/Qbs/error.h | 74 | ||||
-rw-r--r-- | src/lib/Qbs/globals.h | 63 | ||||
-rw-r--r-- | src/lib/Qbs/ilogsink.cpp | 52 | ||||
-rw-r--r-- | src/lib/Qbs/ilogsink.h | 90 | ||||
-rw-r--r-- | src/lib/Qbs/logmessageevent.cpp | 72 | ||||
-rw-r--r-- | src/lib/Qbs/logmessageevent.h | 67 | ||||
-rw-r--r-- | src/lib/Qbs/mainthreadcommunication.cpp | 123 | ||||
-rw-r--r-- | src/lib/Qbs/mainthreadcommunication.h | 78 | ||||
-rw-r--r-- | src/lib/Qbs/oldsourceproject.cpp | 193 | ||||
-rw-r--r-- | src/lib/Qbs/oldsourceproject.h | 74 | ||||
-rw-r--r-- | src/lib/Qbs/processoutput.cpp | 124 | ||||
-rw-r--r-- | src/lib/Qbs/processoutput.h | 80 | ||||
-rw-r--r-- | src/lib/Qbs/processoutputevent.cpp | 65 | ||||
-rw-r--r-- | src/lib/Qbs/processoutputevent.h | 62 | ||||
-rw-r--r-- | src/lib/Qbs/qbserror.cpp | 76 | ||||
-rw-r--r-- | src/lib/Qbs/sourceproject.cpp | 255 | ||||
-rw-r--r-- | src/lib/Qbs/sourceproject.h | 95 |
24 files changed, 2364 insertions, 0 deletions
diff --git a/src/lib/Qbs/Qbs.pri b/src/lib/Qbs/Qbs.pri new file mode 100644 index 000000000..d981359fd --- /dev/null +++ b/src/lib/Qbs/Qbs.pri @@ -0,0 +1,37 @@ +INCLUDEPATH += $$PWD + +HEADERS += \ + $$PWD/sourceproject.h \ + $$PWD/oldsourceproject.h \ + $$PWD/buildproject.h \ + $$PWD/error.h \ + $$PWD/buildproduct.h \ + $$PWD/buildexecutor.h \ + $$PWD/processoutput.h \ + $$PWD/ilogsink.h \ + $$PWD/globals.h \ + $$PWD/mainthreadcommunication.h \ + $$PWD/logmessageevent.h \ + $$PWD/processoutputevent.h + +SOURCES += \ + $$PWD/sourceproject.cpp \ + $$PWD/oldsourceproject.cpp \ + $$PWD/buildproject.cpp \ + $$PWD/qbserror.cpp \ + $$PWD/buildproduct.cpp \ + $$PWD/buildexecutor.cpp \ + $$PWD/processoutput.cpp \ + $$PWD/ilogsink.cpp \ + $$PWD/mainthreadcommunication.cpp \ + $$PWD/logmessageevent.cpp \ + $$PWD/processoutputevent.cpp + + + + + + + + + diff --git a/src/lib/Qbs/buildexecutor.cpp b/src/lib/Qbs/buildexecutor.cpp new file mode 100644 index 000000000..b1a99063a --- /dev/null +++ b/src/lib/Qbs/buildexecutor.cpp @@ -0,0 +1,156 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + + +#include "buildexecutor.h" + +#include <buildgraph/executor.h> +#include <Qbs/buildproduct.h> +#include <Qbs/buildproject.h> + +namespace Qbs { + +BuildExecutor::BuildExecutor() + : m_maximumJobs(1), + m_runOnceAndForgetModeEnabled(false), + m_dryRun(false), + m_keepGoing(false), + m_state(ExecutorIdle) +{ +} + + +void BuildExecutor::setMaximumJobs(int numberOfJobs) +{ + QWriteLocker locker(&m_lock); + m_maximumJobs = numberOfJobs; +} + +int BuildExecutor::maximumJobs() const +{ + QReadLocker locker(&m_lock); + return m_maximumJobs; +} + +void BuildExecutor::setRunOnceAndForgetModeEnabled(bool enable) +{ + QWriteLocker locker(&m_lock); + m_runOnceAndForgetModeEnabled = enable; +} + +bool BuildExecutor::runOnceAndForgetModeIsEnabled() const +{ + QReadLocker locker(&m_lock); + return m_runOnceAndForgetModeEnabled; +} + +void BuildExecutor::setDryRunEnabled(bool enable) +{ + QWriteLocker locker(&m_lock); + m_dryRun = enable; +} + +bool BuildExecutor::isDryRunEnabled() const +{ + QReadLocker locker(&m_lock); + return m_dryRun; +} + +void BuildExecutor::setKeepGoingEnabled(bool enable) +{ + QWriteLocker locker(&m_lock); + m_keepGoing = enable; +} + +bool BuildExecutor::isKeepGoingEnabled() const +{ + QReadLocker locker(&m_lock); + return m_keepGoing; +} + +void BuildExecutor::executeBuildProject(QFutureInterface<bool> &futureInterface, const BuildProject &buildProject) +{ + QList<qbs::BuildProject::Ptr> internalBuildProjects; + internalBuildProjects.append(buildProject.internalBuildProject()); + QStringList changedFiles; // ### populate + QStringList selectedProductNames; // ### populate + executeBuildProjects(futureInterface, internalBuildProjects, changedFiles, selectedProductNames); +} + +/*! + Starts the build for the given list of projects. + + Args: + changedFiles - absolute file names of changed files (optional) + */ +void BuildExecutor::executeBuildProjects(QFutureInterface<bool> &futureInterface, const QList<QSharedPointer<qbs::BuildProject> > internalBuildProjects, + QStringList changedFiles, QStringList selectedProductNames) +{ + QEventLoop eventLoop; + + m_state = ExecutorRunning; + qbs::Executor executor(maximumJobs()); + executor.setRunOnceAndForgetModeEnabled(runOnceAndForgetModeIsEnabled()); + executor.setKeepGoing(isDryRunEnabled()); + executor.setDryRun(isDryRunEnabled()); + + QObject::connect(&executor, SIGNAL(finished()), &eventLoop, SLOT(quit()), Qt::QueuedConnection); + QObject::connect(&executor, SIGNAL(error()), &eventLoop, SLOT(quit()), Qt::QueuedConnection); + + executor.build(internalBuildProjects, changedFiles, selectedProductNames, futureInterface); + + eventLoop.exec(); + + setState(static_cast<ExecutorState>(executor.state())); + + if (futureInterface.resultCount() == 0) + futureInterface.reportResult(true); +} + +BuildExecutor::ExecutorState BuildExecutor::state() const +{ + QReadLocker locker(&m_lock); + return m_state; +} + +void BuildExecutor::setState(const BuildExecutor::ExecutorState &state) +{ + QWriteLocker locker(&m_lock); + m_state = state; +} + +} // namespace Qbs diff --git a/src/lib/Qbs/buildexecutor.h b/src/lib/Qbs/buildexecutor.h new file mode 100644 index 000000000..67047e1ff --- /dev/null +++ b/src/lib/Qbs/buildexecutor.h @@ -0,0 +1,94 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + + +#ifndef QBS_BUILDEXECUTOR_H +#define QBS_BUILDEXECUTOR_H + +#include "buildproduct.h" + +#include <QtCore/QFutureInterface> +#include <QtCore/QReadWriteLock> + +namespace qbs { + class Executor; + class BuildProject; +} + +namespace Qbs { + +class BuildExecutor +{ +public: + BuildExecutor(); + + enum ExecutorState { + ExecutorIdle, + ExecutorRunning, + ExecutorError + }; + + void setMaximumJobs(int numberOfJobs); + int maximumJobs() const; + + void setRunOnceAndForgetModeEnabled(bool enable); + bool runOnceAndForgetModeIsEnabled() const; + void setDryRunEnabled(bool enable); + bool isDryRunEnabled() const; + void setKeepGoingEnabled(bool enable); + bool isKeepGoingEnabled() const; + + void executeBuildProject(QFutureInterface<bool> &futureInterface, const BuildProject &buildProject); + void executeBuildProjects(QFutureInterface<bool> &futureInterface, const QList<QSharedPointer<qbs::BuildProject> > internalBuildProjects, QStringList changedFiles, QStringList selectedProductNames); + + ExecutorState state() const; + +private: //functions + void setState(const ExecutorState &state); + +private: // variables + mutable QReadWriteLock m_lock; + int m_maximumJobs; + bool m_runOnceAndForgetModeEnabled; + bool m_dryRun; + bool m_keepGoing; + ExecutorState m_state; +}; + +} // namespace Qbs + +#endif // QBS_BUILDEXECUTOR_H diff --git a/src/lib/Qbs/buildproduct.cpp b/src/lib/Qbs/buildproduct.cpp new file mode 100644 index 000000000..82733beb5 --- /dev/null +++ b/src/lib/Qbs/buildproduct.cpp @@ -0,0 +1,121 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + + +#include "buildproduct.h" + +#include <buildgraph/buildgraph.h> +#include <tools/scripttools.h> + +namespace Qbs { + +BuildProduct::BuildProduct() +{ +} + +BuildProduct::~BuildProduct() +{ +} + +BuildProduct::BuildProduct(const BuildProduct &other) + : m_internalBuildProduct(other.m_internalBuildProduct) +{ +} + +BuildProduct &BuildProduct::operator =(const BuildProduct &other) +{ + m_internalBuildProduct = other.m_internalBuildProduct; + + return *this; +} + +QVector<SourceFile> BuildProduct::sourceFiles() const +{ + QVector<SourceFile> artifactList; + artifactList.reserve(m_internalBuildProduct->rProduct->sources.size()); + + if (m_internalBuildProduct) { + foreach (const qbs::SourceArtifact::Ptr &artifact, m_internalBuildProduct->rProduct->sources) + artifactList.append(SourceFile(artifact->absoluteFilePath, artifact->fileTags)); + } + + return artifactList; +} + +static QStringList findProjectIncludePathsRecursive(const QVariantMap &variantMap) +{ + QStringList includePathList; + QMapIterator<QString, QVariant> mapIternator(variantMap); + + while (mapIternator.hasNext()) { + mapIternator.next(); + if (mapIternator.key() == QLatin1String("includePaths")) { + includePathList.append(mapIternator.value().toStringList()); + } else if (mapIternator.value().userType() == QVariant::Map) { + includePathList.append(findProjectIncludePathsRecursive(mapIternator.value().toMap())); + } + } + + return includePathList; +} + +QStringList BuildProduct::projectIncludePaths() const +{ + return findProjectIncludePathsRecursive(m_internalBuildProduct->rProduct->configuration->value()); +} + +BuildProduct::BuildProduct(const QSharedPointer<qbs::BuildProduct> &internalBuildProduct) + : m_internalBuildProduct(internalBuildProduct) +{ +} + +QString BuildProduct::displayName() const +{ + return m_internalBuildProduct->rProduct->name; +} + +QString BuildProduct::filePath() const +{ + return m_internalBuildProduct->rProduct->qbsFile; +} + +SourceFile::SourceFile(const QString &fileNameArg, const QSet<QString> &tagsArg) + : fileName(fileNameArg), tags(tagsArg) +{ +} + +} // namespace Qbs diff --git a/src/lib/Qbs/buildproduct.h b/src/lib/Qbs/buildproduct.h new file mode 100644 index 000000000..08b111548 --- /dev/null +++ b/src/lib/Qbs/buildproduct.h @@ -0,0 +1,86 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + + +#ifndef QBS_QBSBUILDPRODUCT_H +#define QBS_QBSBUILDPRODUCT_H + +#include <QtCore/QSharedPointer> +#include <QtCore/QStringList> +#include <QtCore/QSet> + +namespace qbs { + class BuildProduct; +} + +namespace Qbs { + +class BuildProject; + +class SourceFile +{ +public: + SourceFile(const QString &fileName = QString(), const QSet<QString> &tags = QSet<QString>()); + QString fileName; + QSet<QString> tags; +}; + + +class BuildProduct +{ + friend class BuildProject; +public: + BuildProduct(); + ~BuildProduct(); + BuildProduct(const BuildProduct &other); + BuildProduct &operator =(const BuildProduct &other); + + QString displayName() const; + QString filePath() const; + QVector<SourceFile> sourceFiles() const; + QStringList projectIncludePaths() const; + +private: // functions + BuildProduct(const QSharedPointer<qbs::BuildProduct> &internalBuildProduct); + +private: // variables + QSharedPointer<qbs::BuildProduct> m_internalBuildProduct; +}; + +} // namespace Qbs + +#endif // QBS_QBSBUILDPRODUCT_H diff --git a/src/lib/Qbs/buildproject.cpp b/src/lib/Qbs/buildproject.cpp new file mode 100644 index 000000000..abbd693d2 --- /dev/null +++ b/src/lib/Qbs/buildproject.cpp @@ -0,0 +1,139 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + + +#include "buildproject.h" + +#include <QSharedData> + +#include <buildgraph/buildgraph.h> +#include <tools/scripttools.h> + +namespace Qbs { + + + +BuildProject::BuildProject() +{ +} + +BuildProject::~BuildProject() +{ +} + +BuildProject::BuildProject(const BuildProject &other) + : m_internalBuildProject(other.m_internalBuildProject) +{ +} + +BuildProject &BuildProject::operator =(const BuildProject &other) +{ + m_internalBuildProject = other.m_internalBuildProject; + + return *this; +} + +QVector<BuildProduct> BuildProject::buildProducts() const +{ + QVector<BuildProduct> buildProductList; + buildProductList.reserve(m_internalBuildProject->buildProducts().size()); + + foreach (const qbs::BuildProduct::Ptr &internalBuildProduct, m_internalBuildProject->buildProducts()) + buildProductList.append(BuildProduct(internalBuildProduct)); + + return buildProductList; +} + +QString BuildProject::buildDirectory() const +{ + return QString(m_internalBuildProject->buildGraph()->buildDirectoryRoot() + + m_internalBuildProject->resolvedProject()->id + + QLatin1String("/")); +} + +QString BuildProject::displayName() const +{ + return m_internalBuildProject->resolvedProject()->id; +} + +void BuildProject::storeBuildGraph() +{ + m_internalBuildProject->store(); +} + +bool BuildProject::isValid() const +{ + return m_internalBuildProject.data(); +} + +QString BuildProject::qtSourcePath() const +{ + return qbs::getConfigProperty(m_internalBuildProject->resolvedProject()->configuration->value(), + QStringList() << "qt/core" << "qtPath").toString(); +} + +BuildProject::BuildProject(const QSharedPointer<qbs::BuildProject> &internalBuildProject) + : m_internalBuildProject(internalBuildProject) +{ +} + +qbs::BuildProject::Ptr BuildProject::internalBuildProject() const +{ + return m_internalBuildProject; +} + +bool BuildProject::removeBuildDirectory() +{ + bool filesRemoved = false; + +#if defined(Q_OS_LINUX) + QStringList arguments; + arguments.append("-rf"); + arguments.append(buildDirectory()); + filesRemoved = !QProcess::execute("/bin/rm", arguments); +#elif defined(Q_OS_WIN) + QString command = QString("rd /s /q \"%1\"").arg(QDir::toNativeSeparators(buildDirectory())); + QStringList arguments; + arguments.append("/c"); + arguments.append(command); + filesRemoved = !QProcess::execute("cmd", arguments); +#endif + + return filesRemoved; +} + +} // namespace Qbs diff --git a/src/lib/Qbs/buildproject.h b/src/lib/Qbs/buildproject.h new file mode 100644 index 000000000..3521226b9 --- /dev/null +++ b/src/lib/Qbs/buildproject.h @@ -0,0 +1,88 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + + +#ifndef QBS_QBSBUILDPROJECT_H +#define QBS_QBSBUILDPROJECT_H + +#include "buildproduct.h" + +#include <QtCore/QSharedPointer> + +namespace qbs { + class BuildProject; +} + +namespace Qbs { + +class SourceProject; + +class BuildProject +{ + friend class SourceProject; +public: + BuildProject(); + ~BuildProject(); + BuildProject(const BuildProject &other); + BuildProject &operator =(const BuildProject &other); + + QVector<BuildProduct> buildProducts() const; + + QString buildDirectory() const; + QString displayName() const; + + void storeBuildGraph(); + + bool isValid() const; + + QString qtSourcePath() const; + + QSharedPointer<qbs::BuildProject> internalBuildProject() const; + + bool removeBuildDirectory(); + + +private: // functions + BuildProject(const QSharedPointer<qbs::BuildProject> &internalBuildProject); + +private: // variables + QSharedPointer<qbs::BuildProject> m_internalBuildProject; +}; + +} // namespace Qbs + +#endif // QBS_QBSBUILDPROJECT_H diff --git a/src/lib/Qbs/error.h b/src/lib/Qbs/error.h new file mode 100644 index 000000000..6e4ff4d57 --- /dev/null +++ b/src/lib/Qbs/error.h @@ -0,0 +1,74 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + + +#ifndef QBS_ERROR_H +#define QBS_ERROR_H + +#include <QtCore/QSharedPointer> + +namespace qbs { + class Error; +} + +namespace Qbs { + +class SourceProject; + +class Error +{ + friend class SourceProject; +public: + Error(); + ~Error(); + + Error(const Error &other); + Error &operator=(const Error &other); + + QString toString() const; + +private: + Error(const qbs::Error &error); + + +private: + QSharedPointer<qbs::Error> m_error; +}; + +} // namespace Qbs + +#endif // QBS_ERROR_H diff --git a/src/lib/Qbs/globals.h b/src/lib/Qbs/globals.h new file mode 100644 index 000000000..e420ee211 --- /dev/null +++ b/src/lib/Qbs/globals.h @@ -0,0 +1,63 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + + +#ifndef QBSGLOBALS_H +#define QBSGLOBALS_H + + +namespace Qbs { + +enum LoggerLevel +{ + LoggerFatal = 0, + LoggerError, + LoggerWarning, + LoggerInfo, + LoggerDebug, + LoggerTrace, + LoggerMaxLevel = LoggerTrace +}; + +} + + +namespace qbs { +using namespace Qbs; +} + +#endif // QBSGLOBALS_H diff --git a/src/lib/Qbs/ilogsink.cpp b/src/lib/Qbs/ilogsink.cpp new file mode 100644 index 000000000..573bb7d25 --- /dev/null +++ b/src/lib/Qbs/ilogsink.cpp @@ -0,0 +1,52 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + +#include <tools/logger.h> + +namespace Qbs { + +void ILogSink::setGlobalLogSink(ILogSink *logSink) +{ + qbs::Logger::instance().setLogSink(logSink); +} + +void ILogSink::cleanupGlobalLogSink() +{ + qbs::Logger::instance().setLogSink(0); +} + +} diff --git a/src/lib/Qbs/ilogsink.h b/src/lib/Qbs/ilogsink.h new file mode 100644 index 000000000..85a11617c --- /dev/null +++ b/src/lib/Qbs/ilogsink.h @@ -0,0 +1,90 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + + +#ifndef QBS_ILOGSINK_H +#define QBS_ILOGSINK_H + +#include "globals.h" +#include "processoutput.h" +#include <tools/coloredoutput.h> + +namespace qbs { +class Logger; +} + +namespace Qbs { + +enum LogOutputChannel +{ + LogOutputStdOut, + LogOutputStdErr +}; + +struct LogMessage +{ + LogMessage() + : printLogLevel(true) + , outputChannel(LogOutputStdErr) + , textColor(qbs::TextColorDefault) + , backgroundColor(qbs::TextColorDefault) + {} + + QByteArray data; + bool printLogLevel; + LogOutputChannel outputChannel; + qbs::TextColor textColor; + qbs::TextColor backgroundColor; +}; + +class ILogSink +{ + friend class qbs::Logger; +public: + virtual ~ILogSink() { } + + static void setGlobalLogSink(ILogSink *logSink); + static void cleanupGlobalLogSink(); + +protected: + virtual void outputLogMessage(LoggerLevel /*level*/, const LogMessage &/*logMessage*/) {} + virtual void processOutput(const Qbs::ProcessOutput &/*processOutput*/) {} +}; + +} // namespace Qbs + +#endif // QBS_ILOGSINK_H diff --git a/src/lib/Qbs/logmessageevent.cpp b/src/lib/Qbs/logmessageevent.cpp new file mode 100644 index 000000000..1ba591203 --- /dev/null +++ b/src/lib/Qbs/logmessageevent.cpp @@ -0,0 +1,72 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ +#include "logmessageevent.h" + +namespace Qbs { + +int LogMessageEvent::s_eventType = QEvent::registerEventType(); + + +LogMessageEvent::LogMessageEvent(LoggerLevel level, const QString &message) + : QEvent(static_cast<QEvent::Type>(s_eventType)), + m_level(level), + m_message(message) +{ +} + +LogMessageEvent *LogMessageEvent::toLogMessageEvent(QEvent *event) +{ + Q_ASSERT(isLogMessageEvent(event)); + return static_cast<LogMessageEvent*>(event); +} + +LoggerLevel LogMessageEvent::level() const +{ + return m_level; +} + +QString LogMessageEvent::message() const +{ + return m_message; +} + +bool LogMessageEvent::isLogMessageEvent(QEvent *event) +{ + return static_cast<QEvent::Type>(s_eventType) == event->type(); +} + +} // namespace Qbs diff --git a/src/lib/Qbs/logmessageevent.h b/src/lib/Qbs/logmessageevent.h new file mode 100644 index 000000000..cb979baef --- /dev/null +++ b/src/lib/Qbs/logmessageevent.h @@ -0,0 +1,67 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ +#ifndef QBS_QBSLOGMESSAGEEVENT_H +#define QBS_QBSLOGMESSAGEEVENT_H + +#include "globals.h" + +#include <QtCore/QEvent> +#include <QtCore/QString> + +namespace Qbs { + +class LogMessageEvent : public QEvent +{ +public: + LogMessageEvent(LoggerLevel level, const QString &message); + + static LogMessageEvent *toLogMessageEvent(QEvent *event); + static bool isLogMessageEvent(QEvent *event); + + LoggerLevel level() const; + QString message() const; + + +private: + static int s_eventType; + LoggerLevel m_level; + QString m_message; +}; + +} // namespace Qbs + +#endif // QBS_QBSLOGMESSAGEEVENT_H diff --git a/src/lib/Qbs/mainthreadcommunication.cpp b/src/lib/Qbs/mainthreadcommunication.cpp new file mode 100644 index 000000000..b8c705868 --- /dev/null +++ b/src/lib/Qbs/mainthreadcommunication.cpp @@ -0,0 +1,123 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ +#include "mainthreadcommunication.h" + +#include <tools/logger.h> + +#include "logmessageevent.h" +#include "processoutputevent.h" + +#include <QtCore/QCoreApplication> +#include <QtCore/QReadLocker> +#include <QtCore/QWriteLocker> + +namespace Qbs { + +typedef QWeakPointer<QObject> ObjectPointer; + +MainThreadCommunication::MainThreadCommunication() +{ + qbs::Logger::instance().setLevel(LoggerMaxLevel); + setGlobalLogSink(this); +} + +MainThreadCommunication::~MainThreadCommunication() +{ + cleanupGlobalLogSink(); +} + +MainThreadCommunication &MainThreadCommunication::instance() +{ + static MainThreadCommunication instance; + return instance; +} + +void MainThreadCommunication::addLogEventReceiver(QObject *object) +{ + QWriteLocker locker(&m_lock); + if (!m_logReceiverList.contains(ObjectPointer(object))) + m_logReceiverList.append(ObjectPointer(object)); +} + +void MainThreadCommunication::removeLogEventReceiver(QObject *object) +{ + QReadLocker locker(&m_lock); + m_logReceiverList.removeOne(ObjectPointer(object)); +} + +void MainThreadCommunication::addProcessOutputEventReceiver(QObject *object) +{ + QWriteLocker locker(&m_lock); + if (!m_processOutputReceiverList.contains(ObjectPointer(object))) + m_processOutputReceiverList.append(ObjectPointer(object));} + +void MainThreadCommunication::removeProcessOutputEventReceiver(QObject *object) +{ + QReadLocker locker(&m_lock); + m_processOutputReceiverList.append(ObjectPointer(object)); +} + +void MainThreadCommunication::registerMetaType() +{ + qRegisterMetaType<Qbs::ProcessOutput>("Qbs::ProcessOutput"); + qRegisterMetaTypeStreamOperators<Qbs::ProcessOutput>("Qbs::ProcessOutput"); + qRegisterMetaType<Qbs::LoggerLevel>("Qbs::LoggerLevel"); +} + +void MainThreadCommunication::outputLogMessage(LoggerLevel level, const LogMessage &message) +{ + QReadLocker locker(&m_lock); + foreach (const ObjectPointer &logReceiver, m_logReceiverList) { + if (logReceiver.data()) { + LogMessageEvent *logMessageEvent = new LogMessageEvent(level, QString::fromLocal8Bit(message.data)); + QCoreApplication::postEvent(logReceiver.data(), logMessageEvent); + } + } +} + +void MainThreadCommunication::processOutput(const Qbs::ProcessOutput &processOutput) +{ + QReadLocker locker(&m_lock); + foreach (const ObjectPointer &processOutputReceiver, m_processOutputReceiverList) { + if (processOutputReceiver.data()) { + ProcessOutputEvent *processOutputEvent = new ProcessOutputEvent(processOutput); + QCoreApplication::postEvent(processOutputReceiver.data(), processOutputEvent); + } + } +} + +} // namespace Qbs diff --git a/src/lib/Qbs/mainthreadcommunication.h b/src/lib/Qbs/mainthreadcommunication.h new file mode 100644 index 000000000..1cbc6c81b --- /dev/null +++ b/src/lib/Qbs/mainthreadcommunication.h @@ -0,0 +1,78 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ +#ifndef QBS_MAINTHREADCOMMUNICATION_H +#define QBS_MAINTHREADCOMMUNICATION_H + +#include "globals.h" +#include "processoutput.h" +#include "ilogsink.h" + +#include <QtCore/QWeakPointer> +#include <QtCore/QReadWriteLock> + +namespace Qbs { + +class MainThreadCommunication : public ILogSink +{ +public: + MainThreadCommunication(); + ~MainThreadCommunication(); + + static MainThreadCommunication &instance(); + + void addLogEventReceiver(QObject *object); + void removeLogEventReceiver(QObject *object); + + void addProcessOutputEventReceiver(QObject *object); + void removeProcessOutputEventReceiver(QObject *object); + + static void registerMetaType(); + +public: + void outputLogMessage(LoggerLevel level, const LogMessage &message); + void processOutput(const Qbs::ProcessOutput &processOutput); + +private: + QReadWriteLock m_lock; + QList<QWeakPointer<QObject> > m_logReceiverList; + QList<QWeakPointer<QObject> > m_processOutputReceiverList; + +}; + +} // namespace Qbs + +#endif // QBS_MAINTHREADCOMMUNICATION_H diff --git a/src/lib/Qbs/oldsourceproject.cpp b/src/lib/Qbs/oldsourceproject.cpp new file mode 100644 index 000000000..95ba074a4 --- /dev/null +++ b/src/lib/Qbs/oldsourceproject.cpp @@ -0,0 +1,193 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + +#include "oldsourceproject.h" + +#include <buildgraph/buildgraph.h> +#include <buildgraph/executor.h> +#include <language/loader.h> +#include <tools/runenvironment.h> +#include <tools/fileinfo.h> +#include <tools/persistence.h> +#include <tools/logger.h> +#include <tools/scannerpluginmanager.h> +#include <tools/scripttools.h> +#include <tools/platform.h> + +#include <QtCore/QCoreApplication> +#include <QtCore/QProcess> +#include <QtCore/QSettings> +#include <QtCore/QScopedPointer> +#include <QtCore/QDebug> +#include <QtCore/QDir> +#include <QtCore/QElapsedTimer> + +namespace qbs { + +SourceProject::SourceProject(qbs::Settings::Ptr settings) + : m_settings(settings) +{ +} + +void SourceProject::setSearchPaths(const QStringList &searchPaths) +{ + m_searchPaths = searchPaths; +} + +void SourceProject::loadPlugins(const QStringList &pluginPaths) +{ + static bool alreadyCalled = false; + if (alreadyCalled) { + qbsWarning("qbs::SourceProject::loadPlugins was called more than once."); + } + + alreadyCalled = true; + + foreach (const QString &pluginPath, pluginPaths) + QCoreApplication::addLibraryPath(pluginPath); + + qbs::ScannerPluginManager::instance()->loadPlugins(pluginPaths); +} + +void SourceProject::loadProject(QFutureInterface<bool> &futureInterface, QString projectFileName, QList<QVariantMap> buildConfigs) +{ + QHash<QString, qbs::Platform::Ptr > platforms = Platform::platforms(); + if (platforms.isEmpty()) { + qbsFatal("no platforms configured. maybe you want to run 'qbs platforms probe' first."); + futureInterface.reportResult(false); + return; + } + if (buildConfigs.isEmpty()) { + qbsFatal("SourceProject::loadProject: no build configuration given."); + futureInterface.reportResult(false); + return; + } + QList<qbs::Configuration::Ptr> configurations; + foreach (QVariantMap buildCfg, buildConfigs) { + if (!buildCfg.value("platform").isValid()) { + if (!m_settings->value("defaults/platform").isValid()) { + qbsFatal("SourceProject::loadProject: no platform given and no default set."); + continue; + } + buildCfg.insert("platform", m_settings->value("defaults/platform").toString()); + } + Platform::Ptr platform = platforms.value(buildCfg.value("platform").toString()); + if (platform.isNull()) { + qbsFatal("SourceProject::loadProject: unknown platform: %s", qPrintable(buildCfg.value("platform").toString())); + continue; + } + foreach (const QString &key, platform->settings.allKeys()) { + buildCfg.insert(QString(key).replace('/','.'), + platform->settings.value(key)); + } + + if (!buildCfg.value("buildVariant").isValid()) { + qbsFatal("SourceProject::loadProject: property 'buildVariant' missing in build configuration."); + continue; + } + qbs::Configuration::Ptr configure(new qbs::Configuration); + configurations.append(configure); + + foreach (const QString &property, buildCfg.keys()) { + QStringList nameElements = property.split('.'); + if (nameElements.count() == 1) + nameElements.prepend("qbs"); + QVariantMap configValue = configure->value(); + qbs::setConfigProperty(configValue, nameElements, buildCfg.value(property)); + configure->setValue(configValue); + } + } + + qbs::Loader loader; + loader.setSearchPaths(m_searchPaths); + m_buildGraph = QSharedPointer<qbs::BuildGraph>(new qbs::BuildGraph); + m_buildGraph->setOutputDirectoryRoot(QDir::currentPath()); + const QString buildDirectoryRoot = m_buildGraph->buildDirectoryRoot(); + + try { + foreach (const qbs::Configuration::Ptr &configure, configurations) { + qbs::BuildProject::Ptr bProject; + const qbs::FileTime projectFileTimeStamp = qbs::FileInfo(projectFileName).lastModified(); + bProject = qbs::BuildProject::load(m_buildGraph.data(), projectFileTimeStamp, configure, m_searchPaths); + if (!bProject) { + QElapsedTimer timer; + timer.start(); + if (!loader.hasLoaded()) + loader.loadProject(projectFileName); + qbs::ResolvedProject::Ptr rProject = loader.resolveProject(buildDirectoryRoot, configure, futureInterface); + if (rProject->products.isEmpty()) + throw qbs::Error(QString("'%1' does not contain products.").arg(projectFileName)); + qDebug() << "loading project took: " << timer.elapsed() << "ms"; + timer.start(); + bProject = m_buildGraph->resolveProject(rProject, futureInterface); + qDebug() << "build graph took: " << timer.elapsed() << "ms"; + } + + m_buildProjects.append(bProject); + + printf("for %s:\n", qPrintable(bProject->resolvedProject()->id)); + foreach (qbs::ResolvedProduct::Ptr p, bProject->resolvedProject()->products) { + printf(" - [%s] %s as %s\n" + ,qPrintable(p->fileTags.join(", ")) + ,qPrintable(p->name) + ,qPrintable(p->project->id) + ); + } + printf("\n"); + } + + } catch (qbs::Error &e) { + m_errors.append(e); + futureInterface.reportResult(false); + return; + } + + futureInterface.reportResult(true); +} + +QList<BuildProject::Ptr> SourceProject::buildProjects() const +{ + return m_buildProjects; +} + +QList<Error> SourceProject::errors() const +{ + return m_errors; +} + +} // namespace qbs + diff --git a/src/lib/Qbs/oldsourceproject.h b/src/lib/Qbs/oldsourceproject.h new file mode 100644 index 000000000..98a30a8b2 --- /dev/null +++ b/src/lib/Qbs/oldsourceproject.h @@ -0,0 +1,74 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + +#ifndef QBSINTERFACE_H +#define QBSINTERFACE_H + +#include <language/language.h> +#include <buildgraph/buildgraph.h> + +#include <QtCore/QFutureInterface> + +namespace qbs { + +class SourceProject +{ +public: + SourceProject(qbs::Settings::Ptr settings); + + void setSearchPaths(const QStringList &searchPaths); + void loadPlugins(const QStringList &pluginPaths); + void loadProject(QFutureInterface<bool> &futureInterface, QString projectFileName, QList<QVariantMap> buildConfigs); + + QList<qbs::BuildProject::Ptr> buildProjects() const; + + QList<qbs::Error> errors() const; + +private: + QStringList m_searchPaths; + QList<qbs::Configuration::Ptr> m_configurations; + + QSharedPointer<qbs::BuildGraph> m_buildGraph; + QList<qbs::BuildProject::Ptr> m_buildProjects; + + qbs::Settings::Ptr m_settings; + QList<qbs::Error> m_errors; +}; + +} // namespace qbs + +#endif diff --git a/src/lib/Qbs/processoutput.cpp b/src/lib/Qbs/processoutput.cpp new file mode 100644 index 000000000..f633576f4 --- /dev/null +++ b/src/lib/Qbs/processoutput.cpp @@ -0,0 +1,124 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + + +#include "processoutput.h" +#include <QSharedData> + +#include <QtDebug> + +namespace Qbs { + +class ProcessOutputData : public QSharedData +{ +public: + QByteArray standardOutput; + QByteArray standardError; + QString commandLine; +}; + +ProcessOutput::ProcessOutput() + : data(new ProcessOutputData) +{ +} + +ProcessOutput::ProcessOutput(const ProcessOutput &other) + : data(other.data) +{ +} + +ProcessOutput &ProcessOutput::operator=(const ProcessOutput &other) +{ + if (this != &other) + data = other.data; + + return *this; +} + +ProcessOutput::~ProcessOutput() +{ +} + +void ProcessOutput::setStandardOutput(const QByteArray &standardOutput) +{ + data->standardOutput = standardOutput; +} + +QByteArray ProcessOutput::standardOutput() const +{ + return data->standardOutput; +} + +void ProcessOutput::setStandardError(const QByteArray &standardError) +{ + data->standardError = standardError; +} + +QByteArray ProcessOutput::standardError() const +{ + return data->standardError; +} + +void ProcessOutput::setCommandLine(const QString &commandLine) +{ + data->commandLine = commandLine; +} + +QString ProcessOutput::commandLine() const +{ + return data->commandLine; +} + +QDataStream &operator<<(QDataStream &out, const ProcessOutput &processOutput) +{ + out << processOutput.commandLine(); + out << processOutput.standardOutput(); + out << processOutput.standardError(); + + return out; +} + +QDataStream &operator>>(QDataStream &in, ProcessOutput &processOutput) +{ + in >> processOutput.data->commandLine; + in >> processOutput.data->standardOutput; + in >> processOutput.data->standardError; + + return in; +} + +} // namespace Qbs diff --git a/src/lib/Qbs/processoutput.h b/src/lib/Qbs/processoutput.h new file mode 100644 index 000000000..ca9f8bd16 --- /dev/null +++ b/src/lib/Qbs/processoutput.h @@ -0,0 +1,80 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + + +#ifndef QBS_PROCESSOUTPUT_H +#define QBS_PROCESSOUTPUT_H + +#include <QtCore/QByteArray> +#include <QtCore/QSharedDataPointer> +#include <QtCore/QString> +#include <QtCore/QMetaType> + +namespace Qbs { + +class ProcessOutputData; + +class ProcessOutput +{ + friend QDataStream &operator>>(QDataStream &in, ProcessOutput &processOutput); +public: + ProcessOutput(); + ProcessOutput(const ProcessOutput &other); + ProcessOutput &operator=(const ProcessOutput &other); + ~ProcessOutput(); + + void setStandardOutput(const QByteArray &standardOutput); + QByteArray standardOutput() const; + + void setStandardError(const QByteArray &standardError); + QByteArray standardError() const; + + void setCommandLine(const QString &commandLine); + QString commandLine() const; + +private: + QSharedDataPointer<ProcessOutputData> data; +}; + +QDataStream &operator<<(QDataStream &out, const ProcessOutput &processOutput); +QDataStream &operator>>(QDataStream &in, ProcessOutput &processOutput); + +} // namespace Qbs + +Q_DECLARE_METATYPE(Qbs::ProcessOutput) + +#endif // QBS_PROCESSOUTPUT_H diff --git a/src/lib/Qbs/processoutputevent.cpp b/src/lib/Qbs/processoutputevent.cpp new file mode 100644 index 000000000..e3576f619 --- /dev/null +++ b/src/lib/Qbs/processoutputevent.cpp @@ -0,0 +1,65 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ +#include "processoutputevent.h" + +namespace Qbs { + +int ProcessOutputEvent::s_eventType = QEvent::registerEventType(); + +ProcessOutputEvent::ProcessOutputEvent(const ProcessOutput &processOutput) + : QEvent(static_cast<QEvent::Type>(s_eventType)), + m_processOutput(processOutput) +{ +} + +ProcessOutputEvent *ProcessOutputEvent::toProcessOutputEvent(QEvent *event) +{ + Q_ASSERT(isProcessOutputEvent(event)); + return static_cast<ProcessOutputEvent*>(event); +} + +ProcessOutput ProcessOutputEvent::processOutput() const +{ + return m_processOutput; +} + +bool ProcessOutputEvent::isProcessOutputEvent(QEvent *event) +{ + return static_cast<QEvent::Type>(s_eventType) == event->type(); +} + +} // namespace Qbs diff --git a/src/lib/Qbs/processoutputevent.h b/src/lib/Qbs/processoutputevent.h new file mode 100644 index 000000000..74ebd24aa --- /dev/null +++ b/src/lib/Qbs/processoutputevent.h @@ -0,0 +1,62 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ +#ifndef QBS_PROCESSOUTPUTEVENT_H +#define QBS_PROCESSOUTPUTEVENT_H + +#include <QEvent> +#include "processoutput.h" + +namespace Qbs { + +class ProcessOutputEvent : public QEvent +{ +public: + ProcessOutputEvent(const ProcessOutput &processOutput); + + static ProcessOutputEvent *toProcessOutputEvent(QEvent *event); + static bool isProcessOutputEvent(QEvent *event); + + ProcessOutput processOutput() const; + +private: + static int s_eventType; + ProcessOutput m_processOutput; +}; + +} // namespace Qbs + +#endif // QBS_PROCESSOUTPUTEVENT_H diff --git a/src/lib/Qbs/qbserror.cpp b/src/lib/Qbs/qbserror.cpp new file mode 100644 index 000000000..2ccfe0884 --- /dev/null +++ b/src/lib/Qbs/qbserror.cpp @@ -0,0 +1,76 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + +#include "error.h" + +#include <tools/error.h> + +namespace Qbs { + +Error::Error() +{ +} + +Error::Error(const Error &other) + : m_error(other.m_error) +{ +} + +Error &Error::operator =(const Error &other) +{ + m_error = other.m_error; + + return *this; +} + +QString Error::toString() const +{ + return m_error->toString(); +} + +Error::~Error() +{ +} + +Error::Error(const qbs::Error &error) + : m_error(new qbs::Error(error)) +{ + +} + + +} // namespace Qbs diff --git a/src/lib/Qbs/sourceproject.cpp b/src/lib/Qbs/sourceproject.cpp new file mode 100644 index 000000000..bc61220b5 --- /dev/null +++ b/src/lib/Qbs/sourceproject.cpp @@ -0,0 +1,255 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + +#include "sourceproject.h" + +#include <language/loader.h> +#include <tools/logger.h> +#include <tools/scannerpluginmanager.h> +#include <tools/scripttools.h> +#include <tools/platform.h> + +#include <QtCore/QDebug> + +using namespace qbs; + +namespace Qbs { + +class SourceProjectPrivate : public QSharedData +{ +public: + QStringList searchPaths; + QList<qbs::Configuration::Ptr> configurations; + + QSharedPointer<qbs::BuildGraph> buildGraph; + QVector<Qbs::BuildProject> buildProjects; + + qbs::Settings::Ptr settings; + QList<Error> errors; + + QString buildDirectoryRoot; + +}; + +SourceProject::SourceProject() + : d(new SourceProjectPrivate) +{ + d->settings = qbs::Settings::create(); // fix it +} + +SourceProject::~SourceProject() +{ +} + +SourceProject::SourceProject(const SourceProject &other) + : d(other.d) +{ +} + +SourceProject &SourceProject::operator =(const SourceProject &other) +{ + d = other.d; + + return *this; +} + +void SourceProject::setSearchPaths(const QStringList &searchPaths) +{ + d->searchPaths = searchPaths; +} + +void SourceProject::loadPlugins(const QStringList &pluginPaths) +{ + static bool alreadyCalled = false; + if (alreadyCalled) { + qbsWarning("qbs::SourceProject::loadPlugins was called more than once."); + } + + alreadyCalled = true; + + foreach (const QString &pluginPath, pluginPaths) + QCoreApplication::addLibraryPath(pluginPath); + + qbs::ScannerPluginManager::instance()->loadPlugins(pluginPaths); +} + +void SourceProject::loadProject(QFutureInterface<bool> &futureInterface, + const QString projectFileName, + const QList<QVariantMap> buildConfigs) +{ + QHash<QString, qbs::Platform::Ptr > platforms = Platform::platforms(); + if (platforms.isEmpty()) { + qbsFatal("no platforms configured. maybe you want to run 'qbs platforms probe' first."); + futureInterface.reportResult(false); + return; + } + if (buildConfigs.isEmpty()) { + qbsFatal("SourceProject::loadProject: no build configuration given."); + futureInterface.reportResult(false); + return; + } + QList<qbs::Configuration::Ptr> configurations; + foreach (QVariantMap buildConfig, buildConfigs) { + if (!buildConfig.value("platform").isValid()) { + if (!d->settings->value("defaults/platform").isValid()) { + qbsFatal("SourceProject::loadProject: no platform given and no default set."); + continue; + } + buildConfig.insert("platform", d->settings->value("defaults/platform").toString()); + } + Platform::Ptr platform = platforms.value(buildConfig.value("platform").toString()); + if (platform.isNull()) { + qbsFatal("SourceProject::loadProject: unknown platform: %s", qPrintable(buildConfig.value("platform").toString())); + continue; + } + foreach (const QString &key, platform->settings.allKeys()) { + buildConfig.insert(QString(key).replace('/','.'), + platform->settings.value(key)); + } + + if (!buildConfig.value("buildVariant").isValid()) { + qbsFatal("SourceProject::loadProject: property 'buildVariant' missing in build configuration."); + continue; + } + qbs::Configuration::Ptr configuration(new qbs::Configuration); + configurations.append(configuration); + + foreach (const QString &property, buildConfig.keys()) { + QStringList nameElements = property.split('.'); + if (nameElements.count() == 1) + nameElements.prepend("qbs"); + QVariantMap configValue = configuration->value(); + qbs::setConfigProperty(configValue, nameElements, buildConfig.value(property)); + configuration->setValue(configValue); + } + } + + qbs::Loader loader; + loader.setSearchPaths(d->searchPaths); + d->buildGraph = QSharedPointer<qbs::BuildGraph>(new qbs::BuildGraph); + if (buildDirectoryRoot().isEmpty()) { + QByteArray buildDirectoryRootFromEnvironment = qgetenv("QBS_BUILD_ROOT_DIRECTORY"); + if (buildDirectoryRootFromEnvironment.isEmpty()) { + d->buildGraph->setOutputDirectoryRoot(QDir::currentPath()); + } else { + d->buildGraph->setOutputDirectoryRoot(buildDirectoryRootFromEnvironment); + } + } else { + d->buildGraph->setOutputDirectoryRoot(d->buildDirectoryRoot); + } + + const QString buildDirectoryRoot = d->buildGraph->buildDirectoryRoot(); + + + try { + int productCount = 0; + foreach (const qbs::Configuration::Ptr &configure, configurations) { + qbs::BuildProject::Ptr buildProject; + const qbs::FileTime projectFileTimeStamp = qbs::FileInfo(projectFileName).lastModified(); + buildProject = qbs::BuildProject::load(d->buildGraph.data(), projectFileTimeStamp, configure, d->searchPaths); + if (!buildProject) { + if (!loader.hasLoaded()) + loader.loadProject(projectFileName); + productCount += loader.productCount(configure); + } + } + futureInterface.setProgressRange(0, productCount * 2); + + + foreach (const qbs::Configuration::Ptr &configure, configurations) { + qbs::BuildProject::Ptr buildProject; + const qbs::FileTime projectFileTimeStamp = qbs::FileInfo(projectFileName).lastModified(); + buildProject = qbs::BuildProject::load(d->buildGraph.data(), projectFileTimeStamp, configure, d->searchPaths); + if (!buildProject) { + if (!loader.hasLoaded()) + loader.loadProject(projectFileName); + qbs::ResolvedProject::Ptr rProject = loader.resolveProject(buildDirectoryRoot, configure, futureInterface); + if (rProject->products.isEmpty()) + throw qbs::Error(QString("'%1' does not contain products.").arg(projectFileName)); + buildProject = d->buildGraph->resolveProject(rProject, futureInterface); + } + + d->buildProjects.append(BuildProject(buildProject)); + + printf("for %s:\n", qPrintable(buildProject->resolvedProject()->id)); + foreach (qbs::ResolvedProduct::Ptr p, buildProject->resolvedProject()->products) { + printf(" - [%s] %s as %s\n" + ,qPrintable(p->fileTags.join(", ")) + ,qPrintable(p->name) + ,qPrintable(p->project->id) + ); + } + printf("\n"); + } + + } catch (qbs::Error &error) { + d->errors.append(Error(error)); + futureInterface.reportResult(false); + return; + } + + futureInterface.reportResult(true); +} + +void SourceProject::storeBuildProjectsBuildGraph() +{ + foreach (BuildProject buildProject, d->buildProjects) + buildProject.storeBuildGraph(); +} + +void SourceProject::setBuildDirectoryRoot(const QString &buildDirectoryRoot) +{ + d->buildDirectoryRoot = buildDirectoryRoot; +} + +QString SourceProject::buildDirectoryRoot() const +{ + return d->buildDirectoryRoot; +} + +QVector<BuildProject> SourceProject::buildProjects() const +{ + return d->buildProjects; +} + +QList<Error> SourceProject::errors() const +{ + return d->errors; +} + +} + diff --git a/src/lib/Qbs/sourceproject.h b/src/lib/Qbs/sourceproject.h new file mode 100644 index 000000000..fef7ad187 --- /dev/null +++ b/src/lib/Qbs/sourceproject.h @@ -0,0 +1,95 @@ +/************************************************************************** +** +** This file is part of the Qt Build Suite +** +** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (info@qt.nokia.com) +** +** +** GNU Lesser General Public License Usage +** +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this file. +** Please review the following information to ensure the GNU Lesser General +** Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. +** Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +**************************************************************************/ + +#ifndef QBSINTERFACE_H +#define QBSINTERFACE_H + +#include <language/language.h> +#include <buildgraph/buildgraph.h> + +#include "buildproject.h" +#include "error.h" + +#include <QFutureInterface> + +#include <QtCore/QExplicitlySharedDataPointer> +#include <QtCore/QSharedPointer> + + +namespace qbs { + class BuildProject; +} + + +namespace Qbs { + +class SourceProjectPrivate; + +class SourceProject +{ + friend class BuildProject; +public: + SourceProject(); + ~SourceProject(); + + SourceProject(const SourceProject &other); + SourceProject &operator=(const SourceProject &other); + + + void setSearchPaths(const QStringList &searchPaths); + void loadPlugins(const QStringList &pluginPaths); + void loadProject(QFutureInterface<bool> &futureInterface, + const QString projectFileName, + const QList<QVariantMap> buildConfigs); + void storeBuildProjectsBuildGraph(); + + void setBuildDirectoryRoot(const QString &buildDirectoryRoot); + QString buildDirectoryRoot() const; + + QVector<BuildProject> buildProjects() const; + + QList<Qbs::Error> errors() const; + +private: // functions + QList<QSharedPointer<qbs::BuildProject> > toInternalBuildProjectList(const QVector<Qbs::BuildProject> &buildProjects) const; + +private: + QExplicitlySharedDataPointer<SourceProjectPrivate> d; +}; + +} +#endif |