2019-08-19 12:31:25 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) Filippo Cucchetto <filippocucchetto@gmail.com>
|
|
|
|
|
** 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 https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "nimbuildsystem.h"
|
|
|
|
|
|
2019-09-16 22:43:27 +02:00
|
|
|
#include "nimbleproject.h"
|
2019-08-19 12:31:25 +02:00
|
|
|
#include "nimprojectnode.h"
|
|
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
#include <utils/fileutils.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QVariantMap>
|
|
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace Nim {
|
|
|
|
|
|
|
|
|
|
const char SETTINGS_KEY[] = "Nim.BuildSystem";
|
|
|
|
|
const char EXCLUDED_FILES_KEY[] = "ExcludedFiles";
|
|
|
|
|
|
|
|
|
|
NimBuildSystem::NimBuildSystem(Project *project)
|
|
|
|
|
: BuildSystem(project)
|
|
|
|
|
{
|
|
|
|
|
connect(project, &Project::settingsLoaded, this, &NimBuildSystem::loadSettings);
|
|
|
|
|
connect(project, &Project::aboutToSaveSettings, this, &NimBuildSystem::saveSettings);
|
|
|
|
|
|
|
|
|
|
connect(&m_scanner, &TreeScanner::finished, this, &NimBuildSystem::updateProject);
|
|
|
|
|
m_scanner.setFilter([this](const Utils::MimeType &, const Utils::FilePath &fp) {
|
|
|
|
|
const QString path = fp.toString();
|
2019-09-16 22:43:27 +02:00
|
|
|
return excludedFiles().contains(path)
|
|
|
|
|
|| path.endsWith(".nimproject")
|
|
|
|
|
|| path.contains(".nimproject.user");
|
2019-08-19 12:31:25 +02:00
|
|
|
});
|
|
|
|
|
|
2019-09-16 22:43:27 +02:00
|
|
|
connect(&m_directoryWatcher, &FileSystemWatcher::directoryChanged, this, [this] {
|
|
|
|
|
if (!isWaitingForParse())
|
|
|
|
|
requestDelayedParse();
|
2019-08-19 12:31:25 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NimBuildSystem::addFiles(const QStringList &filePaths)
|
|
|
|
|
{
|
|
|
|
|
m_excludedFiles = Utils::filtered(m_excludedFiles, [&](const QString & f) {
|
|
|
|
|
return !filePaths.contains(f);
|
|
|
|
|
});
|
|
|
|
|
requestParse();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NimBuildSystem::removeFiles(const QStringList &filePaths)
|
|
|
|
|
{
|
|
|
|
|
m_excludedFiles.append(filePaths);
|
|
|
|
|
m_excludedFiles = Utils::filteredUnique(m_excludedFiles);
|
|
|
|
|
requestParse();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NimBuildSystem::renameFile(const QString &filePath, const QString &newFilePath)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(filePath)
|
|
|
|
|
m_excludedFiles.removeOne(newFilePath);
|
|
|
|
|
requestParse();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimBuildSystem::setExcludedFiles(const QStringList &list)
|
|
|
|
|
{
|
|
|
|
|
m_excludedFiles = list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList NimBuildSystem::excludedFiles()
|
|
|
|
|
{
|
|
|
|
|
return m_excludedFiles;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimBuildSystem::parseProject(BuildSystem::ParsingContext &&ctx)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!m_currentContext.project, return );
|
|
|
|
|
m_currentContext = std::move(ctx);
|
|
|
|
|
QTC_CHECK(m_currentContext.project);
|
|
|
|
|
m_scanner.asyncScanForFiles(m_currentContext.project->projectDirectory());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FilePathList NimBuildSystem::nimFiles() const
|
|
|
|
|
{
|
2019-09-16 22:43:27 +02:00
|
|
|
return project()->files([](const Node *n) {
|
|
|
|
|
return Project::AllFiles(n) && n->path().endsWith(".nim");
|
|
|
|
|
});
|
2019-08-19 12:31:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimBuildSystem::loadSettings()
|
|
|
|
|
{
|
|
|
|
|
QVariantMap settings = project()->namedSettings(SETTINGS_KEY).toMap();
|
|
|
|
|
if (settings.contains(EXCLUDED_FILES_KEY))
|
|
|
|
|
m_excludedFiles = settings.value(EXCLUDED_FILES_KEY, m_excludedFiles).toStringList();
|
|
|
|
|
|
|
|
|
|
requestParse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimBuildSystem::saveSettings()
|
|
|
|
|
{
|
|
|
|
|
QVariantMap settings;
|
|
|
|
|
settings.insert(EXCLUDED_FILES_KEY, m_excludedFiles);
|
|
|
|
|
project()->setNamedSettings(SETTINGS_KEY, settings);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NimBuildSystem::updateProject()
|
|
|
|
|
{
|
2019-09-16 22:43:27 +02:00
|
|
|
// Collect scanned nodes
|
|
|
|
|
std::vector<std::unique_ptr<FileNode>> nodes;
|
2019-08-19 12:31:25 +02:00
|
|
|
for (FileNode *node : m_scanner.release()) {
|
2019-09-16 22:43:27 +02:00
|
|
|
if (!node->path().endsWith(".nim") && !node->path().endsWith(".nimble"))
|
2019-08-19 15:49:06 +02:00
|
|
|
node->setEnabled(false); // Disable files that do not end in .nim
|
2019-09-16 22:43:27 +02:00
|
|
|
nodes.emplace_back(node);
|
2019-08-19 12:31:25 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-16 22:43:27 +02:00
|
|
|
// Sync watched dirs
|
|
|
|
|
const QSet<QString> fsDirs = Utils::transform<QSet>(nodes, &FileNode::directory);
|
|
|
|
|
const QSet<QString> projectDirs = m_directoryWatcher.directories().toSet();
|
|
|
|
|
m_directoryWatcher.addDirectories(Utils::toList(fsDirs - projectDirs), FileSystemWatcher::WatchAllChanges);
|
|
|
|
|
m_directoryWatcher.removeDirectories(Utils::toList(projectDirs - fsDirs));
|
|
|
|
|
|
|
|
|
|
// Sync project files
|
|
|
|
|
const QSet<FilePath> fsFiles = Utils::transform<QSet>(nodes, &FileNode::filePath);
|
|
|
|
|
const QSet<FilePath> projectFiles = project()->files([](const Node *n) { return Project::AllFiles(n); }).toSet();
|
|
|
|
|
|
|
|
|
|
if (fsFiles != projectFiles) {
|
|
|
|
|
auto projectNode = std::make_unique<ProjectNode>(project()->projectDirectory());
|
|
|
|
|
projectNode->setDisplayName(project()->displayName());
|
|
|
|
|
projectNode->addNestedNodes(std::move(nodes));
|
|
|
|
|
project()->setRootProjectNode(std::move(projectNode));
|
|
|
|
|
}
|
2019-08-19 12:31:25 +02:00
|
|
|
|
2019-09-16 22:43:27 +02:00
|
|
|
// Complete scan
|
2019-08-19 12:31:25 +02:00
|
|
|
m_currentContext.guard.markAsSuccess();
|
|
|
|
|
m_currentContext = {};
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-22 14:55:51 +02:00
|
|
|
bool NimBuildSystem::supportsAction(Node *context, ProjectAction action, const Node *node) const
|
|
|
|
|
{
|
|
|
|
|
if (node->asFileNode()) {
|
|
|
|
|
return action == ProjectAction::Rename
|
|
|
|
|
|| action == ProjectAction::RemoveFile;
|
|
|
|
|
}
|
|
|
|
|
if (node->isFolderNodeType() || node->isProjectNodeType()) {
|
|
|
|
|
return action == ProjectAction::AddNewFile
|
|
|
|
|
|| action == ProjectAction::RemoveFile
|
|
|
|
|
|| action == ProjectAction::AddExistingFile;
|
|
|
|
|
}
|
|
|
|
|
return BuildSystem::supportsAction(context, action, node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NimBuildSystem::addFiles(Node *, const QStringList &filePaths, QStringList *)
|
|
|
|
|
{
|
|
|
|
|
return addFiles(filePaths);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RemovedFilesFromProject NimBuildSystem::removeFiles(Node *,
|
|
|
|
|
const QStringList &filePaths,
|
|
|
|
|
QStringList *)
|
|
|
|
|
{
|
|
|
|
|
return removeFiles(filePaths) ? RemovedFilesFromProject::Ok
|
|
|
|
|
: RemovedFilesFromProject::Error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NimBuildSystem::deleteFiles(Node *, const QStringList &)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NimBuildSystem::renameFile(Node *, const QString &filePath, const QString &newFilePath)
|
|
|
|
|
{
|
|
|
|
|
return renameFile(filePath, newFilePath);
|
|
|
|
|
}
|
2019-08-19 12:31:25 +02:00
|
|
|
} // namespace Nim
|