Skip to content

Commit

Permalink
Update to rust 1.26, and explicitly use Itertools::flatten to avoid r…
Browse files Browse the repository at this point in the history
…ust-lang/rust#48919. Additionally, apply rustfmt changes.
  • Loading branch information
stuhood committed May 13, 2018
1 parent b994d45 commit 0bb085e
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 63 deletions.
2 changes: 1 addition & 1 deletion build-support/bin/native/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ esac
readonly CACHE_ROOT=${XDG_CACHE_HOME:-$HOME/.cache}/pants
readonly NATIVE_ENGINE_CACHE_DIR=${CACHE_ROOT}/bin/native-engine

readonly RUST_TOOLCHAIN="1.25.0"
readonly RUST_TOOLCHAIN="1.26.0"

function calculate_current_hash() {
# Cached and unstaged files, with ignored files excluded.
Expand Down
16 changes: 8 additions & 8 deletions src/rust/engine/fs/brfs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,13 @@ mod test {
extern crate tempdir;
extern crate testutil;

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

#[test]
fn missing_digest() {
Expand Down Expand Up @@ -886,16 +886,16 @@ mod syscall_tests {
extern crate tempdir;
extern crate testutil;

use self::tempdir::TempDir;
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::tempdir::TempDir;
use self::testutil::data::TestData;
use std::ffi::CString;
use std::path::Path;
use std::sync::Arc;

#[test]
fn read_file_by_digest_exact_bytes() {
Expand Down
9 changes: 3 additions & 6 deletions src/rust/engine/fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ extern crate tempdir;
#[cfg(test)]
extern crate testutil;

use std::cmp::min;
use std::collections::HashSet;
use std::io::{self, Read};
use std::os::unix::fs::PermissionsExt;
use std::path::{Component, Path, PathBuf};
use std::sync::Arc;
use std::{fmt, fs};
use std::io::{self, Read};
use std::cmp::min;

use bytes::Bytes;
use futures::future::{self, Future};
Expand Down Expand Up @@ -122,12 +122,9 @@ impl PathStat {

lazy_static! {
static ref PARENT_DIR: &'static str = "..";

static ref SINGLE_STAR_GLOB: Pattern = Pattern::new("*").unwrap();

static ref DOUBLE_STAR: &'static str = "**";
static ref DOUBLE_STAR_GLOB: Pattern = Pattern::new("**").unwrap();

static ref EMPTY_IGNORE: Arc<Gitignore> = Arc::new(Gitignore::empty());
}

Expand Down Expand Up @@ -851,9 +848,9 @@ mod posixfs_test {
extern crate tempdir;
extern crate testutil;

use self::testutil::make_file;
use super::{Dir, File, Link, PathStat, PathStatGetter, PosixFS, ResettablePool, Stat};
use futures::Future;
use self::testutil::make_file;
use std;
use std::path::{Path, PathBuf};
use std::sync::Arc;
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
32 changes: 14 additions & 18 deletions src/rust/engine/fs/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ use futures::future::{self, join_all};
use hashing::{Digest, Fingerprint};
use indexmap::{self, IndexMap};
use itertools::Itertools;
use {File, FileContent, PathStat, PosixFS, Store};
use protobuf;
use std::collections::HashMap;
use std::ffi::OsString;
use std::fmt;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use {File, FileContent, PathStat, PosixFS, Store};

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 @@ -154,11 +154,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 @@ -215,21 +211,21 @@ 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));

// 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 @@ -424,15 +420,15 @@ mod tests {
extern crate tempdir;
extern crate testutil;

use self::testutil::make_file;
use bytes::Bytes;
use futures::future::Future;
use hashing::{Digest, Fingerprint};
use tempdir::TempDir;
use self::testutil::make_file;

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

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

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

#[derive(Clone)]
pub struct ByteStore {
Expand Down Expand Up @@ -910,11 +910,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 @@ -1412,8 +1412,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 @@ -1629,8 +1629,8 @@ mod remote {

extern crate tempdir;

use super::ByteStore;
use super::super::EntryType;
use super::ByteStore;
use bytes::Bytes;
use futures::Future;
use hashing::Digest;
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/process_execution/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ pub fn run_command_locally(
mod tests {
extern crate testutil;

use self::testutil::{as_bytes, owned_string_vec};
use super::{run_command_locally, ExecuteProcessRequest, ExecuteProcessResult};
use fs;
use std::collections::BTreeMap;
use std::path::PathBuf;
use self::testutil::{as_bytes, owned_string_vec};

#[test]
#[cfg(unix)]
Expand Down
28 changes: 15 additions & 13 deletions src/rust/engine/process_execution/src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use digest::{Digest as DigestTrait, FixedOutput};
use fs::Store;
use futures::{future, Future};
use futures_timer::Delay;
use hashing::{Digest, Fingerprint};
use grpcio;
use hashing::{Digest, Fingerprint};
use protobuf::{self, Message, ProtobufEnum};
use resettable::Resettable;
use sha2::Sha256;
Expand Down Expand Up @@ -38,14 +38,14 @@ enum ExecutionError {
}

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();
}
}
};
}};
}

impl CommandRunner {
Expand Down Expand Up @@ -278,10 +278,12 @@ impl CommandRunner {
try_future!(
precondition_failure
.merge_from_bytes(details.get_value())
.map_err(|e| ExecutionError::Fatal(format!(
"Error deserializing FailedPrecondition proto: {:?}",
e
)))
.map_err(|e| {
ExecutionError::Fatal(format!(
"Error deserializing FailedPrecondition proto: {:?}",
e
))
})
);

let mut missing_digests =
Expand Down Expand Up @@ -474,8 +476,8 @@ mod tests {
use futures::Future;
use grpcio;
use hashing::Digest;
use protobuf::{self, Message, ProtobufEnum};
use mock;
use protobuf::{self, Message, ProtobufEnum};
use tempdir::TempDir;
use testutil::data::{TestData, TestDirectory};
use testutil::{as_bytes, owned_string_vec};
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/process_executor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ extern crate tempdir;
use clap::{App, AppSettings, Arg};
use futures::future::Future;
use hashing::{Digest, Fingerprint};
use tempdir::TempDir;
use std::collections::BTreeMap;
use std::iter::Iterator;
use std::process::exit;
use std::sync::Arc;
use std::time::Duration;
use tempdir::TempDir;

/// A binary which takes args of format:
/// process_executor --env=FOO=bar --env=SOME=value --input-digest=abc123 --input-digest-length=80
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use fnv::FnvHasher;

use std::collections::HashMap;
use std::{fmt, hash};
use std::ops::Drop;
use std::{fmt, hash};

use externs;
use handles::{enqueue_drop_handle, Handle};
Expand Down
8 changes: 4 additions & 4 deletions src/rust/engine/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use std::io::{self, BufWriter, Write};
use std::path::{Path, PathBuf};
use std::sync::Mutex;

use futures::future::{self, Future};
use petgraph::Direction;
use petgraph::stable_graph::{NodeIndex, StableDiGraph, StableGraph};
use futures::future::{self, Future};

use externs;
use boxfuture::Boxable;
use context::ContextFactory;
use core::{Failure, Noop, FNV};
use externs;
use hashing;
use nodes::{DigestFile, Node, NodeFuture, NodeKey, NodeResult, TryInto};

Expand Down Expand Up @@ -341,7 +341,7 @@ impl InnerGraph {
};

try!(f.write_all(b"digraph plans {\n"));
try!(f.write_fmt(format_args!(" node[colorscheme={}];\n", viz_color_scheme),));
try!(f.write_fmt(format_args!(" node[colorscheme={}];\n", viz_color_scheme)));
try!(f.write_all(b" concentrate=true;\n"));
try!(f.write_all(b" rankdir=TB;\n"));

Expand Down Expand Up @@ -371,7 +371,7 @@ impl InnerGraph {

// Write an entry per edge.
let dep_str = dep_entry.format::<NodeKey>();
try!(f.write_fmt(format_args!(" \"{}\" -> \"{}\"\n", node_str, dep_str),));
try!(f.write_fmt(format_args!(" \"{}\" -> \"{}\"\n", node_str, dep_str)));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/rust/engine/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
extern crate bazel_protos;
extern crate tempdir;

use std::error::Error;
use std::collections::BTreeMap;
use std::error::Error;
use std::fmt;
use std::os::unix::ffi::OsStrExt;
use std::path::{Path, PathBuf};
Expand All @@ -19,8 +19,8 @@ use context::Context;
use core::{throw, Failure, Key, Noop, TypeConstraint, Value, Variants};
use externs;
use fs::{self, Dir, File, FileContent, Link, PathGlobs, PathStat, StoreFileByDigest, VFS};
use process_execution;
use hashing;
use process_execution;
use rule_graph;
use selectors::{self, Selector};
use tasks::{self, Intrinsic, IntrinsicKind};
Expand Down
2 changes: 1 addition & 1 deletion src/rust/engine/src/rule_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the Apache License, Version 2.0 (see LICENSE).

use std::collections::{hash_map, HashMap, HashSet, VecDeque};
use std::hash::Hash;
use std::fmt;
use std::hash::Hash;
use std::io;

use core::{Function, Key, TypeConstraint, TypeId, Value, ANY_TYPE};
Expand Down

0 comments on commit 0bb085e

Please sign in to comment.