Skip to content

Commit 1bb9892

Browse files
committed
Remove reliance on rustc-serialize: #26. Still awaiting rust-mustache Serde support.
1 parent 559c4e3 commit 1bb9892

File tree

9 files changed

+43
-50
lines changed

9 files changed

+43
-50
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ mustache = "0.8"
2626
regex = "0.2"
2727
rustc-serialize = "0.3"
2828
serde = "0.9"
29+
serde_derive = "0.9"
2930
serde_json = "0.9"
3031
tempfile = "2.1"
31-
zdaemon = "0.0.2"
3232
zfilexfer = "0.0.2"
3333
hostname = "0.1"
3434
czmq = { version = "0.1", optional = true }

src/error.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ use czmq;
1111
use libc::c_char;
1212
use mustache;
1313
use regex;
14-
use rustc_serialize::json;
1514
use serde_json;
1615
use std::{convert, error, ffi, fmt, io, num, ptr, result, str, string};
1716
use std::any::Any;
1817
use std::ffi::CString;
19-
use zdaemon;
2018
#[cfg(feature = "remote-run")]
2119
use zfilexfer;
2220

@@ -70,8 +68,6 @@ pub enum Error {
7068
InvalidFileDescriptor,
7169
/// IO error
7270
Io(io::Error),
73-
/// JSON decoder error
74-
JsonDecoder(json::DecoderError),
7571
/// Mustache template error
7672
Mustache(mustache::Error),
7773
/// FFI null error
@@ -92,8 +88,6 @@ pub enum Error {
9288
StrFromUtf8(str::Utf8Error),
9389
/// Cast String
9490
StringFromUtf8(string::FromUtf8Error),
95-
// ZDaemon error
96-
ZDaemon(zdaemon::Error),
9791
#[cfg(feature = "remote-run")]
9892
/// ZFileXfer error
9993
ZFileXfer(zfilexfer::Error),
@@ -122,7 +116,6 @@ impl fmt::Display for Error {
122116
Error::HostResponse => write!(f, "Invalid response from host"),
123117
Error::InvalidFileDescriptor => write!(f, "Invalid file descriptor"),
124118
Error::Io(ref e) => write!(f, "IO error: {}", e),
125-
Error::JsonDecoder(ref e) => write!(f, "JSON decoder error: {}", e),
126119
Error::Mustache(ref e) => write!(f, "Mustache error: {:?}", e),
127120
Error::NulError(ref e) => write!(f, "Nul error: {}", e),
128121
Error::NullPtr(ref e) => write!(f, "Received null when we expected a {} pointer", e),
@@ -133,7 +126,6 @@ impl fmt::Display for Error {
133126
Error::SerdeJson(ref e) => write!(f, "Serde JSON error: {}", e),
134127
Error::StrFromUtf8(ref e) => write!(f, "Convert from UTF8 slice to str error: {}", e),
135128
Error::StringFromUtf8(ref e) => write!(f, "Convert from UTF8 slice to String error: {}", e),
136-
Error::ZDaemon(ref e) => write!(f, "ZDaemon error: {}", e),
137129
#[cfg(feature = "remote-run")]
138130
Error::ZFileXfer(ref e) => write!(f, "ZFileXfer error: {}", e),
139131
}
@@ -161,7 +153,6 @@ impl error::Error for Error {
161153
Error::HostResponse => "Invalid response from host",
162154
Error::InvalidFileDescriptor => "Invalid file descriptor",
163155
Error::Io(ref e) => e.description(),
164-
Error::JsonDecoder(ref e) => e.description(),
165156
Error::Mustache(ref e) => e.description(),
166157
Error::NulError(ref e) => e.description(),
167158
Error::NullPtr(ref e) => e,
@@ -172,7 +163,6 @@ impl error::Error for Error {
172163
Error::SerdeJson(ref e) => e.description(),
173164
Error::StrFromUtf8(ref e) => e.description(),
174165
Error::StringFromUtf8(ref e) => e.description(),
175-
Error::ZDaemon(ref e) => e.description(),
176166
#[cfg(feature = "remote-run")]
177167
Error::ZFileXfer(ref e) => e.description(),
178168
}
@@ -211,12 +201,6 @@ impl convert::From<io::Error> for Error {
211201
}
212202
}
213203

214-
impl convert::From<json::DecoderError> for Error {
215-
fn from(err: json::DecoderError) -> Error {
216-
Error::JsonDecoder(err)
217-
}
218-
}
219-
220204
#[cfg(feature = "remote-run")]
221205
impl convert::From<MissingFrame> for Error {
222206
fn from(err: MissingFrame) -> Error {
@@ -266,12 +250,6 @@ impl convert::From<num::ParseIntError> for Error {
266250
}
267251
}
268252

269-
impl convert::From<zdaemon::Error> for Error {
270-
fn from(err: zdaemon::Error) -> Error {
271-
Error::ZDaemon(err)
272-
}
273-
}
274-
275253
#[cfg(feature = "remote-run")]
276254
impl convert::From<zfilexfer::Error> for Error {
277255
fn from(err: zfilexfer::Error) -> Error {

src/lib.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ extern crate regex;
3030
extern crate rustc_serialize;
3131
extern crate serde;
3232
#[macro_use]
33+
extern crate serde_derive;
34+
#[macro_use]
3335
extern crate serde_json;
3436
#[cfg(test)]
3537
extern crate tempdir;
3638
extern crate tempfile;
37-
extern crate zdaemon;
3839
extern crate zfilexfer;
3940
extern crate hostname;
4041
extern crate pnet;
@@ -79,7 +80,14 @@ pub use template::{Template, ffi as template_ffi};
7980
pub use zfilexfer::FileOptions;
8081

8182
#[cfg(feature = "remote-run")]
82-
use zdaemon::ConfigFile;
83+
use std::fs;
84+
#[cfg(feature = "remote-run")]
85+
use std::io::Read;
86+
#[cfg(feature = "remote-run")]
87+
#[cfg(test)]
88+
use std::io::Write;
89+
#[cfg(feature = "remote-run")]
90+
use std::path::Path;
8391

8492
#[cfg(all(test, feature = "remote-run"))]
8593
lazy_static! {
@@ -88,6 +96,21 @@ lazy_static! {
8896

8997
#[cfg(feature = "remote-run")]
9098
lazy_static! {
91-
static ref PROJECT_CONFIG: project::ProjectConfig = project::ProjectConfig::load("project.json")
92-
.expect("Could not load project.json");
99+
static ref PROJECT_CONFIG: project::ProjectConfig = read_conf("project.json").expect("Could not load project.json");
100+
}
101+
102+
#[cfg(feature = "remote-run")]
103+
fn read_conf<T: serde::Deserialize, P: AsRef<Path>>(path: P) -> error::Result<T> {
104+
let mut fh = fs::File::open(&path)?;
105+
let mut json = String::new();
106+
fh.read_to_string(&mut json)?;
107+
Ok(serde_json::from_str(&json)?)
108+
}
109+
110+
#[cfg(all(test, feature = "remote-run"))]
111+
fn write_conf<C: serde::Serialize, P: AsRef<Path>>(conf: C, path: P) -> error::Result<()> {
112+
let json = serde_json::to_string(&conf)?;
113+
let mut fh = fs::File::create(&path)?;
114+
fh.write_all(json.as_bytes())?;
115+
Ok(())
93116
}

src/mock_env.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use project::{Language, ProjectConfig};
1111
use std::env::set_current_dir;
1212
use std::thread::{JoinHandle, spawn};
1313
use tempdir::TempDir;
14-
use zdaemon::ConfigFile;
14+
use write_conf;
1515

1616
pub struct MockEnv {
1717
_auth_handler: JoinHandle<()>,
@@ -44,7 +44,7 @@ impl MockEnv {
4444
auth_api_port: 0,
4545
auth_update_port: port as u32,
4646
};
47-
config.save("project.json").unwrap();
47+
write_conf(&config, "project.json").unwrap();
4848

4949
let handle = spawn(move|| MockEnv::auth_handler(sock));
5050

src/payload/config.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@
77
// modified, or distributed except according to those terms.
88

99
use project::Language;
10-
use zdaemon::ConfigFile;
1110

12-
#[derive(Debug, RustcDecodable, RustcEncodable)]
11+
#[derive(Debug, Serialize, Deserialize)]
1312
pub struct Config {
1413
pub author: String,
1514
pub repository: String,
1615
pub language: Language,
1716
pub dependencies: Option<Vec<String>>,
1817
}
19-
20-
impl ConfigFile for Config {}

src/payload/ffi.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ mod tests {
7575
use std::{fs, ptr, thread};
7676
use super::*;
7777
use tempdir::TempDir;
78-
use zdaemon::ConfigFile;
78+
use write_conf;
7979

8080
#[test]
8181
fn test_new() {
@@ -96,7 +96,7 @@ mod tests {
9696
};
9797

9898
buf.push("payload.json");
99-
conf.save(&buf).unwrap();
99+
write_conf(&conf, &buf).unwrap();
100100
buf.pop();
101101

102102
let payload_artifact = CString::new(buf.to_str().unwrap()).unwrap();
@@ -120,7 +120,7 @@ mod tests {
120120

121121
let mut buf = tempdir.path().to_owned();
122122
buf.push("payload.json");
123-
conf.save(&buf).unwrap();
123+
write_conf(&conf, &buf).unwrap();
124124
buf.pop();
125125

126126
let payload_artifact = CString::new(buf.to_str().unwrap()).unwrap();
@@ -159,7 +159,7 @@ mod tests {
159159
};
160160

161161
buf.push("payload.json");
162-
conf.save(&buf).unwrap();
162+
write_conf(&conf, &buf).unwrap();
163163
buf.pop();
164164

165165
let payload_name = buf.into_os_string().into_string().unwrap();

src/payload/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ use czmq::{ZMsg, ZPoller, ZSock, SocketType, ZSys};
1515
use error::{Error, Result};
1616
use host::{Host,HostSendRecv};
1717
use project::Language;
18+
use read_conf;
1819
use self::config::Config;
1920
use serde_json;
2021
use std::env::{current_dir, set_current_dir};
2122
use std::process;
2223
use std::path::PathBuf;
2324
use std::thread;
24-
use zdaemon::ConfigFile;
2525

2626
/// Payloads are self-contained projects that encapsulate a specific
2727
/// feature or system function.
@@ -84,7 +84,7 @@ impl Payload {
8484
buf.push(payload);
8585

8686
buf.push("payload.json");
87-
let config = try!(Config::load(&buf));
87+
let config: Config = read_conf(&buf)?;
8888
buf.pop();
8989

9090
// Check dependencies
@@ -350,7 +350,7 @@ mod tests {
350350
use super::*;
351351
use super::config::Config;
352352
use tempdir::TempDir;
353-
use zdaemon::ConfigFile;
353+
use write_conf;
354354

355355
#[test]
356356
fn test_new_nodeps() {
@@ -369,7 +369,7 @@ mod tests {
369369
};
370370

371371
buf.push("payload.json");
372-
conf.save(&buf).unwrap();
372+
write_conf(&conf, &buf).unwrap();
373373
buf.pop();
374374

375375
assert!(Payload::new(buf.to_str().unwrap()).is_err());
@@ -393,7 +393,7 @@ mod tests {
393393
};
394394

395395
buf.push("payload.json");
396-
conf.save(&buf).unwrap();
396+
write_conf(&conf, &buf).unwrap();
397397
buf.pop();
398398

399399
let payload = Payload::new(buf.to_str().unwrap()).unwrap();
@@ -417,7 +417,7 @@ mod tests {
417417
};
418418

419419
buf.push("payload.json");
420-
conf.save(&buf).unwrap();
420+
write_conf(&conf, &buf).unwrap();
421421
buf.pop();
422422

423423
let payload_name = buf.into_os_string().into_string().unwrap();

src/project.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,19 @@
66
// https://www.tldrlegal.com/l/mpl-2.0>. This file may not be copied,
77
// modified, or distributed except according to those terms.
88

9-
use zdaemon::ConfigFile;
10-
119
#[repr(C)]
12-
#[derive(Clone, Debug, PartialEq, RustcDecodable, RustcEncodable)]
10+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1311
/// The payload's programming language.
1412
pub enum Language {
1513
C,
1614
Php,
1715
Rust,
1816
}
1917

20-
#[derive(Debug, RustcDecodable, RustcEncodable)]
18+
#[derive(Debug, Serialize, Deserialize)]
2119
pub struct ProjectConfig {
2220
pub language: Language,
2321
pub auth_server: String,
2422
pub auth_api_port: u32,
2523
pub auth_update_port: u32,
2624
}
27-
28-
impl ConfigFile for ProjectConfig {}

src/target/unix_base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
use error::{Error, Result};
1010
use file::FileOwner;
11-
use host::telemetry::Netif;
1211
use regex::Regex;
1312
use std::{process, str};
1413
use std::path::Path;

0 commit comments

Comments
 (0)