forked from qt-creator/qt-creator
ProjectExplorer: Add functionality for mapping source files to binaries
Works out of the box with qbs. cmake and qmake need backend adaptations. Task-number: QTCREATORBUG-28815 Change-Id: I0238416a23c1574bc2b6121e2ef942a9260d94d9 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -869,11 +869,32 @@ const Node *Project::nodeForFilePath(const FilePath &filePath,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FilePaths Project::binariesForSourceFile(const Utils::FilePath &sourceFile) const
|
||||
FilePaths Project::binariesForSourceFile(const FilePath &sourceFile) const
|
||||
{
|
||||
Q_UNUSED(sourceFile);
|
||||
// TODO: QTCREATORBUG-28815
|
||||
if (!rootProjectNode())
|
||||
return {};
|
||||
const QList<Node *> fileNodes = rootProjectNode()->findNodes([&sourceFile](Node *n) {
|
||||
return n->filePath() == sourceFile;
|
||||
});
|
||||
FilePaths binaries;
|
||||
for (const Node * const fileNode : fileNodes) {
|
||||
for (ProjectNode *projectNode = fileNode->parentProjectNode(); projectNode;
|
||||
projectNode = projectNode->parentProjectNode()) {
|
||||
if (!projectNode->isProduct())
|
||||
continue;
|
||||
if (projectNode->productType() == ProductType::App
|
||||
|| projectNode->productType() == ProductType::Lib) {
|
||||
const QList<Node *> binaryNodes = projectNode->findNodes([](Node *n) {
|
||||
return n->asFileNode() && (n->asFileNode()->fileType() == FileType::App
|
||||
|| n->asFileNode()->fileType() == FileType::Lib);
|
||||
|
||||
});
|
||||
binaries << Utils::transform(binaryNodes, &Node::filePath);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return binaries;
|
||||
}
|
||||
|
||||
void Project::setProjectLanguages(Context language)
|
||||
@@ -1533,19 +1554,23 @@ void ProjectExplorerPlugin::testSourceToBinaryMapping()
|
||||
}
|
||||
QVERIFY(!bs->isWaitingForParse() && !bs->isParsing());
|
||||
|
||||
// Build project.
|
||||
if (QLatin1String(QTest::currentDataTag()) == QLatin1String("qbs")) {
|
||||
BuildManager::buildProjectWithoutDependencies(theProject.project());
|
||||
if (BuildManager::isBuilding()) {
|
||||
QSignalSpy buildingFinishedSpy(BuildManager::instance(), &BuildManager::buildQueueFinished);
|
||||
QVERIFY(buildingFinishedSpy.wait(10000));
|
||||
}
|
||||
QVERIFY(!BuildManager::isBuilding());
|
||||
QSignalSpy projectUpdateSpy(theProject.project(), &Project::fileListChanged);
|
||||
QVERIFY(projectUpdateSpy.wait(5000));
|
||||
}
|
||||
|
||||
// Check mapping
|
||||
const auto binariesForSource = [&](const QString &fileName) {
|
||||
return theProject.project()->binariesForSourceFile(projectDir.pathAppended(fileName));
|
||||
};
|
||||
QEXPECT_FAIL(0, "QTCREATORBUG-28815", Abort);
|
||||
QEXPECT_FAIL("cmake", "QTCREATORBUG-28815", Abort);
|
||||
QEXPECT_FAIL("qmake", "QTCREATORBUG-28815", Abort);
|
||||
QCOMPARE(binariesForSource("multi-target-project-main.cpp").size(), 1);
|
||||
QCOMPARE(binariesForSource("multi-target-project-lib.cpp").size(), 1);
|
||||
QCOMPARE(binariesForSource("multi-target-project-shared.h").size(), 2);
|
||||
|
||||
@@ -32,6 +32,8 @@ enum class FileType : quint16 {
|
||||
Resource,
|
||||
QML,
|
||||
Project,
|
||||
App,
|
||||
Lib,
|
||||
FileTypeSize
|
||||
};
|
||||
|
||||
|
||||
@@ -42,6 +42,10 @@ static FileType fileType(const QJsonObject &artifact)
|
||||
return FileType::StateChart;
|
||||
if (fileTags.contains("qt.qml.qml"))
|
||||
return FileType::QML;
|
||||
if (fileTags.contains("application"))
|
||||
return FileType::App;
|
||||
if (fileTags.contains("staticlibrary") || fileTags.contains("dynamiclibrary"))
|
||||
return FileType::Lib;
|
||||
return FileType::Unknown;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user