MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / getTargetRootPath

Function getTargetRootPath

src/plugins/cxx/cmake/project/cmakeasynparse.cpp:87–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87QString getTargetRootPath(const CMakeBuildTarget &target, const dpfservice::ProjectInfo &prjInfo)
88{
89 auto srcFiles = target.srcfiles;
90 auto topPath = target.sourceDirectory;
91
92 if (srcFiles.isEmpty()) {
93 return QString();
94 }
95
96 //get target root path by build-directory
97 auto workingDirectory = target.workingDirectory;
98 auto buildDirectory = prjInfo.buildFolder();
99 if (workingDirectory.startsWith(buildDirectory)) {
100 workingDirectory.remove(buildDirectory);
101 return topPath + workingDirectory;
102 }
103
104 //get target root path by srcFiles path
105 // Divide all paths into multiple lists according to directory hierarchy
106 QList<QList<QString>> pathPartsList;
107 for (const QString &filePath : srcFiles) {
108 // remove outter file.
109 if ((!topPath.isEmpty() && !filePath.startsWith(topPath)) /* || QFileInfo(filePath).suffix() == "h" || QFileInfo(filePath).suffix() == "hpp"*/) {
110 continue;
111 }
112
113 QList<QString> pathParts = filePath.split(QDir::separator());
114 pathPartsList.append(pathParts);
115 }
116
117 // Find the shortest path list
118 int minPathLength = INT_MAX;
119 for (const QList<QString> &pathParts : pathPartsList) {
120 if (pathParts.length() < minPathLength) {
121 minPathLength = pathParts.length();
122 }
123 }
124 if (pathPartsList.size() == 0)
125 return {};
126
127 // Starting from the shortest path list, compare whether the paths are the same layer by layer
128 QList<QString> rootPathParts;
129 for (int i = 0; i < minPathLength; i++) {
130 QString currentPart = pathPartsList[0][i];
131 bool allMatched = true;
132 for (int j = 1; j < pathPartsList.length(); j++) {
133 if (pathPartsList[j][i] != currentPart) {
134 allMatched = false;
135 break;
136 }
137 }
138 if (allMatched) {
139 rootPathParts.append(currentPart);
140 } else {
141 break;
142 }
143 }
144

Callers 1

parseProjectMethod · 0.85

Calls 8

startsWithMethod · 0.80
QStringClass · 0.50
isEmptyMethod · 0.45
removeMethod · 0.45
appendMethod · 0.45
lengthMethod · 0.45
sizeMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected