2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-03-10 14:20:07 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2009-03-10 14:20:07 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-03-10 14:20:07 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2009-03-10 14:20:07 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-03-10 14:20:07 +01:00
|
|
|
|
|
|
|
|
#include "genericproject.h"
|
2010-02-08 15:50:06 +01:00
|
|
|
|
2009-11-23 12:11:48 +01:00
|
|
|
#include "genericbuildconfiguration.h"
|
2012-04-24 15:49:09 +02:00
|
|
|
#include "genericmakestep.h"
|
2012-08-14 15:37:38 +02:00
|
|
|
#include "genericprojectconstants.h"
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2012-08-14 15:37:38 +02:00
|
|
|
#include <coreplugin/documentmanager.h>
|
|
|
|
|
#include <coreplugin/icontext.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2013-01-08 16:08:38 +01:00
|
|
|
#include <cpptools/cpptoolsconstants.h>
|
2014-09-15 00:12:27 +02:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
2016-01-12 12:51:33 +01:00
|
|
|
#include <cpptools/projectinfo.h>
|
2017-02-06 16:59:53 +01:00
|
|
|
#include <cpptools/cppprojectupdater.h>
|
2012-08-14 15:37:38 +02:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2011-08-18 13:46:52 +02:00
|
|
|
#include <projectexplorer/abi.h>
|
2012-04-24 15:49:09 +02:00
|
|
|
#include <projectexplorer/buildsteplist.h>
|
2016-05-12 17:42:36 +02:00
|
|
|
#include <projectexplorer/customexecutablerunconfiguration.h>
|
2011-02-28 16:50:14 +01:00
|
|
|
#include <projectexplorer/headerpath.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
|
#include <projectexplorer/kitmanager.h>
|
2009-03-10 14:20:07 +01:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2015-04-21 09:08:07 +03:00
|
|
|
#include <qtsupport/baseqtversion.h>
|
|
|
|
|
#include <qtsupport/qtkitinformation.h>
|
2015-12-22 13:27:22 +01:00
|
|
|
#include <utils/algorithm.h>
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
2012-08-14 15:37:38 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDir>
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2012-08-14 15:37:38 +02:00
|
|
|
using namespace Core;
|
2009-09-24 16:02:02 +02:00
|
|
|
using namespace ProjectExplorer;
|
2017-03-03 18:16:34 +01:00
|
|
|
using namespace Utils;
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2012-08-14 15:37:38 +02:00
|
|
|
namespace GenericProjectManager {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2009-03-18 13:33:00 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
2012-08-14 15:37:38 +02:00
|
|
|
//
|
2009-03-18 13:33:00 +01:00
|
|
|
// GenericProject
|
2012-08-14 15:37:38 +02:00
|
|
|
//
|
2009-03-18 13:33:00 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2017-03-29 11:25:01 +02:00
|
|
|
GenericProject::GenericProject(const Utils::FileName &fileName) :
|
|
|
|
|
Project(Constants::GENERICMIMETYPE, fileName, [this]() { refresh(Everything); }),
|
|
|
|
|
m_cppCodeModelUpdater(new CppTools::CppProjectUpdater(this))
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2013-09-27 16:30:20 +02:00
|
|
|
setId(Constants::GENERICPROJECT_ID);
|
2012-08-14 15:37:38 +02:00
|
|
|
setProjectContext(Context(GenericProjectManager::Constants::PROJECTCONTEXT));
|
2017-01-30 14:59:10 +01:00
|
|
|
setProjectLanguages(Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
|
2011-04-12 12:17:19 +02:00
|
|
|
|
2016-12-25 17:59:17 +01:00
|
|
|
const QFileInfo fileInfo = projectFilePath().toFileInfo();
|
|
|
|
|
const QDir dir = fileInfo.dir();
|
2009-03-16 11:49:57 +01:00
|
|
|
|
2017-03-03 17:10:00 +01:00
|
|
|
const QString projectName = fileInfo.completeBaseName();
|
|
|
|
|
|
|
|
|
|
m_filesFileName = QFileInfo(dir, projectName + ".files").absoluteFilePath();
|
|
|
|
|
m_includesFileName = QFileInfo(dir, projectName + ".includes").absoluteFilePath();
|
|
|
|
|
m_configFileName = QFileInfo(dir, projectName + ".config").absoluteFilePath();
|
2009-03-16 11:49:57 +01:00
|
|
|
|
2017-03-29 11:11:49 +02:00
|
|
|
m_filesIDocument
|
|
|
|
|
= new ProjectDocument(Constants::GENERICMIMETYPE, FileName::fromString(m_filesFileName),
|
|
|
|
|
[this]() { refresh(Files); });
|
|
|
|
|
m_includesIDocument
|
|
|
|
|
= new ProjectDocument(Constants::GENERICMIMETYPE, FileName::fromString(m_includesFileName),
|
|
|
|
|
[this]() { refresh(Configuration); });
|
|
|
|
|
m_configIDocument
|
|
|
|
|
= new ProjectDocument(Constants::GENERICMIMETYPE, FileName::fromString(m_configFileName),
|
|
|
|
|
[this]() { refresh(Configuration); });
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GenericProject::~GenericProject()
|
|
|
|
|
{
|
2017-02-06 16:59:53 +01:00
|
|
|
delete m_cppCodeModelUpdater;
|
2009-09-24 16:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
2009-03-16 11:49:57 +01:00
|
|
|
QString GenericProject::filesFileName() const
|
2011-04-12 08:20:54 +02:00
|
|
|
{
|
|
|
|
|
return m_filesFileName;
|
|
|
|
|
}
|
2009-03-16 11:49:57 +01:00
|
|
|
|
|
|
|
|
QString GenericProject::includesFileName() const
|
2011-04-12 08:20:54 +02:00
|
|
|
{
|
|
|
|
|
return m_includesFileName;
|
|
|
|
|
}
|
2009-03-16 11:49:57 +01:00
|
|
|
|
|
|
|
|
QString GenericProject::configFileName() const
|
2011-04-12 08:20:54 +02:00
|
|
|
{
|
|
|
|
|
return m_configFileName;
|
|
|
|
|
}
|
2009-03-16 11:49:57 +01:00
|
|
|
|
2009-03-19 17:58:56 +01:00
|
|
|
static QStringList readLines(const QString &absoluteFileName)
|
2009-03-16 11:08:07 +01:00
|
|
|
{
|
|
|
|
|
QStringList lines;
|
|
|
|
|
|
|
|
|
|
QFile file(absoluteFileName);
|
|
|
|
|
if (file.open(QFile::ReadOnly)) {
|
|
|
|
|
QTextStream stream(&file);
|
|
|
|
|
|
2016-12-25 17:59:17 +01:00
|
|
|
for (;;) {
|
2015-12-22 15:09:12 +01:00
|
|
|
const QString line = stream.readLine();
|
2009-03-16 11:08:07 +01:00
|
|
|
if (line.isNull())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
lines.append(line);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return lines;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-10 16:38:50 +01:00
|
|
|
bool GenericProject::saveRawFileList(const QStringList &rawFileList)
|
2014-07-28 14:41:55 +02:00
|
|
|
{
|
|
|
|
|
bool result = saveRawList(rawFileList, filesFileName());
|
|
|
|
|
refresh(GenericProject::Files);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GenericProject::saveRawList(const QStringList &rawList, const QString &fileName)
|
2009-06-29 18:04:29 +02:00
|
|
|
{
|
2016-07-18 10:04:42 +02:00
|
|
|
FileChangeBlocker changeGuard(fileName);
|
2009-06-29 18:42:59 +02:00
|
|
|
// Make sure we can open the file for writing
|
2014-07-28 14:41:55 +02:00
|
|
|
Utils::FileSaver saver(fileName, QIODevice::Text);
|
2011-03-30 15:15:15 +02:00
|
|
|
if (!saver.hasError()) {
|
|
|
|
|
QTextStream stream(saver.file());
|
2016-12-25 17:59:17 +01:00
|
|
|
for (const QString &filePath : rawList)
|
|
|
|
|
stream << filePath << '\n';
|
2011-03-30 15:15:15 +02:00
|
|
|
saver.setResult(&stream);
|
|
|
|
|
}
|
2014-07-28 14:43:43 +02:00
|
|
|
bool result = saver.finalize(ICore::mainWindow());
|
|
|
|
|
return result;
|
2009-06-29 18:04:29 +02:00
|
|
|
}
|
2009-03-16 11:08:07 +01:00
|
|
|
|
2015-12-22 13:27:22 +01:00
|
|
|
static void insertSorted(QStringList *list, const QString &value)
|
|
|
|
|
{
|
|
|
|
|
int pos = Utils::indexOf(*list, [value](const QString &s) { return s > value; });
|
|
|
|
|
list->insert(pos, value);
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-30 14:07:07 +02:00
|
|
|
bool GenericProject::addFiles(const QStringList &filePaths)
|
|
|
|
|
{
|
2010-02-10 16:38:50 +01:00
|
|
|
QStringList newList = m_rawFileList;
|
|
|
|
|
|
2016-12-25 17:59:17 +01:00
|
|
|
const QDir baseDir(projectDirectory().toString());
|
|
|
|
|
for (const QString &filePath : filePaths)
|
2015-12-22 13:27:22 +01:00
|
|
|
insertSorted(&newList, baseDir.relativeFilePath(filePath));
|
2014-07-28 14:41:55 +02:00
|
|
|
|
2016-12-25 17:59:17 +01:00
|
|
|
const QSet<QString> includes = projectIncludePaths().toSet();
|
2014-07-28 14:41:55 +02:00
|
|
|
QSet<QString> toAdd;
|
|
|
|
|
|
2016-12-25 17:59:17 +01:00
|
|
|
for (const QString &filePath : filePaths) {
|
2015-12-22 15:09:12 +01:00
|
|
|
const QString directory = QFileInfo(filePath).absolutePath();
|
2017-01-02 11:40:16 +01:00
|
|
|
if (!includes.contains(directory))
|
2014-07-28 14:41:55 +02:00
|
|
|
toAdd << directory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QDir dir(projectDirectory().toString());
|
2016-12-25 17:59:17 +01:00
|
|
|
const auto candidates = toAdd;
|
|
|
|
|
for (const QString &path : candidates) {
|
2014-07-28 14:41:55 +02:00
|
|
|
QString relative = dir.relativeFilePath(path);
|
|
|
|
|
if (relative.isEmpty())
|
2016-12-25 17:59:17 +01:00
|
|
|
relative = '.';
|
2014-07-28 14:41:55 +02:00
|
|
|
m_rawProjectIncludePaths.append(relative);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool result = saveRawList(newList, filesFileName());
|
|
|
|
|
result &= saveRawList(m_rawProjectIncludePaths, includesFileName());
|
|
|
|
|
refresh(GenericProject::Everything);
|
|
|
|
|
|
|
|
|
|
return result;
|
2009-06-30 14:07:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool GenericProject::removeFiles(const QStringList &filePaths)
|
|
|
|
|
{
|
2010-02-10 16:38:50 +01:00
|
|
|
QStringList newList = m_rawFileList;
|
2009-06-30 15:00:30 +02:00
|
|
|
|
2016-12-25 17:59:17 +01:00
|
|
|
for (const QString &filePath : filePaths) {
|
2010-02-10 16:38:50 +01:00
|
|
|
QHash<QString, QString>::iterator i = m_rawListEntries.find(filePath);
|
|
|
|
|
if (i != m_rawListEntries.end())
|
|
|
|
|
newList.removeOne(i.value());
|
2009-06-30 15:00:30 +02:00
|
|
|
}
|
2009-06-30 14:07:07 +02:00
|
|
|
|
2010-02-10 16:38:50 +01:00
|
|
|
return saveRawFileList(newList);
|
2009-06-30 14:07:07 +02:00
|
|
|
}
|
|
|
|
|
|
2011-06-20 11:57:20 +02:00
|
|
|
bool GenericProject::setFiles(const QStringList &filePaths)
|
|
|
|
|
{
|
|
|
|
|
QStringList newList;
|
2016-01-08 12:12:27 +01:00
|
|
|
QDir baseDir(projectDirectory().toString());
|
2016-12-25 17:59:17 +01:00
|
|
|
for (const QString &filePath : filePaths)
|
2011-06-20 11:57:20 +02:00
|
|
|
newList.append(baseDir.relativeFilePath(filePath));
|
2015-12-22 13:27:22 +01:00
|
|
|
Utils::sort(newList);
|
2011-06-20 11:57:20 +02:00
|
|
|
|
|
|
|
|
return saveRawFileList(newList);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-24 21:42:11 +02:00
|
|
|
bool GenericProject::renameFile(const QString &filePath, const QString &newFilePath)
|
|
|
|
|
{
|
|
|
|
|
QStringList newList = m_rawFileList;
|
|
|
|
|
|
|
|
|
|
QHash<QString, QString>::iterator i = m_rawListEntries.find(filePath);
|
|
|
|
|
if (i != m_rawListEntries.end()) {
|
|
|
|
|
int index = newList.indexOf(i.value());
|
|
|
|
|
if (index != -1) {
|
2016-01-08 12:12:27 +01:00
|
|
|
QDir baseDir(projectDirectory().toString());
|
2015-12-22 13:27:22 +01:00
|
|
|
newList.removeAt(index);
|
|
|
|
|
insertSorted(&newList, baseDir.relativeFilePath(newFilePath));
|
2011-10-24 21:42:11 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return saveRawFileList(newList);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-19 17:58:56 +01:00
|
|
|
void GenericProject::parseProject(RefreshOptions options)
|
2009-03-12 15:07:54 +01:00
|
|
|
{
|
2010-02-10 16:38:50 +01:00
|
|
|
if (options & Files) {
|
|
|
|
|
m_rawListEntries.clear();
|
|
|
|
|
m_rawFileList = readLines(filesFileName());
|
2010-02-11 16:42:23 +01:00
|
|
|
m_files = processEntries(m_rawFileList, &m_rawListEntries);
|
2010-02-10 16:38:50 +01:00
|
|
|
}
|
2009-03-16 11:49:57 +01:00
|
|
|
|
2009-03-19 17:58:56 +01:00
|
|
|
if (options & Configuration) {
|
2014-07-28 14:41:55 +02:00
|
|
|
m_rawProjectIncludePaths = readLines(includesFileName());
|
|
|
|
|
m_projectIncludePaths = processEntries(m_rawProjectIncludePaths);
|
2009-03-16 11:08:07 +01:00
|
|
|
|
2010-02-10 17:28:53 +01:00
|
|
|
// TODO: Possibly load some configuration from the project file
|
|
|
|
|
//QSettings projectInfo(m_fileName, QSettings::IniFormat);
|
2009-03-19 17:58:56 +01:00
|
|
|
}
|
2009-03-12 15:07:54 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-19 17:58:56 +01:00
|
|
|
void GenericProject::refresh(RefreshOptions options)
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2009-03-19 17:58:56 +01:00
|
|
|
parseProject(options);
|
|
|
|
|
|
2016-10-06 11:31:00 +02:00
|
|
|
if (options & Files) {
|
2017-03-10 17:30:40 +01:00
|
|
|
auto newRoot = new GenericProjectNode(this);
|
|
|
|
|
|
2017-03-27 12:12:38 +02:00
|
|
|
for (const QString &f : m_files) {
|
2016-10-31 13:47:42 +01:00
|
|
|
FileType fileType = FileType::Source; // ### FIXME
|
2016-12-25 17:59:17 +01:00
|
|
|
if (f.endsWith(".qrc"))
|
2016-10-31 13:47:42 +01:00
|
|
|
fileType = FileType::Resource;
|
2017-03-10 17:30:40 +01:00
|
|
|
newRoot->addNestedNode(new FileNode(Utils::FileName::fromString(f), fileType, false));
|
|
|
|
|
}
|
2016-12-29 13:46:03 +01:00
|
|
|
|
2017-03-10 17:30:40 +01:00
|
|
|
newRoot->addNestedNode(new FileNode(Utils::FileName::fromString(m_filesFileName),
|
2017-01-11 09:29:37 +01:00
|
|
|
FileType::Project,
|
2017-03-10 17:30:40 +01:00
|
|
|
/* generated = */ false));
|
|
|
|
|
newRoot->addNestedNode(new FileNode(Utils::FileName::fromString(m_includesFileName),
|
|
|
|
|
FileType::Project,
|
|
|
|
|
/* generated = */ false));
|
|
|
|
|
newRoot->addNestedNode(new FileNode(Utils::FileName::fromString(m_configFileName),
|
|
|
|
|
FileType::Project,
|
|
|
|
|
/* generated = */ false));
|
2017-03-03 15:13:06 +01:00
|
|
|
|
|
|
|
|
setRootProjectNode(newRoot);
|
2016-10-06 11:31:00 +02:00
|
|
|
}
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2014-06-18 16:16:55 +02:00
|
|
|
refreshCppCodeModel();
|
2016-10-20 13:18:54 +02:00
|
|
|
emit parsingFinished();
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-11 16:42:23 +01:00
|
|
|
/**
|
|
|
|
|
* Expands environment variables and converts the path from relative to the
|
|
|
|
|
* project to an absolute path.
|
|
|
|
|
*
|
2010-02-10 16:38:50 +01:00
|
|
|
* The \a map variable is an optional argument that will map the returned
|
2010-02-11 16:42:23 +01:00
|
|
|
* absolute paths back to their original \a entries.
|
2010-02-10 16:38:50 +01:00
|
|
|
*/
|
2010-02-11 16:42:23 +01:00
|
|
|
QStringList GenericProject::processEntries(const QStringList &paths,
|
|
|
|
|
QHash<QString, QString> *map) const
|
2009-03-12 15:07:54 +01:00
|
|
|
{
|
2016-12-20 16:40:28 +01:00
|
|
|
const BuildConfiguration *const buildConfig = activeTarget() ? activeTarget()->activeBuildConfiguration()
|
|
|
|
|
: nullptr;
|
2016-12-20 16:42:01 +01:00
|
|
|
|
2016-12-20 16:40:28 +01:00
|
|
|
const Utils::Environment buildEnv = buildConfig ? buildConfig->environment()
|
|
|
|
|
: Utils::Environment::systemEnvironment();
|
2016-12-20 16:42:01 +01:00
|
|
|
|
|
|
|
|
const Utils::MacroExpander *expander = macroExpander();
|
|
|
|
|
if (buildConfig)
|
|
|
|
|
expander = buildConfig->macroExpander();
|
|
|
|
|
else if (activeTarget())
|
|
|
|
|
expander = activeTarget()->macroExpander();
|
|
|
|
|
|
2016-01-08 12:12:27 +01:00
|
|
|
const QDir projectDir(projectDirectory().toString());
|
2010-02-11 16:42:23 +01:00
|
|
|
|
2013-03-26 18:06:38 +01:00
|
|
|
QFileInfo fileInfo;
|
2009-03-12 15:07:54 +01:00
|
|
|
QStringList absolutePaths;
|
2016-12-25 17:59:17 +01:00
|
|
|
for (const QString &path : paths) {
|
2010-02-11 16:42:23 +01:00
|
|
|
QString trimmedPath = path.trimmed();
|
|
|
|
|
if (trimmedPath.isEmpty())
|
2010-02-10 16:38:50 +01:00
|
|
|
continue;
|
|
|
|
|
|
2016-12-20 16:40:28 +01:00
|
|
|
trimmedPath = buildEnv.expandVariables(trimmedPath);
|
2016-12-20 16:42:01 +01:00
|
|
|
trimmedPath = expander->expand(trimmedPath);
|
2010-02-11 16:42:23 +01:00
|
|
|
|
2012-12-13 12:11:31 +01:00
|
|
|
trimmedPath = Utils::FileName::fromUserInput(trimmedPath).toString();
|
|
|
|
|
|
2013-03-26 18:06:38 +01:00
|
|
|
fileInfo.setFile(projectDir, trimmedPath);
|
|
|
|
|
if (fileInfo.exists()) {
|
|
|
|
|
const QString absPath = fileInfo.absoluteFilePath();
|
|
|
|
|
absolutePaths.append(absPath);
|
|
|
|
|
if (map)
|
|
|
|
|
map->insert(absPath, trimmedPath);
|
|
|
|
|
}
|
2009-03-12 15:07:54 +01:00
|
|
|
}
|
|
|
|
|
absolutePaths.removeDuplicates();
|
|
|
|
|
return absolutePaths;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-18 16:16:55 +02:00
|
|
|
void GenericProject::refreshCppCodeModel()
|
|
|
|
|
{
|
2017-02-06 16:59:53 +01:00
|
|
|
const Kit *k = nullptr;
|
|
|
|
|
if (Target *target = activeTarget())
|
|
|
|
|
k = target->kit();
|
|
|
|
|
else
|
|
|
|
|
k = KitManager::defaultKit();
|
|
|
|
|
QTC_ASSERT(k, return);
|
2014-06-18 16:16:55 +02:00
|
|
|
|
2017-02-06 16:59:53 +01:00
|
|
|
ToolChain *cToolChain
|
|
|
|
|
= ToolChainKitInformation::toolChain(k, ProjectExplorer::Constants::C_LANGUAGE_ID);
|
|
|
|
|
ToolChain *cxxToolChain
|
|
|
|
|
= ToolChainKitInformation::toolChain(k, ProjectExplorer::Constants::CXX_LANGUAGE_ID);
|
2014-06-18 16:16:55 +02:00
|
|
|
|
2017-02-06 16:59:53 +01:00
|
|
|
m_cppCodeModelUpdater->cancel();
|
2015-04-21 09:08:07 +03:00
|
|
|
|
|
|
|
|
CppTools::ProjectPart::QtVersion activeQtVersion = CppTools::ProjectPart::NoQt;
|
|
|
|
|
if (QtSupport::BaseQtVersion *qtVersion =
|
|
|
|
|
QtSupport::QtKitInformation::qtVersion(activeTarget()->kit())) {
|
|
|
|
|
if (qtVersion->qtVersion() < QtSupport::QtVersionNumber(5,0,0))
|
|
|
|
|
activeQtVersion = CppTools::ProjectPart::Qt4;
|
|
|
|
|
else
|
|
|
|
|
activeQtVersion = CppTools::ProjectPart::Qt5;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 16:59:53 +01:00
|
|
|
CppTools::RawProjectPart rpp;
|
2017-02-21 14:40:31 +01:00
|
|
|
rpp.setDisplayName(displayName());
|
2017-03-09 14:13:22 +01:00
|
|
|
rpp.setProjectFileLocation(projectFilePath().toString());
|
2017-02-06 16:59:53 +01:00
|
|
|
rpp.setQtVersion(activeQtVersion);
|
|
|
|
|
rpp.setIncludePaths(projectIncludePaths());
|
|
|
|
|
rpp.setConfigFileName(configFileName());
|
2017-03-27 12:12:38 +02:00
|
|
|
rpp.setFiles(m_files);
|
2014-06-18 16:16:55 +02:00
|
|
|
|
2017-02-06 16:59:53 +01:00
|
|
|
const CppTools::ProjectUpdateInfo projectInfoUpdate(this, cToolChain, cxxToolChain, k, {rpp});
|
|
|
|
|
m_cppCodeModelUpdater->update(projectInfoUpdate);
|
2014-06-18 16:16:55 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-20 22:17:20 +01:00
|
|
|
void GenericProject::activeTargetWasChanged()
|
|
|
|
|
{
|
|
|
|
|
if (m_activeTarget) {
|
|
|
|
|
disconnect(m_activeTarget, &Target::activeBuildConfigurationChanged,
|
|
|
|
|
this, &GenericProject::activeBuildConfigurationWasChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_activeTarget = activeTarget();
|
|
|
|
|
|
|
|
|
|
if (!m_activeTarget)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
connect(m_activeTarget, &Target::activeBuildConfigurationChanged,
|
|
|
|
|
this, &GenericProject::activeBuildConfigurationWasChanged);
|
|
|
|
|
refresh(Everything);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericProject::activeBuildConfigurationWasChanged()
|
|
|
|
|
{
|
|
|
|
|
refresh(Everything);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-13 15:12:54 +01:00
|
|
|
QStringList GenericProject::projectIncludePaths() const
|
2011-04-12 08:20:54 +02:00
|
|
|
{
|
|
|
|
|
return m_projectIncludePaths;
|
|
|
|
|
}
|
2009-03-13 15:12:54 +01:00
|
|
|
|
2010-01-07 18:17:24 +01:00
|
|
|
QString GenericProject::displayName() const
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2017-03-03 17:10:00 +01:00
|
|
|
return projectFilePath().toFileInfo().completeBaseName();
|
2009-03-10 14:20:07 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
QStringList GenericProject::buildTargets() const
|
2009-03-10 14:20:07 +01:00
|
|
|
{
|
2016-12-25 17:59:17 +01:00
|
|
|
const QStringList targets = { "all", "clean" };
|
2009-03-10 14:20:07 +01:00
|
|
|
return targets;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 16:57:29 +02:00
|
|
|
Project::RestoreResult GenericProject::fromMap(const QVariantMap &map, QString *errorMessage)
|
2010-01-19 16:33:44 +01:00
|
|
|
{
|
2016-12-25 17:59:17 +01:00
|
|
|
const RestoreResult result = Project::fromMap(map, errorMessage);
|
2015-05-18 16:57:29 +02:00
|
|
|
if (result != RestoreResult::Ok)
|
|
|
|
|
return result;
|
2009-03-10 14:20:07 +01:00
|
|
|
|
2013-08-21 12:48:46 +02:00
|
|
|
Kit *defaultKit = KitManager::defaultKit();
|
2012-09-03 18:31:44 +02:00
|
|
|
if (!activeTarget() && defaultKit)
|
|
|
|
|
addTarget(createTarget(defaultKit));
|
2012-04-24 15:49:09 +02:00
|
|
|
|
2010-04-27 10:58:36 +02:00
|
|
|
// Sanity check: We need both a buildconfiguration and a runconfiguration!
|
2016-12-25 17:59:17 +01:00
|
|
|
const QList<Target *> targetList = targets();
|
2015-09-04 14:59:40 +02:00
|
|
|
if (targetList.isEmpty())
|
|
|
|
|
return RestoreResult::Error;
|
|
|
|
|
|
2016-12-25 17:59:17 +01:00
|
|
|
for (Target *t : targetList) {
|
2010-04-27 10:58:36 +02:00
|
|
|
if (!t->activeBuildConfiguration()) {
|
|
|
|
|
removeTarget(t);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!t->activeRunConfiguration())
|
2016-05-12 17:42:36 +02:00
|
|
|
t->addRunConfiguration(new CustomExecutableRunConfiguration(t));
|
2010-04-27 10:58:36 +02:00
|
|
|
}
|
|
|
|
|
|
2016-12-20 22:17:20 +01:00
|
|
|
m_activeTarget = activeTarget();
|
|
|
|
|
if (m_activeTarget) {
|
|
|
|
|
connect(m_activeTarget, &Target::activeBuildConfigurationChanged,
|
|
|
|
|
this, &GenericProject::activeBuildConfigurationWasChanged);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connect(this, &Project::activeTargetChanged,
|
|
|
|
|
this, &GenericProject::activeTargetWasChanged);
|
2012-04-24 15:49:09 +02:00
|
|
|
refresh(Everything);
|
2015-05-18 16:57:29 +02:00
|
|
|
return RestoreResult::Ok;
|
2009-08-21 15:59:17 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-14 15:37:38 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace GenericProjectManager
|