ProjectExplorer: Move BuildSystem owership to BuildConfiguration

... or Target.

This patch moves build system from conceptually "one per project"
to "one per target (i.e. per project-and-kit)" or "per
BuildConfigurations" for targets where the builds differ
significantly.

Building requires usually items from the kit (Qt version, compiler,
...) so a target-agnostic build is practically almost always wrong.

Moving the build system to the target also has the potential
to solve issues caused by switching targets while parsing, that
used Project::activeTarget() regularly, with potentially different
results before and after the switch.

This patch might create performance/size regressions when several
targets are set up per project as the build system implementation's
internal data are duplicated in this case.

The idea is to fix that by sharing per-project pieces again in
the project implementation once these problems occur.

Change-Id: I87f640ce418b93175b5029124eaa55f3b8721dca
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-10-25 09:55:32 +02:00
parent 9073c46c9c
commit 2758682723
127 changed files with 2541 additions and 2532 deletions

View File

@@ -337,9 +337,46 @@ void createTree(std::unique_ptr<ProjectNode> &root,
} // anonymous namespace
void CompilationDatabaseProject::buildTreeAndProjectParts()
CompilationDatabaseBuildSystem::CompilationDatabaseBuildSystem(Target *target)
: BuildSystem(target)
, m_cppCodeModelUpdater(std::make_unique<CppTools::CppProjectUpdater>())
, m_parseDelay(new QTimer(this))
, m_deployFileWatcher(new FileSystemWatcher(this))
{
ProjectExplorer::KitInfo kitInfo(this);
connect(target->project(), &CompilationDatabaseProject::rootProjectDirectoryChanged,
this, [this] {
m_projectFileHash.clear();
m_parseDelay->start();
});
connect(m_parseDelay, &QTimer::timeout, this, &CompilationDatabaseBuildSystem::reparseProject);
m_parseDelay->setSingleShot(true);
m_parseDelay->setInterval(1000);
m_parseDelay->start();
connect(project(), &Project::projectFileIsDirty, this, &CompilationDatabaseBuildSystem::reparseProject);
connect(m_deployFileWatcher, &FileSystemWatcher::fileChanged,
this, &CompilationDatabaseBuildSystem::updateDeploymentData);
connect(target->project(), &Project::activeTargetChanged,
this, &CompilationDatabaseBuildSystem::updateDeploymentData);
}
CompilationDatabaseBuildSystem::~CompilationDatabaseBuildSystem()
{
m_parserWatcher.cancel();
m_parserWatcher.waitForFinished();
}
void CompilationDatabaseBuildSystem::triggerParsing()
{
reparseProject();
}
void CompilationDatabaseBuildSystem::buildTreeAndProjectParts()
{
ProjectExplorer::KitInfo kitInfo(project());
QTC_ASSERT(kitInfo.isValid(), return);
// Reset toolchains to pick them based on the database entries.
kitInfo.cToolChain = nullptr;
@@ -349,6 +386,7 @@ void CompilationDatabaseProject::buildTreeAndProjectParts()
QTC_ASSERT(m_parser, return);
const DbContents dbContents = m_parser->dbContents();
const DbEntry *prevEntry = nullptr;
Kit *kit = static_cast<CompilationDatabaseProject *>(project())->kit();
for (const DbEntry &entry : dbContents.entries) {
if (prevEntry && prevEntry->flags == entry.flags) {
rpps.back().files.append(entry.fileName.toString());
@@ -358,7 +396,7 @@ void CompilationDatabaseProject::buildTreeAndProjectParts()
prevEntry = &entry;
RawProjectPart rpp = makeRawProjectPart(projectFilePath(),
m_kit.get(),
kit,
kitInfo,
entry.workingDir,
entry.fileName,
@@ -381,7 +419,7 @@ void CompilationDatabaseProject::buildTreeAndProjectParts()
auto root = std::make_unique<ProjectNode>(projectDirectory());
createTree(root, rootProjectDirectory(), rpps, m_parser->scannedFiles());
createTree(root, project()->rootProjectDirectory(), rpps, m_parser->scannedFiles());
root->addNode(std::make_unique<FileNode>(projectFilePath(), FileType::Project));
@@ -389,43 +427,26 @@ void CompilationDatabaseProject::buildTreeAndProjectParts()
root->addNode(std::make_unique<FileNode>(Utils::FilePath::fromString(dbContents.extraFileName),
FileType::Project));
setRootProjectNode(std::move(root));
project()->setRootProjectNode(std::move(root));
m_cppCodeModelUpdater->update({this, kitInfo, activeParseEnvironment(), rpps});
m_cppCodeModelUpdater->update({project(), kitInfo, activeParseEnvironment(), rpps});
updateDeploymentData();
}
CompilationDatabaseProject::CompilationDatabaseProject(const Utils::FilePath &projectFile)
: Project(Constants::COMPILATIONDATABASEMIMETYPE, projectFile)
, m_cppCodeModelUpdater(std::make_unique<CppTools::CppProjectUpdater>())
, m_parseDelay(new QTimer(this))
, m_deployFileWatcher(new FileSystemWatcher(this))
{
setId(Constants::COMPILATIONDATABASEPROJECT_ID);
setProjectLanguages(Core::Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
setDisplayName(projectDirectory().fileName());
setBuildSystemCreator([](Target *t) { return new CompilationDatabaseBuildSystem(t); });
m_kit.reset(KitManager::defaultKit()->clone());
addTargetForKit(m_kit.get());
connect(this, &CompilationDatabaseProject::rootProjectDirectoryChanged,
this, [this] {
m_projectFileHash.clear();
m_parseDelay->start();
});
setExtraProjectFiles(
{projectFile.stringAppended(Constants::COMPILATIONDATABASEPROJECT_FILES_SUFFIX)});
connect(m_parseDelay, &QTimer::timeout, this, &CompilationDatabaseProject::reparseProject);
m_parseDelay->setSingleShot(true);
m_parseDelay->setInterval(1000);
connect(this, &Project::projectFileIsDirty, this, &CompilationDatabaseProject::reparseProject);
connect(m_deployFileWatcher, &FileSystemWatcher::fileChanged,
this, &CompilationDatabaseProject::updateDeploymentData);
connect(this, &Project::activeTargetChanged,
this, &CompilationDatabaseProject::updateDeploymentData);
}
Utils::FilePath CompilationDatabaseProject::rootPathFromSettings() const
@@ -442,26 +463,19 @@ Project::RestoreResult CompilationDatabaseProject::fromMap(const QVariantMap &ma
QString *errorMessage)
{
Project::RestoreResult result = Project::fromMap(map, errorMessage);
if (result == Project::RestoreResult::Ok) {
const Utils::FilePath rootPath = rootPathFromSettings();
if (rootPath.isEmpty())
changeRootProjectDirectory(); // This triggers reparse itself.
else
reparseProject();
}
return result;
}
void CompilationDatabaseProject::reparseProject()
void CompilationDatabaseBuildSystem::reparseProject()
{
if (m_parser) {
QTC_CHECK(isParsing());
m_parser->stop();
}
m_parser = new CompilationDbParser(displayName(),
const FilePath rootPath = static_cast<CompilationDatabaseProject *>(project())->rootPathFromSettings();
m_parser = new CompilationDbParser(project()->displayName(),
projectFilePath(),
rootPathFromSettings(),
rootPath,
m_mimeBinaryCache,
guardParsingRun(),
this);
@@ -475,17 +489,14 @@ void CompilationDatabaseProject::reparseProject()
m_parser->start();
}
void CompilationDatabaseProject::updateDeploymentData()
void CompilationDatabaseBuildSystem::updateDeploymentData()
{
Target * const target = activeTarget();
if (!target)
return;
const Utils::FilePath deploymentFilePath = projectDirectory()
.pathAppended("QtCreatorDeployment.txt");
DeploymentData deploymentData;
deploymentData.addFilesFromDeploymentFile(deploymentFilePath.toString(),
projectDirectory().toString());
target->setDeploymentData(deploymentData);
setDeploymentData(deploymentData);
if (m_deployFileWatcher->files() != QStringList(deploymentFilePath.toString())) {
m_deployFileWatcher->removeFiles(m_deployFileWatcher->files());
m_deployFileWatcher->addFile(deploymentFilePath.toString(),
@@ -493,12 +504,6 @@ void CompilationDatabaseProject::updateDeploymentData()
}
}
CompilationDatabaseProject::~CompilationDatabaseProject()
{
m_parserWatcher.cancel();
m_parserWatcher.waitForFinished();
}
static TextEditor::TextDocument *createCompilationDatabaseDocument()
{
auto doc = new TextEditor::TextDocument;