CMake: Do not make the CMake tool invalid on timeout

Do no mark the CMake tool as invalid when it times out when fetching
auto-completion information. This happens the first time a CMakeLists.txt
file is edited in Creator.

Also increase the timeout so that there is less of a chance
to trigger have the information retrival time out -- which breaks
auto-completion of cmake variables, etc. in the CMakeLists.txt editor.

Closes: QTCREATORBUG-18530
Change-Id: I914377a6ece90c6f78ea5eb007da8fbe07785563
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Tobias Hunger
2019-11-14 15:50:00 +01:00
parent 631efb8611
commit cca33e2e26
2 changed files with 37 additions and 40 deletions

View File

@@ -105,7 +105,7 @@ class IntrospectionData
{ {
public: public:
bool m_didAttemptToRun = false; bool m_didAttemptToRun = false;
bool m_didRun = false; bool m_didRun = true;
bool m_hasServerMode = false; bool m_hasServerMode = false;
bool m_queriedServerMode = false; bool m_queriedServerMode = false;
@@ -200,26 +200,17 @@ bool CMakeTool::isValid() const
return m_introspection->m_didRun; return m_introspection->m_didRun;
} }
Utils::SynchronousProcessResponse CMakeTool::run(const QStringList &args, bool mayFail) const Utils::SynchronousProcessResponse CMakeTool::run(const QStringList &args, int timeoutS) const
{ {
if (m_introspection->m_didAttemptToRun && !m_introspection->m_didRun) {
Utils::SynchronousProcessResponse response;
response.result = Utils::SynchronousProcessResponse::StartFailed;
return response;
}
Utils::SynchronousProcess cmake; Utils::SynchronousProcess cmake;
cmake.setTimeoutS(1); cmake.setTimeoutS(timeoutS);
cmake.setFlags(Utils::SynchronousProcess::UnixTerminalDisabled); cmake.setFlags(Utils::SynchronousProcess::UnixTerminalDisabled);
Utils::Environment env = Utils::Environment::systemEnvironment(); Utils::Environment env = Utils::Environment::systemEnvironment();
Utils::Environment::setupEnglishOutput(&env); Utils::Environment::setupEnglishOutput(&env);
cmake.setProcessEnvironment(env.toProcessEnvironment()); cmake.setProcessEnvironment(env.toProcessEnvironment());
cmake.setTimeOutMessageBoxEnabled(false); cmake.setTimeOutMessageBoxEnabled(false);
Utils::SynchronousProcessResponse response = cmake.runBlocking({cmakeExecutable(), args}); return cmake.runBlocking({cmakeExecutable(), args});
m_introspection->m_didAttemptToRun = true;
m_introspection->m_didRun = mayFail ? true : (response.result == Utils::SynchronousProcessResponse::Finished);
return response;
} }
QVariantMap CMakeTool::toMap() const QVariantMap CMakeTool::toMap() const
@@ -280,21 +271,21 @@ QList<CMakeTool::Generator> CMakeTool::supportedGenerators() const
TextEditor::Keywords CMakeTool::keywords() TextEditor::Keywords CMakeTool::keywords()
{ {
if (m_introspection->m_functions.isEmpty()) { if (m_introspection->m_functions.isEmpty() && m_introspection->m_didRun) {
Utils::SynchronousProcessResponse response; Utils::SynchronousProcessResponse response;
response = run({"--help-command-list"}); response = run({"--help-command-list"}, 5);
if (response.result == Utils::SynchronousProcessResponse::Finished) if (response.result == Utils::SynchronousProcessResponse::Finished)
m_introspection->m_functions = response.stdOut().split('\n'); m_introspection->m_functions = response.stdOut().split('\n');
response = run({"--help-commands"}); response = run({"--help-commands"}, 5);
if (response.result == Utils::SynchronousProcessResponse::Finished) if (response.result == Utils::SynchronousProcessResponse::Finished)
parseFunctionDetailsOutput(response.stdOut()); parseFunctionDetailsOutput(response.stdOut());
response = run({"--help-property-list"}); response = run({"--help-property-list"}, 5);
if (response.result == Utils::SynchronousProcessResponse::Finished) if (response.result == Utils::SynchronousProcessResponse::Finished)
m_introspection->m_variables = parseVariableOutput(response.stdOut()); m_introspection->m_variables = parseVariableOutput(response.stdOut());
response = run({"--help-variable-list"}); response = run({"--help-variable-list"}, 5);
if (response.result == Utils::SynchronousProcessResponse::Finished) { if (response.result == Utils::SynchronousProcessResponse::Finished) {
m_introspection->m_variables.append(parseVariableOutput(response.stdOut())); m_introspection->m_variables.append(parseVariableOutput(response.stdOut()));
m_introspection->m_variables = Utils::filteredUnique(m_introspection->m_variables); m_introspection->m_variables = Utils::filteredUnique(m_introspection->m_variables);
@@ -377,6 +368,11 @@ CMakeTool::ReaderType CMakeTool::readerType() const
void CMakeTool::readInformation(CMakeTool::QueryType type) const void CMakeTool::readInformation(CMakeTool::QueryType type) const
{ {
if (!m_introspection->m_didRun && m_introspection->m_didAttemptToRun)
return;
m_introspection->m_didAttemptToRun = true;
if ((type == QueryType::GENERATORS && !m_introspection->m_generators.isEmpty()) if ((type == QueryType::GENERATORS && !m_introspection->m_generators.isEmpty())
|| (type == QueryType::SERVER_MODE && m_introspection->m_queriedServerMode) || (type == QueryType::SERVER_MODE && m_introspection->m_queriedServerMode)
|| (type == QueryType::VERSION && !m_introspection->m_version.fullVersion.isEmpty())) || (type == QueryType::VERSION && !m_introspection->m_version.fullVersion.isEmpty()))
@@ -386,10 +382,7 @@ void CMakeTool::readInformation(CMakeTool::QueryType type) const
fetchFromCapabilities(); fetchFromCapabilities();
m_introspection->m_triedCapabilities = true; m_introspection->m_triedCapabilities = true;
m_introspection->m_queriedServerMode = true; // Got added after "-E capabilities" support! m_introspection->m_queriedServerMode = true; // Got added after "-E capabilities" support!
if (type == QueryType::GENERATORS && !m_introspection->m_generators.isEmpty()) } else {
return;
}
if (type == QueryType::GENERATORS) { if (type == QueryType::GENERATORS) {
fetchGeneratorsFromHelp(); fetchGeneratorsFromHelp();
} else if (type == QueryType::SERVER_MODE) { } else if (type == QueryType::SERVER_MODE) {
@@ -400,6 +393,7 @@ void CMakeTool::readInformation(CMakeTool::QueryType type) const
QTC_ASSERT(false, return ); QTC_ASSERT(false, return );
} }
} }
}
static QStringList parseDefinition(const QString &definition) static QStringList parseDefinition(const QString &definition)
{ {
@@ -495,8 +489,10 @@ QStringList CMakeTool::parseVariableOutput(const QString &output)
void CMakeTool::fetchGeneratorsFromHelp() const void CMakeTool::fetchGeneratorsFromHelp() const
{ {
Utils::SynchronousProcessResponse response = run({"--help"}); Utils::SynchronousProcessResponse response = run({"--help"});
if (response.result != Utils::SynchronousProcessResponse::Finished) m_introspection->m_didRun = m_introspection->m_didRun
return; && response.result == Utils::SynchronousProcessResponse::Finished;
if (response.result == Utils::SynchronousProcessResponse::Finished)
parseGeneratorsFromHelp(response.stdOut().split('\n')); parseGeneratorsFromHelp(response.stdOut().split('\n'));
} }
@@ -550,9 +546,11 @@ void CMakeTool::parseGeneratorsFromHelp(const QStringList &lines) const
void CMakeTool::fetchVersionFromVersionOutput() const void CMakeTool::fetchVersionFromVersionOutput() const
{ {
Utils::SynchronousProcessResponse response = run({"--version"}); Utils::SynchronousProcessResponse response = run({"--version"});
if (response.result != Utils::SynchronousProcessResponse::Finished)
return;
m_introspection->m_didRun = m_introspection->m_didRun
&& response.result == Utils::SynchronousProcessResponse::Finished;
if (response.result == Utils::SynchronousProcessResponse::Finished)
parseVersionFormVersionOutput(response.stdOut().split('\n')); parseVersionFormVersionOutput(response.stdOut().split('\n'));
} }
@@ -574,10 +572,9 @@ void CMakeTool::parseVersionFormVersionOutput(const QStringList &lines) const
void CMakeTool::fetchFromCapabilities() const void CMakeTool::fetchFromCapabilities() const
{ {
Utils::SynchronousProcessResponse response = run({"-E", "capabilities"}, true); Utils::SynchronousProcessResponse response = run({"-E", "capabilities"});
if (response.result != Utils::SynchronousProcessResponse::Finished)
return;
if (response.result == Utils::SynchronousProcessResponse::Finished)
parseFromCapabilities(response.stdOut()); parseFromCapabilities(response.stdOut());
} }

View File

@@ -122,7 +122,7 @@ private:
}; };
void readInformation(QueryType type) const; void readInformation(QueryType type) const;
Utils::SynchronousProcessResponse run(const QStringList &args, bool mayFail = false) const; Utils::SynchronousProcessResponse run(const QStringList &args, int timeoutS = 1) const;
void parseFunctionDetailsOutput(const QString &output); void parseFunctionDetailsOutput(const QString &output);
QStringList parseVariableOutput(const QString &output); QStringList parseVariableOutput(const QString &output);