Skip to content

Commit b9d3ef7

Browse files
authored
Move From impls from hashing to bazel_protos (#5706)
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.
1 parent 326da57 commit b9d3ef7

File tree

7 files changed

+61
-53
lines changed

7 files changed

+61
-53
lines changed

src/rust/engine/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rust/engine/hashing/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ version = "0.0.1"
44
authors = [ "Pants Build <pantsbuild@gmail.com>" ]
55

66
[dependencies]
7-
bazel_protos = { path = "../process_execution/bazel_protos" }
87
digest = "0.6.2"
98
hex = "0.3.1"
109
sha2 = "0.6.0"

src/rust/engine/hashing/src/lib.rs

+1-51
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2017 Pants project contributors (see CONTRIBUTORS.md).
22
// Licensed under the Apache License, Version 2.0 (see LICENSE).
33

4-
extern crate bazel_protos;
54
extern crate digest;
65
extern crate hex;
76
extern crate sha2;
@@ -79,24 +78,6 @@ impl AsRef<[u8]> for Fingerprint {
7978
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
8079
pub struct Digest(pub Fingerprint, pub usize);
8180

82-
impl<'a> From<&'a Digest> for bazel_protos::remote_execution::Digest {
83-
fn from(d: &Digest) -> Self {
84-
let mut digest = bazel_protos::remote_execution::Digest::new();
85-
digest.set_hash(d.0.to_hex());
86-
digest.set_size_bytes(d.1 as i64);
87-
digest
88-
}
89-
}
90-
91-
impl<'a> From<&'a bazel_protos::remote_execution::Digest> for Digest {
92-
fn from(d: &bazel_protos::remote_execution::Digest) -> Self {
93-
Digest(
94-
Fingerprint::from_hex_string(d.get_hash()).expect("Bad fingerprint in Digest"),
95-
d.get_size_bytes() as usize,
96-
)
97-
}
98-
}
99-
10081
///
10182
/// A Write instance that fingerprints all data that passes through it.
10283
///
@@ -136,7 +117,7 @@ impl<W: Write> Write for WriterHasher<W> {
136117

137118
#[cfg(test)]
138119
mod fingerprint_tests {
139-
use super::{bazel_protos, Digest, Fingerprint};
120+
use super::Fingerprint;
140121

141122
#[test]
142123
fn from_bytes_unsafe() {
@@ -204,35 +185,4 @@ mod fingerprint_tests {
204185
hex.to_lowercase()
205186
)
206187
}
207-
208-
#[test]
209-
fn from_our_digest() {
210-
let our_digest = &Digest(
211-
Fingerprint::from_hex_string(
212-
"0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff",
213-
).unwrap(),
214-
10,
215-
);
216-
let converted: bazel_protos::remote_execution::Digest = our_digest.into();
217-
let mut want = bazel_protos::remote_execution::Digest::new();
218-
want.set_hash("0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff".to_owned());
219-
want.set_size_bytes(10);
220-
assert_eq!(converted, want);
221-
}
222-
223-
#[test]
224-
fn from_bazel_digest() {
225-
let mut bazel_digest = bazel_protos::remote_execution::Digest::new();
226-
bazel_digest
227-
.set_hash("0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff".to_owned());
228-
bazel_digest.set_size_bytes(10);
229-
let converted: Digest = (&bazel_digest).into();
230-
let want = Digest(
231-
Fingerprint::from_hex_string(
232-
"0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff",
233-
).unwrap(),
234-
10,
235-
);
236-
assert_eq!(converted, want);
237-
}
238188
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
src/*.rs
2+
!src/conversions.rs
23
!src/lib.rs
34
!src/verification.rs

src/rust/engine/process_execution/bazel_protos/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ authors = [ "Pants Build <pantsbuild@gmail.com>" ]
77
bytes = "0.4.5"
88
futures = "0.1.16"
99
grpcio = { version = "0.2.0", features = ["secure"] }
10+
hashing = { path = "../../hashing" }
1011
protobuf = { version = "1.4.1", features = ["with-bytes"] }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use hashing;
2+
3+
impl<'a> From<&'a hashing::Digest> for super::remote_execution::Digest {
4+
fn from(d: &hashing::Digest) -> Self {
5+
let mut digest = super::remote_execution::Digest::new();
6+
digest.set_hash(d.0.to_hex());
7+
digest.set_size_bytes(d.1 as i64);
8+
digest
9+
}
10+
}
11+
12+
impl<'a> From<&'a super::remote_execution::Digest> for hashing::Digest {
13+
fn from(d: &super::remote_execution::Digest) -> Self {
14+
hashing::Digest(
15+
hashing::Fingerprint::from_hex_string(d.get_hash()).expect("Bad fingerprint in Digest"),
16+
d.get_size_bytes() as usize,
17+
)
18+
}
19+
}
20+
21+
#[cfg(test)]
22+
mod tests {
23+
use hashing;
24+
25+
#[test]
26+
fn from_our_digest() {
27+
let our_digest = &hashing::Digest(
28+
hashing::Fingerprint::from_hex_string(
29+
"0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff",
30+
).unwrap(),
31+
10,
32+
);
33+
let converted: super::super::remote_execution::Digest = our_digest.into();
34+
let mut want = super::super::remote_execution::Digest::new();
35+
want.set_hash("0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff".to_owned());
36+
want.set_size_bytes(10);
37+
assert_eq!(converted, want);
38+
}
39+
40+
#[test]
41+
fn from_bazel_digest() {
42+
let mut bazel_digest = super::super::remote_execution::Digest::new();
43+
bazel_digest
44+
.set_hash("0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff".to_owned());
45+
bazel_digest.set_size_bytes(10);
46+
let converted: hashing::Digest = (&bazel_digest).into();
47+
let want = hashing::Digest(
48+
hashing::Fingerprint::from_hex_string(
49+
"0123456789abcdeffedcba98765432100000000000000000ffffffffffffffff",
50+
).unwrap(),
51+
10,
52+
);
53+
assert_eq!(converted, want);
54+
}
55+
}

src/rust/engine/process_execution/bazel_protos/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
extern crate bytes;
22
extern crate futures;
33
extern crate grpcio;
4+
extern crate hashing;
45
extern crate protobuf;
56

67
pub mod bytestream;
@@ -14,5 +15,6 @@ pub mod remote_execution;
1415
pub mod remote_execution_grpc;
1516
pub mod status;
1617

18+
mod conversions;
1719
mod verification;
1820
pub use verification::verify_directory_canonical;

0 commit comments

Comments
 (0)