Commit 255b5850 authored by Benjamin Zeller's avatar Benjamin Zeller

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: default avatarDaniel Teske <daniel.teske@theqtcompany.com>
parent 9f7c801e
......@@ -29,6 +29,8 @@
****************************************************************************/
#include "cmakecbpparser.h"
#include "cmakekitinformation.h"
#include "cmaketool.h"
#include <utils/fileutils.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";
}
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_sourceDirectory = sourceDirectory;
......@@ -245,6 +248,9 @@ void CMakeCbpParser::parseBuildTargetOption()
{
if (attributes().hasAttribute(QLatin1String("output"))) {
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"))) {
const QStringRef value = attributes().value(QLatin1String("type"));
if (value == QLatin1String("2") || value == QLatin1String("3"))
......@@ -304,8 +310,13 @@ void CMakeCbpParser::parseMakeCommands()
void CMakeCbpParser::parseBuildTargetBuild()
{
if (attributes().hasAttribute(QLatin1String("command")))
if (attributes().hasAttribute(QLatin1String("command"))) {
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()) {
readNext();
if (isEndElement())
......@@ -317,8 +328,13 @@ void CMakeCbpParser::parseBuildTargetBuild()
void CMakeCbpParser::parseBuildTargetClean()
{
if (attributes().hasAttribute(QLatin1String("command")))
if (attributes().hasAttribute(QLatin1String("command"))) {
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()) {
readNext();
if (isEndElement())
......@@ -346,7 +362,12 @@ void CMakeCbpParser::parseAdd()
// CMake only supports <Add option=\> and <Add directory=\>
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
if (!includeDirectory.isEmpty())
m_buildTarget.includeFiles.append(includeDirectory);
......@@ -380,6 +401,13 @@ void CMakeCbpParser::parseUnit()
//qDebug()<<stream.attributes().value("filename");
FileName fileName =
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;
while (!atEnd()) {
readNext();
......
......@@ -36,7 +36,10 @@
#include <QXmlStreamReader>
namespace ProjectExplorer { class FileNode; }
namespace ProjectExplorer {
class FileNode;
class Kit;
}
namespace CMakeProjectManager {
namespace Internal {
......@@ -44,7 +47,7 @@ namespace Internal {
class CMakeCbpParser : public QXmlStreamReader
{
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 *> cmakeFileList();
QList<CMakeBuildTarget> buildTargets();
......@@ -69,6 +72,7 @@ private:
void parseUnknownElement();
void sortFiles();
ProjectExplorer::Kit *m_kit;
QList<ProjectExplorer::FileNode *> m_fileList;
QList<ProjectExplorer::FileNode *> m_cmakeFileList;
QSet<Utils::FileName> m_processedUnits;
......
......@@ -246,12 +246,14 @@ bool CMakeProject::parseCMakeLists()
return false;
}
Kit *k = activeTarget()->kit();
// setFolderName
m_rootNode->setDisplayName(QFileInfo(cbpFile).completeBaseName());
CMakeCbpParser cbpparser;
// Parsing
//qDebug()<<"Parsing file "<<cbpFile;
if (!cbpparser.parseCbpFile(cbpFile, projectDirectory().toString())) {
if (!cbpparser.parseCbpFile(k,cbpFile, projectDirectory().toString())) {
// TODO report error
emit buildTargetsChanged();
return false;
......@@ -305,7 +307,6 @@ bool CMakeProject::parseCMakeLists()
createUiCodeModelSupport();
Kit *k = activeTarget()->kit();
ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(k);
if (!tc) {
emit buildTargetsChanged();
......
......@@ -284,6 +284,17 @@ void CMakeTool::setDisplayName(const QString &displayName)
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)
{
......
......@@ -43,6 +43,8 @@
QT_FORWARD_DECLARE_CLASS(QProcess)
namespace ProjectExplorer { class Kit; }
namespace CMakeProjectManager {
class CMAKE_EXPORT CMakeTool : public QObject
......@@ -54,6 +56,8 @@ public:
AutoDetection
};
typedef std::function<QString (ProjectExplorer::Kit *, const QString &)> PathMapper;
explicit CMakeTool(Detection d, const Core::Id &id = Core::Id());
explicit CMakeTool(const QVariantMap &map, bool fromSdk);
~CMakeTool();
......@@ -75,6 +79,9 @@ public:
QString displayName() const;
void setDisplayName(const QString &displayName);
void setPathMapper(const PathMapper &includePathMapper);
QString mapAllPaths(ProjectExplorer::Kit *kit, const QString &in) const;
private slots:
void finished(int exitCode);
......@@ -103,6 +110,7 @@ private:
Core::Id m_id;
QString m_displayName;
PathMapper m_pathMapper;
};
} // namespace CMakeProjectManager
......
......@@ -394,6 +394,7 @@ void CMakeToolManager::restoreCMakeTools()
// restore the legacy cmake settings only once and keep them around
readAndDeleteLegacyCMakeSettings();
emit m_instance->cmakeToolsLoaded();
}
void CMakeToolManager::registerAutodetectionHelper(CMakeToolManager::AutodetectionHelper helper)
......
......@@ -75,6 +75,7 @@ signals:
void cmakeRemoved (const Core::Id &id);
void cmakeUpdated (const Core::Id &id);
void cmakeToolsChanged ();
void cmakeToolsLoaded ();
void defaultCMakeChanged ();
private:
......
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