diff options
Diffstat (limited to 'src/lib/corelib')
19 files changed, 1420 insertions, 2 deletions
diff --git a/src/lib/corelib/corelib.qbs b/src/lib/corelib/corelib.qbs index a9ca5131a..92d7eb052 100644 --- a/src/lib/corelib/corelib.qbs +++ b/src/lib/corelib/corelib.qbs @@ -198,7 +198,24 @@ QbsLibrary { "generatableprojectiterator.h", "generator.cpp", "generatordata.cpp", + "generatorutils.cpp", + "generatorutils.h", + "generatorversioninfo.cpp", + "generatorversioninfo.h", "igeneratableprojectvisitor.h", + "ixmlnodevisitor.h", + "xmlproject.cpp", + "xmlproject.h", + "xmlprojectwriter.cpp", + "xmlprojectwriter.h", + "xmlproperty.cpp", + "xmlproperty.h", + "xmlpropertygroup.cpp", + "xmlpropertygroup.h", + "xmlworkspace.cpp", + "xmlworkspace.h", + "xmlworkspacewriter.cpp", + "xmlworkspacewriter.h", ] } Group { 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..4f76eab7f --- /dev/null +++ b/src/lib/corelib/generators/generatorutils.cpp @@ -0,0 +1,211 @@ +/**************************************************************************** +** +** 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; + 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; +} + +} // 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..e13740105 --- /dev/null +++ b/src/lib/corelib/generators/generatorutils.h @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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, + 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); + +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..6d62c86ed --- /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 visitStart(const Workspace *workspace) { Q_UNUSED(workspace) } + virtual void visitEnd(const Workspace *workspace) { Q_UNUSED(workspace) } + + virtual void visitStart(const Project *project) { Q_UNUSED(project) } + virtual void visitEnd(const Project *project) { Q_UNUSED(project) } + + virtual void visitStart(const Property *property) = 0; + virtual void visitEnd(const Property *property) = 0; + + virtual void visitStart(const PropertyGroup *propertyGroup) = 0; + virtual void visitEnd(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..becd31dda --- /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->visitStart(this); + + for (const auto &child : children()) + child->accept(visitor); + + visitor->visitEnd(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..5b96564bd --- /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::visitStart(const Property *property) +{ + const auto value = property->value().toString(); + const auto name = QString::fromUtf8(property->name()); + m_writer->writeTextElement(name, value); +} + +void ProjectWriter::visitEnd(const Property *property) +{ + Q_UNUSED(property) +} + +void ProjectWriter::visitStart(const PropertyGroup *propertyGroup) +{ + const auto name = QString::fromUtf8(propertyGroup->name()); + m_writer->writeStartElement(name); +} + +void ProjectWriter::visitEnd(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..da4100a92 --- /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 visitStart(const Property *property) final; + void visitEnd(const Property *property) final; + + void visitStart(const PropertyGroup *propertyGroup) final; + void visitEnd(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..ae41eab4a --- /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->visitStart(this); + + for (const auto &child : children()) + child->accept(visitor); + + visitor->visitEnd(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..2111b9b1e --- /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->visitStart(this); + + for (const auto &child : children()) + child->accept(visitor); + + visitor->visitEnd(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..8913ceffd --- /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->visitStart(this); + + for (const auto &child : children()) + child->accept(visitor); + + visitor->visitEnd(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..2358d4047 --- /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::visitStart(const Property *property) +{ + const auto value = property->value().toString(); + const auto name = QString::fromUtf8(property->name()); + m_writer->writeTextElement(name, value); +} + +void WorkspaceWriter::visitEnd(const Property *property) +{ + Q_UNUSED(property) +} + +void WorkspaceWriter::visitStart(const PropertyGroup *propertyGroup) +{ + const auto name = QString::fromUtf8(propertyGroup->name()); + m_writer->writeStartElement(name); +} + +void WorkspaceWriter::visitEnd(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..73e7d0686 --- /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 visitStart(const Property *property) final; + void visitEnd(const Property *property) final; + + void visitStart(const PropertyGroup *propertyGroup) final; + void visitEnd(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 |