-
Notifications
You must be signed in to change notification settings - Fork 566
/
Copy pathprotocol.rs
75 lines (70 loc) · 2.51 KB
/
protocol.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::compiler::ColorMode;
use crate::server::{DistInfo, ServerInfo};
use serde::{Deserialize, Serialize};
use std::ffi::OsString;
/// A client request.
#[derive(Serialize, Deserialize, Debug)]
pub enum Request {
/// Zero the server's statistics.
ZeroStats,
/// Get server statistics.
GetStats,
/// Get dist status.
DistStatus,
/// Shut the server down gracefully.
Shutdown,
/// Execute a compile or fetch a cached compilation result.
Compile(Compile),
}
/// A server response.
#[derive(Serialize, Deserialize, Debug)]
pub enum Response {
/// Response for `Request::Compile`.
Compile(CompileResponse),
/// Response for `Request::ZeroStats`.
ZeroStats,
/// Response for `Request::GetStats`, containing server statistics.
Stats(Box<ServerInfo>),
/// Response for `Request::DistStatus`, containing client info.
DistStatus(DistInfo),
/// Response for `Request::Shutdown`, containing server statistics.
ShuttingDown(Box<ServerInfo>),
/// Second response for `Request::Compile`, containing the results of the compilation.
CompileFinished(CompileFinished),
}
/// Possible responses from the server for a `Compile` request.
#[derive(Serialize, Deserialize, Debug)]
pub enum CompileResponse {
/// The compilation was started.
CompileStarted,
/// The server could not handle this compilation request.
UnhandledCompile,
/// The compiler was not supported.
UnsupportedCompiler(OsString),
}
/// Information about a finished compile, either from cache or executed locally.
#[derive(Serialize, Deserialize, Debug, Default)]
pub struct CompileFinished {
/// The return code of the compile process, if available.
pub retcode: Option<i32>,
/// The signal that terminated the compile process, if available.
pub signal: Option<i32>,
/// The compiler's stdout.
pub stdout: Vec<u8>,
/// The compiler's stderr.
pub stderr: Vec<u8>,
/// The state of any compiler options passed to control color output.
pub color_mode: ColorMode,
}
/// The contents of a compile request from a client.
#[derive(Serialize, Deserialize, Debug)]
pub struct Compile {
/// The full path to the compiler executable.
pub exe: OsString,
/// The current working directory in which to execute the compile.
pub cwd: OsString,
/// The commandline arguments passed to the compiler.
pub args: Vec<OsString>,
/// The environment variables present when the compiler was executed, as (var, val).
pub env_vars: Vec<(OsString, OsString)>,
}