Skip to content

Commit

Permalink
Move From impls from hashing to bazel_protos (#5706)
Browse files Browse the repository at this point in the history
hashing should be a nice quick/easy/small thing to compile, which
shouldn't rely on protocol buffer compilation because it just has a
couple of value types in.

bazel_protos already needs to depend on protocol buffer compilation.
  • Loading branch information
illicitonion authored Apr 27, 2018
1 parent 326da57 commit b9d3ef7
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/rust/engine/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/rust/engine/hashing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ version = "0.0.1"
authors = [ "Pants Build <pantsbuild@gmail.com>" ]

[dependencies]
bazel_protos = { path = "../process_execution/bazel_protos" }
digest = "0.6.2"
hex = "0.3.1"
sha2 = "0.6.0"
52 changes: 1 addition & 51 deletions src/rust/engine/hashing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2017 Pants project contributors (see CONTRIBUTORS.md).
// Licensed under the Apache License, Version 2.0 (see LICENSE).

extern crate bazel_protos;
extern crate digest;
extern crate hex;
extern crate sha2;
Expand Down Expand Up @@ -79,24 +78,6 @@ impl AsRef<[u8]> for Fingerprint {
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct Digest(pub Fingerprint, pub usize);

impl<'a> From<&'a Digest> for bazel_protos::remote_execution::Digest {
fn from(d: &Digest) -> Self {
let mut digest = bazel_protos::remote_execution::Digest::new();
digest.set_hash(d.0.to_hex());
digest.set_size_bytes(d.1 as i64);
digest
}
}

impl<'a> From<&'a bazel_protos::remote_execution::Digest> for Digest {
fn from(d: &bazel_protos::remote_execution::Digest) -> Self {
Digest(
Fingerprint::from_hex_string(d.get_hash()).expect("Bad fingerprint in Digest"),
d.get_size_bytes() as usize,
)
}
}

///
/// A Write instance that fingerprints all data that passes through it.
///
Expand Down Expand Up @@ -136,7 +117,7 @@ impl<W: Write> Write for WriterHasher<W> {

#[cfg(test)]
mod fingerprint_tests {
use super::{bazel_protos, Digest, Fingerprint};
use super::Fingerprint;

#[test]
fn from_bytes_unsafe() {
Expand Down Expand Up @@ -204,35 +185,4 @@ mod fingerprint_tests {
hex.to_lowercase()
)
}

#[test]
fn from_our_digest() {
let our_digest = &Digest(
Fingerprint::from_hex_string(
"0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff",
).unwrap(),
10,
);
let converted: bazel_protos::remote_execution::Digest = our_digest.into();
let mut want = bazel_protos::remote_execution::Digest::new();
want.set_hash("0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff".to_owned());
want.set_size_bytes(10);
assert_eq!(converted, want);
}

#[test]
fn from_bazel_digest() {
let mut bazel_digest = bazel_protos::remote_execution::Digest::new();
bazel_digest
.set_hash("0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff".to_owned());
bazel_digest.set_size_bytes(10);
let converted: Digest = (&bazel_digest).into();
let want = Digest(
Fingerprint::from_hex_string(
"0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff",
).unwrap(),
10,
);
assert_eq!(converted, want);
}
}
1 change: 1 addition & 0 deletions src/rust/engine/process_execution/bazel_protos/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
src/*.rs
!src/conversions.rs
!src/lib.rs
!src/verification.rs
1 change: 1 addition & 0 deletions src/rust/engine/process_execution/bazel_protos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ authors = [ "Pants Build <pantsbuild@gmail.com>" ]
bytes = "0.4.5"
futures = "0.1.16"
grpcio = { version = "0.2.0", features = ["secure"] }
hashing = { path = "../../hashing" }
protobuf = { version = "1.4.1", features = ["with-bytes"] }
55 changes: 55 additions & 0 deletions src/rust/engine/process_execution/bazel_protos/src/conversions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use hashing;

impl<'a> From<&'a hashing::Digest> for super::remote_execution::Digest {
fn from(d: &hashing::Digest) -> Self {
let mut digest = super::remote_execution::Digest::new();
digest.set_hash(d.0.to_hex());
digest.set_size_bytes(d.1 as i64);
digest
}
}

impl<'a> From<&'a super::remote_execution::Digest> for hashing::Digest {
fn from(d: &super::remote_execution::Digest) -> Self {
hashing::Digest(
hashing::Fingerprint::from_hex_string(d.get_hash()).expect("Bad fingerprint in Digest"),
d.get_size_bytes() as usize,
)
}
}

#[cfg(test)]
mod tests {
use hashing;

#[test]
fn from_our_digest() {
let our_digest = &hashing::Digest(
hashing::Fingerprint::from_hex_string(
"0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff",
).unwrap(),
10,
);
let converted: super::super::remote_execution::Digest = our_digest.into();
let mut want = super::super::remote_execution::Digest::new();
want.set_hash("0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff".to_owned());
want.set_size_bytes(10);
assert_eq!(converted, want);
}

#[test]
fn from_bazel_digest() {
let mut bazel_digest = super::super::remote_execution::Digest::new();
bazel_digest
.set_hash("0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff".to_owned());
bazel_digest.set_size_bytes(10);
let converted: hashing::Digest = (&bazel_digest).into();
let want = hashing::Digest(
hashing::Fingerprint::from_hex_string(
"0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff",
).unwrap(),
10,
);
assert_eq!(converted, want);
}
}
2 changes: 2 additions & 0 deletions src/rust/engine/process_execution/bazel_protos/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extern crate bytes;
extern crate futures;
extern crate grpcio;
extern crate hashing;
extern crate protobuf;

pub mod bytestream;
Expand All @@ -14,5 +15,6 @@ pub mod remote_execution;
pub mod remote_execution_grpc;
pub mod status;

mod conversions;
mod verification;
pub use verification::verify_directory_canonical;

0 comments on commit b9d3ef7

Please sign in to comment.