forked from qt-creator/qt-creator
CMake: Add logging output to file -> target mapping
The logic for mapping files to targets is a heuristic, and a pretty bad one. Add some logging output, which can be enabled by setting the env variable QT_LOGGING_RULES to qtc.cmakeprojectmanager.filetargetmapping.debug=true . This will allow easier debugging of problematic cases. Change-Id: I17086a30beb8962333109fce9198edde4540d169 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -867,6 +867,7 @@ int distance(const QString &targetDirectory, const Utils::FileName &fileName)
|
|||||||
// compiler flags
|
// compiler flags
|
||||||
void CMakeCbpParser::sortFiles()
|
void CMakeCbpParser::sortFiles()
|
||||||
{
|
{
|
||||||
|
QLoggingCategory log("qtc.cmakeprojectmanager.filetargetmapping");
|
||||||
QList<Utils::FileName> fileNames = Utils::transform(m_fileList, [] (FileNode *node) {
|
QList<Utils::FileName> fileNames = Utils::transform(m_fileList, [] (FileNode *node) {
|
||||||
return Utils::FileName::fromString(node->path());
|
return Utils::FileName::fromString(node->path());
|
||||||
});
|
});
|
||||||
@@ -877,6 +878,13 @@ void CMakeCbpParser::sortFiles()
|
|||||||
CMakeBuildTarget *last = 0;
|
CMakeBuildTarget *last = 0;
|
||||||
Utils::FileName parentDirectory;
|
Utils::FileName parentDirectory;
|
||||||
|
|
||||||
|
qCDebug(log) << "###############";
|
||||||
|
qCDebug(log) << "# Pre Dump #";
|
||||||
|
qCDebug(log) << "###############";
|
||||||
|
foreach (const CMakeBuildTarget &target, m_buildTargets)
|
||||||
|
qCDebug(log) << target.title << target.sourceDirectory <<
|
||||||
|
target.includeFiles << target.defines << target.files << "\n";
|
||||||
|
|
||||||
// find a good build target to fall back
|
// find a good build target to fall back
|
||||||
int fallbackIndex = 0;
|
int fallbackIndex = 0;
|
||||||
{
|
{
|
||||||
@@ -893,10 +901,16 @@ void CMakeCbpParser::sortFiles()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qCDebug(log) << "###############";
|
||||||
|
qCDebug(log) << "# Sorting #";
|
||||||
|
qCDebug(log) << "###############";
|
||||||
|
|
||||||
foreach (const Utils::FileName &fileName, fileNames) {
|
foreach (const Utils::FileName &fileName, fileNames) {
|
||||||
|
qCDebug(log) << fileName;
|
||||||
if (fileName.parentDir() == parentDirectory && last) {
|
if (fileName.parentDir() == parentDirectory && last) {
|
||||||
// easy case, same parent directory as last file
|
// easy case, same parent directory as last file
|
||||||
last->files.append(fileName.toString());
|
last->files.append(fileName.toString());
|
||||||
|
qCDebug(log) << " into" << last->title;
|
||||||
} else {
|
} else {
|
||||||
int bestDistance = std::numeric_limits<int>::max();
|
int bestDistance = std::numeric_limits<int>::max();
|
||||||
int bestIndex = -1;
|
int bestIndex = -1;
|
||||||
@@ -907,6 +921,7 @@ void CMakeCbpParser::sortFiles()
|
|||||||
if (target.includeFiles.isEmpty())
|
if (target.includeFiles.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
int dist = distance(target.sourceDirectory, fileName);
|
int dist = distance(target.sourceDirectory, fileName);
|
||||||
|
qCDebug(log) << "distance to target" << target.title << dist;
|
||||||
if (dist < bestDistance ||
|
if (dist < bestDistance ||
|
||||||
(dist == bestDistance &&
|
(dist == bestDistance &&
|
||||||
target.includeFiles.count() > bestIncludeCount)) {
|
target.includeFiles.count() > bestIncludeCount)) {
|
||||||
@@ -916,16 +931,25 @@ void CMakeCbpParser::sortFiles()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bestIndex == -1 && !m_buildTargets.isEmpty())
|
if (bestIndex == -1 && !m_buildTargets.isEmpty()) {
|
||||||
bestIndex = fallbackIndex;
|
bestIndex = fallbackIndex;
|
||||||
|
qCDebug(log) << " using fallbackIndex";
|
||||||
|
}
|
||||||
|
|
||||||
if (bestIndex != -1) {
|
if (bestIndex != -1) {
|
||||||
m_buildTargets[bestIndex].files.append(fileName.toString());
|
m_buildTargets[bestIndex].files.append(fileName.toString());
|
||||||
last = &m_buildTargets[bestIndex];
|
last = &m_buildTargets[bestIndex];
|
||||||
parentDirectory = fileName.parentDir();
|
parentDirectory = fileName.parentDir();
|
||||||
|
qCDebug(log) << " into" << last->title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qCDebug(log) << "###############";
|
||||||
|
qCDebug(log) << "# After Dump #";
|
||||||
|
qCDebug(log) << "###############";
|
||||||
|
foreach (const CMakeBuildTarget &target, m_buildTargets)
|
||||||
|
qCDebug(log) << target.title << target.sourceDirectory << target.includeFiles << target.defines << target.files << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CMakeCbpParser::parseCbpFile(const QString &fileName, const QString &sourceDirectory)
|
bool CMakeCbpParser::parseCbpFile(const QString &fileName, const QString &sourceDirectory)
|
||||||
|
|||||||
Reference in New Issue
Block a user