summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cpprawprojectpart.h
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@qt.io>2017-02-06 16:59:53 +0100
committerNikolai Kosjar <nikolai.kosjar@qt.io>2017-02-20 09:18:13 +0000
commit8c90998fff6ec3cf85ad87b56175e86b6f0a93d0 (patch)
treec3f838d24e4cd7c3484c5a50d1f07a5b73de5bf9 /src/plugins/cpptools/cpprawprojectpart.h
parent010060de5c205a79dba0343ef82f10f3446c1e58 (diff)
downloadqt-creator-8c90998fff6ec3cf85ad87b56175e86b6f0a93d0.tar.gz
CppTools/ProjectManagers: Reduce ui blocking when loading projects
${AnyProject}::updateCppCodeModel() did two potentially not that cheap operations in the ui thread: (1) Querying the MimeDatabase for the mime type for the source files of the project. In 99.9% of the cases no files need to be read for this as the file extension will resolve the type. The expensiveness comes from the sheer number of files that can occur. (2) Calling compilers with the "(sub)project's compiler command line" to determine the macros. While the caches avoid redundant calls, the number of the unique compiler calls makes this still a ui-freezing experience. These two operations are moved into a worker thread. For this, the expensive compiler calls are encapsulated in thread safe lambdas ("runners") in order to keep the "mutexed" data minimal. The original API calls of the toolchains are implemented in terms of the runners. While adapting the project managers, remove also the calls to setProjectLanguage(). These are redundant because all of the project managers already set a proper value in the constructor. Also, currently there is no need (client) to report back detection of C sources in project parts. This also keeps CppProjectUpdater simple. There is still room for improvement: * Run the compiler calls in parallel instead of sequence. * Ensure that the mime type for a file is determined exactly once. Change-Id: I2efc4e132ee88e3c8f264012ec8fafe3d86c404f Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Diffstat (limited to 'src/plugins/cpptools/cpprawprojectpart.h')
-rw-r--r--src/plugins/cpptools/cpprawprojectpart.h98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cpprawprojectpart.h b/src/plugins/cpptools/cpprawprojectpart.h
new file mode 100644
index 0000000000..7e6d36f459
--- /dev/null
+++ b/src/plugins/cpptools/cpprawprojectpart.h
@@ -0,0 +1,98 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://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.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "cpptools_global.h"
+#include "projectpart.h"
+
+#include <projectexplorer/toolchain.h>
+
+#include <functional>
+
+namespace CppTools {
+
+class CPPTOOLS_EXPORT RawProjectPartFlags
+{
+public:
+ RawProjectPartFlags() = default;
+ RawProjectPartFlags(const ProjectExplorer::ToolChain *toolChain,
+ const QStringList &commandLineFlags);
+
+public:
+ QStringList commandLineFlags;
+ // The following are deduced from commandLineFlags.
+ ProjectExplorer::WarningFlags warningFlags = ProjectExplorer::WarningFlags::Default;
+ ProjectExplorer::ToolChain::CompilerFlags compilerFlags
+ = ProjectExplorer::ToolChain::CompilerFlag::NoFlags;
+};
+
+class CPPTOOLS_EXPORT RawProjectPart
+{
+public:
+ RawProjectPart() {}
+
+ void setDisplayName(const QString &displayName);
+
+ // FileClassifier must be thread-safe.
+ using FileClassifier = std::function<ProjectFile::Kind (const QString &filePath)>;
+ void setFiles(const QStringList &files, FileClassifier fileClassifier = FileClassifier());
+
+ void setProjectFile(const QString &projectFile);
+ void setConfigFileName(const QString &configFileName);
+
+ void setQtVersion(ProjectPart::QtVersion qtVersion);
+
+ void setDefines(const QByteArray &defines);
+ void setHeaderPaths(const ProjectPartHeaderPaths &headerPaths);
+ void setIncludePaths(const QStringList &includePaths);
+
+ void setPreCompiledHeaders(const QStringList &preCompiledHeaders);
+
+ void setSelectedForBuilding(bool yesno);
+
+ void setFlagsForC(const RawProjectPartFlags &flags);
+ void setFlagsForCxx(const RawProjectPartFlags &flags);
+
+public:
+ QString displayName;
+ QString projectFile;
+ QString projectConfigFile; // currently only used by the Generic Project Manager
+ QStringList precompiledHeaders;
+ ProjectPartHeaderPaths headerPaths;
+ QByteArray projectDefines;
+ ProjectPart::QtVersion qtVersion = ProjectPart::UnknownQt;
+ bool selectedForBuilding = true;
+
+ RawProjectPartFlags flagsForC;
+ RawProjectPartFlags flagsForCxx;
+
+ QStringList files;
+ FileClassifier fileClassifier;
+};
+
+using RawProjectParts = QVector<RawProjectPart>;
+
+} // namespace CppTools