Skip to content
Snippets Groups Projects
Commit bc77bd9e authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Simplify codepath

Reviewed-by: dt
parent 5c651c9f
No related branches found
No related tags found
No related merge requests found
...@@ -167,45 +167,51 @@ bool CMakeProject::parseCMakeLists() ...@@ -167,45 +167,51 @@ bool CMakeProject::parseCMakeLists()
CMakeCbpParser cbpparser; CMakeCbpParser cbpparser;
// Parsing // Parsing
//qDebug()<<"Parsing file "<<cbpFile; //qDebug()<<"Parsing file "<<cbpFile;
if (cbpparser.parseCbpFile(cbpFile)) { if (!cbpparser.parseCbpFile(cbpFile)) {
// ToolChain // TODO report error
// activeBC->updateToolChain(cbpparser.compilerName()); qDebug()<<"Parsing failed";
// activeBC->updateToolChain(QString::null);
emit buildTargetsChanged();
return false;
}
m_projectName = cbpparser.projectName(); // ToolChain
m_rootNode->setFolderName(cbpparser.projectName()); // activeBC->updateToolChain(cbpparser.compilerName());
m_projectName = cbpparser.projectName();
m_rootNode->setFolderName(cbpparser.projectName());
//qDebug()<<"Building Tree"; //qDebug()<<"Building Tree";
QList<ProjectExplorer::FileNode *> fileList = cbpparser.fileList(); QList<ProjectExplorer::FileNode *> fileList = cbpparser.fileList();
QSet<QString> projectFiles; QSet<QString> projectFiles;
if (cbpparser.hasCMakeFiles()) { if (cbpparser.hasCMakeFiles()) {
fileList.append(cbpparser.cmakeFileList()); fileList.append(cbpparser.cmakeFileList());
foreach(const ProjectExplorer::FileNode *node, cbpparser.cmakeFileList()) foreach(const ProjectExplorer::FileNode *node, cbpparser.cmakeFileList())
projectFiles.insert(node->path()); projectFiles.insert(node->path());
} else { } else {
// Manually add the CMakeLists.txt file // Manually add the CMakeLists.txt file
QString cmakeListTxt = sourceDirectory() + "/CMakeLists.txt"; QString cmakeListTxt = sourceDirectory() + "/CMakeLists.txt";
fileList.append(new ProjectExplorer::FileNode(cmakeListTxt, ProjectExplorer::ProjectFileType, false)); fileList.append(new ProjectExplorer::FileNode(cmakeListTxt, ProjectExplorer::ProjectFileType, false));
projectFiles.insert(cmakeListTxt); projectFiles.insert(cmakeListTxt);
} }
QSet<QString> added = projectFiles; QSet<QString> added = projectFiles;
added.subtract(m_watchedFiles); added.subtract(m_watchedFiles);
foreach(const QString &add, added) foreach(const QString &add, added)
m_watcher->addFile(add); m_watcher->addFile(add);
foreach(const QString &remove, m_watchedFiles.subtract(projectFiles)) foreach(const QString &remove, m_watchedFiles.subtract(projectFiles))
m_watcher->removeFile(remove); m_watcher->removeFile(remove);
m_watchedFiles = projectFiles; m_watchedFiles = projectFiles;
m_files.clear(); m_files.clear();
foreach (ProjectExplorer::FileNode *fn, fileList) foreach (ProjectExplorer::FileNode *fn, fileList)
m_files.append(fn->path()); m_files.append(fn->path());
m_files.sort(); m_files.sort();
buildTree(m_rootNode, fileList); buildTree(m_rootNode, fileList);
//qDebug()<<"Adding Targets"; //qDebug()<<"Adding Targets";
m_buildTargets = cbpparser.buildTargets(); m_buildTargets = cbpparser.buildTargets();
// qDebug()<<"Printing targets"; // qDebug()<<"Printing targets";
// foreach(CMakeTarget ct, m_targets) { // foreach(CMakeTarget ct, m_targets) {
// qDebug()<<ct.title<<" with executable:"<<ct.executable; // qDebug()<<ct.title<<" with executable:"<<ct.executable;
...@@ -214,94 +220,88 @@ bool CMakeProject::parseCMakeLists() ...@@ -214,94 +220,88 @@ bool CMakeProject::parseCMakeLists()
// qDebug()<<""; // qDebug()<<"";
// } // }
//qDebug()<<"Updating CodeModel"; //qDebug()<<"Updating CodeModel";
QStringList allIncludePaths; QStringList allIncludePaths;
QStringList allFrameworkPaths; QStringList allFrameworkPaths;
QList<ProjectExplorer::HeaderPath> allHeaderPaths = activeBC->toolChain()->systemHeaderPaths(); QList<ProjectExplorer::HeaderPath> allHeaderPaths = activeBC->toolChain()->systemHeaderPaths();
foreach (const ProjectExplorer::HeaderPath &headerPath, allHeaderPaths) { foreach (const ProjectExplorer::HeaderPath &headerPath, allHeaderPaths) {
if (headerPath.kind() == ProjectExplorer::HeaderPath::FrameworkHeaderPath) if (headerPath.kind() == ProjectExplorer::HeaderPath::FrameworkHeaderPath)
allFrameworkPaths.append(headerPath.path()); allFrameworkPaths.append(headerPath.path());
else else
allIncludePaths.append(headerPath.path()); allIncludePaths.append(headerPath.path());
} }
// This explicitly adds -I. to the include paths // This explicitly adds -I. to the include paths
allIncludePaths.append(sourceDirectory()); allIncludePaths.append(sourceDirectory());
allIncludePaths.append(cbpparser.includeFiles()); allIncludePaths.append(cbpparser.includeFiles());
CppTools::CppModelManagerInterface *modelmanager = CppTools::CppModelManagerInterface *modelmanager =
ExtensionSystem::PluginManager::instance()->getObject<CppTools::CppModelManagerInterface>(); ExtensionSystem::PluginManager::instance()->getObject<CppTools::CppModelManagerInterface>();
if (modelmanager) { if (modelmanager) {
CppTools::CppModelManagerInterface::ProjectInfo pinfo = modelmanager->projectInfo(this); CppTools::CppModelManagerInterface::ProjectInfo pinfo = modelmanager->projectInfo(this);
if (pinfo.includePaths != allIncludePaths if (pinfo.includePaths != allIncludePaths
|| pinfo.sourceFiles != m_files || pinfo.sourceFiles != m_files
|| pinfo.defines != activeBC->toolChain()->predefinedMacros() || pinfo.defines != activeBC->toolChain()->predefinedMacros()
|| pinfo.frameworkPaths != allFrameworkPaths) { || pinfo.frameworkPaths != allFrameworkPaths) {
pinfo.includePaths = allIncludePaths; pinfo.includePaths = allIncludePaths;
// TODO we only want C++ files, not all other stuff that might be in the project // TODO we only want C++ files, not all other stuff that might be in the project
pinfo.sourceFiles = m_files; pinfo.sourceFiles = m_files;
pinfo.defines = activeBC->toolChain()->predefinedMacros(); // TODO this is to simplistic pinfo.defines = activeBC->toolChain()->predefinedMacros(); // TODO this is to simplistic
pinfo.frameworkPaths = allFrameworkPaths; pinfo.frameworkPaths = allFrameworkPaths;
modelmanager->updateProjectInfo(pinfo); modelmanager->updateProjectInfo(pinfo);
modelmanager->updateSourceFiles(pinfo.sourceFiles); modelmanager->updateSourceFiles(pinfo.sourceFiles);
}
} }
}
// Create run configurations for m_targets // Create run configurations for m_targets
//qDebug()<<"Create run configurations of m_targets"; //qDebug()<<"Create run configurations of m_targets";
QMultiMap<QString, CMakeRunConfiguration* > existingRunConfigurations; QMultiMap<QString, CMakeRunConfiguration* > existingRunConfigurations;
foreach(ProjectExplorer::RunConfiguration* cmakeRunConfiguration, runConfigurations()) { foreach(ProjectExplorer::RunConfiguration* cmakeRunConfiguration, runConfigurations()) {
if (CMakeRunConfiguration* rc = qobject_cast<CMakeRunConfiguration *>(cmakeRunConfiguration)) { if (CMakeRunConfiguration* rc = qobject_cast<CMakeRunConfiguration *>(cmakeRunConfiguration)) {
existingRunConfigurations.insert(rc->title(), rc); existingRunConfigurations.insert(rc->title(), rc);
}
} }
}
bool setActive = existingRunConfigurations.isEmpty(); bool setActive = existingRunConfigurations.isEmpty();
foreach(const CMakeBuildTarget &ct, m_buildTargets) { foreach(const CMakeBuildTarget &ct, m_buildTargets) {
if (ct.executable.isEmpty()) if (ct.executable.isEmpty())
continue; continue;
if (ct.title.endsWith(QLatin1String("/fast"))) if (ct.title.endsWith(QLatin1String("/fast")))
continue; continue;
QList<CMakeRunConfiguration *> list = existingRunConfigurations.values(ct.title); QList<CMakeRunConfiguration *> list = existingRunConfigurations.values(ct.title);
if (!list.isEmpty()) { if (!list.isEmpty()) {
// Already exists, so override the settings... // Already exists, so override the settings...
foreach (CMakeRunConfiguration *rc, list) { foreach (CMakeRunConfiguration *rc, list) {
//qDebug()<<"Updating Run Configuration with title"<<ct.title; //qDebug()<<"Updating Run Configuration with title"<<ct.title;
//qDebug()<<" Executable new:"<<ct.executable<< "old:"<<rc->executable(); //qDebug()<<" Executable new:"<<ct.executable<< "old:"<<rc->executable();
//qDebug()<<" WD new:"<<ct.workingDirectory<<"old:"<<rc->workingDirectory(); //qDebug()<<" WD new:"<<ct.workingDirectory<<"old:"<<rc->workingDirectory();
rc->setExecutable(ct.executable); rc->setExecutable(ct.executable);
rc->setWorkingDirectory(ct.workingDirectory); rc->setWorkingDirectory(ct.workingDirectory);
} }
existingRunConfigurations.remove(ct.title); existingRunConfigurations.remove(ct.title);
} else { } else {
// Does not exist yet // Does not exist yet
//qDebug()<<"Adding new run configuration with title"<<ct.title; //qDebug()<<"Adding new run configuration with title"<<ct.title;
//qDebug()<<" Executable:"<<ct.executable<<"WD:"<<ct.workingDirectory; //qDebug()<<" Executable:"<<ct.executable<<"WD:"<<ct.workingDirectory;
ProjectExplorer::RunConfiguration *rc(new CMakeRunConfiguration(this, ct.executable, ct.workingDirectory, ct.title)); ProjectExplorer::RunConfiguration *rc(new CMakeRunConfiguration(this, ct.executable, ct.workingDirectory, ct.title));
addRunConfiguration(rc); addRunConfiguration(rc);
// The first one gets the honour of being the active one // The first one gets the honour of being the active one
if (setActive) { if (setActive) {
setActiveRunConfiguration(rc); setActiveRunConfiguration(rc);
setActive = false; setActive = false;
}
} }
} }
QMultiMap<QString, CMakeRunConfiguration *>::const_iterator it =
existingRunConfigurations.constBegin();
for( ; it != existingRunConfigurations.constEnd(); ++it) {
CMakeRunConfiguration *rc = it.value();
//qDebug()<<"Removing old RunConfiguration with title:"<<rc->title();
//qDebug()<<" Executable:"<<rc->executable()<<rc->workingDirectory();
removeRunConfiguration(rc);
}
//qDebug()<<"\n";
} else {
// TODO report error
qDebug()<<"Parsing failed";
// activeBC->updateToolChain(QString::null);
emit buildTargetsChanged();
return false;
} }
QMultiMap<QString, CMakeRunConfiguration *>::const_iterator it =
existingRunConfigurations.constBegin();
for( ; it != existingRunConfigurations.constEnd(); ++it) {
CMakeRunConfiguration *rc = it.value();
//qDebug()<<"Removing old RunConfiguration with title:"<<rc->title();
//qDebug()<<" Executable:"<<rc->executable()<<rc->workingDirectory();
removeRunConfiguration(rc);
}
//qDebug()<<"\n";
emit buildTargetsChanged(); emit buildTargetsChanged();
return true; return true;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment