aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@petroules.com>2014-07-16 11:33:49 -0400
committerJake Petroules <jake.petroules@petroules.com>2015-02-12 02:22:42 +0000
commit5447c56a01ac944900026e4634ef1c6e285eda00 (patch)
tree8bc2c2f96a760468f37d71fb737ac07f119c3fbd /src/lib
parent2e9bb43b47f27641f3ad166665aec5a5e00a8c77 (diff)
Add an API to support build system generators.
More generally, a plugin-based API to support performing arbitrary operations producing some output given a resolved qbs project. Task-number: QBS-658 Change-Id: I5c0c3652520ec17e751ad9980bc186dde58e48d1 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/corelib/corelib.pro1
-rw-r--r--src/lib/corelib/corelib.qbs4
-rw-r--r--src/lib/corelib/generators/generator.h106
-rw-r--r--src/lib/corelib/generators/generators.pri2
-rw-r--r--src/lib/corelib/qbs.h2
-rw-r--r--src/lib/corelib/tools/generateoptions.cpp91
-rw-r--r--src/lib/corelib/tools/generateoptions.h61
-rw-r--r--src/lib/corelib/tools/projectgeneratormanager.cpp77
-rw-r--r--src/lib/corelib/tools/projectgeneratormanager.h70
-rw-r--r--src/lib/corelib/tools/tools.pri6
10 files changed, 420 insertions, 0 deletions
diff --git a/src/lib/corelib/corelib.pro b/src/lib/corelib/corelib.pro
index 9580973c5..cf70291c1 100644
--- a/src/lib/corelib/corelib.pro
+++ b/src/lib/corelib/corelib.pro
@@ -14,6 +14,7 @@ DEFINES += SRCDIR=\\\"$$PWD\\\"
include(api/api.pri)
include(buildgraph/buildgraph.pri)
+include(generators/generators.pri)
include(jsextensions/jsextensions.pri)
include(language/language.pri)
include(logging/logging.pri)
diff --git a/src/lib/corelib/corelib.qbs b/src/lib/corelib/corelib.qbs
index ed7b48f88..d30f59887 100644
--- a/src/lib/corelib/corelib.qbs
+++ b/src/lib/corelib/corelib.qbs
@@ -307,6 +307,7 @@ QbsLibrary {
"fileinfo.cpp",
"fileinfo.h",
"filetime.h",
+ "generateoptions.cpp",
"hostosinfo.h",
"id.cpp",
"id.h",
@@ -320,6 +321,7 @@ QbsLibrary {
"profile.cpp",
"progressobserver.cpp",
"progressobserver.h",
+ "projectgeneratormanager.cpp",
"propertyfinder.cpp",
"propertyfinder.h",
"qbsassert.cpp",
@@ -349,10 +351,12 @@ QbsLibrary {
"cleanoptions.h",
"codelocation.h",
"error.h",
+ "generateoptions.h",
"installoptions.h",
"preferences.h",
"processresult.h",
"profile.h",
+ "projectgeneratormanager.h",
"qbs_export.h",
"settings.h",
"settingsmodel.h",
diff --git a/src/lib/corelib/generators/generator.h b/src/lib/corelib/generators/generator.h
new file mode 100644
index 000000000..0c2ffada6
--- /dev/null
+++ b/src/lib/corelib/generators/generator.h
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2015 Jake Petroules.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Build Suite.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef GENERATORPLUGIN_H
+#define GENERATORPLUGIN_H
+
+#include <api/project.h>
+#include <QList>
+#include <QString>
+
+namespace qbs {
+
+/*!
+ * \class ProjectGenerator
+ * \brief The \c ProjectGenerator class is an abstract base class for generators which generate
+ * arbitrary output given a resolved Qbs project.
+ */
+
+class ProjectGenerator
+{
+public:
+ virtual ~ProjectGenerator()
+ {
+ }
+
+ /*!
+ * Returns the name of the generator used to create the external build system files.
+ */
+ virtual QString generatorName() const = 0;
+
+ virtual void generate(const InstallOptions &installOptions) = 0;
+
+ QList<Project> projects() const
+ {
+ return m_projects;
+ }
+
+ void addProject(const Project &project)
+ {
+ m_projects << project;
+ }
+
+ void addProjects(const QList<Project> &projects)
+ {
+ m_projects << projects;
+ }
+
+ void removeProject(const Project &project)
+ {
+ m_projects.removeOne(project);
+ }
+
+ void clearProjects()
+ {
+ m_projects.clear();
+ }
+
+protected:
+ ProjectGenerator()
+ {
+ }
+
+private:
+ QList<Project> m_projects;
+};
+
+} // namespace qbs
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef qbs::ProjectGenerator **(*getGenerators_f)();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // GENERATORPLUGIN_H
diff --git a/src/lib/corelib/generators/generators.pri b/src/lib/corelib/generators/generators.pri
new file mode 100644
index 000000000..6372e8197
--- /dev/null
+++ b/src/lib/corelib/generators/generators.pri
@@ -0,0 +1,2 @@
+HEADERS += \
+ $$PWD/generator.h
diff --git a/src/lib/corelib/qbs.h b/src/lib/corelib/qbs.h
index ca07e66a6..f045f926f 100644
--- a/src/lib/corelib/qbs.h
+++ b/src/lib/corelib/qbs.h
@@ -40,6 +40,8 @@
#include "tools/buildoptions.h"
#include "tools/cleanoptions.h"
#include "tools/error.h"
+#include "tools/generateoptions.h"
+#include "tools/projectgeneratormanager.h"
#include "tools/installoptions.h"
#include "tools/preferences.h"
#include "tools/profile.h"
diff --git a/src/lib/corelib/tools/generateoptions.cpp b/src/lib/corelib/tools/generateoptions.cpp
new file mode 100644
index 000000000..e12c58eb3
--- /dev/null
+++ b/src/lib/corelib/tools/generateoptions.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2015 Jake Petroules.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Build Suite.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+#include "generateoptions.h"
+
+#include <QSharedData>
+#include <QString>
+
+namespace qbs {
+namespace Internal {
+
+class GenerateOptionsPrivate : public QSharedData
+{
+public:
+ GenerateOptionsPrivate()
+ : generatorName()
+ {}
+
+ QString generatorName;
+};
+
+} // namespace Internal
+
+/*!
+ * \class GenerateOptions
+ * \brief The \c GenerateOptions class comprises parameters that influence the behavior of
+ * generate operations.
+ */
+
+GenerateOptions::GenerateOptions() : d(new Internal::GenerateOptionsPrivate)
+{
+}
+
+GenerateOptions::GenerateOptions(const GenerateOptions &other) : d(other.d)
+{
+}
+
+GenerateOptions &GenerateOptions::operator=(const GenerateOptions &other)
+{
+ d = other.d;
+ return *this;
+}
+
+GenerateOptions::~GenerateOptions()
+{
+}
+
+/*!
+ * Returns the name of the generator used to create the external build system files.
+ * The default is empty.
+ */
+QString GenerateOptions::generatorName() const
+{
+ return d->generatorName;
+}
+
+/*!
+ * \brief Sets the name of the generator used to create the external build system files.
+ */
+void GenerateOptions::setGeneratorName(const QString &generatorName)
+{
+ d->generatorName = generatorName;
+}
+
+} // namespace qbs
diff --git a/src/lib/corelib/tools/generateoptions.h b/src/lib/corelib/tools/generateoptions.h
new file mode 100644
index 000000000..edb736c06
--- /dev/null
+++ b/src/lib/corelib/tools/generateoptions.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2015 Jake Petroules.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Build Suite.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+#ifndef QBS_GENERATEOPTIONS_H
+#define QBS_GENERATEOPTIONS_H
+
+#include "qbs_export.h"
+
+#include <QSharedDataPointer>
+
+QT_BEGIN_NAMESPACE
+class QString;
+QT_END_NAMESPACE
+
+namespace qbs {
+namespace Internal { class GenerateOptionsPrivate; }
+
+class QBS_EXPORT GenerateOptions
+{
+public:
+ GenerateOptions();
+ GenerateOptions(const GenerateOptions &other);
+ GenerateOptions &operator=(const GenerateOptions &other);
+ ~GenerateOptions();
+
+ QString generatorName() const;
+ void setGeneratorName(const QString &generatorName);
+
+private:
+ QSharedDataPointer<Internal::GenerateOptionsPrivate> d;
+};
+
+} // namespace qbs
+
+#endif // QBS_GENERATEOPTIONS_H
diff --git a/src/lib/corelib/tools/projectgeneratormanager.cpp b/src/lib/corelib/tools/projectgeneratormanager.cpp
new file mode 100644
index 000000000..cd45f4682
--- /dev/null
+++ b/src/lib/corelib/tools/projectgeneratormanager.cpp
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2015 Jake Petroules.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Build Suite.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "projectgeneratormanager.h"
+
+#include <logging/logger.h>
+#include <logging/translator.h>
+#include <tools/hostosinfo.h>
+
+#include <QCoreApplication>
+#include <QDirIterator>
+#include <QLibrary>
+
+namespace qbs {
+
+using namespace Internal;
+
+ProjectGeneratorManager::~ProjectGeneratorManager()
+{
+ foreach (QLibrary * const lib, m_libs) {
+ lib->unload();
+ delete lib;
+ }
+}
+
+ProjectGeneratorManager *ProjectGeneratorManager::instance()
+{
+ static ProjectGeneratorManager generatorPlugin;
+ return &generatorPlugin;
+}
+
+ProjectGeneratorManager::ProjectGeneratorManager()
+{
+ QList<QSharedPointer<ProjectGenerator> > generators;
+ foreach (QSharedPointer<ProjectGenerator> generator, generators) {
+ m_generators[generator->generatorName()] = generator;
+ }
+}
+
+QStringList ProjectGeneratorManager::loadedGeneratorNames()
+{
+ return instance()->m_generators.keys();
+}
+
+QSharedPointer<ProjectGenerator> ProjectGeneratorManager::findGenerator(const QString &generatorName)
+{
+ return instance()->m_generators.value(generatorName);
+}
+
+} // namespace qbs
diff --git a/src/lib/corelib/tools/projectgeneratormanager.h b/src/lib/corelib/tools/projectgeneratormanager.h
new file mode 100644
index 000000000..8a79e5afc
--- /dev/null
+++ b/src/lib/corelib/tools/projectgeneratormanager.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Copyright (C) 2015 Jake Petroules.
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Build Suite.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef QBS_PROJECTGENERATORMANAGER_H
+#define QBS_PROJECTGENERATORMANAGER_H
+
+#include <language/filetags.h>
+#include <generators/generator.h>
+
+#include <QMap>
+#include <QSharedPointer>
+#include <QString>
+#include <QStringList>
+
+QT_BEGIN_NAMESPACE
+class QLibrary;
+QT_END_NAMESPACE
+
+namespace qbs {
+class ProjectGenerator;
+namespace Internal {
+class Logger;
+}
+
+class QBS_EXPORT ProjectGeneratorManager
+{
+public:
+ ~ProjectGeneratorManager();
+ static ProjectGeneratorManager *instance();
+ static QStringList loadedGeneratorNames();
+ static QSharedPointer<ProjectGenerator> findGenerator(const QString &generatorName);
+
+private:
+ ProjectGeneratorManager();
+
+private:
+ QList<QLibrary *> m_libs;
+ QMap<QString, QSharedPointer<ProjectGenerator> > m_generators;
+};
+
+} // namespace qbs
+
+#endif
diff --git a/src/lib/corelib/tools/tools.pri b/src/lib/corelib/tools/tools.pri
index 14433de2b..c6e508aa3 100644
--- a/src/lib/corelib/tools/tools.pri
+++ b/src/lib/corelib/tools/tools.pri
@@ -8,6 +8,7 @@ HEADERS += \
$$PWD/executablefinder.h \
$$PWD/fileinfo.h \
$$PWD/filetime.h \
+ $$PWD/generateoptions.h \
$$PWD/id.h \
$$PWD/persistence.h \
$$PWD/scannerpluginmanager.h \
@@ -19,6 +20,7 @@ HEADERS += \
$$PWD/processresult.h \
$$PWD/processresult_p.h \
$$PWD/progressobserver.h \
+ $$PWD/projectgeneratormanager.h \
$$PWD/propertyfinder.h \
$$PWD/shellutils.h \
$$PWD/hostosinfo.h \
@@ -40,6 +42,7 @@ SOURCES += \
$$PWD/error.cpp \
$$PWD/executablefinder.cpp \
$$PWD/fileinfo.cpp \
+ $$PWD/generateoptions.cpp \
$$PWD/id.cpp \
$$PWD/persistence.cpp \
$$PWD/scannerpluginmanager.cpp \
@@ -50,6 +53,7 @@ SOURCES += \
$$PWD/processresult.cpp \
$$PWD/profile.cpp \
$$PWD/progressobserver.cpp \
+ $$PWD/projectgeneratormanager.cpp \
$$PWD/propertyfinder.cpp \
$$PWD/shellutils.cpp \
$$PWD/buildoptions.cpp \
@@ -86,6 +90,8 @@ qbs_enable_unit_tests {
$$PWD/processresult.h \
$$PWD/qbs_export.h \
$$PWD/buildoptions.h \
+ $$PWD/generateoptions.h \
+ $$PWD/generatorpluginmanager.h \
$$PWD/installoptions.h \
$$PWD/setupprojectparameters.h
tools_headers.path = $${QBS_INSTALL_PREFIX}/include/qbs/tools