cmServer: add braces around conditional statements
This commit is contained in:
parent
6757e66089
commit
92207752df
|
@ -123,8 +123,9 @@ void cmServer::RegisterProtocol(cmServerProtocol* protocol)
|
||||||
[version](cmServerProtocol* p) {
|
[version](cmServerProtocol* p) {
|
||||||
return p->ProtocolVersion() == version;
|
return p->ProtocolVersion() == version;
|
||||||
});
|
});
|
||||||
if (it == this->SupportedProtocols.end())
|
if (it == this->SupportedProtocols.end()) {
|
||||||
this->SupportedProtocols.push_back(protocol);
|
this->SupportedProtocols.push_back(protocol);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmServer::PrintHello() const
|
void cmServer::PrintHello() const
|
||||||
|
@ -181,37 +182,44 @@ void cmServer::reportMessage(const char* msg, const char* title,
|
||||||
|
|
||||||
cmServerResponse cmServer::SetProtocolVersion(const cmServerRequest& request)
|
cmServerResponse cmServer::SetProtocolVersion(const cmServerRequest& request)
|
||||||
{
|
{
|
||||||
if (request.Type != kHANDSHAKE_TYPE)
|
if (request.Type != kHANDSHAKE_TYPE) {
|
||||||
return request.ReportError("Waiting for type \"" + kHANDSHAKE_TYPE +
|
return request.ReportError("Waiting for type \"" + kHANDSHAKE_TYPE +
|
||||||
"\".");
|
"\".");
|
||||||
|
}
|
||||||
|
|
||||||
Json::Value requestedProtocolVersion = request.Data[kPROTOCOL_VERSION_KEY];
|
Json::Value requestedProtocolVersion = request.Data[kPROTOCOL_VERSION_KEY];
|
||||||
if (requestedProtocolVersion.isNull())
|
if (requestedProtocolVersion.isNull()) {
|
||||||
return request.ReportError("\"" + kPROTOCOL_VERSION_KEY +
|
return request.ReportError("\"" + kPROTOCOL_VERSION_KEY +
|
||||||
"\" is required for \"" + kHANDSHAKE_TYPE +
|
"\" is required for \"" + kHANDSHAKE_TYPE +
|
||||||
"\".");
|
"\".");
|
||||||
|
}
|
||||||
|
|
||||||
if (!requestedProtocolVersion.isObject())
|
if (!requestedProtocolVersion.isObject()) {
|
||||||
return request.ReportError("\"" + kPROTOCOL_VERSION_KEY +
|
return request.ReportError("\"" + kPROTOCOL_VERSION_KEY +
|
||||||
"\" must be a JSON object.");
|
"\" must be a JSON object.");
|
||||||
|
}
|
||||||
|
|
||||||
Json::Value majorValue = requestedProtocolVersion[kMAJOR_KEY];
|
Json::Value majorValue = requestedProtocolVersion[kMAJOR_KEY];
|
||||||
if (!majorValue.isInt())
|
if (!majorValue.isInt()) {
|
||||||
return request.ReportError("\"" + kMAJOR_KEY +
|
return request.ReportError("\"" + kMAJOR_KEY +
|
||||||
"\" must be set and an integer.");
|
"\" must be set and an integer.");
|
||||||
|
}
|
||||||
|
|
||||||
Json::Value minorValue = requestedProtocolVersion[kMINOR_KEY];
|
Json::Value minorValue = requestedProtocolVersion[kMINOR_KEY];
|
||||||
if (!minorValue.isNull() && !minorValue.isInt())
|
if (!minorValue.isNull() && !minorValue.isInt()) {
|
||||||
return request.ReportError("\"" + kMINOR_KEY +
|
return request.ReportError("\"" + kMINOR_KEY +
|
||||||
"\" must be unset or an integer.");
|
"\" must be unset or an integer.");
|
||||||
|
}
|
||||||
|
|
||||||
const int major = majorValue.asInt();
|
const int major = majorValue.asInt();
|
||||||
const int minor = minorValue.isNull() ? -1 : minorValue.asInt();
|
const int minor = minorValue.isNull() ? -1 : minorValue.asInt();
|
||||||
if (major < 0)
|
if (major < 0) {
|
||||||
return request.ReportError("\"" + kMAJOR_KEY + "\" must be >= 0.");
|
return request.ReportError("\"" + kMAJOR_KEY + "\" must be >= 0.");
|
||||||
if (!minorValue.isNull() && minor < 0)
|
}
|
||||||
|
if (!minorValue.isNull() && minor < 0) {
|
||||||
return request.ReportError("\"" + kMINOR_KEY +
|
return request.ReportError("\"" + kMINOR_KEY +
|
||||||
"\" must be >= 0 when set.");
|
"\" must be >= 0 when set.");
|
||||||
|
}
|
||||||
|
|
||||||
this->Protocol =
|
this->Protocol =
|
||||||
this->FindMatchingProtocol(this->SupportedProtocols, major, minor);
|
this->FindMatchingProtocol(this->SupportedProtocols, major, minor);
|
||||||
|
@ -284,12 +292,15 @@ cmServerProtocol* cmServer::FindMatchingProtocol(
|
||||||
cmServerProtocol* bestMatch = nullptr;
|
cmServerProtocol* bestMatch = nullptr;
|
||||||
for (auto protocol : protocols) {
|
for (auto protocol : protocols) {
|
||||||
auto version = protocol->ProtocolVersion();
|
auto version = protocol->ProtocolVersion();
|
||||||
if (major != version.first)
|
if (major != version.first) {
|
||||||
continue;
|
continue;
|
||||||
if (minor == version.second)
|
}
|
||||||
|
if (minor == version.second) {
|
||||||
return protocol;
|
return protocol;
|
||||||
if (!bestMatch || bestMatch->ProtocolVersion().second < version.second)
|
}
|
||||||
|
if (!bestMatch || bestMatch->ProtocolVersion().second < version.second) {
|
||||||
bestMatch = protocol;
|
bestMatch = protocol;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return minor < 0 ? bestMatch : nullptr;
|
return minor < 0 ? bestMatch : nullptr;
|
||||||
}
|
}
|
||||||
|
@ -317,8 +328,9 @@ void cmServer::WriteMessage(const cmServerRequest& request,
|
||||||
const std::string& message,
|
const std::string& message,
|
||||||
const std::string& title) const
|
const std::string& title) const
|
||||||
{
|
{
|
||||||
if (message.empty())
|
if (message.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Json::Value obj = Json::objectValue;
|
Json::Value obj = Json::objectValue;
|
||||||
obj[kTYPE_KEY] = kMESSAGE_TYPE;
|
obj[kTYPE_KEY] = kMESSAGE_TYPE;
|
||||||
|
|
|
@ -146,8 +146,9 @@ void cmServerConnection::ReadData(const std::string& data)
|
||||||
}
|
}
|
||||||
std::string line = this->RawReadBuffer.substr(0, needle);
|
std::string line = this->RawReadBuffer.substr(0, needle);
|
||||||
const auto ls = line.size();
|
const auto ls = line.size();
|
||||||
if (ls > 1 && line.at(ls - 1) == '\r')
|
if (ls > 1 && line.at(ls - 1) == '\r') {
|
||||||
line.erase(ls - 1, 1);
|
line.erase(ls - 1, 1);
|
||||||
|
}
|
||||||
this->RawReadBuffer.erase(this->RawReadBuffer.begin(),
|
this->RawReadBuffer.erase(this->RawReadBuffer.begin(),
|
||||||
this->RawReadBuffer.begin() +
|
this->RawReadBuffer.begin() +
|
||||||
static_cast<long>(needle) + 1);
|
static_cast<long>(needle) + 1);
|
||||||
|
|
|
@ -97,10 +97,10 @@ bool cmServerResponse::IsError() const
|
||||||
|
|
||||||
std::string cmServerResponse::ErrorMessage() const
|
std::string cmServerResponse::ErrorMessage() const
|
||||||
{
|
{
|
||||||
if (this->m_Payload == PAYLOAD_ERROR)
|
if (this->m_Payload == PAYLOAD_ERROR) {
|
||||||
return this->m_ErrorMessage;
|
return this->m_ErrorMessage;
|
||||||
else
|
}
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value cmServerResponse::Data() const
|
Json::Value cmServerResponse::Data() const
|
||||||
|
@ -117,16 +117,18 @@ bool cmServerProtocol::Activate(cmServer* server,
|
||||||
this->m_Server = server;
|
this->m_Server = server;
|
||||||
this->m_CMakeInstance = std::make_unique<cmake>();
|
this->m_CMakeInstance = std::make_unique<cmake>();
|
||||||
const bool result = this->DoActivate(request, errorMessage);
|
const bool result = this->DoActivate(request, errorMessage);
|
||||||
if (!result)
|
if (!result) {
|
||||||
this->m_CMakeInstance = CM_NULLPTR;
|
this->m_CMakeInstance = CM_NULLPTR;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmServerProtocol::SendSignal(const std::string& name,
|
void cmServerProtocol::SendSignal(const std::string& name,
|
||||||
const Json::Value& data) const
|
const Json::Value& data) const
|
||||||
{
|
{
|
||||||
if (this->m_Server)
|
if (this->m_Server) {
|
||||||
this->m_Server->WriteSignal(name, data);
|
this->m_Server->WriteSignal(name, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmake* cmServerProtocol::CMakeInstance() const
|
cmake* cmServerProtocol::CMakeInstance() const
|
||||||
|
@ -155,17 +157,19 @@ bool cmServerProtocol1_0::DoActivate(const cmServerRequest& request,
|
||||||
std::string extraGenerator = request.Data[kEXTRA_GENERATOR_KEY].asString();
|
std::string extraGenerator = request.Data[kEXTRA_GENERATOR_KEY].asString();
|
||||||
|
|
||||||
if (buildDirectory.empty()) {
|
if (buildDirectory.empty()) {
|
||||||
if (errorMessage)
|
if (errorMessage) {
|
||||||
*errorMessage =
|
*errorMessage =
|
||||||
std::string("\"") + kBUILD_DIRECTORY_KEY + "\" is missing.";
|
std::string("\"") + kBUILD_DIRECTORY_KEY + "\" is missing.";
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cmake* cm = CMakeInstance();
|
cmake* cm = CMakeInstance();
|
||||||
if (cmSystemTools::PathExists(buildDirectory)) {
|
if (cmSystemTools::PathExists(buildDirectory)) {
|
||||||
if (!cmSystemTools::FileIsDirectory(buildDirectory)) {
|
if (!cmSystemTools::FileIsDirectory(buildDirectory)) {
|
||||||
if (errorMessage)
|
if (errorMessage) {
|
||||||
*errorMessage = std::string("\"") + kBUILD_DIRECTORY_KEY +
|
*errorMessage = std::string("\"") + kBUILD_DIRECTORY_KEY +
|
||||||
"\" exists but is not a directory.";
|
"\" exists but is not a directory.";
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,18 +181,20 @@ bool cmServerProtocol1_0::DoActivate(const cmServerRequest& request,
|
||||||
const std::string cachedGenerator =
|
const std::string cachedGenerator =
|
||||||
std::string(state->GetCacheEntryValue("CMAKE_GENERATOR"));
|
std::string(state->GetCacheEntryValue("CMAKE_GENERATOR"));
|
||||||
if (cachedGenerator.empty() && generator.empty()) {
|
if (cachedGenerator.empty() && generator.empty()) {
|
||||||
if (errorMessage)
|
if (errorMessage) {
|
||||||
*errorMessage =
|
*errorMessage =
|
||||||
std::string("\"") + kGENERATOR_KEY + "\" is required but unset.";
|
std::string("\"") + kGENERATOR_KEY + "\" is required but unset.";
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (generator.empty()) {
|
if (generator.empty()) {
|
||||||
generator = cachedGenerator;
|
generator = cachedGenerator;
|
||||||
}
|
}
|
||||||
if (generator != cachedGenerator) {
|
if (generator != cachedGenerator) {
|
||||||
if (errorMessage)
|
if (errorMessage) {
|
||||||
*errorMessage = std::string("\"") + kGENERATOR_KEY +
|
*errorMessage = std::string("\"") + kGENERATOR_KEY +
|
||||||
"\" set but incompatible with configured generator.";
|
"\" set but incompatible with configured generator.";
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,9 +203,10 @@ bool cmServerProtocol1_0::DoActivate(const cmServerRequest& request,
|
||||||
std::string(state->GetCacheEntryValue("CMAKE_EXTRA_GENERATOR"));
|
std::string(state->GetCacheEntryValue("CMAKE_EXTRA_GENERATOR"));
|
||||||
if (!cachedExtraGenerator.empty() && !extraGenerator.empty() &&
|
if (!cachedExtraGenerator.empty() && !extraGenerator.empty() &&
|
||||||
cachedExtraGenerator != extraGenerator) {
|
cachedExtraGenerator != extraGenerator) {
|
||||||
if (errorMessage)
|
if (errorMessage) {
|
||||||
*errorMessage = std::string("\"") + kEXTRA_GENERATOR_KEY +
|
*errorMessage = std::string("\"") + kEXTRA_GENERATOR_KEY +
|
||||||
"\" is set but incompatible with configured extra generator.";
|
"\" is set but incompatible with configured extra generator.";
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (extraGenerator.empty()) {
|
if (extraGenerator.empty()) {
|
||||||
|
@ -211,9 +218,10 @@ bool cmServerProtocol1_0::DoActivate(const cmServerRequest& request,
|
||||||
std::string(state->GetCacheEntryValue("CMAKE_HOME_DIRECTORY"));
|
std::string(state->GetCacheEntryValue("CMAKE_HOME_DIRECTORY"));
|
||||||
if (!cachedSourceDirectory.empty() && !sourceDirectory.empty() &&
|
if (!cachedSourceDirectory.empty() && !sourceDirectory.empty() &&
|
||||||
cachedSourceDirectory != sourceDirectory) {
|
cachedSourceDirectory != sourceDirectory) {
|
||||||
if (errorMessage)
|
if (errorMessage) {
|
||||||
*errorMessage = std::string("\"") + kSOURCE_DIRECTORY_KEY +
|
*errorMessage = std::string("\"") + kSOURCE_DIRECTORY_KEY +
|
||||||
"\" is set but incompatible with configured source directory.";
|
"\" is set but incompatible with configured source directory.";
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (sourceDirectory.empty()) {
|
if (sourceDirectory.empty()) {
|
||||||
|
@ -223,21 +231,24 @@ bool cmServerProtocol1_0::DoActivate(const cmServerRequest& request,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceDirectory.empty()) {
|
if (sourceDirectory.empty()) {
|
||||||
if (errorMessage)
|
if (errorMessage) {
|
||||||
*errorMessage = std::string("\"") + kSOURCE_DIRECTORY_KEY +
|
*errorMessage = std::string("\"") + kSOURCE_DIRECTORY_KEY +
|
||||||
"\" is unset but required.";
|
"\" is unset but required.";
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!cmSystemTools::FileIsDirectory(sourceDirectory)) {
|
if (!cmSystemTools::FileIsDirectory(sourceDirectory)) {
|
||||||
if (errorMessage)
|
if (errorMessage) {
|
||||||
*errorMessage =
|
*errorMessage =
|
||||||
std::string("\"") + kSOURCE_DIRECTORY_KEY + "\" is not a directory.";
|
std::string("\"") + kSOURCE_DIRECTORY_KEY + "\" is not a directory.";
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (generator.empty()) {
|
if (generator.empty()) {
|
||||||
if (errorMessage)
|
if (errorMessage) {
|
||||||
*errorMessage =
|
*errorMessage =
|
||||||
std::string("\"") + kGENERATOR_KEY + "\" is unset but required.";
|
std::string("\"") + kGENERATOR_KEY + "\" is unset but required.";
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,10 +258,11 @@ bool cmServerProtocol1_0::DoActivate(const cmServerRequest& request,
|
||||||
|
|
||||||
cmGlobalGenerator* gg = cm->CreateGlobalGenerator(fullGeneratorName);
|
cmGlobalGenerator* gg = cm->CreateGlobalGenerator(fullGeneratorName);
|
||||||
if (!gg) {
|
if (!gg) {
|
||||||
if (errorMessage)
|
if (errorMessage) {
|
||||||
*errorMessage =
|
*errorMessage =
|
||||||
std::string("Could not set up the requested combination of \"") +
|
std::string("Could not set up the requested combination of \"") +
|
||||||
kGENERATOR_KEY + "\" and \"" + kEXTRA_GENERATOR_KEY + "\"";
|
kGENERATOR_KEY + "\" and \"" + kEXTRA_GENERATOR_KEY + "\"";
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue