Commit 1ae50954 authored by Marco Bubke's avatar Marco Bubke

CppTools: Moving ProjectPartBuilder in its own header

Change-Id: I0aa65ec6c80dcd437f13ff70021388b0da57ccfd
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@theqtcompany.com>
parent da1f8e66
......@@ -123,42 +123,5 @@ QDebug operator<<(QDebug stream, const CppTools::ProjectFile &cxxFile)
return stream;
}
namespace Internal {
ProjectFileAdder::ProjectFileAdder(QVector<ProjectFile> &files)
: m_files(files)
{
addMapping(CppTools::Constants::C_SOURCE_MIMETYPE, ProjectFile::CSource);
addMapping(CppTools::Constants::C_HEADER_MIMETYPE, ProjectFile::CHeader);
addMapping(CppTools::Constants::CPP_SOURCE_MIMETYPE, ProjectFile::CXXSource);
addMapping(CppTools::Constants::CPP_HEADER_MIMETYPE, ProjectFile::CXXHeader);
addMapping(CppTools::Constants::OBJECTIVE_C_SOURCE_MIMETYPE, ProjectFile::ObjCSource);
addMapping(CppTools::Constants::OBJECTIVE_CPP_SOURCE_MIMETYPE, ProjectFile::ObjCXXSource);
}
ProjectFileAdder::~ProjectFileAdder()
{
}
bool ProjectFileAdder::maybeAdd(const QString &path)
{
Utils::MimeDatabase mdb;
const Utils::MimeType mt = mdb.mimeTypeForFile(path);
if (m_mimeNameMapping.contains(mt.name())) {
m_files << ProjectFile(path, m_mimeNameMapping.value(mt.name()));
return true;
}
return false;
}
void ProjectFileAdder::addMapping(const char *mimeName, ProjectFile::Kind kind)
{
Utils::MimeDatabase mdb;
Utils::MimeType mimeType = mdb.mimeTypeForName(QLatin1String(mimeName));
if (mimeType.isValid())
m_mimeNameMapping.insert(mimeType.name(), kind);
}
} // namespace Internal
} // namespace CppTools
......@@ -70,25 +70,6 @@ public:
QDebug operator<<(QDebug stream, const CppTools::ProjectFile &cxxFile);
namespace Internal {
class ProjectFileAdder
{
public:
ProjectFileAdder(QVector<ProjectFile> &files);
~ProjectFileAdder();
bool maybeAdd(const QString &path);
private:
void addMapping(const char *mimeName, ProjectFile::Kind kind);
QVector<ProjectFile> &m_files;
QHash<QString, ProjectFile::Kind> m_mimeNameMapping;
};
} // namespace Internal
} // namespace CppTools
#endif // CPPTOOLS_CPPPROJECTFILE_H
......@@ -46,235 +46,8 @@
#include <QTextStream>
using namespace CppTools;
using namespace CppTools::Internal;
using namespace ProjectExplorer;
namespace {
class ProjectFileCategorizer
{
public:
ProjectFileCategorizer(const QString &partName, const QStringList &files)
: m_partName(partName)
{
using CppTools::ProjectFile;
QStringList cHeaders, cxxHeaders;
foreach (const QString &file, files) {
switch (ProjectFile::classify(file)) {
case ProjectFile::CSource: m_cSources += file; break;
case ProjectFile::CHeader: cHeaders += file; break;
case ProjectFile::CXXSource: m_cxxSources += file; break;
case ProjectFile::CXXHeader: cxxHeaders += file; break;
case ProjectFile::ObjCSource: m_objcSources += file; break;
case ProjectFile::ObjCXXSource: m_objcxxSources += file; break;
default:
continue;
}
}
const bool hasC = !m_cSources.isEmpty();
const bool hasCxx = !m_cxxSources.isEmpty();
const bool hasObjc = !m_objcSources.isEmpty();
const bool hasObjcxx = !m_objcxxSources.isEmpty();
if (hasObjcxx)
m_objcxxSources += cxxHeaders + cHeaders;
if (hasCxx)
m_cxxSources += cxxHeaders + cHeaders;
else if (!hasObjcxx)
m_cxxSources += cxxHeaders;
if (hasObjc)
m_objcSources += cHeaders;
if (hasC || (!hasObjc && !hasObjcxx && !hasCxx))
m_cSources += cHeaders;
m_partCount =
(m_cSources.isEmpty() ? 0 : 1) +
(m_cxxSources.isEmpty() ? 0 : 1) +
(m_objcSources.isEmpty() ? 0 : 1) +
(m_objcxxSources.isEmpty() ? 0 : 1);
}
bool hasCSources() const { return !m_cSources.isEmpty(); }
bool hasCxxSources() const { return !m_cxxSources.isEmpty(); }
bool hasObjcSources() const { return !m_objcSources.isEmpty(); }
bool hasObjcxxSources() const { return !m_objcxxSources.isEmpty(); }
QStringList cSources() const { return m_cSources; }
QStringList cxxSources() const { return m_cxxSources; }
QStringList objcSources() const { return m_objcSources; }
QStringList objcxxSources() const { return m_objcxxSources; }
bool hasMultipleParts() const { return m_partCount > 1; }
bool hasNoParts() const { return m_partCount == 0; }
QString partName(const QString &languageName) const
{
if (hasMultipleParts())
return QString::fromLatin1("%1 (%2)").arg(m_partName).arg(languageName);
return m_partName;
}
private:
QString m_partName;
QStringList m_cSources, m_cxxSources, m_objcSources, m_objcxxSources;
int m_partCount;
};
} // anonymous namespace
ProjectPartBuilder::ProjectPartBuilder(ProjectInfo &pInfo)
: m_templatePart(new ProjectPart)
, m_pInfo(pInfo)
{
m_templatePart->project = pInfo.project();
m_templatePart->displayName = pInfo.project()->displayName();
m_templatePart->projectFile = pInfo.project()->projectFilePath().toString();
}
void ProjectPartBuilder::setQtVersion(ProjectPart::QtVersion qtVersion)
{
m_templatePart->qtVersion = qtVersion;
}
void ProjectPartBuilder::setCFlags(const QStringList &flags)
{
m_cFlags = flags;
}
void ProjectPartBuilder::setCxxFlags(const QStringList &flags)
{
m_cxxFlags = flags;
}
void ProjectPartBuilder::setDefines(const QByteArray &defines)
{
m_templatePart->projectDefines = defines;
}
void ProjectPartBuilder::setHeaderPaths(const ProjectPartHeaderPaths &headerPaths)
{
m_templatePart->headerPaths = headerPaths;
}
void ProjectPartBuilder::setIncludePaths(const QStringList &includePaths)
{
m_templatePart->headerPaths.clear();
foreach (const QString &includeFile, includePaths) {
ProjectPartHeaderPath hp(includeFile, ProjectPartHeaderPath::IncludePath);
// The simple project managers are utterly ignorant of frameworks on OSX, and won't report
// framework paths. The work-around is to check if the include path ends in ".framework",
// and if so, add the parent directory as framework path.
if (includeFile.endsWith(QLatin1String(".framework"))) {
const int slashIdx = includeFile.lastIndexOf(QLatin1Char('/'));
if (slashIdx != -1) {
hp = ProjectPartHeaderPath(includeFile.left(slashIdx),
ProjectPartHeaderPath::FrameworkPath);
}
}
m_templatePart->headerPaths += hp;
}
}
void ProjectPartBuilder::setPreCompiledHeaders(const QStringList &pchs)
{
m_templatePart->precompiledHeaders = pchs;
}
void ProjectPartBuilder::setProjectFile(const QString &projectFile)
{
m_templatePart->projectFile = projectFile;
}
void ProjectPartBuilder::setDisplayName(const QString &displayName)
{
m_templatePart->displayName = displayName;
}
void ProjectPartBuilder::setConfigFileName(const QString &configFileName)
{
m_templatePart->projectConfigFile = configFileName;
}
QList<Core::Id> ProjectPartBuilder::createProjectPartsForFiles(const QStringList &files)
{
QList<Core::Id> languages;
ProjectFileCategorizer cat(m_templatePart->displayName, files);
if (cat.hasNoParts())
return languages;
using CppTools::ProjectFile;
using CppTools::ProjectPart;
if (cat.hasCSources()) {
createProjectPart(cat.cSources(),
cat.partName(QCoreApplication::translate("CppTools", "C11")),
ProjectPart::C11,
ProjectPart::NoExtensions);
// TODO: there is no C...
// languages += ProjectExplorer::Constants::LANG_C;
}
if (cat.hasObjcSources()) {
createProjectPart(cat.objcSources(),
cat.partName(QCoreApplication::translate("CppTools", "Obj-C11")),
ProjectPart::C11,
ProjectPart::ObjectiveCExtensions);
// TODO: there is no Ojective-C...
// languages += ProjectExplorer::Constants::LANG_OBJC;
}
if (cat.hasCxxSources()) {
createProjectPart(cat.cxxSources(),
cat.partName(QCoreApplication::translate("CppTools", "C++11")),
ProjectPart::CXX11,
ProjectPart::NoExtensions);
languages += ProjectExplorer::Constants::LANG_CXX;
}
if (cat.hasObjcxxSources()) {
createProjectPart(cat.objcxxSources(),
cat.partName(QCoreApplication::translate("CppTools", "Obj-C++11")),
ProjectPart::CXX11,
ProjectPart::ObjectiveCExtensions);
// TODO: there is no Objective-C++...
languages += ProjectExplorer::Constants::LANG_CXX;
}
return languages;
}
void ProjectPartBuilder::createProjectPart(const QStringList &theSources,
const QString &partName,
ProjectPart::LanguageVersion languageVersion,
ProjectPart::LanguageExtensions languageExtensions)
{
ProjectPart::Ptr part(m_templatePart->copy());
part->displayName = partName;
QTC_ASSERT(part->project, return);
if (Target *activeTarget = part->project->activeTarget()) {
if (Kit *kit = activeTarget->kit()) {
if (ToolChain *toolChain = ToolChainKitInformation::toolChain(kit)) {
const QStringList flags = languageVersion >= ProjectPart::CXX98 ? m_cxxFlags
: m_cFlags;
part->evaluateToolchain(toolChain, flags, SysRootKitInformation::sysRoot(kit));
}
}
}
part->languageExtensions |= languageExtensions;
ProjectFileAdder adder(part->files);
foreach (const QString &file, theSources)
adder.maybeAdd(file);
m_pInfo.appendProjectPart(part);
}
CompilerOptionsBuilder::CompilerOptionsBuilder(const ProjectPart &projectPart)
: m_projectPart(projectPart)
{
......
......@@ -34,6 +34,7 @@
#include "cpptools_global.h"
#include "cppprojectfile.h"
#include "projectpartbuilder.h"
#include "projectinfo.h"
#include "projectpart.h"
......@@ -52,34 +53,6 @@ namespace Utils { class FileName; }
namespace CppTools {
class CPPTOOLS_EXPORT ProjectPartBuilder
{
public:
ProjectPartBuilder(ProjectInfo &m_pInfo);
void setQtVersion(ProjectPart::QtVersion qtVersion);
void setCFlags(const QStringList &flags);
void setCxxFlags(const QStringList &flags);
void setDefines(const QByteArray &defines);
void setHeaderPaths(const ProjectPartHeaderPaths &headerPaths);
void setIncludePaths(const QStringList &includePaths);
void setPreCompiledHeaders(const QStringList &pchs);
void setProjectFile(const QString &projectFile);
void setDisplayName(const QString &displayName);
void setConfigFileName(const QString &configFileName);
QList<Core::Id> createProjectPartsForFiles(const QStringList &files);
private:
void createProjectPart(const QStringList &theSources, const QString &partName,
ProjectPart::LanguageVersion languageVersion,
ProjectPart::LanguageExtensions languageExtensions);
private:
ProjectPart::Ptr m_templatePart;
ProjectInfo &m_pInfo;
QStringList m_cFlags, m_cxxFlags;
};
class CPPTOOLS_EXPORT CompilerOptionsBuilder
{
......
......@@ -72,7 +72,8 @@ HEADERS += \
cpptoolsbridgeqtcreatorimplementation.h \
projectpart.h \
projectpartheaderpath.h \
projectinfo.h
projectinfo.h \
projectpartbuilder.h
SOURCES += \
abstracteditorsupport.cpp \
......@@ -140,7 +141,8 @@ SOURCES += \
cpptoolsbridge.cpp \
cpptoolsbridgeqtcreatorimplementation.cpp \
projectpart.cpp \
projectinfo.cpp
projectinfo.cpp \
projectpartbuilder.cpp
FORMS += \
completionsettingspage.ui \
......
......@@ -88,6 +88,7 @@ QtcPlugin {
"insertionpointlocator.cpp", "insertionpointlocator.h",
"projectinfo.cpp", "projectinfo.h",
"projectpart.cpp", "projectpart.h",
"projectpartbuilder.cpp", "projectpartbuilder.h",
"projectpartheaderpath.h",
"searchsymbols.cpp", "searchsymbols.h",
"semantichighlighter.cpp", "semantichighlighter.h",
......
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CPPTOOLS_PROJECTPARTBUILDER_H
#define CPPTOOLS_PROJECTPARTBUILDER_H
#include "cpptools_global.h"
#include "projectinfo.h"
#include "projectpart.h"
namespace CppTools {
class CPPTOOLS_EXPORT ProjectPartBuilder
{
public:
ProjectPartBuilder(ProjectInfo &m_pInfo);
void setQtVersion(ProjectPart::QtVersion qtVersion);
void setCFlags(const QStringList &flags);
void setCxxFlags(const QStringList &flags);
void setDefines(const QByteArray &defines);
void setHeaderPaths(const ProjectPartHeaderPaths &headerPaths);
void setIncludePaths(const QStringList &includePaths);
void setPreCompiledHeaders(const QStringList &pchs);
void setProjectFile(const QString &projectFile);
void setDisplayName(const QString &displayName);
void setConfigFileName(const QString &configFileName);
QList<Core::Id> createProjectPartsForFiles(const QStringList &files);
private:
void createProjectPart(const QStringList &theSources, const QString &partName,
ProjectPart::LanguageVersion languageVersion,
ProjectPart::LanguageExtensions languageExtensions);
private:
ProjectPart::Ptr m_templatePart;
ProjectInfo &m_pInfo;
QStringList m_cFlags, m_cxxFlags;
};
} // namespace CppTools
#endif // CPPTOOLS_PROJECTPARTBUILDER_H
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