diff --git a/Cargo.lock b/Cargo.lock index 49633c0..2d6737c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5,7 +5,6 @@ dependencies = [ "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "chan 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", "chan-signal 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)", "docopt 0.6.86 (registry+https://github.com/rust-lang/crates.io-index)", "ffmpeg 0.2.0-alpha.2 (git+https://github.com/scottlamb/rust-ffmpeg?branch=2.x)", "ffmpeg-sys 2.8.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -99,28 +98,6 @@ dependencies = [ "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "clippy" -version = "0.0.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "clippy_lints 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "clippy_lints" -version = "0.0.103" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)", - "semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "cookie" version = "0.2.5" @@ -370,11 +347,6 @@ dependencies = [ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "nom" -version = "1.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "num" version = "0.1.36" @@ -490,11 +462,6 @@ dependencies = [ "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "quine-mc_cluskey" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "quote" version = "0.3.10" @@ -555,14 +522,6 @@ name = "semver" version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "semver" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "serde" version = "0.8.19" @@ -775,14 +734,6 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "toml" -version = "0.1.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rustc-serialize 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "traitobject" version = "0.0.1" @@ -871,8 +822,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum chan 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "82b22acfef7960fd8f829bc50749273be637cbd76b9d4cc20497666cc3a33329" "checksum chan-signal 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "365122ab60a9dc6240b48e39d011b4389c3853093d98bf586edd2b79bfb4fbfa" "checksum chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "9213f7cd7c27e95c2b57c49f0e69b1ea65b27138da84a170133fd21b07659c00" -"checksum clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "5b4fabf979ddf6419a313c1c0ada4a5b95cfd2049c56e8418d622d27b4b6ff32" -"checksum clippy_lints 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "ce96ec05bfe018a0d5d43da115e54850ea2217981ff0f2e462780ab9d594651a" "checksum cookie 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0e3d6405328b6edb412158b3b7710e2634e23f3614b9bb1c412df7952489a626" "checksum crossbeam 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0c5ea215664ca264da8a9d9c3be80d2eaf30923c259d03e870388eb927508f97" "checksum docopt 0.6.86 (registry+https://github.com/rust-lang/crates.io-index)" = "4a7ef30445607f6fc8720f0a0a2c7442284b629cf0d049286860fae23e71c4d9" @@ -905,7 +854,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" "checksum memmap 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b3c19d7eabbbf4a7b3aa4a60b30216be2a47ee226f74c6b9358196977bb2ed3" "checksum mime 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b5c93a4bd787ddc6e7833c519b73a50883deb5863d76d9b71eb8216fb7f94e66" -"checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce" "checksum num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "bde7c03b09e7c6a301ee81f6ddf66d7a28ec305699e3d3b056d2fc56470e3120" "checksum num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "fb24d9bfb3f222010df27995441ded1e954f8f69cd35021f6bef02ca9552fb92" "checksum num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "287a1c9969a847055e1122ec0ea7a5c5d6f72aad97934e131c83d5c08ab4e45c" @@ -919,7 +867,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum openssl-verify 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ed86cce894f6b0ed4572e21eb34026f1dc8869cb9ee3869029131bc8c3feb2d" "checksum pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8cee804ecc7eaf201a4a207241472cc870e825206f6c031e3ee2a72fa425f2fa" "checksum pnacl-build-helper 1.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "61c9231d31aea845007443d62fcbb58bb6949ab9c18081ee1e09920e0cf1118b" -"checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45" "checksum quote 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)" = "6732e32663c9c271bfc7c1823486b471f18c47a2dbf87c066897b7b51afc83be" "checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" "checksum regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)" = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f" @@ -928,7 +875,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustc-serialize 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)" = "bff9fc1c79f2dec76b253273d07682e94a978bd8f132ded071188122b2af9818" "checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084" "checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" -"checksum semver 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d5b7638a1f03815d94e88cb3b3c08e87f0db4d683ef499d1836aaf70a45623f" "checksum serde 0.8.19 (registry+https://github.com/rust-lang/crates.io-index)" = "58a19c0871c298847e6b68318484685cd51fa5478c0c905095647540031356e5" "checksum serde_codegen 0.8.19 (registry+https://github.com/rust-lang/crates.io-index)" = "ce29a6ae259579707650ec292199b5fed2c0b8e2a4bdc994452d24d1bcf2242a" "checksum serde_codegen_internals 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "59933a62554548c690d2673c5164f0c4a46be7c5731edfd94b0ecb1048940732" @@ -952,7 +898,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" "checksum thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5" "checksum time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "3c7ec6d62a20df54e07ab3b78b9a3932972f4b7981de295563686849eb3989af" -"checksum toml 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)" = "0590d72182e50e879c4da3b11c6488dae18fccb1ae0c7a3eda18e16795844796" "checksum traitobject 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "07eaeb7689bb7fca7ce15628319635758eda769fed481ecfe6686ddef2600616" "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" "checksum unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "13a5906ca2b98c799f4b1ab4557b76367ebd6ae5ef14930ec841c74aed5f3764" diff --git a/Cargo.toml b/Cargo.toml index a62627a..6278191 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,9 +4,11 @@ version = "0.1.0" authors = ["Scott Lamb "] build = "build.rs" +[features] +nightly = [] + [dependencies] byteorder = "0.5" -clippy = "0.0.103" chan = "0.1" chan-signal = "0.1" docopt = "0.6" diff --git a/README.md b/README.md index bbd3a96..dc24d56 100644 --- a/README.md +++ b/README.md @@ -102,8 +102,11 @@ uuid-runtime is only necessary if you wish to use the uuid command to generate uuids for your cameras (see below). If you obtain them elsewhere, you can skip this package. -Next, you need a nightly version of Rust and Cargo. The easiest way to install -them is by following the instructions at [rustup.rs](https://www.rustup.rs/). +Next, you need Rust and Cargo. The easiest way to install them is by following +the instructions at [rustup.rs](https://www.rustup.rs/). Note that Rust 1.13 +has a serious bug on ARM ([see +announcement](https://blog.rust-lang.org/2016/11/10/Rust-1.13.html)); on those +platforms, prefer using Rust 1.14 betas instead. You can continue to follow the build/install instructions below for a manual build and install, or alternatively you can run the prep script called `prep.sh`. diff --git a/src/db.rs b/src/db.rs index 05b254e..b6ff422 100644 --- a/src/db.rs +++ b/src/db.rs @@ -51,11 +51,7 @@ //! * the `Transaction` interface allows callers to batch write operations to reduce latency and //! SSD write samples. -// Suppress false positive warnings caused by using the word SQLite in a docstring. -// clippy thinks this is an identifier which should be enclosed in backticks. -#![allow(doc_markdown)] - -use error::Error; +use error::{Error, ResultExt}; use fnv; use lru_cache::LruCache; use openssl::crypto::hash; @@ -999,12 +995,12 @@ impl Database { })); { let mut l = &mut *db.0.lock().unwrap(); - l.init_video_sample_entries().map_err(Error::annotator("init_video_sample_entries"))?; - l.init_cameras().map_err(Error::annotator("init_cameras"))?; + l.init_video_sample_entries().annotate_err("init_video_sample_entries")?; + l.init_cameras().annotate_err("init_cameras")?; for (&camera_id, ref mut camera) in &mut l.state.cameras_by_id { // TODO: we could use one thread per camera if we had multiple db conns. init_recordings(&mut l.conn, camera_id, camera) - .map_err(Error::annotator("init_recordings"))?; + .annotate_err("init_recordings")?; } } Ok(db) @@ -1024,8 +1020,6 @@ impl Database { #[cfg(test)] mod tests { - extern crate test; - use core::cmp::Ord; use recording::{self, TIME_UNITS_PER_SEC}; use rusqlite::Connection; diff --git a/src/error.rs b/src/error.rs index 0edb1a0..6b02648 100644 --- a/src/error.rs +++ b/src/error.rs @@ -55,11 +55,20 @@ impl Error { pub fn new(description: String) -> Self { Error{description: description, cause: None } } +} - // Returns a function to pass to std::result::Result::map_err which annotates the given error - // with a prefix. - pub fn annotator(prefix: &'static str) -> impl Fn(Error) -> Error { - move |e| { Error{description: format!("{}: {}", prefix, e.description), cause: e.cause} } +pub trait ResultExt { + /// Returns a new `Result` like this one except that errors are of type `Error` and annotated + /// with the given prefix. + fn annotate_err(self, prefix: &'static str) -> Result; +} + +impl ResultExt for result::Result where E: 'static + error::Error + Send + Sync { + fn annotate_err(self, prefix: &'static str) -> Result { + self.map_err(|e| Error{ + description: format!("{}: {}", prefix, e.description()), + cause: Some(Box::new(e)), + }) } } diff --git a/src/main.rs b/src/main.rs index d0501a1..e9b10fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,9 +28,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![cfg_attr(test, feature(test))] -#![feature(conservative_impl_trait, plugin, proc_macro)] -#![plugin(clippy)] +#![cfg_attr(all(nightly, test), feature(test))] extern crate byteorder; extern crate core; diff --git a/src/mp4.rs b/src/mp4.rs index 386d573..3cb596d 100644 --- a/src/mp4.rs +++ b/src/mp4.rs @@ -1175,19 +1175,22 @@ impl resource::Resource for Mp4File { /// to verify the output is byte-for-byte as expected. #[cfg(test)] mod tests { - extern crate test; + #[cfg(nightly)] extern crate test; + use byteorder::{BigEndian, ByteOrder}; use db; use dir; use ffmpeg; - use hyper::{self, header}; + #[cfg(nightly)] use hyper; + use hyper::header; use openssl::crypto::hash; use recording::{self, TIME_UNITS_PER_SEC}; use resource::{self, Resource}; - use self::test::Bencher; + #[cfg(nightly)] use self::test::Bencher; use std::fs; use std::io; use std::mem; + use std::ops::Range; use std::path::Path; use std::sync::Arc; use std::str; @@ -1195,7 +1198,7 @@ mod tests { use super::*; use stream::{self, Opener, Stream}; use testutil::{self, TestDb}; - use uuid::Uuid; + #[cfg(nightly)] use uuid::Uuid; /// A wrapper around openssl's SHA-1 hashing that implements the `Write` trait. struct Sha1(hash::Hasher); @@ -1305,7 +1308,6 @@ mod tests { } /// Navigates to the next box after the current one, or up if the current one is last. - #[allow(should_implement_trait)] pub fn next(&mut self) -> bool { let old = self.stack.pop().expect("positioned at root; there is no next"); let max = self.stack.last().map(|b| b.interior.end).unwrap_or_else(|| self.mp4.len()); @@ -1421,6 +1423,7 @@ mod tests { db.syncer_channel.flush(); } + #[cfg(nightly)] fn add_dummy_recordings_to_db(db: &db::Database) { let mut data = Vec::new(); data.extend_from_slice(include_bytes!("testdata/video_sample_index.bin")); @@ -1738,11 +1741,13 @@ mod tests { /// Currently this only serves a single `.mp4` file but we could set up variations to benchmark /// different scenarios: with/without subtitles and edit lists, different lengths, serving /// different fractions of the file, etc. + #[cfg(nightly)] struct BenchServer { url: hyper::Url, generated_len: u64, } + #[cfg(nightly)] impl BenchServer { fn new() -> BenchServer { let mut listener = hyper::net::HttpListener::new("127.0.0.1:0").unwrap(); @@ -1771,11 +1776,13 @@ mod tests { } } + #[cfg(nightly)] lazy_static! { static ref SERVER: BenchServer = { BenchServer::new() }; } /// Benchmarks serving the generated part of a `.mp4` file (up to the first byte from disk). + #[cfg(nightly)] #[bench] fn serve_generated_bytes_fresh_client(b: &mut Bencher) { testutil::init(); @@ -1801,6 +1808,7 @@ mod tests { /// This should be faster than the `fresh` version, but see /// [this hyper issue](https://github.com/hyperium/hyper/issues/944) relating to Nagle's /// algorithm. + #[cfg(nightly)] #[bench] fn serve_generated_bytes_reuse_client(b: &mut Bencher) { testutil::init(); @@ -1822,6 +1830,7 @@ mod tests { }); } + #[cfg(nightly)] #[bench] fn mp4_construction(b: &mut Bencher) { testutil::init(); diff --git a/src/recording.rs b/src/recording.rs index 326ca89..329b4f6 100644 --- a/src/recording.rs +++ b/src/recording.rs @@ -28,8 +28,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![allow(inline_always)] - extern crate uuid; use db; @@ -484,11 +482,12 @@ impl Segment { #[cfg(test)] mod tests { + #[cfg(nightly)] extern crate test; use super::{append_varint32, decode_varint32, unzigzag32, zigzag32}; use super::*; - use self::test::Bencher; + #[cfg(nightly)] use self::test::Bencher; use testutil::TestDb; #[test] @@ -746,6 +745,7 @@ mod tests { // TODO: test segment error cases involving mismatch between row frames/key_frames and index. /// Benchmarks the decoder, which is performance-critical for .mp4 serving. + #[cfg(nightly)] #[bench] fn bench_decoder(b: &mut Bencher) { let data = include_bytes!("testdata/video_sample_index.bin");