| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
| 3 |
|
| 4 |
#ifndef MSBUILD_OBJECTMODEL_H |
| 5 |
#define MSBUILD_OBJECTMODEL_H |
| 6 |
|
| 7 |
#include "project.h" |
| 8 |
#include "xmloutput.h" |
| 9 |
#include "msvc_objectmodel.h" |
| 10 |
#include <qlist.h> |
| 11 |
#include <qstring.h> |
| 12 |
#include <qmap.h> |
| 13 |
|
| 14 |
QT_BEGIN_NAMESPACE |
| 15 |
|
| 16 |
// Tree & Flat view of files -------------------------------------------------- |
| 17 |
class XNode |
| 18 |
{ |
| 19 |
public: |
| 20 |
virtual ~XNode() { } |
| 21 |
void addElement(const VCFilterFile &file) { |
| 22 |
addElement(file.file, file); |
| 23 |
} |
| 24 |
virtual void addElement(const QString &filepath, const VCFilterFile &allInfo) = 0; |
| 25 |
virtual void removeElements()= 0; |
| 26 |
virtual void generateXML(XmlOutput &xml, XmlOutput &xmlFilter, const QString &tagName, |
| 27 |
VCProject &tool, const QString &filter) = 0; |
| 28 |
virtual bool hasElements() = 0; |
| 29 |
}; |
| 30 |
|
| 31 |
class XTreeNode : public XNode |
| 32 |
{ |
| 33 |
typedef QMap<QString, XTreeNode*> ChildrenMap; |
| 34 |
VCFilterFile info; |
| 35 |
ChildrenMap children; |
| 36 |
|
| 37 |
public: |
| 38 |
virtual ~XTreeNode() { removeElements(); } |
| 39 |
|
| 40 |
int pathIndex(const QString &filepath) { |
| 41 |
int Windex = filepath.indexOf("\\"); |
| 42 |
int Uindex = filepath.indexOf("/"); |
| 43 |
if (Windex != -1 && Uindex != -1) |
| 44 |
return qMin(Windex, Uindex); |
| 45 |
else if (Windex != -1) |
| 46 |
return Windex; |
| 47 |
return Uindex; |
| 48 |
} |
| 49 |
|
| 50 |
void addElement(const QString &filepath, const VCFilterFile &allInfo) override { |
| 51 |
QString newNodeName(filepath); |
| 52 |
|
| 53 |
int index = pathIndex(filepath); |
| 54 |
if (index != -1) |
| 55 |
newNodeName = filepath.left(index); |
| 56 |
|
| 57 |
XTreeNode *n = children.value(newNodeName); |
| 58 |
if (!n) { |
| 59 |
n = new XTreeNode; |
| 60 |
n->info = allInfo; |
| 61 |
children.insert(newNodeName, n); |
| 62 |
} |
| 63 |
if (index != -1) |
| 64 |
n->addElement(filepath.mid(index+1), allInfo); |
| 65 |
} |
| 66 |
|
| 67 |
void removeElements() override { |
| 68 |
ChildrenMap::ConstIterator it = children.constBegin(); |
| 69 |
ChildrenMap::ConstIterator end = children.constEnd(); |
| 70 |
for( ; it != end; it++) { |
| 71 |
(*it)->removeElements(); |
| 72 |
delete it.value(); |
| 73 |
} |
| 74 |
children.clear(); |
| 75 |
} |
| 76 |
|
| 77 |
void generateXML(XmlOutput &xml, XmlOutput &xmlFilter, const QString &tagName, VCProject &tool, |
| 78 |
const QString &filter) override; |
| 79 |
bool hasElements() override { |
| 80 |
return children.size() != 0; |
| 81 |
} |
| 82 |
}; |
| 83 |
|
| 84 |
class XFlatNode : public XNode |
| 85 |
{ |
| 86 |
typedef QMap<QString, VCFilterFile> ChildrenMapFlat; |
| 87 |
ChildrenMapFlat children; |
| 88 |
|
| 89 |
public: |
| 90 |
virtual ~XFlatNode() { removeElements(); } |
| 91 |
|
| 92 |
int pathIndex(const QString &filepath) { |
| 93 |
int Windex = filepath.lastIndexOf("\\"); |
| 94 |
int Uindex = filepath.lastIndexOf("/"); |
| 95 |
if (Windex != -1 && Uindex != -1) |
| 96 |
return qMax(Windex, Uindex); |
| 97 |
else if (Windex != -1) |
| 98 |
return Windex; |
| 99 |
return Uindex; |
| 100 |
} |
| 101 |
|
| 102 |
void addElement(const QString &filepath, const VCFilterFile &allInfo) override { |
| 103 |
QString newKey(filepath); |
| 104 |
|
| 105 |
int index = pathIndex(filepath); |
| 106 |
if (index != -1) |
| 107 |
newKey = filepath.mid(index+1); |
| 108 |
|
| 109 |
// Key designed to sort files with same |
| 110 |
// name in different paths correctly |
| 111 |
children.insert(newKey + "\0" + allInfo.file, allInfo); |
| 112 |
} |
| 113 |
|
| 114 |
void removeElements() override { |
| 115 |
children.clear(); |
| 116 |
} |
| 117 |
|
| 118 |
void generateXML(XmlOutput &xml, XmlOutput &xmlFilter, const QString &tagName, VCProject &proj, |
| 119 |
const QString &filter) override; |
| 120 |
bool hasElements() override { |
| 121 |
return children.size() != 0; |
| 122 |
} |
| 123 |
}; |
| 124 |
|
| 125 |
class VCXProjectWriter : public VCProjectWriter |
| 126 |
{ |
| 127 |
public: |
| 128 |
void write(XmlOutput &, VCProjectSingleConfig &) override; |
| 129 |
void write(XmlOutput &, VCProject &) override; |
| 130 |
|
| 131 |
void write(XmlOutput &, const VCCLCompilerTool &) override; |
| 132 |
void write(XmlOutput &, const VCLinkerTool &) override; |
| 133 |
void write(XmlOutput &, const VCMIDLTool &) override; |
| 134 |
void write(XmlOutput &, const VCCustomBuildTool &) override; |
| 135 |
void write(XmlOutput &, const VCLibrarianTool &) override; |
| 136 |
void write(XmlOutput &, const VCResourceCompilerTool &) override; |
| 137 |
void write(XmlOutput &, const VCEventTool &) override; |
| 138 |
void write(XmlOutput &, const VCDeploymentTool &) override; |
| 139 |
void write(XmlOutput &, const VCWinDeployQtTool &) override; |
| 140 |
void write(XmlOutput &, const VCConfiguration &) override; |
| 141 |
void write(XmlOutput &, VCFilter &) override; |
| 142 |
|
| 143 |
private: |
| 144 |
struct OutputFilterData |
| 145 |
{ |
| 146 |
VCFilter filter; |
| 147 |
VCFilterFile info; |
| 148 |
bool inBuild; |
| 149 |
}; |
| 150 |
|
| 151 |
static void addFilters(VCProject &project, XmlOutput &xmlFilter, const QString &filterName); |
| 152 |
static void outputFilter(VCProject &project, XmlOutput &xml, XmlOutput &xmlFilter, const QString &filtername); |
| 153 |
static void outputFileConfigs(VCProject &project, XmlOutput &xml, XmlOutput &xmlFilter, |
| 154 |
const VCFilterFile &info, const QString &filtername); |
| 155 |
static bool outputFileConfig(OutputFilterData *d, XmlOutput &xml, XmlOutput &xmlFilter, |
| 156 |
const QString &filename, const QString &fullFilterName, |
| 157 |
bool fileAdded, bool hasCustomBuildStep); |
| 158 |
static void outputFileConfig(XmlOutput &xml, XmlOutput &xmlFilter, const QString &fileName, const QString &filterName); |
| 159 |
static QString generateCondition(const VCConfiguration &config); |
| 160 |
static XmlOutput::xml_output attrTagToolsVersion(const VCConfiguration &config); |
| 161 |
|
| 162 |
friend class XTreeNode; |
| 163 |
friend class XFlatNode; |
| 164 |
}; |
| 165 |
|
| 166 |
QT_END_NAMESPACE |
| 167 |
|
| 168 |
#endif // MSVC_OBJECTMODEL_H |