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()
|
||||
{
|
||||
resetData();
|
||||
if (m_reader)
|
||||
if (m_reader) {
|
||||
disconnect(m_reader.get(), nullptr, this, nullptr);
|
||||
m_reader->stop();
|
||||
}
|
||||
m_reader.reset();
|
||||
resetData();
|
||||
}
|
||||
|
||||
void BuildDirManager::setParametersAndRequestParse(const BuildDirParameters ¶meters,
|
||||
|
||||
@@ -91,11 +91,10 @@ CMakeBuildConfiguration::CMakeBuildConfiguration(Target *parent, Core::Id id)
|
||||
if (isActive())
|
||||
project()->requestReparse(options);
|
||||
});
|
||||
connect(&m_buildDirManager, &BuildDirManager::dataAvailable, this, [this]() {
|
||||
clearError();
|
||||
if (isActive())
|
||||
project()->handleParsingSuccess(this);
|
||||
});
|
||||
connect(&m_buildDirManager,
|
||||
&BuildDirManager::dataAvailable,
|
||||
this,
|
||||
&CMakeBuildConfiguration::handleParsingSucceeded);
|
||||
connect(&m_buildDirManager, &BuildDirManager::errorOccured, this, [this](const QString &msg) {
|
||||
setError(msg);
|
||||
QString errorMessage;
|
||||
@@ -513,6 +512,62 @@ void CMakeBuildConfiguration::setWarning(const QString &message)
|
||||
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
|
||||
{
|
||||
return m_error;
|
||||
@@ -534,13 +589,15 @@ ProjectExplorer::NamedWidget *CMakeBuildConfiguration::createConfigWidget()
|
||||
|
||||
CMakeBuildConfigurationFactory::CMakeBuildConfigurationFactory()
|
||||
{
|
||||
registerBuildConfiguration<CMakeBuildConfiguration>("CMakeProjectManager.CMakeBuildConfiguration");
|
||||
registerBuildConfiguration<CMakeBuildConfiguration>(
|
||||
"CMakeProjectManager.CMakeBuildConfiguration");
|
||||
|
||||
setSupportedProjectType(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
|
||||
setSupportedProjectMimeTypeName(Constants::CMAKEPROJECTMIMETYPE);
|
||||
}
|
||||
|
||||
CMakeBuildConfigurationFactory::BuildType CMakeBuildConfigurationFactory::buildTypeFromByteArray(const QByteArray &in)
|
||||
CMakeBuildConfigurationFactory::BuildType CMakeBuildConfigurationFactory::buildTypeFromByteArray(
|
||||
const QByteArray &in)
|
||||
{
|
||||
const QByteArray bt = in.toLower();
|
||||
if (bt == "debug")
|
||||
@@ -554,7 +611,8 @@ CMakeBuildConfigurationFactory::BuildType CMakeBuildConfigurationFactory::buildT
|
||||
return BuildTypeNone;
|
||||
}
|
||||
|
||||
BuildConfiguration::BuildType CMakeBuildConfigurationFactory::cmakeBuildTypeToBuildType(const CMakeBuildConfigurationFactory::BuildType &in)
|
||||
BuildConfiguration::BuildType CMakeBuildConfigurationFactory::cmakeBuildTypeToBuildType(
|
||||
const CMakeBuildConfigurationFactory::BuildType &in)
|
||||
{
|
||||
// Cover all common CMake build types
|
||||
if (in == BuildTypeRelease || in == BuildTypeMinSizeRel)
|
||||
@@ -567,8 +625,9 @@ BuildConfiguration::BuildType CMakeBuildConfigurationFactory::cmakeBuildTypeToBu
|
||||
return BuildConfiguration::Unknown;
|
||||
}
|
||||
|
||||
QList<BuildInfo> CMakeBuildConfigurationFactory::availableBuilds
|
||||
(const Kit *k, const FilePath &projectPath, bool forSetup) const
|
||||
QList<BuildInfo> CMakeBuildConfigurationFactory::availableBuilds(const Kit *k,
|
||||
const FilePath &projectPath,
|
||||
bool forSetup) const
|
||||
{
|
||||
QList<BuildInfo> result;
|
||||
|
||||
@@ -578,9 +637,10 @@ QList<BuildInfo> CMakeBuildConfigurationFactory::availableBuilds
|
||||
BuildInfo info = createBuildInfo(k, path.toString(), BuildType(type));
|
||||
if (forSetup) {
|
||||
info.displayName = info.typeName;
|
||||
info.buildDirectory
|
||||
= CMakeBuildConfiguration::shadowBuildDirectory(projectPath, k,
|
||||
info.displayName, info.buildType);
|
||||
info.buildDirectory = CMakeBuildConfiguration::shadowBuildDirectory(projectPath,
|
||||
k,
|
||||
info.displayName,
|
||||
info.buildType);
|
||||
}
|
||||
result << info;
|
||||
}
|
||||
|
||||
@@ -105,6 +105,13 @@ private:
|
||||
void setError(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;
|
||||
|
||||
CMakeConfig m_configurationForCMake;
|
||||
|
||||
@@ -178,32 +178,15 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
|
||||
QTC_ASSERT(bc == aBc, 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;
|
||||
settingFileItem.key = "ANDROID_DEPLOYMENT_SETTINGS_FILE";
|
||||
settingFileItem.value = bc->buildDirectory()
|
||||
.pathAppended("android_deployment_settings.json")
|
||||
.toString()
|
||||
.toUtf8();
|
||||
patchedConfig.append(settingFileItem);
|
||||
}
|
||||
CMakeConfigItem settingFileItem;
|
||||
settingFileItem.key = "ANDROID_DEPLOYMENT_SETTINGS_FILE";
|
||||
settingFileItem.value = bc->buildDirectory()
|
||||
.pathAppended("android_deployment_settings.json")
|
||||
.toString()
|
||||
.toUtf8();
|
||||
patchedConfig.append(settingFileItem);
|
||||
}
|
||||
{
|
||||
TraceTimer appsTimer(" application data");
|
||||
@@ -234,7 +217,7 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
|
||||
|
||||
{
|
||||
TraceTimer projectTreeTimer(" project tree");
|
||||
auto newRoot = generateProjectTree(m_allFiles);
|
||||
auto newRoot = bc->generateProjectTree(m_allFiles);
|
||||
if (newRoot) {
|
||||
setRootProjectNode(std::move(newRoot));
|
||||
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");
|
||||
qDeleteAll(m_extraCompilers);
|
||||
@@ -287,28 +263,21 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
|
||||
}
|
||||
{
|
||||
TraceTimer qmlCodemodelTimer(" qml codemodel");
|
||||
updateQmlJSCodeModel();
|
||||
updateQmlJSCodeModel(bc);
|
||||
}
|
||||
|
||||
{
|
||||
TraceTimer resetTimer(" resetting builddirmanager");
|
||||
bc->m_buildDirManager.resetData();
|
||||
}
|
||||
emit fileListChanged();
|
||||
|
||||
{
|
||||
TraceTimer emitTimer(" emitting signals");
|
||||
emit fileListChanged();
|
||||
|
||||
bc->emitBuildTypeChanged();
|
||||
}
|
||||
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();
|
||||
|
||||
if (!modelManager || !activeTarget() || !activeTarget()->activeBuildConfiguration())
|
||||
if (!modelManager)
|
||||
return;
|
||||
|
||||
QmlJS::ModelManagerInterface::ProjectInfo projectInfo =
|
||||
@@ -316,18 +285,8 @@ void CMakeProject::updateQmlJSCodeModel()
|
||||
|
||||
projectInfo.importPaths.clear();
|
||||
|
||||
QString cmakeImports;
|
||||
auto bc = qobject_cast<const CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
|
||||
if (!bc)
|
||||
return;
|
||||
|
||||
const CMakeConfig &cm = bc->configurationFromCMake();
|
||||
foreach (const CMakeConfigItem &di, cm) {
|
||||
if (di.key.contains("QML_IMPORT_PATH")) {
|
||||
cmakeImports = QString::fromUtf8(di.value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
const QString cmakeImports = QString::fromUtf8(CMakeConfigItem::valueOf("QML_IMPORT_PATH", cm));
|
||||
|
||||
foreach (const QString &cmakeImport, CMakeConfigItem::cmakeSplitValue(cmakeImports))
|
||||
projectInfo.importPaths.maybeInsert(FilePath::fromString(cmakeImport), QmlJS::Dialect::Qml);
|
||||
@@ -335,19 +294,6 @@ void CMakeProject::updateQmlJSCodeModel()
|
||||
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
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -100,10 +100,7 @@ private:
|
||||
void handleParsingError(Internal::CMakeBuildConfiguration *bc);
|
||||
void combineScanAndParse(Internal::CMakeBuildConfiguration *bc);
|
||||
void updateProjectData(Internal::CMakeBuildConfiguration *bc);
|
||||
void updateQmlJSCodeModel();
|
||||
|
||||
std::unique_ptr<Internal::CMakeProjectNode>
|
||||
generateProjectTree(const QList<const ProjectExplorer::FileNode*> &allFiles) const;
|
||||
void updateQmlJSCodeModel(Internal::CMakeBuildConfiguration *bc);
|
||||
|
||||
QList<ProjectExplorer::ExtraCompiler *> findExtraCompilers() const;
|
||||
QStringList filesGeneratedFrom(const QString &sourceFile) const final;
|
||||
|
||||
Reference in New Issue
Block a user