CMakeProjectManager: Support mapping chroot include paths

Provide a way for plugins to map include paths into a build chroot.
Plugins can register a path mapper if required, otherwise the paths
are not touched.

Change-Id: I621982831fa354d6d0f558a6c1dce4e014421f12
Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
Benjamin Zeller
2015-03-10 15:47:09 +01:00
parent 9f7c801e4d
commit 255b5850e2
7 changed files with 62 additions and 8 deletions

View File

@@ -29,6 +29,8 @@
****************************************************************************/ ****************************************************************************/
#include "cmakecbpparser.h" #include "cmakecbpparser.h"
#include "cmakekitinformation.h"
#include "cmaketool.h"
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/stringutils.h> #include <utils/stringutils.h>
@@ -147,8 +149,9 @@ void CMakeCbpParser::sortFiles()
qCDebug(log) << target.title << target.sourceDirectory << target.includeFiles << target.defines << target.files << "\n"; 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(Kit *kit, const QString &fileName, const QString &sourceDirectory)
{ {
m_kit = kit;
m_buildDirectory = QFileInfo(fileName).absolutePath(); m_buildDirectory = QFileInfo(fileName).absolutePath();
m_sourceDirectory = sourceDirectory; m_sourceDirectory = sourceDirectory;
@@ -245,6 +248,9 @@ void CMakeCbpParser::parseBuildTargetOption()
{ {
if (attributes().hasAttribute(QLatin1String("output"))) { if (attributes().hasAttribute(QLatin1String("output"))) {
m_buildTarget.executable = attributes().value(QLatin1String("output")).toString(); m_buildTarget.executable = attributes().value(QLatin1String("output")).toString();
CMakeTool *tool = CMakeKitInformation::cmakeTool(m_kit);
if (tool)
m_buildTarget.executable = tool->mapAllPaths(m_kit, m_buildTarget.executable);
} else if (attributes().hasAttribute(QLatin1String("type"))) { } else if (attributes().hasAttribute(QLatin1String("type"))) {
const QStringRef value = attributes().value(QLatin1String("type")); const QStringRef value = attributes().value(QLatin1String("type"));
if (value == QLatin1String("2") || value == QLatin1String("3")) if (value == QLatin1String("2") || value == QLatin1String("3"))
@@ -304,8 +310,13 @@ void CMakeCbpParser::parseMakeCommands()
void CMakeCbpParser::parseBuildTargetBuild() void CMakeCbpParser::parseBuildTargetBuild()
{ {
if (attributes().hasAttribute(QLatin1String("command"))) if (attributes().hasAttribute(QLatin1String("command"))) {
m_buildTarget.makeCommand = attributes().value(QLatin1String("command")).toString(); m_buildTarget.makeCommand = attributes().value(QLatin1String("command")).toString();
CMakeTool *tool = CMakeKitInformation::cmakeTool(m_kit);
if (tool)
m_buildTarget.makeCommand = tool->mapAllPaths(m_kit, m_buildTarget.makeCommand);
}
while (!atEnd()) { while (!atEnd()) {
readNext(); readNext();
if (isEndElement()) if (isEndElement())
@@ -317,8 +328,13 @@ void CMakeCbpParser::parseBuildTargetBuild()
void CMakeCbpParser::parseBuildTargetClean() void CMakeCbpParser::parseBuildTargetClean()
{ {
if (attributes().hasAttribute(QLatin1String("command"))) if (attributes().hasAttribute(QLatin1String("command"))) {
m_buildTarget.makeCleanCommand = attributes().value(QLatin1String("command")).toString(); m_buildTarget.makeCleanCommand = attributes().value(QLatin1String("command")).toString();
CMakeTool *tool = CMakeKitInformation::cmakeTool(m_kit);
if (tool)
m_buildTarget.makeCleanCommand = tool->mapAllPaths(m_kit, m_buildTarget.makeCleanCommand);
}
while (!atEnd()) { while (!atEnd()) {
readNext(); readNext();
if (isEndElement()) if (isEndElement())
@@ -346,7 +362,12 @@ void CMakeCbpParser::parseAdd()
// CMake only supports <Add option=\> and <Add directory=\> // CMake only supports <Add option=\> and <Add directory=\>
const QXmlStreamAttributes addAttributes = attributes(); const QXmlStreamAttributes addAttributes = attributes();
const QString includeDirectory = addAttributes.value(QLatin1String("directory")).toString(); QString includeDirectory = addAttributes.value(QLatin1String("directory")).toString();
CMakeTool *tool = CMakeKitInformation::cmakeTool(m_kit);
if (tool)
includeDirectory = tool->mapAllPaths(m_kit, includeDirectory);
// allow adding multiple times because order happens // allow adding multiple times because order happens
if (!includeDirectory.isEmpty()) if (!includeDirectory.isEmpty())
m_buildTarget.includeFiles.append(includeDirectory); m_buildTarget.includeFiles.append(includeDirectory);
@@ -380,6 +401,13 @@ void CMakeCbpParser::parseUnit()
//qDebug()<<stream.attributes().value("filename"); //qDebug()<<stream.attributes().value("filename");
FileName fileName = FileName fileName =
FileName::fromUserInput(attributes().value(QLatin1String("filename")).toString()); FileName::fromUserInput(attributes().value(QLatin1String("filename")).toString());
CMakeTool *tool = CMakeKitInformation::cmakeTool(m_kit);
if (tool) {
QString mappedFile = tool->mapAllPaths(m_kit, fileName.toString());
fileName = FileName::fromUserInput(mappedFile);
}
m_parsingCmakeUnit = false; m_parsingCmakeUnit = false;
while (!atEnd()) { while (!atEnd()) {
readNext(); readNext();

View File

@@ -36,7 +36,10 @@
#include <QXmlStreamReader> #include <QXmlStreamReader>
namespace ProjectExplorer { class FileNode; } namespace ProjectExplorer {
class FileNode;
class Kit;
}
namespace CMakeProjectManager { namespace CMakeProjectManager {
namespace Internal { namespace Internal {
@@ -44,7 +47,7 @@ namespace Internal {
class CMakeCbpParser : public QXmlStreamReader class CMakeCbpParser : public QXmlStreamReader
{ {
public: public:
bool parseCbpFile(const QString &fileName, const QString &sourceDirectory); bool parseCbpFile(ProjectExplorer::Kit *kit, const QString &fileName, const QString &sourceDirectory);
QList<ProjectExplorer::FileNode *> fileList(); QList<ProjectExplorer::FileNode *> fileList();
QList<ProjectExplorer::FileNode *> cmakeFileList(); QList<ProjectExplorer::FileNode *> cmakeFileList();
QList<CMakeBuildTarget> buildTargets(); QList<CMakeBuildTarget> buildTargets();
@@ -69,6 +72,7 @@ private:
void parseUnknownElement(); void parseUnknownElement();
void sortFiles(); void sortFiles();
ProjectExplorer::Kit *m_kit;
QList<ProjectExplorer::FileNode *> m_fileList; QList<ProjectExplorer::FileNode *> m_fileList;
QList<ProjectExplorer::FileNode *> m_cmakeFileList; QList<ProjectExplorer::FileNode *> m_cmakeFileList;
QSet<Utils::FileName> m_processedUnits; QSet<Utils::FileName> m_processedUnits;

View File

@@ -246,12 +246,14 @@ bool CMakeProject::parseCMakeLists()
return false; return false;
} }
Kit *k = activeTarget()->kit();
// setFolderName // setFolderName
m_rootNode->setDisplayName(QFileInfo(cbpFile).completeBaseName()); m_rootNode->setDisplayName(QFileInfo(cbpFile).completeBaseName());
CMakeCbpParser cbpparser; CMakeCbpParser cbpparser;
// Parsing // Parsing
//qDebug()<<"Parsing file "<<cbpFile; //qDebug()<<"Parsing file "<<cbpFile;
if (!cbpparser.parseCbpFile(cbpFile, projectDirectory().toString())) { if (!cbpparser.parseCbpFile(k,cbpFile, projectDirectory().toString())) {
// TODO report error // TODO report error
emit buildTargetsChanged(); emit buildTargetsChanged();
return false; return false;
@@ -305,7 +307,6 @@ bool CMakeProject::parseCMakeLists()
createUiCodeModelSupport(); createUiCodeModelSupport();
Kit *k = activeTarget()->kit();
ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(k); ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(k);
if (!tc) { if (!tc) {
emit buildTargetsChanged(); emit buildTargetsChanged();

View File

@@ -284,6 +284,17 @@ void CMakeTool::setDisplayName(const QString &displayName)
CMakeToolManager::notifyAboutUpdate(this); CMakeToolManager::notifyAboutUpdate(this);
} }
void CMakeTool::setPathMapper(const CMakeTool::PathMapper &pathMapper)
{
m_pathMapper = pathMapper;
}
QString CMakeTool::mapAllPaths(ProjectExplorer::Kit *kit, const QString &in) const
{
if (m_pathMapper)
return m_pathMapper(kit, in);
return in;
}
void CMakeTool::parseFunctionDetailsOutput(const QByteArray &output) void CMakeTool::parseFunctionDetailsOutput(const QByteArray &output)
{ {

View File

@@ -43,6 +43,8 @@
QT_FORWARD_DECLARE_CLASS(QProcess) QT_FORWARD_DECLARE_CLASS(QProcess)
namespace ProjectExplorer { class Kit; }
namespace CMakeProjectManager { namespace CMakeProjectManager {
class CMAKE_EXPORT CMakeTool : public QObject class CMAKE_EXPORT CMakeTool : public QObject
@@ -54,6 +56,8 @@ public:
AutoDetection AutoDetection
}; };
typedef std::function<QString (ProjectExplorer::Kit *, const QString &)> PathMapper;
explicit CMakeTool(Detection d, const Core::Id &id = Core::Id()); explicit CMakeTool(Detection d, const Core::Id &id = Core::Id());
explicit CMakeTool(const QVariantMap &map, bool fromSdk); explicit CMakeTool(const QVariantMap &map, bool fromSdk);
~CMakeTool(); ~CMakeTool();
@@ -75,6 +79,9 @@ public:
QString displayName() const; QString displayName() const;
void setDisplayName(const QString &displayName); void setDisplayName(const QString &displayName);
void setPathMapper(const PathMapper &includePathMapper);
QString mapAllPaths(ProjectExplorer::Kit *kit, const QString &in) const;
private slots: private slots:
void finished(int exitCode); void finished(int exitCode);
@@ -103,6 +110,7 @@ private:
Core::Id m_id; Core::Id m_id;
QString m_displayName; QString m_displayName;
PathMapper m_pathMapper;
}; };
} // namespace CMakeProjectManager } // namespace CMakeProjectManager

View File

@@ -394,6 +394,7 @@ void CMakeToolManager::restoreCMakeTools()
// restore the legacy cmake settings only once and keep them around // restore the legacy cmake settings only once and keep them around
readAndDeleteLegacyCMakeSettings(); readAndDeleteLegacyCMakeSettings();
emit m_instance->cmakeToolsLoaded();
} }
void CMakeToolManager::registerAutodetectionHelper(CMakeToolManager::AutodetectionHelper helper) void CMakeToolManager::registerAutodetectionHelper(CMakeToolManager::AutodetectionHelper helper)

View File

@@ -75,6 +75,7 @@ signals:
void cmakeRemoved (const Core::Id &id); void cmakeRemoved (const Core::Id &id);
void cmakeUpdated (const Core::Id &id); void cmakeUpdated (const Core::Id &id);
void cmakeToolsChanged (); void cmakeToolsChanged ();
void cmakeToolsLoaded ();
void defaultCMakeChanged (); void defaultCMakeChanged ();
private: private: