| 85 | } |
| 86 | |
| 87 | QString 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 |
no test coverage detected