Skip to content

Commit

Permalink
Update to rust 1.27 (#6035)
Browse files Browse the repository at this point in the history
Bump to rust `1.27`, explicitly use Itertools::flatten, re-apply `rustfmt`, and bump the travis OSX image.
  • Loading branch information
Stu Hood committed Jun 27, 2018
1 parent 6229c41 commit 9be434e
Show file tree
Hide file tree
Showing 18 changed files with 199 additions and 212 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ matrix:
include:
- os: osx
# We request the oldest image we can (corresponding to OSX 10.11) for maximum compatibility.
# We use 10.11 not 10.10 because 10.11 has a functioning version of lldb which can be useful
# for debugging native code issues.
# We use 10.11 as a minimum to avoid https://github.com/rust-lang/regex/issues/489.
# See: https://docs.travis-ci.com/user/reference/osx/#OS-X-Version
osx_image: xcode7.3
osx_image: xcode8
stage: Test Pants
language: generic
env:
Expand Down
2 changes: 1 addition & 1 deletion build-support/bin/native/bootstrap_rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd ../../.. && pwd -P)"
# + fingerprint_data: Fingerprints the data on stdin.
source "${REPO_ROOT}/build-support/common.sh"

readonly RUST_TOOLCHAIN="1.25.0"
readonly RUST_TOOLCHAIN="1.27.0"
readonly RUST_COMPONENTS=(
"rustfmt-preview"
"rust-src"
Expand Down
4 changes: 2 additions & 2 deletions src/rust/engine/async_semaphore/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
extern crate futures;

use std::sync::{Arc, Mutex};
use std::collections::VecDeque;
use std::sync::{Arc, Mutex};

use futures::{Async, Poll};
use futures::future::Future;
use futures::task::{self, Task};
use futures::{Async, Poll};

struct Inner {
waiters: VecDeque<Task>,
Expand Down
14 changes: 7 additions & 7 deletions src/rust/engine/boxfuture/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ where
///
#[macro_export]
macro_rules! try_future {
( $x:expr) => {
{
match $x {
Ok(value) => {value}
Err(error) => {return future::err(error).to_boxed();}
}
($x:expr) => {{
match $x {
Ok(value) => value,
Err(error) => {
return future::err(error).to_boxed();
}
}
};
}};
}
16 changes: 9 additions & 7 deletions src/rust/engine/fs/brfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ extern crate time;

use futures::future::Future;
use hashing::{Digest, Fingerprint};
use std::collections::HashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::collections::HashMap;
use std::ffi::{CString, OsStr, OsString};
use std::path::Path;
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -655,12 +655,14 @@ mod test {
extern crate tempfile;
extern crate testutil;

use self::testutil::{
data::{TestData, TestDirectory}, file,
};
use super::mount;
use fs;
use futures::future::Future;
use hashing;
use std::sync::Arc;
use super::mount;
use self::testutil::{file, data::{TestData, TestDirectory}};

#[test]
fn missing_digest() {
Expand Down Expand Up @@ -898,15 +900,15 @@ mod syscall_tests {
extern crate tempfile;
extern crate testutil;

use self::testutil::data::TestData;
use super::mount;
use super::test::digest_to_filepath;
use fs;
use futures::Future;
use libc;
use std::sync::Arc;
use super::mount;
use super::test::digest_to_filepath;
use self::testutil::data::TestData;
use std::ffi::CString;
use std::path::Path;
use std::sync::Arc;
use test::make_dirs;

#[test]
Expand Down
10 changes: 6 additions & 4 deletions src/rust/engine/fs/src/glob_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;

use boxfuture::{BoxFuture, Boxable};
use futures::Future;
use futures::future;
use futures::Future;
use glob::Pattern;
use indexmap::{IndexMap, IndexSet, map::Entry::Occupied};
use indexmap::{map::Entry::Occupied, IndexMap, IndexSet};

use {Dir, GitignoreStyleExcludes, GlobParsedSource, GlobSource, GlobWithSource, Link, PathGlob,
PathGlobs, PathStat, Stat, VFS};
use {
Dir, GitignoreStyleExcludes, GlobParsedSource, GlobSource, GlobWithSource, Link, PathGlob,
PathGlobs, PathStat, Stat, VFS,
};

pub trait GlobMatching<E: Send + Sync + 'static>: VFS<E> {
///
Expand Down
27 changes: 14 additions & 13 deletions src/rust/engine/fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
mod glob_matching;
pub use glob_matching::GlobMatching;
mod snapshot;
pub use snapshot::{OneOffStoreFileByDigest, Snapshot, StoreFileByDigest, EMPTY_DIGEST,
EMPTY_FINGERPRINT};
pub use snapshot::{
OneOffStoreFileByDigest, Snapshot, StoreFileByDigest, EMPTY_DIGEST, EMPTY_FINGERPRINT,
};
mod store;
pub use store::Store;
mod pool;
Expand Down Expand Up @@ -365,19 +366,19 @@ impl PathGlob {
PathGlob::parse_globs(canonical_dir_parent, symbolic_path_parent, &parts[1..])
} else if parts.len() == 1 {
// This is the path basename.
Ok(vec![
PathGlob::wildcard(canonical_dir, symbolic_path, parts[0].clone()),
])
Ok(vec![PathGlob::wildcard(
canonical_dir,
symbolic_path,
parts[0].clone(),
)])
} else {
// This is a path dirname.
Ok(vec![
PathGlob::dir_wildcard(
canonical_dir,
symbolic_path,
parts[0].clone(),
parts[1..].to_vec(),
),
])
Ok(vec![PathGlob::dir_wildcard(
canonical_dir,
symbolic_path,
parts[0].clone(),
parts[1..].to_vec(),
)])
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/fs/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use std::sync::RwLock;

use futures_cpupool::{self, CpuFuture, CpuPool};
use futures::future::IntoFuture;
use futures_cpupool::{self, CpuFuture, CpuPool};

///
/// A wrapper around a CpuPool, to add the ability to drop the pool before forking,
Expand Down
40 changes: 19 additions & 21 deletions src/rust/engine/fs/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

use bazel_protos;
use boxfuture::{BoxFuture, Boxable};
use futures::Future;
use futures::future::{self, join_all};
use futures::Future;
use hashing::{Digest, Fingerprint};
use indexmap::{self, IndexMap};
use itertools::Itertools;
use {File, PathStat, PosixFS, Store};
use protobuf;
use std::ffi::OsString;
use std::fmt;
use std::path::PathBuf;
use std::sync::Arc;
use {File, PathStat, PosixFS, Store};

pub const EMPTY_FINGERPRINT: Fingerprint = Fingerprint([
0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24,
Expand Down Expand Up @@ -163,11 +163,7 @@ impl Snapshot {
// `Directory` structure. Only `Dir+Dir` collisions are legal.
let path_stats = {
let mut uniq_paths: IndexMap<PathBuf, PathStat> = IndexMap::new();
for path_stat in snapshots
.iter()
.map(|s| s.path_stats.iter().cloned())
.flatten()
{
for path_stat in Itertools::flatten(snapshots.iter().map(|s| s.path_stats.iter().cloned())) {
match uniq_paths.entry(path_stat.path().to_owned()) {
indexmap::map::Entry::Occupied(e) => match (&path_stat, e.get()) {
(&PathStat::Dir { .. }, &PathStat::Dir { .. }) => (),
Expand Down Expand Up @@ -223,11 +219,11 @@ impl Snapshot {

// Merge FileNodes.
out_dir.set_files(protobuf::RepeatedField::from_vec(
directories
.iter_mut()
.map(|directory| directory.take_files().into_iter())
.flatten()
.collect(),
Itertools::flatten(
directories
.iter_mut()
.map(|directory| directory.take_files().into_iter()),
).collect(),
));
out_dir.mut_files().sort_by(|a, b| a.name.cmp(&b.name));
let unique_count = out_dir
Expand All @@ -253,11 +249,11 @@ impl Snapshot {

// Group and recurse for DirectoryNodes.
let sorted_child_directories = {
let mut merged_directories = directories
.iter_mut()
.map(|directory| directory.take_directories().into_iter())
.flatten()
.collect::<Vec<_>>();
let mut merged_directories = Itertools::flatten(
directories
.iter_mut()
.map(|directory| directory.take_directories().into_iter()),
).collect::<Vec<_>>();
merged_directories.sort_by(|a, b| a.name.cmp(&b.name));
merged_directories
};
Expand Down Expand Up @@ -370,14 +366,16 @@ mod tests {
extern crate tempfile;
extern crate testutil;

use self::testutil::data::TestDirectory;
use self::testutil::make_file;
use futures::future::Future;
use hashing::{Digest, Fingerprint};
use self::testutil::make_file;
use self::testutil::data::TestDirectory;

use super::super::{
Dir, File, GlobMatching, Path, PathGlobs, PathStat, PosixFS, ResettablePool, Snapshot, Store,
StrictGlobMatching, VFS,
};
use super::OneOffStoreFileByDigest;
use super::super::{Dir, File, GlobMatching, Path, PathGlobs, PathStat, PosixFS, ResettablePool,
Snapshot, Store, StrictGlobMatching, VFS};

use std;
use std::path::PathBuf;
Expand Down
48 changes: 22 additions & 26 deletions src/rust/engine/fs/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,11 @@ mod local {
use digest::{Digest as DigestTrait, FixedOutput};
use futures::future;
use hashing::{Digest, Fingerprint};
use lmdb::{self, Cursor, Database, DatabaseFlags, Environment, RwTransaction, Transaction,
WriteFlags, NO_OVERWRITE, NO_SYNC, NO_TLS};
use lmdb::Error::{KeyExist, NotFound};
use lmdb::{
self, Cursor, Database, DatabaseFlags, Environment, RwTransaction, Transaction, WriteFlags,
NO_OVERWRITE, NO_SYNC, NO_TLS,
};
use resettable::Resettable;
use sha2::Sha256;
use std::collections::{BinaryHeap, HashMap};
Expand All @@ -578,9 +580,9 @@ mod local {
use std::sync::Arc;
use std::time;

use pool::ResettablePool;
use super::MAX_LOCAL_STORE_SIZE_BYTES;
use super::super::EMPTY_FINGERPRINT;
use super::MAX_LOCAL_STORE_SIZE_BYTES;
use pool::ResettablePool;

#[derive(Clone)]
pub struct ByteStore {
Expand Down Expand Up @@ -995,11 +997,11 @@ mod local {

#[cfg(test)]
pub mod tests {
use super::super::super::safe_create_dir_all;
use super::{ByteStore, EntryType, ResettablePool};
use bytes::Bytes;
use futures::Future;
use hashing::{Digest, Fingerprint};
use super::{ByteStore, EntryType, ResettablePool};
use super::super::super::safe_create_dir_all;
use lmdb::{DatabaseFlags, Environment, Transaction, WriteFlags};
use std::path::Path;
use std::sync::Arc;
Expand Down Expand Up @@ -1523,8 +1525,8 @@ mod remote {
use bytes::{Bytes, BytesMut};
use digest::{Digest as DigestTrait, FixedOutput};
use futures::{self, future, Future, Sink, Stream};
use hashing::{Digest, Fingerprint};
use grpcio;
use hashing::{Digest, Fingerprint};
use resettable::Resettable;
use sha2::Sha256;
use std::cmp::min;
Expand Down Expand Up @@ -1737,8 +1739,8 @@ mod remote {

extern crate tempfile;

use super::ByteStore;
use super::super::EntryType;
use super::ByteStore;
use bytes::Bytes;
use futures::Future;
use hashing::Digest;
Expand Down Expand Up @@ -2316,12 +2318,10 @@ mod tests {

let cas = StubCAS::with_unverified_content(
1024,
vec![
(
non_canonical_directory_fingerprint.clone(),
non_canonical_directory_bytes,
),
].into_iter()
vec![(
non_canonical_directory_fingerprint.clone(),
non_canonical_directory_bytes,
)].into_iter()
.collect(),
);
new_store(dir.path(), cas.address())
Expand All @@ -2346,12 +2346,10 @@ mod tests {

let cas = StubCAS::with_unverified_content(
1024,
vec![
(
testdata.fingerprint(),
TestDirectory::containing_roland().bytes(),
),
].into_iter()
vec![(
testdata.fingerprint(),
TestDirectory::containing_roland().bytes(),
)].into_iter()
.collect(),
);
load_file_bytes(&new_store(dir.path(), cas.address()), testdata.digest())
Expand All @@ -2371,12 +2369,10 @@ mod tests {

let cas = StubCAS::with_unverified_content(
1024,
vec![
(
testdir.fingerprint(),
TestDirectory::containing_roland().bytes(),
),
].into_iter()
vec![(
testdir.fingerprint(),
TestDirectory::containing_roland().bytes(),
)].into_iter()
.collect(),
);
load_file_bytes(&new_store(dir.path(), cas.address()), testdir.digest())
Expand Down
Loading

0 comments on commit 9be434e

Please sign in to comment.