forked from qt-creator/qt-creator
CMake: Move code from CMakeProject into CMakeBuildConfiguration
Move code closer to the BuildDirManager that was moved into the CMakeBuildConfiguration. Change-Id: I21d7188e4a3b03a02b12b01c7dd3e46754d653f8 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -196,10 +196,12 @@ bool BuildDirManager::isParsing() const
|
|||||||
|
|
||||||
void BuildDirManager::stopParsingAndClearState()
|
void BuildDirManager::stopParsingAndClearState()
|
||||||
{
|
{
|
||||||
resetData();
|
if (m_reader) {
|
||||||
if (m_reader)
|
disconnect(m_reader.get(), nullptr, this, nullptr);
|
||||||
m_reader->stop();
|
m_reader->stop();
|
||||||
|
}
|
||||||
m_reader.reset();
|
m_reader.reset();
|
||||||
|
resetData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildDirManager::setParametersAndRequestParse(const BuildDirParameters ¶meters,
|
void BuildDirManager::setParametersAndRequestParse(const BuildDirParameters ¶meters,
|
||||||
|
|||||||
@@ -91,11 +91,10 @@ CMakeBuildConfiguration::CMakeBuildConfiguration(Target *parent, Core::Id id)
|
|||||||
if (isActive())
|
if (isActive())
|
||||||
project()->requestReparse(options);
|
project()->requestReparse(options);
|
||||||
});
|
});
|
||||||
connect(&m_buildDirManager, &BuildDirManager::dataAvailable, this, [this]() {
|
connect(&m_buildDirManager,
|
||||||
clearError();
|
&BuildDirManager::dataAvailable,
|
||||||
if (isActive())
|
this,
|
||||||
project()->handleParsingSuccess(this);
|
&CMakeBuildConfiguration::handleParsingSucceeded);
|
||||||
});
|
|
||||||
connect(&m_buildDirManager, &BuildDirManager::errorOccured, this, [this](const QString &msg) {
|
connect(&m_buildDirManager, &BuildDirManager::errorOccured, this, [this](const QString &msg) {
|
||||||
setError(msg);
|
setError(msg);
|
||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
@@ -513,6 +512,62 @@ void CMakeBuildConfiguration::setWarning(const QString &message)
|
|||||||
emit warningOccured(m_warning);
|
emit warningOccured(m_warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CMakeBuildConfiguration::handleParsingSucceeded()
|
||||||
|
{
|
||||||
|
if (!isActive()) {
|
||||||
|
m_buildDirManager.stopParsingAndClearState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearError();
|
||||||
|
|
||||||
|
QString errorMessage;
|
||||||
|
{
|
||||||
|
const QList<CMakeBuildTarget> buildTargets = m_buildDirManager.takeBuildTargets(
|
||||||
|
errorMessage);
|
||||||
|
checkAndReportError(errorMessage);
|
||||||
|
setBuildTargets(buildTargets);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const CMakeConfig cmakeConfig = m_buildDirManager.takeCMakeConfiguration(errorMessage);
|
||||||
|
checkAndReportError(errorMessage);
|
||||||
|
setConfigurationFromCMake(cmakeConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
target()->setApplicationTargets(appTargets());
|
||||||
|
target()->setDeploymentData(deploymentData());
|
||||||
|
}
|
||||||
|
|
||||||
|
project()->handleParsingSuccess(this);
|
||||||
|
|
||||||
|
{
|
||||||
|
m_buildDirManager.resetData();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
emitBuildTypeChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<CMakeProjectNode> CMakeBuildConfiguration::generateProjectTree(
|
||||||
|
const QList<const FileNode *> &allFiles)
|
||||||
|
{
|
||||||
|
QString errorMessage;
|
||||||
|
auto root = m_buildDirManager.generateProjectTree(allFiles, errorMessage);
|
||||||
|
checkAndReportError(errorMessage);
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CMakeBuildConfiguration::checkAndReportError(QString &errorMessage)
|
||||||
|
{
|
||||||
|
if (!errorMessage.isEmpty()) {
|
||||||
|
setError(errorMessage);
|
||||||
|
errorMessage.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QString CMakeBuildConfiguration::error() const
|
QString CMakeBuildConfiguration::error() const
|
||||||
{
|
{
|
||||||
return m_error;
|
return m_error;
|
||||||
@@ -534,13 +589,15 @@ ProjectExplorer::NamedWidget *CMakeBuildConfiguration::createConfigWidget()
|
|||||||
|
|
||||||
CMakeBuildConfigurationFactory::CMakeBuildConfigurationFactory()
|
CMakeBuildConfigurationFactory::CMakeBuildConfigurationFactory()
|
||||||
{
|
{
|
||||||
registerBuildConfiguration<CMakeBuildConfiguration>("CMakeProjectManager.CMakeBuildConfiguration");
|
registerBuildConfiguration<CMakeBuildConfiguration>(
|
||||||
|
"CMakeProjectManager.CMakeBuildConfiguration");
|
||||||
|
|
||||||
setSupportedProjectType(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
|
setSupportedProjectType(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
|
||||||
setSupportedProjectMimeTypeName(Constants::CMAKEPROJECTMIMETYPE);
|
setSupportedProjectMimeTypeName(Constants::CMAKEPROJECTMIMETYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
CMakeBuildConfigurationFactory::BuildType CMakeBuildConfigurationFactory::buildTypeFromByteArray(const QByteArray &in)
|
CMakeBuildConfigurationFactory::BuildType CMakeBuildConfigurationFactory::buildTypeFromByteArray(
|
||||||
|
const QByteArray &in)
|
||||||
{
|
{
|
||||||
const QByteArray bt = in.toLower();
|
const QByteArray bt = in.toLower();
|
||||||
if (bt == "debug")
|
if (bt == "debug")
|
||||||
@@ -554,7 +611,8 @@ CMakeBuildConfigurationFactory::BuildType CMakeBuildConfigurationFactory::buildT
|
|||||||
return BuildTypeNone;
|
return BuildTypeNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildConfiguration::BuildType CMakeBuildConfigurationFactory::cmakeBuildTypeToBuildType(const CMakeBuildConfigurationFactory::BuildType &in)
|
BuildConfiguration::BuildType CMakeBuildConfigurationFactory::cmakeBuildTypeToBuildType(
|
||||||
|
const CMakeBuildConfigurationFactory::BuildType &in)
|
||||||
{
|
{
|
||||||
// Cover all common CMake build types
|
// Cover all common CMake build types
|
||||||
if (in == BuildTypeRelease || in == BuildTypeMinSizeRel)
|
if (in == BuildTypeRelease || in == BuildTypeMinSizeRel)
|
||||||
@@ -567,8 +625,9 @@ BuildConfiguration::BuildType CMakeBuildConfigurationFactory::cmakeBuildTypeToBu
|
|||||||
return BuildConfiguration::Unknown;
|
return BuildConfiguration::Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<BuildInfo> CMakeBuildConfigurationFactory::availableBuilds
|
QList<BuildInfo> CMakeBuildConfigurationFactory::availableBuilds(const Kit *k,
|
||||||
(const Kit *k, const FilePath &projectPath, bool forSetup) const
|
const FilePath &projectPath,
|
||||||
|
bool forSetup) const
|
||||||
{
|
{
|
||||||
QList<BuildInfo> result;
|
QList<BuildInfo> result;
|
||||||
|
|
||||||
@@ -578,9 +637,10 @@ QList<BuildInfo> CMakeBuildConfigurationFactory::availableBuilds
|
|||||||
BuildInfo info = createBuildInfo(k, path.toString(), BuildType(type));
|
BuildInfo info = createBuildInfo(k, path.toString(), BuildType(type));
|
||||||
if (forSetup) {
|
if (forSetup) {
|
||||||
info.displayName = info.typeName;
|
info.displayName = info.typeName;
|
||||||
info.buildDirectory
|
info.buildDirectory = CMakeBuildConfiguration::shadowBuildDirectory(projectPath,
|
||||||
= CMakeBuildConfiguration::shadowBuildDirectory(projectPath, k,
|
k,
|
||||||
info.displayName, info.buildType);
|
info.displayName,
|
||||||
|
info.buildType);
|
||||||
}
|
}
|
||||||
result << info;
|
result << info;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,13 @@ private:
|
|||||||
void setError(const QString &message);
|
void setError(const QString &message);
|
||||||
void setWarning(const QString &message);
|
void setWarning(const QString &message);
|
||||||
|
|
||||||
|
void handleParsingSucceeded();
|
||||||
|
|
||||||
|
std::unique_ptr<CMakeProjectNode> generateProjectTree(
|
||||||
|
const QList<const ProjectExplorer::FileNode *> &allFiles);
|
||||||
|
|
||||||
|
void checkAndReportError(QString &errorMessage);
|
||||||
|
|
||||||
Internal::BuildDirManager m_buildDirManager;
|
Internal::BuildDirManager m_buildDirManager;
|
||||||
|
|
||||||
CMakeConfig m_configurationForCMake;
|
CMakeConfig m_configurationForCMake;
|
||||||
|
|||||||
@@ -178,23 +178,7 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
|
|||||||
QTC_ASSERT(bc == aBc, return);
|
QTC_ASSERT(bc == aBc, return);
|
||||||
QTC_ASSERT(m_treeScanner.isFinished() && !bc->m_buildDirManager.isParsing(), return );
|
QTC_ASSERT(m_treeScanner.isFinished() && !bc->m_buildDirManager.isParsing(), return );
|
||||||
|
|
||||||
{
|
CMakeConfig patchedConfig = bc->configurationFromCMake();
|
||||||
TraceTimer buildTargetsTimer(" build targets");
|
|
||||||
const QList<CMakeBuildTarget> buildTargets = bc->m_buildDirManager.takeBuildTargets(
|
|
||||||
errorMessage);
|
|
||||||
checkAndReportError(errorMessage);
|
|
||||||
bc->setBuildTargets(buildTargets);
|
|
||||||
qCDebug(cmakeProjectLog) << "Build target data set.";
|
|
||||||
}
|
|
||||||
CMakeConfig patchedConfig;
|
|
||||||
{
|
|
||||||
TraceTimer cacheTimer(" cache data (plus patching)");
|
|
||||||
const CMakeConfig cmakeConfig = bc->m_buildDirManager.takeCMakeConfiguration(errorMessage);
|
|
||||||
checkAndReportError(errorMessage);
|
|
||||||
bc->setConfigurationFromCMake(cmakeConfig);
|
|
||||||
qCDebug(cmakeProjectLog) << "CMake configuration data set.";
|
|
||||||
|
|
||||||
patchedConfig = cmakeConfig;
|
|
||||||
{
|
{
|
||||||
CMakeConfigItem settingFileItem;
|
CMakeConfigItem settingFileItem;
|
||||||
settingFileItem.key = "ANDROID_DEPLOYMENT_SETTINGS_FILE";
|
settingFileItem.key = "ANDROID_DEPLOYMENT_SETTINGS_FILE";
|
||||||
@@ -204,7 +188,6 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
|
|||||||
.toUtf8();
|
.toUtf8();
|
||||||
patchedConfig.append(settingFileItem);
|
patchedConfig.append(settingFileItem);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
{
|
{
|
||||||
TraceTimer appsTimer(" application data");
|
TraceTimer appsTimer(" application data");
|
||||||
QSet<QString> res;
|
QSet<QString> res;
|
||||||
@@ -234,7 +217,7 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
|
|||||||
|
|
||||||
{
|
{
|
||||||
TraceTimer projectTreeTimer(" project tree");
|
TraceTimer projectTreeTimer(" project tree");
|
||||||
auto newRoot = generateProjectTree(m_allFiles);
|
auto newRoot = bc->generateProjectTree(m_allFiles);
|
||||||
if (newRoot) {
|
if (newRoot) {
|
||||||
setRootProjectNode(std::move(newRoot));
|
setRootProjectNode(std::move(newRoot));
|
||||||
if (rootProjectNode())
|
if (rootProjectNode())
|
||||||
@@ -250,13 +233,6 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
TraceTimer projectTreeTimer(" target updated");
|
|
||||||
Target *t = bc->target();
|
|
||||||
t->setApplicationTargets(bc->appTargets());
|
|
||||||
t->setDeploymentData(bc->deploymentData());
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
TraceTimer projectTreeTimer(" extra compilers");
|
TraceTimer projectTreeTimer(" extra compilers");
|
||||||
qDeleteAll(m_extraCompilers);
|
qDeleteAll(m_extraCompilers);
|
||||||
@@ -287,28 +263,21 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
TraceTimer qmlCodemodelTimer(" qml codemodel");
|
TraceTimer qmlCodemodelTimer(" qml codemodel");
|
||||||
updateQmlJSCodeModel();
|
updateQmlJSCodeModel(bc);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
TraceTimer resetTimer(" resetting builddirmanager");
|
|
||||||
bc->m_buildDirManager.resetData();
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
TraceTimer emitTimer(" emitting signals");
|
|
||||||
emit fileListChanged();
|
emit fileListChanged();
|
||||||
|
|
||||||
bc->emitBuildTypeChanged();
|
|
||||||
}
|
|
||||||
qCDebug(cmakeProjectLog) << "All CMake project data up to date.";
|
qCDebug(cmakeProjectLog) << "All CMake project data up to date.";
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeProject::updateQmlJSCodeModel()
|
void CMakeProject::updateQmlJSCodeModel(CMakeBuildConfiguration *bc)
|
||||||
{
|
{
|
||||||
|
QTC_ASSERT(bc, return );
|
||||||
|
|
||||||
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
|
QmlJS::ModelManagerInterface *modelManager = QmlJS::ModelManagerInterface::instance();
|
||||||
|
|
||||||
if (!modelManager || !activeTarget() || !activeTarget()->activeBuildConfiguration())
|
if (!modelManager)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QmlJS::ModelManagerInterface::ProjectInfo projectInfo =
|
QmlJS::ModelManagerInterface::ProjectInfo projectInfo =
|
||||||
@@ -316,18 +285,8 @@ void CMakeProject::updateQmlJSCodeModel()
|
|||||||
|
|
||||||
projectInfo.importPaths.clear();
|
projectInfo.importPaths.clear();
|
||||||
|
|
||||||
QString cmakeImports;
|
|
||||||
auto bc = qobject_cast<const CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
|
|
||||||
if (!bc)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const CMakeConfig &cm = bc->configurationFromCMake();
|
const CMakeConfig &cm = bc->configurationFromCMake();
|
||||||
foreach (const CMakeConfigItem &di, cm) {
|
const QString cmakeImports = QString::fromUtf8(CMakeConfigItem::valueOf("QML_IMPORT_PATH", cm));
|
||||||
if (di.key.contains("QML_IMPORT_PATH")) {
|
|
||||||
cmakeImports = QString::fromUtf8(di.value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (const QString &cmakeImport, CMakeConfigItem::cmakeSplitValue(cmakeImports))
|
foreach (const QString &cmakeImport, CMakeConfigItem::cmakeSplitValue(cmakeImports))
|
||||||
projectInfo.importPaths.maybeInsert(FilePath::fromString(cmakeImport), QmlJS::Dialect::Qml);
|
projectInfo.importPaths.maybeInsert(FilePath::fromString(cmakeImport), QmlJS::Dialect::Qml);
|
||||||
@@ -335,19 +294,6 @@ void CMakeProject::updateQmlJSCodeModel()
|
|||||||
modelManager->updateProjectInfo(projectInfo, this);
|
modelManager->updateProjectInfo(projectInfo, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<CMakeProjectNode>
|
|
||||||
CMakeProject::generateProjectTree(const QList<const FileNode *> &allFiles) const
|
|
||||||
{
|
|
||||||
CMakeBuildConfiguration *bc = activeBc(this);
|
|
||||||
if (bc->m_buildDirManager.isParsing())
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
QString errorMessage;
|
|
||||||
auto root = bc->m_buildDirManager.generateProjectTree(allFiles, errorMessage);
|
|
||||||
checkAndReportError(errorMessage);
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CMakeProject::knowsAllBuildExecutables() const
|
bool CMakeProject::knowsAllBuildExecutables() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -100,10 +100,7 @@ private:
|
|||||||
void handleParsingError(Internal::CMakeBuildConfiguration *bc);
|
void handleParsingError(Internal::CMakeBuildConfiguration *bc);
|
||||||
void combineScanAndParse(Internal::CMakeBuildConfiguration *bc);
|
void combineScanAndParse(Internal::CMakeBuildConfiguration *bc);
|
||||||
void updateProjectData(Internal::CMakeBuildConfiguration *bc);
|
void updateProjectData(Internal::CMakeBuildConfiguration *bc);
|
||||||
void updateQmlJSCodeModel();
|
void updateQmlJSCodeModel(Internal::CMakeBuildConfiguration *bc);
|
||||||
|
|
||||||
std::unique_ptr<Internal::CMakeProjectNode>
|
|
||||||
generateProjectTree(const QList<const ProjectExplorer::FileNode*> &allFiles) const;
|
|
||||||
|
|
||||||
QList<ProjectExplorer::ExtraCompiler *> findExtraCompilers() const;
|
QList<ProjectExplorer::ExtraCompiler *> findExtraCompilers() const;
|
||||||
QStringList filesGeneratedFrom(const QString &sourceFile) const final;
|
QStringList filesGeneratedFrom(const QString &sourceFile) const final;
|
||||||
|
|||||||
Reference in New Issue
Block a user