aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/generators
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/corelib/generators')
-rw-r--r--src/lib/corelib/generators/generators.pri22
-rw-r--r--src/lib/corelib/generators/generatorutils.cpp262
-rw-r--r--src/lib/corelib/generators/generatorutils.h96
-rw-r--r--src/lib/corelib/generators/generatorversioninfo.cpp83
-rw-r--r--src/lib/corelib/generators/generatorversioninfo.h78
-rw-r--r--src/lib/corelib/generators/ixmlnodevisitor.h69
-rw-r--r--src/lib/corelib/generators/xmlproject.cpp50
-rw-r--r--src/lib/corelib/generators/xmlproject.h54
-rw-r--r--src/lib/corelib/generators/xmlprojectwriter.cpp92
-rw-r--r--src/lib/corelib/generators/xmlprojectwriter.h70
-rw-r--r--src/lib/corelib/generators/xmlproperty.cpp56
-rw-r--r--src/lib/corelib/generators/xmlproperty.h88
-rw-r--r--src/lib/corelib/generators/xmlpropertygroup.cpp67
-rw-r--r--src/lib/corelib/generators/xmlpropertygroup.h78
-rw-r--r--src/lib/corelib/generators/xmlworkspace.cpp66
-rw-r--r--src/lib/corelib/generators/xmlworkspace.h69
-rw-r--r--src/lib/corelib/generators/xmlworkspacewriter.cpp92
-rw-r--r--src/lib/corelib/generators/xmlworkspacewriter.h70
18 files changed, 1460 insertions, 2 deletions
diff --git a/src/lib/corelib/generators/generators.pri b/src/lib/corelib/generators/generators.pri
index 093e45f40..e9730d895 100644
--- a/src/lib/corelib/generators/generators.pri
+++ b/src/lib/corelib/generators/generators.pri
@@ -3,13 +3,31 @@ include(../../../install_prefix.pri)
SOURCES += \
$$PWD/generatableprojectiterator.cpp \
$$PWD/generator.cpp \
- $$PWD/generatordata.cpp
+ $$PWD/generatordata.cpp \
+ $$PWD/generatorutils.cpp \
+ $$PWD/generatorversioninfo.cpp \
+ $$PWD/xmlproject.cpp \
+ $$PWD/xmlprojectwriter.cpp\
+ $$PWD/xmlproperty.cpp \
+ $$PWD/xmlpropertygroup.cpp \
+ $$PWD/xmlworkspace.cpp \
+ $$PWD/xmlworkspacewriter.cpp
HEADERS += \
$$PWD/generatableprojectiterator.h \
$$PWD/generator.h \
$$PWD/generatordata.h \
- $$PWD/igeneratableprojectvisitor.h
+ $$PWD/generatorutils.h \
+ $$PWD/generatorversioninfo.h \
+ $$PWD/igeneratableprojectvisitor.h \
+ $$PWD/ixmlnodevisitor.h \
+ $$PWD/ixmlnodevisitor.h \
+ $$PWD/xmlproject.h \
+ $$PWD/xmlprojectwriter.h \
+ $$PWD/xmlproperty.h \
+ $$PWD/xmlpropertygroup.h \
+ $$PWD/xmlworkspace.h \
+ $$PWD/xmlworkspacewriter.h
!qbs_no_dev_install {
generators_headers.files = \
diff --git a/src/lib/corelib/generators/generatorutils.cpp b/src/lib/corelib/generators/generatorutils.cpp
new file mode 100644
index 000000000..9c00eef05
--- /dev/null
+++ b/src/lib/corelib/generators/generatorutils.cpp
@@ -0,0 +1,262 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qbs.
+**
+** 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 The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "generatorutils.h"
+
+namespace qbs {
+namespace gen {
+namespace utils {
+
+QString architectureName(Architecture arch)
+{
+ switch (arch) {
+ case Architecture::Arm:
+ return QStringLiteral("arm");
+ case Architecture::Avr:
+ return QStringLiteral("avr");
+ case Architecture::Mcs51:
+ return QStringLiteral("mcs51");
+ default:
+ return QStringLiteral("unknown");
+ }
+}
+
+Architecture architecture(const Project &qbsProject)
+{
+ const auto qbsArch = qbsProject.projectConfiguration()
+ .value(Internal::StringConstants::qbsModule()).toMap()
+ .value(QStringLiteral("architecture")).toString();
+
+ if (qbsArch == QLatin1String("arm"))
+ return Architecture::Arm;
+ if (qbsArch == QLatin1String("avr"))
+ return Architecture::Avr;
+ if (qbsArch == QLatin1String("mcs51"))
+ return Architecture::Mcs51;
+ if (qbsArch == QLatin1String("stm8"))
+ return Architecture::Stm8;
+ if (qbsArch == QLatin1String("msp430"))
+ return Architecture::Msp430;
+ return Architecture::Unknown;
+}
+
+QString buildConfigurationName(const Project &qbsProject)
+{
+ return qbsProject.projectConfiguration()
+ .value(Internal::StringConstants::qbsModule()).toMap()
+ .value(QStringLiteral("configurationName")).toString();
+}
+
+int debugInformation(const ProductData &qbsProduct)
+{
+ return qbsProduct.moduleProperties().getModuleProperty(
+ Internal::StringConstants::qbsModule(),
+ QStringLiteral("debugInformation"))
+ .toInt();
+}
+
+QString buildRootPath(const Project &qbsProject)
+{
+ QDir dir(qbsProject.projectData().buildDirectory());
+ dir.cdUp();
+ return dir.absolutePath();
+}
+
+QString relativeFilePath(const QString &baseDirectory,
+ const QString &fullFilePath)
+{
+ return QDir(baseDirectory).relativeFilePath(fullFilePath);
+}
+
+QString binaryOutputDirectory(const QString &baseDirectory,
+ const ProductData &qbsProduct)
+{
+ return QDir(baseDirectory).relativeFilePath(
+ qbsProduct.buildDirectory())
+ + QLatin1String("/bin");
+}
+
+QString objectsOutputDirectory(const QString &baseDirectory,
+ const ProductData &qbsProduct)
+{
+ return QDir(baseDirectory).relativeFilePath(
+ qbsProduct.buildDirectory())
+ + QLatin1String("/obj");
+}
+
+QString listingOutputDirectory(const QString &baseDirectory,
+ const ProductData &qbsProduct)
+{
+ return QDir(baseDirectory).relativeFilePath(
+ qbsProduct.buildDirectory())
+ + QLatin1String("/lst");
+}
+
+std::vector<ProductData> dependenciesOf(const ProductData &qbsProduct,
+ const GeneratableProject &genProject,
+ const QString &configurationName)
+{
+ std::vector<ProductData> result;
+ const auto depsNames = qbsProduct.dependencies();
+ for (const auto &product : qAsConst(genProject.products)) {
+ const auto pt = product.type();
+ if (!pt.contains(QLatin1String("staticlibrary")))
+ continue;
+ const auto pn = product.name();
+ if (!depsNames.contains(pn))
+ continue;
+ result.push_back(product.data.value(configurationName));
+ }
+ return result;
+}
+
+QString targetBinary(const ProductData &qbsProduct)
+{
+ const auto type = qbsProduct.type();
+ if (type.contains(QLatin1String("application"))) {
+ return QFileInfo(qbsProduct.targetExecutable()).fileName();
+ } else if (type.contains(QLatin1String("staticlibrary"))) {
+ const auto artifacts = qbsProduct.targetArtifacts();
+ for (const auto &artifact : artifacts) {
+ if (artifact.fileTags().contains(QLatin1String("staticlibrary")))
+ return QFileInfo(artifact.filePath()).fileName();
+ }
+ }
+
+ return {};
+}
+
+QString targetBinaryPath(const QString &baseDirectory,
+ const ProductData &qbsProduct)
+{
+ return binaryOutputDirectory(baseDirectory, qbsProduct)
+ + QLatin1Char('/') + targetBinary(qbsProduct);
+}
+
+QString cppStringModuleProperty(const PropertyMap &qbsProps,
+ const QString &propertyName)
+{
+ return qbsProps.getModuleProperty(
+ Internal::StringConstants::cppModule(),
+ propertyName).toString().trimmed();
+}
+
+bool cppBooleanModuleProperty(const PropertyMap &qbsProps,
+ const QString &propertyName)
+{
+ return qbsProps.getModuleProperty(
+ Internal::StringConstants::cppModule(),
+ propertyName).toBool();
+}
+
+int cppIntegerModuleProperty(const PropertyMap &qbsProps,
+ const QString &propertyName)
+{
+ return qbsProps.getModuleProperty(
+ Internal::StringConstants::cppModule(),
+ propertyName).toInt();
+}
+
+QStringList cppStringModuleProperties(const PropertyMap &qbsProps,
+ const QStringList &propertyNames)
+{
+ QStringList properties;
+ for (const auto &propertyName : propertyNames) {
+ const auto entries = qbsProps.getModuleProperty(
+ Internal::StringConstants::cppModule(),
+ propertyName).toStringList();
+ for (const auto &entry : entries)
+ properties.push_back(entry.trimmed());
+ }
+ return properties;
+}
+
+QVariantList cppVariantModuleProperties(const PropertyMap &qbsProps,
+ const QStringList &propertyNames)
+{
+ QVariantList properties;
+ for (const auto &propertyName : propertyNames) {
+ properties << qbsProps.getModuleProperty(
+ Internal::StringConstants::cppModule(),
+ propertyName).toList();
+ }
+ return properties;
+}
+
+static QString parseFlagValue(const QString &flagKey,
+ QStringList::const_iterator &flagIt,
+ const QStringList::const_iterator &flagEnd)
+{
+ if (flagIt->contains(QLatin1Char('='))) {
+ // In this case an option is in form of 'flagKey=<flagValue>'.
+ const auto parts = flagIt->split(QLatin1Char('='));
+ if (parts.count() == 2)
+ return parts.at(1).trimmed();
+ } else if (flagKey < *flagIt) {
+ // In this case an option is in form of 'flagKey<flagValue>'.
+ return flagIt->mid(flagKey.count()).trimmed();
+ } else {
+ // In this case an option is in form of 'flagKey <flagValue>'.
+ ++flagIt;
+ if (flagIt < flagEnd && !flagIt->startsWith(QLatin1Char('-')))
+ return (*flagIt).trimmed();
+ }
+ return {};
+}
+
+QString firstFlagValue(const QStringList &flags, const QString &flagKey)
+{
+ const auto flagBegin = flags.cbegin();
+ const auto flagEnd = flags.cend();
+ auto flagIt = std::find_if(flagBegin, flagEnd, [flagKey](const QString &flag) {
+ return flag == flagKey || flag.startsWith(flagKey);
+ });
+ if (flagIt == flagEnd)
+ return {};
+ return parseFlagValue(flagKey, flagIt, flagEnd);
+}
+
+QStringList allFlagValues(const QStringList &flags, const QString &flagKey)
+{
+ QStringList values;
+ const auto flagEnd = flags.cend();
+ for (auto flagIt = flags.cbegin(); flagIt < flagEnd; ++flagIt) {
+ if (*flagIt == flagKey || flagIt->startsWith(flagKey)) {
+ const QString value = parseFlagValue(flagKey, flagIt, flagEnd);
+ if (!value.isEmpty())
+ values.push_back(value);
+ }
+ }
+ return values;
+}
+
+} // namespace utils
+} // namespace gen
+} // namespace qbs
diff --git a/src/lib/corelib/generators/generatorutils.h b/src/lib/corelib/generators/generatorutils.h
new file mode 100644
index 000000000..9348ab18c
--- /dev/null
+++ b/src/lib/corelib/generators/generatorutils.h
@@ -0,0 +1,96 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qbs.
+**
+** 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 The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef GENERATORS_UTILS_H
+#define GENERATORS_UTILS_H
+
+#include <qbs.h>
+
+#include <tools/qbs_export.h>
+#include <tools/stringconstants.h>
+
+namespace qbs {
+namespace gen {
+namespace utils {
+
+enum class Architecture {
+ Arm,
+ Avr,
+ Mcs51,
+ Stm8,
+ Msp430,
+ Unknown
+};
+
+QBS_EXPORT QString architectureName(Architecture arch);
+QBS_EXPORT Architecture architecture(const Project &qbsProject);
+QBS_EXPORT QString buildConfigurationName(const Project &qbsProject);
+QBS_EXPORT int debugInformation(const ProductData &qbsProduct);
+QBS_EXPORT QString buildRootPath(const Project &qbsProject);
+QBS_EXPORT QString relativeFilePath(const QString &baseDirectory,
+ const QString &fullFilePath);
+QBS_EXPORT QString binaryOutputDirectory(const QString &baseDirectory,
+ const ProductData &qbsProduct);
+QBS_EXPORT QString objectsOutputDirectory(const QString &baseDirectory,
+ const ProductData &qbsProduct);
+QBS_EXPORT QString listingOutputDirectory(const QString &baseDirectory,
+ const ProductData &qbsProduct);
+QBS_EXPORT std::vector<ProductData> dependenciesOf(const ProductData &qbsProduct,
+ const GeneratableProject &genProject,
+ const QString &configurationName);
+QBS_EXPORT QString targetBinary(const ProductData &qbsProduct);
+QBS_EXPORT QString targetBinaryPath(const QString &baseDirectory,
+ const ProductData &qbsProduct);
+QBS_EXPORT QString cppStringModuleProperty(const PropertyMap &qbsProps,
+ const QString &propertyName);
+QBS_EXPORT bool cppBooleanModuleProperty(const PropertyMap &qbsProps,
+ const QString &propertyName);
+QBS_EXPORT int cppIntegerModuleProperty(const PropertyMap &qbsProps,
+ const QString &propertyName);
+QBS_EXPORT QStringList cppStringModuleProperties(const PropertyMap &qbsProps,
+ const QStringList &propertyNames);
+QBS_EXPORT QVariantList cppVariantModuleProperties(const PropertyMap &qbsProps,
+ const QStringList &propertyNames);
+QBS_EXPORT QString firstFlagValue(const QStringList &flags,
+ const QString &flagKey);
+QBS_EXPORT QStringList allFlagValues(const QStringList &flags,
+ const QString &flagKey);
+
+template <typename T>
+bool inBounds(const T &value, const T &low, const T &high)
+{
+ return !(value < low) && !(high < value);
+}
+
+} // namespace utils
+} // namespace gen
+} // namespace qbs
+
+#endif // GENERATORS_UTILS_H
diff --git a/src/lib/corelib/generators/generatorversioninfo.cpp b/src/lib/corelib/generators/generatorversioninfo.cpp
new file mode 100644
index 000000000..3e2106b57
--- /dev/null
+++ b/src/lib/corelib/generators/generatorversioninfo.cpp
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qbs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "generatorversioninfo.h"
+
+namespace qbs {
+namespace gen {
+
+VersionInfo::VersionInfo(const Version &version,
+ const std::set<utils::Architecture> &archs)
+ : m_version(version), m_archs(archs)
+{
+}
+
+bool VersionInfo::operator<(const VersionInfo &other) const
+{
+ return m_version < other.m_version;
+}
+
+bool VersionInfo::operator==(const VersionInfo &other) const
+{
+ return m_version == other.m_version
+ && m_archs == other.m_archs;
+}
+
+Version VersionInfo::version() const
+{
+ return m_version;
+}
+
+bool VersionInfo::containsArchitecture(utils::Architecture arch) const
+{
+ return m_archs.find(arch) != m_archs.cend();
+}
+
+int VersionInfo::marketingVersion() const
+{
+ return m_version.majorVersion();
+}
+
+quint32 qHash(const VersionInfo &info)
+{
+ return qHash(info.version().toString());
+}
+
+} // namespace gen
+} // namespace qbs
diff --git a/src/lib/corelib/generators/generatorversioninfo.h b/src/lib/corelib/generators/generatorversioninfo.h
new file mode 100644
index 000000000..65bfcf685
--- /dev/null
+++ b/src/lib/corelib/generators/generatorversioninfo.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qbs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GENERATORS_VERSION_INFO_H
+#define GENERATORS_VERSION_INFO_H
+
+#include "generatorutils.h"
+
+#include <tools/qbs_export.h>
+#include <tools/version.h>
+
+#include <set>
+
+namespace qbs {
+namespace gen {
+
+class QBS_EXPORT VersionInfo
+{
+public:
+ VersionInfo(const Version &version,
+ const std::set<utils::Architecture> &archs);
+ virtual ~VersionInfo() = default;
+
+ bool operator<(const VersionInfo &other) const;
+ bool operator==(const VersionInfo &other) const;
+
+ Version version() const;
+ bool containsArchitecture(utils::Architecture arch) const;
+
+ virtual int marketingVersion() const;
+
+private:
+ Version m_version;
+ std::set<utils::Architecture> m_archs;
+};
+
+quint32 qHash(const VersionInfo &info);
+
+} // namespace gen
+} // namespace qbs
+
+#endif // GENERATORS_VERSION_INFO_H
diff --git a/src/lib/corelib/generators/ixmlnodevisitor.h b/src/lib/corelib/generators/ixmlnodevisitor.h
new file mode 100644
index 000000000..d3d118975
--- /dev/null
+++ b/src/lib/corelib/generators/ixmlnodevisitor.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qbs.
+**
+** 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 The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef GENERATORS_XML_INODE_VISITOR_H
+#define GENERATORS_XML_INODE_VISITOR_H
+
+#include <tools/qbs_export.h>
+
+#include <QtCore/qxmlstream.h>
+
+namespace qbs {
+namespace gen {
+namespace xml {
+
+class Project;
+class Property;
+class PropertyGroup;
+class Workspace;
+
+class QBS_EXPORT INodeVisitor
+{
+public:
+ virtual ~INodeVisitor() {}
+
+ virtual void visitWorkspaceStart(const Workspace *workspace) { Q_UNUSED(workspace) }
+ virtual void visitWorkspaceEnd(const Workspace *workspace) { Q_UNUSED(workspace) }
+
+ virtual void visitProjectStart(const Project *project) { Q_UNUSED(project) }
+ virtual void visitProjectEnd(const Project *project) { Q_UNUSED(project) }
+
+ virtual void visitPropertyStart(const Property *property) = 0;
+ virtual void visitPropertyEnd(const Property *property) = 0;
+
+ virtual void visitPropertyGroupStart(const PropertyGroup *propertyGroup) = 0;
+ virtual void visitPropertyGroupEnd(const PropertyGroup *propertyGroup) = 0;
+};
+
+} // namespace xml
+} // namespace gen
+} // namespace qbs
+
+#endif // GENERATORS_XML_INODE_VISITOR_H
diff --git a/src/lib/corelib/generators/xmlproject.cpp b/src/lib/corelib/generators/xmlproject.cpp
new file mode 100644
index 000000000..e2ac951aa
--- /dev/null
+++ b/src/lib/corelib/generators/xmlproject.cpp
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qbs.
+**
+** 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 The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "xmlproject.h"
+#include "ixmlnodevisitor.h"
+
+namespace qbs {
+namespace gen {
+namespace xml {
+
+void Project::accept(INodeVisitor *visitor) const
+{
+ visitor->visitProjectStart(this);
+
+ for (const auto &child : children())
+ child->accept(visitor);
+
+ visitor->visitProjectEnd(this);
+}
+
+} // namespace xml
+} // namespace gen
+} // namespace qbs
diff --git a/src/lib/corelib/generators/xmlproject.h b/src/lib/corelib/generators/xmlproject.h
new file mode 100644
index 000000000..a7f5b2b65
--- /dev/null
+++ b/src/lib/corelib/generators/xmlproject.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qbs.
+**
+** 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 The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef GENERATORS_XML_PROJECT_H
+#define GENERATORS_XML_PROJECT_H
+
+#include "xmlproperty.h"
+
+#include <tools/qbs_export.h>
+
+#include <memory>
+
+namespace qbs {
+namespace gen {
+namespace xml {
+
+class QBS_EXPORT Project : public Property
+{
+public:
+ void accept(INodeVisitor *visitor) const final;
+};
+
+} // namespace xml
+} // namespace gen
+} // namespace qbs
+
+#endif // GENERATORS_XML_PROJECT_H
diff --git a/src/lib/corelib/generators/xmlprojectwriter.cpp b/src/lib/corelib/generators/xmlprojectwriter.cpp
new file mode 100644
index 000000000..5554e5935
--- /dev/null
+++ b/src/lib/corelib/generators/xmlprojectwriter.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qbs.
+**
+** 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 The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "xmlproject.h"
+#include "xmlprojectwriter.h"
+#include "xmlproperty.h"
+#include "xmlpropertygroup.h"
+
+#include <ostream>
+
+namespace qbs {
+namespace gen {
+namespace xml {
+
+ProjectWriter::ProjectWriter(std::ostream *device)
+ : m_device(device)
+{
+ m_writer.reset(new QXmlStreamWriter(&m_buffer));
+ m_writer->setAutoFormatting(true);
+}
+
+bool ProjectWriter::write(const Project *project)
+{
+ m_buffer.clear();
+ m_writer->writeStartDocument();
+ project->accept(this);
+ m_writer->writeEndDocument();
+ if (m_writer->hasError())
+ return false;
+ m_device->write(&*std::begin(m_buffer), m_buffer.size());
+ return m_device->good();
+}
+
+void ProjectWriter::visitPropertyStart(const Property *property)
+{
+ const auto value = property->value().toString();
+ const auto name = QString::fromUtf8(property->name());
+ m_writer->writeTextElement(name, value);
+}
+
+void ProjectWriter::visitPropertyEnd(const Property *property)
+{
+ Q_UNUSED(property)
+}
+
+void ProjectWriter::visitPropertyGroupStart(const PropertyGroup *propertyGroup)
+{
+ const auto name = QString::fromUtf8(propertyGroup->name());
+ m_writer->writeStartElement(name);
+}
+
+void ProjectWriter::visitPropertyGroupEnd(const PropertyGroup *propertyGroup)
+{
+ Q_UNUSED(propertyGroup)
+ m_writer->writeEndElement();
+}
+
+QXmlStreamWriter *ProjectWriter::writer() const
+{
+ return m_writer.get();
+}
+
+} // namespace xml
+} // namespace gen
+} // namespace qbs
diff --git a/src/lib/corelib/generators/xmlprojectwriter.h b/src/lib/corelib/generators/xmlprojectwriter.h
new file mode 100644
index 000000000..8198de61c
--- /dev/null
+++ b/src/lib/corelib/generators/xmlprojectwriter.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qbs.
+**
+** 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 The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef GENERATORS_XML_PROJECT_WRITER_H
+#define GENERATORS_XML_PROJECT_WRITER_H
+
+#include "ixmlnodevisitor.h"
+
+#include <tools/qbs_export.h>
+
+#include <memory>
+
+namespace qbs {
+namespace gen {
+namespace xml {
+
+class QBS_EXPORT ProjectWriter : public INodeVisitor
+{
+ Q_DISABLE_COPY(ProjectWriter)
+public:
+ explicit ProjectWriter(std::ostream *device);
+ bool write(const Project *project);
+
+protected:
+ QXmlStreamWriter *writer() const;
+
+private:
+ void visitPropertyStart(const Property *property) final;
+ void visitPropertyEnd(const Property *property) final;
+
+ void visitPropertyGroupStart(const PropertyGroup *propertyGroup) final;
+ void visitPropertyGroupEnd(const PropertyGroup *propertyGroup) final;
+
+ std::ostream *m_device = nullptr;
+ QByteArray m_buffer;
+ std::unique_ptr<QXmlStreamWriter> m_writer;
+};
+
+} // namespace xml
+} // namespace gen
+} // namespace qbs
+
+#endif // GENERATORS_XML_PROJECT_WRITER_H
diff --git a/src/lib/corelib/generators/xmlproperty.cpp b/src/lib/corelib/generators/xmlproperty.cpp
new file mode 100644
index 000000000..2fe5a0147
--- /dev/null
+++ b/src/lib/corelib/generators/xmlproperty.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qbs.
+**
+** 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 The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "ixmlnodevisitor.h"
+#include "xmlproperty.h"
+
+namespace qbs {
+namespace gen {
+namespace xml {
+
+Property::Property(QByteArray name, QVariant value)
+{
+ setName(std::move(name));
+ setValue(std::move(value));
+}
+
+void Property::accept(INodeVisitor *visitor) const
+{
+ visitor->visitPropertyStart(this);
+
+ for (const auto &child : children())
+ child->accept(visitor);
+
+ visitor->visitPropertyEnd(this);
+}
+
+} // namespace xml
+} // namespace gen
+} // namespace qbs
diff --git a/src/lib/corelib/generators/xmlproperty.h b/src/lib/corelib/generators/xmlproperty.h
new file mode 100644
index 000000000..795735881
--- /dev/null
+++ b/src/lib/corelib/generators/xmlproperty.h
@@ -0,0 +1,88 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qbs.
+**
+** 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 The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef GENERATORS_XML_PROPERTY_H
+#define GENERATORS_XML_PROPERTY_H
+
+#include <tools/qbs_export.h>
+
+#include <QtCore/qvariant.h>
+
+#include <memory>
+
+namespace qbs {
+namespace gen {
+namespace xml {
+
+class INodeVisitor;
+
+class QBS_EXPORT Property
+{
+ Q_DISABLE_COPY(Property)
+public:
+ Property() = default;
+ explicit Property(QByteArray name, QVariant value);
+ virtual ~Property() = default;
+
+ QByteArray name() const { return m_name; }
+ void setName(QByteArray name) { m_name = std::move(name); }
+
+ QVariant value() const { return m_value; }
+ void setValue(QVariant value) { m_value = std::move(value); }
+
+ template<class T>
+ T *appendChild(std::unique_ptr<T> child) {
+ const auto p = child.get();
+ m_children.push_back(std::move(child));
+ return p;
+ }
+
+ template<class T, class... Args>
+ T *appendChild(Args&&... args) {
+ return appendChild(std::make_unique<T>(std::forward<Args>(args)...));
+ }
+
+ virtual void accept(INodeVisitor *visitor) const;
+
+protected:
+ const std::vector<std::unique_ptr<Property>> &children() const
+ { return m_children; }
+
+private:
+ QByteArray m_name;
+ QVariant m_value;
+ std::vector<std::unique_ptr<Property>> m_children;
+};
+
+} // namespace xml
+} // namespace gen
+} // namespace qbs
+
+#endif // GENERATORS_XML_PROPERTY_H
diff --git a/src/lib/corelib/generators/xmlpropertygroup.cpp b/src/lib/corelib/generators/xmlpropertygroup.cpp
new file mode 100644
index 000000000..398d68e77
--- /dev/null
+++ b/src/lib/corelib/generators/xmlpropertygroup.cpp
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qbs.
+**
+** 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 The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "ixmlnodevisitor.h"
+#include "xmlpropertygroup.h"
+
+namespace qbs {
+namespace gen {
+namespace xml {
+
+PropertyGroup::PropertyGroup(QByteArray name)
+{
+ setName(std::move(name));
+}
+
+void PropertyGroup::appendProperty(QByteArray name, QVariant value)
+{
+ appendChild<Property>(std::move(name), std::move(value));
+}
+
+void PropertyGroup::appendMultiLineProperty(
+ QByteArray key, QStringList values, QChar sep)
+{
+ const auto line = values.join(std::move(sep));
+ appendProperty(std::move(key), QVariant::fromValue(line));
+}
+
+void PropertyGroup::accept(INodeVisitor *visitor) const
+{
+ visitor->visitPropertyGroupStart(this);
+
+ for (const auto &child : children())
+ child->accept(visitor);
+
+ visitor->visitPropertyGroupEnd(this);
+}
+
+} // namespace xml
+} // namespace gen
+} // namespace qbs
diff --git a/src/lib/corelib/generators/xmlpropertygroup.h b/src/lib/corelib/generators/xmlpropertygroup.h
new file mode 100644
index 000000000..e63b515fc
--- /dev/null
+++ b/src/lib/corelib/generators/xmlpropertygroup.h
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qbs.
+**
+** 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 The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef GENERATORS_XML_PROPERTY_GROUP_H
+#define GENERATORS_XML_PROPERTY_GROUP_H
+
+#include "generatorversioninfo.h"
+#include "xmlproperty.h"
+
+#include <tools/qbs_export.h>
+
+#include <memory>
+
+namespace qbs {
+
+class ProductData;
+class Project;
+
+namespace gen {
+namespace xml {
+
+class QBS_EXPORT PropertyGroup : public Property
+{
+public:
+ explicit PropertyGroup(QByteArray name);
+
+ void appendProperty(QByteArray name, QVariant value);
+ void appendMultiLineProperty(QByteArray key, QStringList values,
+ QChar sep = QLatin1Char(','));
+
+ void accept(INodeVisitor *visitor) const final;
+};
+
+class PropertyGroupFactory
+{
+public:
+ virtual ~PropertyGroupFactory() = default;
+ virtual bool canCreate(utils::Architecture arch,
+ const Version &version) const = 0;
+
+ virtual std::unique_ptr<PropertyGroup> create(
+ const qbs::Project &qbsProject,
+ const qbs::ProductData &qbsProduct,
+ const std::vector<ProductData> &qbsProductDeps) const = 0;
+};
+
+} // namespace xml
+} // namespace gen
+} // namespace qbs
+
+#endif // GENERATORS_XML_PROPERTY_GROUP_H
diff --git a/src/lib/corelib/generators/xmlworkspace.cpp b/src/lib/corelib/generators/xmlworkspace.cpp
new file mode 100644
index 000000000..7ce3f5164
--- /dev/null
+++ b/src/lib/corelib/generators/xmlworkspace.cpp
@@ -0,0 +1,66 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qbs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "ixmlnodevisitor.h"
+#include "xmlproperty.h"
+#include "xmlpropertygroup.h"
+#include "xmlworkspace.h"
+
+namespace qbs {
+namespace gen {
+namespace xml {
+
+Workspace::Workspace(const QString &workspacePath)
+ : m_baseDirectory(QFileInfo(workspacePath).absoluteDir())
+{
+}
+
+void Workspace::accept(INodeVisitor *visitor) const
+{
+ visitor->visitWorkspaceStart(this);
+
+ for (const auto &child : children())
+ child->accept(visitor);
+
+ visitor->visitWorkspaceEnd(this);
+}
+
+} // namespace xml
+} // namespace gen
+} // namespace qbs
diff --git a/src/lib/corelib/generators/xmlworkspace.h b/src/lib/corelib/generators/xmlworkspace.h
new file mode 100644
index 000000000..beab22c4a
--- /dev/null
+++ b/src/lib/corelib/generators/xmlworkspace.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qbs.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GENERATORS_XML_WWORKSPACE_H
+#define GENERATORS_XML_WWORKSPACE_H
+
+#include "xmlproperty.h"
+
+#include <tools/qbs_export.h>
+
+#include <QtCore/qdir.h>
+
+namespace qbs {
+namespace gen {
+namespace xml {
+
+class QBS_EXPORT Workspace : public Property
+{
+public:
+ explicit Workspace(const QString &workspacePath);
+ void accept(INodeVisitor *visitor) const final;
+
+ virtual void addProject(const QString &projectPath) = 0;
+
+protected:
+ const QDir m_baseDirectory;
+};
+
+} // namespace xml
+} // namespace gen
+} // namespace qbs
+
+#endif // GENERATORS_XML_WWORKSPACE_H
diff --git a/src/lib/corelib/generators/xmlworkspacewriter.cpp b/src/lib/corelib/generators/xmlworkspacewriter.cpp
new file mode 100644
index 000000000..c88cb06d0
--- /dev/null
+++ b/src/lib/corelib/generators/xmlworkspacewriter.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qbs.
+**
+** 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 The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "xmlproperty.h"
+#include "xmlpropertygroup.h"
+#include "xmlworkspace.h"
+#include "xmlworkspacewriter.h"
+
+#include <ostream>
+
+namespace qbs {
+namespace gen {
+namespace xml {
+
+WorkspaceWriter::WorkspaceWriter(std::ostream *device)
+ : m_device(device)
+{
+ m_writer.reset(new QXmlStreamWriter(&m_buffer));
+ m_writer->setAutoFormatting(true);
+}
+
+bool WorkspaceWriter::write(const Workspace *workspace)
+{
+ m_buffer.clear();
+ m_writer->writeStartDocument();
+ workspace->accept(this);
+ m_writer->writeEndDocument();
+ if (m_writer->hasError())
+ return false;
+ m_device->write(&*std::begin(m_buffer), m_buffer.size());
+ return m_device->good();
+}
+
+void WorkspaceWriter::visitPropertyStart(const Property *property)
+{
+ const auto value = property->value().toString();
+ const auto name = QString::fromUtf8(property->name());
+ m_writer->writeTextElement(name, value);
+}
+
+void WorkspaceWriter::visitPropertyEnd(const Property *property)
+{
+ Q_UNUSED(property)
+}
+
+void WorkspaceWriter::visitPropertyGroupStart(const PropertyGroup *propertyGroup)
+{
+ const auto name = QString::fromUtf8(propertyGroup->name());
+ m_writer->writeStartElement(name);
+}
+
+void WorkspaceWriter::visitPropertyGroupEnd(const PropertyGroup *propertyGroup)
+{
+ Q_UNUSED(propertyGroup)
+ m_writer->writeEndElement();
+}
+
+QXmlStreamWriter *WorkspaceWriter::writer() const
+{
+ return m_writer.get();
+}
+
+} // namespace xml
+} // namespace gen
+} // namespace qbs
diff --git a/src/lib/corelib/generators/xmlworkspacewriter.h b/src/lib/corelib/generators/xmlworkspacewriter.h
new file mode 100644
index 000000000..343face5d
--- /dev/null
+++ b/src/lib/corelib/generators/xmlworkspacewriter.h
@@ -0,0 +1,70 @@
+/****************************************************************************
+**
+** Copyright (C) 2019 Denis Shienkov <denis.shienkov@gmail.com>
+** Contact: http://www.qt.io/licensing
+**
+** This file is part of Qbs.
+**
+** 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 The Qt Company. For licensing terms and
+** conditions see http://www.qt.io/terms-conditions. For further information
+** use the contact form at http://www.qt.io/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 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef GENERATORS_XML_WORKSPACE_WRITER_H
+#define GENERATORS_XML_WORKSPACE_WRITER_H
+
+#include "ixmlnodevisitor.h"
+
+#include <tools/qbs_export.h>
+
+#include <memory>
+
+namespace qbs {
+namespace gen {
+namespace xml {
+
+class QBS_EXPORT WorkspaceWriter : public INodeVisitor
+{
+ Q_DISABLE_COPY(WorkspaceWriter)
+public:
+ explicit WorkspaceWriter(std::ostream *device);
+ bool write(const Workspace *workspace);
+
+protected:
+ QXmlStreamWriter *writer() const;
+
+private:
+ void visitPropertyStart(const Property *property) final;
+ void visitPropertyEnd(const Property *property) final;
+
+ void visitPropertyGroupStart(const PropertyGroup *propertyGroup) final;
+ void visitPropertyGroupEnd(const PropertyGroup *propertyGroup) final;
+
+ std::ostream *m_device = nullptr;
+ QByteArray m_buffer;
+ std::unique_ptr<QXmlStreamWriter> m_writer;
+};
+
+} // namespace xml
+} // namespace gen
+} // namespace qbs
+
+#endif // GENERATORS_XML_WORKSPACE_WRITER_H