server-mode: Watch CMakeLists.txt files
Watch CMakeLists.txt files (and similar) from the Server
This commit is contained in:
parent
262500028c
commit
4e34f04250
|
@ -194,6 +194,49 @@ are of type "signal", have an empty "cookie" and "inReplyTo" field and always
|
||||||
have a "name" set to show which signal was sent.
|
have a "name" set to show which signal was sent.
|
||||||
|
|
||||||
|
|
||||||
|
Specific Signals
|
||||||
|
----------------
|
||||||
|
|
||||||
|
The cmake server may sent signals with the following names:
|
||||||
|
|
||||||
|
"dirty" Signal
|
||||||
|
^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
The "dirty" signal is sent whenever the server determines that the configuration
|
||||||
|
of the project is no longer up-to-date. This happens when any of the files that have
|
||||||
|
an influence on the build system is changed.
|
||||||
|
|
||||||
|
The "dirty" signal may look like this::
|
||||||
|
|
||||||
|
[== CMake Server ==[
|
||||||
|
{
|
||||||
|
"cookie":"",
|
||||||
|
"inReplyTo":"",
|
||||||
|
"name":"dirty",
|
||||||
|
"type":"signal"}
|
||||||
|
]== CMake Server ==]
|
||||||
|
|
||||||
|
|
||||||
|
"fileChange" Signal
|
||||||
|
^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
The "fileChange" signal is sent whenever a watched file is changed. It contains
|
||||||
|
the "path" that has changed and a list of "properties" with the kind of change
|
||||||
|
that was detected. Possible changes are "change" and "rename".
|
||||||
|
|
||||||
|
The "fileChange" signal looks like this::
|
||||||
|
|
||||||
|
[== CMake Server ==[
|
||||||
|
{
|
||||||
|
"cookie":"",
|
||||||
|
"inReplyTo":"",
|
||||||
|
"name":"fileChange",
|
||||||
|
"path":"/absolute/CMakeLists.txt",
|
||||||
|
"properties":["change"],
|
||||||
|
"type":"signal"}
|
||||||
|
]== CMake Server ==]
|
||||||
|
|
||||||
|
|
||||||
Specific Message Types
|
Specific Message Types
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
|
|
||||||
// Vocabulary:
|
// Vocabulary:
|
||||||
|
|
||||||
|
static const std::string kDIRTY_SIGNAL = "dirty";
|
||||||
|
static const std::string kFILE_CHANGE_SIGNAL = "fileChange";
|
||||||
|
|
||||||
static const std::string kCACHE_TYPE = "cache";
|
static const std::string kCACHE_TYPE = "cache";
|
||||||
static const std::string kCMAKE_INPUTS_TYPE = "cmakeInputs";
|
static const std::string kCMAKE_INPUTS_TYPE = "cmakeInputs";
|
||||||
static const std::string kCODE_MODEL_TYPE = "codemodel";
|
static const std::string kCODE_MODEL_TYPE = "codemodel";
|
||||||
|
@ -86,3 +89,6 @@ static const std::string kWATCHED_FILES_KEY = "watchedFiles";
|
||||||
|
|
||||||
static const std::string kSTART_MAGIC = "[== CMake Server ==[";
|
static const std::string kSTART_MAGIC = "[== CMake Server ==[";
|
||||||
static const std::string kEND_MAGIC = "]== CMake Server ==]";
|
static const std::string kEND_MAGIC = "]== CMake Server ==]";
|
||||||
|
|
||||||
|
static const std::string kRENAME_PROPERTY_VALUE = "rename";
|
||||||
|
static const std::string kCHANGE_PROPERTY_VALUE = "change";
|
||||||
|
|
|
@ -371,6 +371,30 @@ bool cmServerProtocol1_0::DoActivate(const cmServerRequest& request,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmServerProtocol1_0::HandleCMakeFileChanges(const std::string& path,
|
||||||
|
int event, int status)
|
||||||
|
{
|
||||||
|
assert(status == 0);
|
||||||
|
static_cast<void>(status);
|
||||||
|
|
||||||
|
if (!m_isDirty) {
|
||||||
|
m_isDirty = true;
|
||||||
|
SendSignal(kDIRTY_SIGNAL, Json::objectValue);
|
||||||
|
}
|
||||||
|
Json::Value obj = Json::objectValue;
|
||||||
|
obj[kPATH_KEY] = path;
|
||||||
|
Json::Value properties = Json::arrayValue;
|
||||||
|
if (event & UV_RENAME) {
|
||||||
|
properties.append(kRENAME_PROPERTY_VALUE);
|
||||||
|
}
|
||||||
|
if (event & UV_CHANGE) {
|
||||||
|
properties.append(kCHANGE_PROPERTY_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
obj[kPROPERTIES_KEY] = properties;
|
||||||
|
SendSignal(kFILE_CHANGE_SIGNAL, obj);
|
||||||
|
}
|
||||||
|
|
||||||
const cmServerResponse cmServerProtocol1_0::Process(
|
const cmServerResponse cmServerProtocol1_0::Process(
|
||||||
const cmServerRequest& request)
|
const cmServerRequest& request)
|
||||||
{
|
{
|
||||||
|
@ -949,7 +973,17 @@ cmServerResponse cmServerProtocol1_0::ProcessConfigure(
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
return request.ReportError("Configuration failed.");
|
return request.ReportError("Configuration failed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> toWatchList;
|
||||||
|
getCMakeInputs(gg, std::string(), buildDir, nullptr, &toWatchList, nullptr);
|
||||||
|
|
||||||
|
FileMonitor()->MonitorPaths(toWatchList,
|
||||||
|
[this](const std::string& p, int e, int s) {
|
||||||
|
this->HandleCMakeFileChanges(p, e, s);
|
||||||
|
});
|
||||||
|
|
||||||
m_State = STATE_CONFIGURED;
|
m_State = STATE_CONFIGURED;
|
||||||
|
m_isDirty = false;
|
||||||
return request.Reply(Json::Value());
|
return request.Reply(Json::Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,6 +109,8 @@ private:
|
||||||
bool DoActivate(const cmServerRequest& request,
|
bool DoActivate(const cmServerRequest& request,
|
||||||
std::string* errorMessage) override;
|
std::string* errorMessage) override;
|
||||||
|
|
||||||
|
void HandleCMakeFileChanges(const std::string& path, int event, int status);
|
||||||
|
|
||||||
// Handle requests:
|
// Handle requests:
|
||||||
cmServerResponse ProcessCache(const cmServerRequest& request);
|
cmServerResponse ProcessCache(const cmServerRequest& request);
|
||||||
cmServerResponse ProcessCMakeInputs(const cmServerRequest& request);
|
cmServerResponse ProcessCMakeInputs(const cmServerRequest& request);
|
||||||
|
@ -127,4 +129,6 @@ private:
|
||||||
STATE_COMPUTED
|
STATE_COMPUTED
|
||||||
};
|
};
|
||||||
State m_State = STATE_INACTIVE;
|
State m_State = STATE_INACTIVE;
|
||||||
|
|
||||||
|
bool m_isDirty = false;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue