Commit e255baaa authored by Christian Stenger's avatar Christian Stenger

CppTools: Add target type information to project part

Let project managers store information whether a project part
belongs to an executable or a library and use this information
inside the AutoTest plugin.
This information will help to determine which targets are
relevant for the execution of tests.

Change-Id: I93b42797bf55225425398dc83aecea3c99eea290
Reviewed-by: Nikolai Kosjar's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent 8288eada
......@@ -294,6 +294,8 @@ QSet<QString> GTestTreeItem::internalTargets() const
const auto cppMM = CppTools::CppModelManager::instance();
const auto projectInfo = cppMM->projectInfo(ProjectExplorer::SessionManager::startupProject());
for (const CppTools::ProjectPart::Ptr projectPart : projectInfo.projectParts()) {
if (projectPart->buildTargetType != CppTools::ProjectPart::Executable)
continue;
if (projectPart->projectFile == proFile())
result.insert(projectPart->buildSystemTarget + '|' + projectPart->projectFile);
}
......
......@@ -292,6 +292,8 @@ QSet<QString> QuickTestTreeItem::internalTargets() const
const auto cppMM = CppTools::CppModelManager::instance();
const auto projectInfo = cppMM->projectInfo(ProjectExplorer::SessionManager::startupProject());
for (const CppTools::ProjectPart::Ptr projectPart : projectInfo.projectParts()) {
if (projectPart->buildTargetType != CppTools::ProjectPart::Executable)
continue;
if (projectPart->projectFile == proFile()) {
result.insert(projectPart->buildSystemTarget + '|' + projectPart->projectFile);
break;
......
......@@ -288,8 +288,11 @@ QSet<QString> TestTreeItem::internalTargets() const
auto cppMM = CppTools::CppModelManager::instance();
const QList<CppTools::ProjectPart::Ptr> projectParts = cppMM->projectPart(filePath());
QSet<QString> targets;
for (const CppTools::ProjectPart::Ptr part : projectParts)
for (const CppTools::ProjectPart::Ptr part : projectParts) {
if (part->buildTargetType != CppTools::ProjectPart::Executable)
continue;
targets.insert(part->buildSystemTarget + '|' + part->projectFile);
}
return targets;
}
......
......@@ -347,6 +347,9 @@ void ServerModeReader::updateCodeModel(CppTools::RawProjectParts &rpps)
rpp.setFiles(transform(fg->sources, &FileName::toString));
const bool isExecutable = fg->target->type == "EXECUTABLE";
rpp.setBuildTargetType(isExecutable ? CppTools::ProjectPart::Executable
: CppTools::ProjectPart::Library);
rpps.append(rpp);
}
......
......@@ -388,6 +388,9 @@ void TeaLeafReader::updateCodeModel(CppTools::RawProjectParts &rpps)
rpp.setDisplayName(cbt.title);
rpp.setFiles(transform(cbt.files, [](const FileName &fn) { return fn.toString(); }));
const bool isExecutable = cbt.targetType == ExecutableType;
rpp.setBuildTargetType(isExecutable ? CppTools::ProjectPart::Executable
: CppTools::ProjectPart::Library);
rpps.append(rpp);
}
}
......
......@@ -1800,6 +1800,7 @@ void CppCodeModelInspectorDialog::updateProjectPartData(const ProjectPart::Ptr &
{QString::fromLatin1("Callgroup Id"), callGroupId},
{QString::fromLatin1("Precompiled Headers"), precompiledHeaders},
{QString::fromLatin1("Selected For Building"), CMI::Utils::toString(part->selectedForBuilding)},
{QString::fromLatin1("Build Target Type"), CMI::Utils::toString(part->buildTargetType)},
{QString::fromLatin1("Language Version"), CMI::Utils::toString(part->languageVersion)},
{QString::fromLatin1("Language Extensions"), CMI::Utils::toString(part->languageExtensions)},
{QString::fromLatin1("Qt Version"), CMI::Utils::toString(part->qtVersion)}
......
......@@ -154,6 +154,18 @@ QString Utils::toString(ProjectPart::QtVersion qtVersion)
return QString();
}
QString Utils::toString(ProjectPart::BuildTargetType buildTargetType)
{
#define CASE_BUILDTARGETTYPE(x) case ProjectPart::x: return QLatin1String(#x)
switch (buildTargetType) {
CASE_BUILDTARGETTYPE(Unknown);
CASE_BUILDTARGETTYPE(Executable);
CASE_BUILDTARGETTYPE(Library);
}
#undef CASE_BUILDTARGETTYPE
return QString();
}
QString Utils::toString(ProjectFile::Kind kind)
{
return QString::fromLatin1(projectFileKindToText(kind));
......@@ -483,6 +495,7 @@ void Dumper::dumpProjectInfos( const QList<ProjectInfo> &projectInfos)
m_out << i3 << "Project Name : " << projectName << "\n";
m_out << i3 << "Project File : " << projectFilePath << "\n";
m_out << i3 << "Selected For Building: " << part->selectedForBuilding << "\n";
m_out << i3 << "Build Target Type : " << Utils::toString(part->buildTargetType) << "\n";
m_out << i3 << "Lanugage Version : " << Utils::toString(part->languageVersion)<<"\n";
m_out << i3 << "Lanugage Extensions : " << Utils::toString(part->languageExtensions)
<< "\n";
......
......@@ -50,6 +50,7 @@ struct CPPTOOLS_EXPORT Utils
static QString toString(CppTools::ProjectPart::LanguageVersion languageVersion);
static QString toString(CppTools::ProjectPart::LanguageExtensions languageExtension);
static QString toString(CppTools::ProjectPart::QtVersion qtVersion);
static QString toString(CppTools::ProjectPart::BuildTargetType buildTargetType);
static QString toString(const QVector<CppTools::ProjectFile> &projectFiles);
static QString toString(CppTools::ProjectFile::Kind kind);
static QString toString(CPlusPlus::Kind kind);
......
......@@ -186,6 +186,7 @@ static ProjectPart::Ptr projectPartFromRawProjectPart(const RawProjectPart &rawP
part->projectFileColumn = rawProjectPart.projectFileColumn;
part->callGroupId = rawProjectPart.callGroupId;
part->buildSystemTarget = rawProjectPart.buildSystemTarget;
part->buildTargetType = rawProjectPart.buildTargetType;
part->qtVersion = rawProjectPart.qtVersion;
part->projectMacros = rawProjectPart.projectMacros;
part->headerPaths = rawProjectPart.headerPaths;
......
......@@ -133,4 +133,9 @@ void RawProjectPart::setFlagsForCxx(const RawProjectPartFlags &flags)
flagsForCxx = flags;
}
void RawProjectPart::setBuildTargetType(ProjectPart::BuildTargetType type)
{
buildTargetType = type;
}
} // namespace CppTools
......@@ -78,6 +78,7 @@ public:
void setFlagsForC(const RawProjectPartFlags &flags);
void setFlagsForCxx(const RawProjectPartFlags &flags);
void setBuildTargetType(ProjectPart::BuildTargetType type);
public:
QString displayName;
QString projectFile;
......@@ -97,6 +98,7 @@ public:
QStringList files;
FileClassifier fileClassifier;
ProjectPart::BuildTargetType buildTargetType = ProjectPart::BuildTargetType::Unknown;
};
using RawProjectParts = QVector<RawProjectPart>;
......
......@@ -91,6 +91,12 @@ public:
WordWidth64Bit,
};
enum BuildTargetType {
Unknown,
Executable,
Library
};
using Ptr = QSharedPointer<ProjectPart>;
public:
......@@ -134,6 +140,7 @@ public:
ProjectExplorer::Macros toolChainMacros;
ToolChainWordWidth toolChainWordWidth = WordWidth32Bit;
QString toolChainTargetTriple;
BuildTargetType buildTargetType = Unknown;
};
} // namespace CppTools
......@@ -1004,6 +1004,8 @@ void QbsProject::updateCppCodeModel()
rpp.setProjectFileLocation(grp.location().filePath(),
grp.location().line(), grp.location().column());
rpp.setBuildSystemTarget(prd.name());
rpp.setBuildTargetType(prd.isRunnable() ? CppTools::ProjectPart::Executable
: CppTools::ProjectPart::Library);
QHash<QString, qbs::ArtifactData> filePathToSourceArtifact;
bool hasCFiles = false;
......
......@@ -290,6 +290,10 @@ void QmakeProject::updateCppCodeModel()
rpp.setDisplayName(pro->displayName());
rpp.setProjectFileLocation(pro->filePath().toString());
rpp.setBuildSystemTarget(pro->targetInformation().target);
const bool isExecutable = pro->projectType() == ProjectType::ApplicationTemplate;
rpp.setBuildTargetType(isExecutable ? CppTools::ProjectPart::Executable
: CppTools::ProjectPart::Library);
// TODO: Handle QMAKE_CFLAGS
rpp.setFlagsForCxx({cxxToolChain, pro->variableValue(Variable::CppFlags)});
rpp.setMacros(ProjectExplorer::Macro::toMacros(pro->cxxDefines()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment