CMake: Move builddirmanager into CMakeBuildConfiguration

Change-Id: I1854b6021e7d573abd4ac9d64c8d5dbd0618ed71
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Tobias Hunger
2019-08-05 15:56:03 +02:00
parent 8c34d653be
commit 338a7184a5
6 changed files with 161 additions and 162 deletions

View File

@@ -194,6 +194,14 @@ bool BuildDirManager::isParsing() const
return m_reader && m_reader->isParsing();
}
void BuildDirManager::stopParsingAndClearState()
{
resetData();
if (m_reader)
m_reader->stop();
m_reader.reset();
}
void BuildDirManager::setParametersAndRequestParse(const BuildDirParameters &parameters,
int newReaderReparseOptions,
int existingReaderReparseOptions)
@@ -204,12 +212,10 @@ void BuildDirManager::setParametersAndRequestParse(const BuildDirParameters &par
ProjectExplorer::Constants::TASK_CATEGORY_BUILDSYSTEM);
return;
}
QTC_ASSERT(parameters.isValid(), return);
if (m_reader)
m_reader->stop();
QTC_ASSERT(parameters.isValid(), return );
BuildDirReader *old = m_reader.get();
stopParsingAndClearState();
m_parameters = parameters;
m_parameters.workDirectory = workDirectory(parameters);

View File

@@ -64,8 +64,11 @@ public:
bool isParsing() const;
void stopParsingAndClearState();
void setParametersAndRequestParse(const BuildDirParameters &parameters,
int newReaderReparseOptions, int existingReaderReparseOptions);
int newReaderReparseOptions,
int existingReaderReparseOptions);
// nullptr if the BC is not active anymore!
CMakeBuildConfiguration *buildConfiguration() const;
CMakeProject *project() const {return m_project; }

View File

@@ -78,12 +78,98 @@ const char CONFIGURATION_KEY[] = "CMake.Configuration";
CMakeBuildConfiguration::CMakeBuildConfiguration(Target *parent, Core::Id id)
: BuildConfiguration(parent, id)
, m_buildDirManager(qobject_cast<CMakeProject *>(parent->project()))
{
auto project = target()->project();
setBuildDirectory(shadowBuildDirectory(project->projectFilePath(),
setBuildDirectory(shadowBuildDirectory(project()->projectFilePath(),
target()->kit(),
displayName(), BuildConfiguration::Unknown));
connect(project, &Project::parsingFinished, this, &BuildConfiguration::enabledChanged);
displayName(),
BuildConfiguration::Unknown));
connect(project(), &Project::parsingFinished, this, &BuildConfiguration::enabledChanged);
// BuildDirManager:
connect(&m_buildDirManager, &BuildDirManager::requestReparse, this, [this](int options) {
if (isActive())
project()->requestReparse(options);
});
connect(&m_buildDirManager, &BuildDirManager::dataAvailable, this, [this]() {
clearError();
if (isActive())
project()->handleParsingSuccess(this);
});
connect(&m_buildDirManager, &BuildDirManager::errorOccured, this, [this](const QString &msg) {
setError(msg);
QString errorMessage;
setConfigurationFromCMake(m_buildDirManager.takeCMakeConfiguration(errorMessage));
// ignore errorMessage here, we already got one.
project()->handleParsingError(this);
});
connect(&m_buildDirManager, &BuildDirManager::parsingStarted, this, [this]() {
clearError(CMakeBuildConfiguration::ForceEnabledChanged::True);
});
// Kit changed:
connect(KitManager::instance(), &KitManager::kitUpdated, this, [this](Kit *k) {
if (k != target()->kit())
return; // not for us...
// Build configuration has not changed, but Kit settings might have:
// reparse and check the configuration, independent of whether the reader has changed
m_buildDirManager.setParametersAndRequestParse(BuildDirParameters(this),
BuildDirManager::REPARSE_CHECK_CONFIGURATION,
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
});
// Became active/inactive:
connect(project(), &Project::activeBuildConfigurationChanged, this, [this]() {
if (isActive()) {
// Build configuration has switched:
// * Check configuration if reader changes due to it not existing yet:-)
// * run cmake without configuration arguments if the reader stays
m_buildDirManager
.setParametersAndRequestParse(BuildDirParameters(this),
BuildDirManager::REPARSE_CHECK_CONFIGURATION,
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
} else {
m_buildDirManager.stopParsingAndClearState();
}
});
// BuildConfiguration changed:
connect(this, &CMakeBuildConfiguration::environmentChanged, this, [this]() {
if (isActive()) {
// The environment on our BC has changed:
// * Error out if the reader updates, cannot happen since all BCs share a target/kit.
// * run cmake without configuration arguments if the reader stays
m_buildDirManager.setParametersAndRequestParse(
BuildDirParameters(this),
BuildDirManager::REPARSE_CHECK_CONFIGURATION, // server-mode might need a restart...
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
}
});
connect(this, &CMakeBuildConfiguration::buildDirectoryChanged, this, [this]() {
if (isActive()) {
// The build directory of our BC has changed:
// * Error out if the reader updates, cannot happen since all BCs share a target/kit.
// * run cmake without configuration arguments if the reader stays
// If no configuration exists, then the arguments will get added automatically by
// the reader.
m_buildDirManager
.setParametersAndRequestParse(BuildDirParameters(this),
BuildDirManager::REPARSE_FAIL,
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
}
});
connect(this, &CMakeBuildConfiguration::configurationForCMakeChanged, this, [this]() {
if (isActive()) {
// The CMake configuration has changed on our BC:
// * Error out if the reader updates, cannot happen since all BCs share a target/kit.
// * run cmake with configuration arguments if the reader stays
m_buildDirManager
.setParametersAndRequestParse(BuildDirParameters(this),
BuildDirManager::REPARSE_FAIL,
BuildDirManager::REPARSE_FORCE_CONFIGURATION);
}
});
}
void CMakeBuildConfiguration::initialize(const BuildInfo &info)
@@ -582,5 +668,10 @@ ProjectExplorer::BuildConfiguration::BuildType CMakeBuildConfiguration::buildTyp
return CMakeBuildConfigurationFactory::cmakeBuildTypeToBuildType(cmakeBuildType);
}
CMakeProject *CMakeBuildConfiguration::project() const
{
return qobject_cast<CMakeProject *>(BuildConfiguration::project());
}
} // namespace Internal
} // namespace CMakeProjectManager

View File

@@ -62,6 +62,8 @@ public:
QString error() const;
QString warning() const;
CMakeProject *project() const;
QStringList buildTargetTitles() const;
const QList<CMakeBuildTarget> &buildTargets() const;
const QList<ProjectExplorer::BuildTargetInfo> appTargets() const;
@@ -103,6 +105,8 @@ private:
void setError(const QString &message);
void setWarning(const QString &message);
Internal::BuildDirManager m_buildDirManager;
CMakeConfig m_configurationForCMake;
CMakeConfig m_initialConfiguration;
QString m_error;

View File

@@ -103,9 +103,9 @@ static CMakeBuildConfiguration *activeBc(const CMakeProject *p)
/*!
\class CMakeProject
*/
CMakeProject::CMakeProject(const FilePath &fileName) : Project(Constants::CMAKEMIMETYPE, fileName),
m_cppCodeModelUpdater(new CppTools::CppProjectUpdater),
m_buildDirManager(this)
CMakeProject::CMakeProject(const FilePath &fileName)
: Project(Constants::CMAKEMIMETYPE, fileName)
, m_cppCodeModelUpdater(new CppTools::CppProjectUpdater)
{
setId(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
setProjectLanguages(Core::Context(ProjectExplorer::Constants::CXX_LANGUAGE_ID));
@@ -118,126 +118,6 @@ CMakeProject::CMakeProject(const FilePath &fileName) : Project(Constants::CMAKEM
connect(&m_delayedParsingTimer, &QTimer::timeout,
this, [this]() { startParsing(m_delayedParsingParameters); });
// BuildDirManager:
connect(&m_buildDirManager, &BuildDirManager::requestReparse,
this, &CMakeProject::handleReparseRequest);
connect(&m_buildDirManager, &BuildDirManager::dataAvailable,
this, [this]() {
CMakeBuildConfiguration *bc = m_buildDirManager.buildConfiguration();
if (bc) {
bc->clearError();
handleParsingSuccess(bc);
}
});
connect(&m_buildDirManager, &BuildDirManager::errorOccured,
this, [this](const QString &msg) {
reportError(msg);
CMakeBuildConfiguration *bc = m_buildDirManager.buildConfiguration();
if (bc) {
QString errorMessage;
bc->setConfigurationFromCMake(m_buildDirManager.takeCMakeConfiguration(errorMessage));
// ignore errorMessage here, we already got one.
handleParsingError(bc);
}
});
connect(&m_buildDirManager, &BuildDirManager::parsingStarted,
this, [this]() {
CMakeBuildConfiguration *bc = m_buildDirManager.buildConfiguration();
if (bc)
bc->clearError(CMakeBuildConfiguration::ForceEnabledChanged::True);
});
// Kit changed:
connect(KitManager::instance(), &KitManager::kitUpdated,
this, [this](Kit *k) {
CMakeBuildConfiguration *bc = activeBc(this);
if (!bc || k != bc->target()->kit())
return; // not for us...
// Build configuration has not changed, but Kit settings might have:
// reparse and check the configuration, independent of whether the reader has changed
m_buildDirManager.setParametersAndRequestParse(
BuildDirParameters(bc),
BuildDirManager::REPARSE_CHECK_CONFIGURATION,
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
});
// Target switched:
connect(this, &Project::activeTargetChanged, this, [this]() {
CMakeBuildConfiguration *bc = activeBc(this);
if (!bc)
return;
// Target has switched, so the kit has changed, too.
// * run cmake with configuration arguments if the reader needs to be switched
// * run cmake without configuration arguments if the reader stays
m_buildDirManager.setParametersAndRequestParse(
BuildDirParameters(bc),
BuildDirManager::REPARSE_CHECK_CONFIGURATION,
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
});
// BuildConfiguration switched:
subscribeSignal(&Target::activeBuildConfigurationChanged, this, [this]() {
CMakeBuildConfiguration *bc = activeBc(this);
if (!bc)
return;
// Build configuration has switched:
// * Check configuration if reader changes due to it not existing yet:-)
// * run cmake without configuration arguments if the reader stays
m_buildDirManager.setParametersAndRequestParse(
BuildDirParameters(bc),
BuildDirManager::REPARSE_CHECK_CONFIGURATION,
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
});
// BuildConfiguration changed:
subscribeSignal(&CMakeBuildConfiguration::environmentChanged, this, [this]() {
auto senderBc = qobject_cast<CMakeBuildConfiguration *>(sender());
if (senderBc && senderBc->isActive()) {
// The environment on our BC has changed:
// * Error out if the reader updates, cannot happen since all BCs share a target/kit.
// * run cmake without configuration arguments if the reader stays
m_buildDirManager.setParametersAndRequestParse(
BuildDirParameters(senderBc),
BuildDirManager::REPARSE_CHECK_CONFIGURATION, // server-mode might need a restart...
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
}
});
subscribeSignal(&CMakeBuildConfiguration::buildDirectoryChanged, this, [this]() {
auto senderBc = qobject_cast<CMakeBuildConfiguration *>(sender());
if (senderBc && senderBc == m_buildDirManager.buildConfiguration()) {
// The build directory of our BC has changed:
// * Error out if the reader updates, cannot happen since all BCs share a target/kit.
// * run cmake without configuration arguments if the reader stays
// If no configuration exists, then the arguments will get added automatically by
// the reader.
m_buildDirManager.setParametersAndRequestParse(
BuildDirParameters(senderBc),
BuildDirManager::REPARSE_FAIL,
BuildDirManager::REPARSE_CHECK_CONFIGURATION);
}
});
subscribeSignal(&CMakeBuildConfiguration::configurationForCMakeChanged, this, [this]() {
auto senderBc = qobject_cast<CMakeBuildConfiguration *>(sender());
if (senderBc && senderBc == m_buildDirManager.buildConfiguration()) {
// The CMake configuration has changed on our BC:
// * Error out if the reader updates, cannot happen since all BCs share a target/kit.
// * run cmake with configuration arguments if the reader stays
m_buildDirManager.setParametersAndRequestParse(
BuildDirParameters(senderBc),
BuildDirManager::REPARSE_FAIL,
BuildDirManager::REPARSE_FORCE_CONFIGURATION);
}
});
// TreeScanner:
connect(&m_treeScanner, &TreeScanner::finished, this, &CMakeProject::handleTreeScanningFinished);
@@ -296,11 +176,11 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
QTC_ASSERT(bc, return);
QTC_ASSERT(bc == aBc, return);
QTC_ASSERT(m_treeScanner.isFinished() && !m_buildDirManager.isParsing(), return);
QTC_ASSERT(m_treeScanner.isFinished() && !bc->m_buildDirManager.isParsing(), return );
{
TraceTimer buildTargetsTimer(" build targets");
const QList<CMakeBuildTarget> buildTargets = m_buildDirManager.takeBuildTargets(
const QList<CMakeBuildTarget> buildTargets = bc->m_buildDirManager.takeBuildTargets(
errorMessage);
checkAndReportError(errorMessage);
bc->setBuildTargets(buildTargets);
@@ -309,7 +189,7 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
CMakeConfig patchedConfig;
{
TraceTimer cacheTimer(" cache data (plus patching)");
const CMakeConfig cmakeConfig = m_buildDirManager.takeCMakeConfiguration(errorMessage);
const CMakeConfig cmakeConfig = bc->m_buildDirManager.takeCMakeConfiguration(errorMessage);
checkAndReportError(errorMessage);
bc->setConfigurationFromCMake(cmakeConfig);
qCDebug(cmakeProjectLog) << "CMake configuration data set.";
@@ -390,7 +270,7 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
{
TraceTimer cxxCodemodelTimer(" cxx codemodel");
CppTools::RawProjectParts rpps = m_buildDirManager.createRawProjectParts(errorMessage);
CppTools::RawProjectParts rpps = bc->m_buildDirManager.createRawProjectParts(errorMessage);
checkAndReportError(errorMessage);
qCDebug(cmakeProjectLog) << "Raw project parts created.";
@@ -412,7 +292,7 @@ void CMakeProject::updateProjectData(CMakeBuildConfiguration *bc)
{
TraceTimer resetTimer(" resetting builddirmanager");
m_buildDirManager.resetData();
bc->m_buildDirManager.resetData();
}
{
@@ -458,11 +338,12 @@ void CMakeProject::updateQmlJSCodeModel()
std::unique_ptr<CMakeProjectNode>
CMakeProject::generateProjectTree(const QList<const FileNode *> &allFiles) const
{
if (m_buildDirManager.isParsing())
CMakeBuildConfiguration *bc = activeBc(this);
if (bc->m_buildDirManager.isParsing())
return nullptr;
QString errorMessage;
auto root = m_buildDirManager.generateProjectTree(allFiles, errorMessage);
auto root = bc->m_buildDirManager.generateProjectTree(allFiles, errorMessage);
checkAndReportError(errorMessage);
return root;
}
@@ -491,11 +372,12 @@ void CMakeProject::runCMake()
return;
BuildDirParameters parameters(bc);
m_buildDirManager.setParametersAndRequestParse(parameters,
BuildDirManager::REPARSE_CHECK_CONFIGURATION
| BuildDirManager::REPARSE_FORCE_CMAKE_RUN,
BuildDirManager::REPARSE_CHECK_CONFIGURATION
| BuildDirManager::REPARSE_FORCE_CMAKE_RUN);
bc->m_buildDirManager
.setParametersAndRequestParse(parameters,
BuildDirManager::REPARSE_CHECK_CONFIGURATION
| BuildDirManager::REPARSE_FORCE_CMAKE_RUN,
BuildDirManager::REPARSE_CHECK_CONFIGURATION
| BuildDirManager::REPARSE_FORCE_CMAKE_RUN);
}
void CMakeProject::runCMakeAndScanProjectTree()
@@ -506,9 +388,11 @@ void CMakeProject::runCMakeAndScanProjectTree()
QTC_ASSERT(m_treeScanner.isFinished(), return);
BuildDirParameters parameters(bc);
m_buildDirManager.setParametersAndRequestParse(parameters,
BuildDirManager::REPARSE_CHECK_CONFIGURATION | BuildDirManager::REPARSE_SCAN,
BuildDirManager::REPARSE_CHECK_CONFIGURATION | BuildDirManager::REPARSE_SCAN);
bc->m_buildDirManager.setParametersAndRequestParse(parameters,
BuildDirManager::REPARSE_CHECK_CONFIGURATION
| BuildDirManager::REPARSE_SCAN,
BuildDirManager::REPARSE_CHECK_CONFIGURATION
| BuildDirManager::REPARSE_SCAN);
}
void CMakeProject::buildCMakeTarget(const QString &buildTarget)
@@ -528,25 +412,20 @@ ProjectImporter *CMakeProject::projectImporter() const
bool CMakeProject::persistCMakeState()
{
return m_buildDirManager.persistCMakeState();
CMakeBuildConfiguration *bc = activeBc(this);
return bc ? bc->m_buildDirManager.persistCMakeState() : false;
}
void CMakeProject::clearCMakeCache()
{
m_buildDirManager.clearCache();
CMakeBuildConfiguration *bc = activeBc(this);
if (bc)
bc->m_buildDirManager.clearCache();
}
void CMakeProject::handleReparseRequest(int reparseParameters)
{
QTC_ASSERT(!(reparseParameters & BuildDirManager::REPARSE_FAIL), return);
if (reparseParameters & BuildDirManager::REPARSE_IGNORE)
return;
m_delayedParsingTimer.setInterval((reparseParameters & BuildDirManager::REPARSE_URGENT) ? 0 : 1000);
m_delayedParsingTimer.start();
m_delayedParsingParameters = m_delayedParsingParameters | reparseParameters;
if (m_allFiles.isEmpty())
m_delayedParsingParameters |= BuildDirManager::REPARSE_SCAN;
requestReparse(reparseParameters);
}
void CMakeProject::startParsing(int reparseParameters)
@@ -557,7 +436,8 @@ void CMakeProject::startParsing(int reparseParameters)
if (reparseParameters & BuildDirManager::REPARSE_IGNORE)
return;
QTC_ASSERT(activeBc(this), return);
CMakeBuildConfiguration *bc = activeBc(this);
QTC_ASSERT(bc, return );
emitParsingStarted();
@@ -573,7 +453,7 @@ void CMakeProject::startParsing(int reparseParameters)
"CMake.Scan.Tree");
}
m_buildDirManager.parse(reparseParameters);
bc->m_buildDirManager.parse(reparseParameters);
}
QStringList CMakeProject::buildTargetTitles() const
@@ -601,11 +481,25 @@ bool CMakeProject::setupTarget(Target *t)
void CMakeProject::reportError(const QString &errorMessage) const
{
CMakeBuildConfiguration *bc = m_buildDirManager.buildConfiguration();
CMakeBuildConfiguration *bc = activeBc(this);
if (bc)
bc->setError(errorMessage);
}
void CMakeProject::requestReparse(int reparseParameters)
{
QTC_ASSERT(!(reparseParameters & BuildDirManager::REPARSE_FAIL), return );
if (reparseParameters & BuildDirManager::REPARSE_IGNORE)
return;
m_delayedParsingTimer.setInterval((reparseParameters & BuildDirManager::REPARSE_URGENT) ? 0
: 1000);
m_delayedParsingTimer.start();
m_delayedParsingParameters = m_delayedParsingParameters | reparseParameters;
if (m_allFiles.isEmpty())
m_delayedParsingParameters |= BuildDirManager::REPARSE_SCAN;
}
void CMakeProject::handleTreeScanningFinished()
{
QTC_CHECK(m_waitingForScan);

View File

@@ -84,6 +84,8 @@ public:
void checkAndReportError(QString &errorMessage) const;
void reportError(const QString &errorMessage) const;
void requestReparse(int reparseParameters);
protected:
RestoreResult fromMap(const QVariantMap &map, QString *errorMessage) final;
bool setupTarget(ProjectExplorer::Target *t) final;
@@ -115,7 +117,6 @@ private:
QList<ProjectExplorer::ExtraCompiler *> m_extraCompilers;
ProjectExplorer::TreeScanner m_treeScanner;
Internal::BuildDirManager m_buildDirManager;
bool m_waitingForScan = false;
bool m_waitingForParse = false;