More 2018-ification and minor formatting changes

2018-ification changes include:
* replacing `extern crate` imports (except for ones annotated with
`#[macro_use]` to prevent touching more files; maybe in a follow-up)
* removing standalone imports; for example, `use serde_json;` -- the
code already uses `serde_json::*` where necessary

Minor formatting changes include:
* collapsing imports from the same root (e.g. `use std::io::Read; use
std::io::BufRead` -> `use std::io::{BufRead, Read};`
* separating `crate` imports from external imports from `std` imports --
this is how many project seem to order their imports, most notably the
official Rust repo
* moving some `use`s from the first line to below the file's doc comment
* changing file-level doc comments from `///` to `//!` (so they actually
show up as documentation)
* `rustfmt` messing with the `nom` macros in `src/commentparser.rs`

Most of the 2018-ification was done by `cargo fix --edition-idioms`, but
all changes were manually inspected to catch any detrimental changes,
and `cargo test`/`cargo check` still succeed.
This commit is contained in:
Cole Helbling 2020-03-31 18:59:43 -07:00
parent c7978aca74
commit cbe2e62162
No known key found for this signature in database
GPG key ID: B37E0F2371016A4C
45 changed files with 125 additions and 254 deletions

View file

@ -4,7 +4,7 @@ version = "0.1.8"
authors = ["Graham Christensen <graham@grahamc.com>"]
include = ["Cargo.toml", "Cargo.lock", "src", "test-srcs", "build.rs"]
build = "build.rs"
edition = "2018"
[dependencies]
either = "1.4.0"

View file

@ -1,18 +1,8 @@
use std::thread;
use std::collections::HashMap;
use std::io;
use std::io::BufRead;
use std::io::BufReader;
use std::io::Read;
use std::process::Child;
use std::process::Command;
use std::process::ExitStatus;
use std::process::Stdio;
use std::sync::mpsc;
use std::sync::mpsc::sync_channel;
use std::sync::mpsc::{Receiver, SyncSender};
use std::thread::JoinHandle;
use std::io::{self, BufRead, BufReader, Read};
use std::process::{Child, Command, ExitStatus, Stdio};
use std::sync::mpsc::{self, sync_channel, Receiver, SyncSender};
use std::thread::{self, JoinHandle};
// Specifically set to fall under 1/2 of the AMQP library's
// SyncSender limitation.

View file

@ -1,22 +1,12 @@
extern crate amqp;
extern crate env_logger;
extern crate ofborg;
extern crate hubcaps;
extern crate hyper;
extern crate hyper_native_tls;
use std::env;
use ofborg::commentparser;
use ofborg::config;
use ofborg::easyamqp;
use ofborg::message::buildjob;
use ofborg::message::{Pr, Repo};
use ofborg::notifyworker;
use ofborg::notifyworker::NotificationReceiver;
use ofborg::message::{buildjob, Pr, Repo};
use ofborg::notifyworker::{self, NotificationReceiver};
use ofborg::worker;
use std::env;
fn main() {
let cfg = config::load(env::args().nth(1).unwrap().as_ref());
ofborg::setup_log();

View file

@ -1,19 +1,12 @@
extern crate amqp;
extern crate env_logger;
extern crate ofborg;
#[macro_use]
extern crate log;
use std::env;
use amqp::Basic;
use log::{log, warn};
use ofborg::checkout;
use ofborg::config;
use ofborg::easyamqp;
use ofborg::easyamqp::TypedWrappers;
use ofborg::easyamqp::{self, TypedWrappers};
use ofborg::notifyworker;
use ofborg::tasks;
use std::env;
use std::path::Path;
fn main() {

View file

@ -1,21 +1,11 @@
extern crate amqp;
extern crate env_logger;
extern crate ofborg;
extern crate hubcaps;
extern crate hyper;
extern crate hyper_native_tls;
use std::env;
use amqp::Basic;
use ofborg::config;
use ofborg::easyamqp;
use ofborg::easyamqp::TypedWrappers;
use ofborg::easyamqp::{self, TypedWrappers};
use ofborg::tasks;
use ofborg::worker;
use std::env;
fn main() {
let cfg = config::load(env::args().nth(1).unwrap().as_ref());
ofborg::setup_log();

View file

@ -1,21 +1,11 @@
extern crate amqp;
extern crate env_logger;
extern crate ofborg;
extern crate hubcaps;
extern crate hyper;
extern crate hyper_native_tls;
use std::env;
use amqp::Basic;
use ofborg::config;
use ofborg::easyamqp;
use ofborg::easyamqp::TypedWrappers;
use ofborg::easyamqp::{self, TypedWrappers};
use ofborg::tasks;
use ofborg::worker;
use std::env;
fn main() {
let cfg = config::load(env::args().nth(1).unwrap().as_ref());
ofborg::setup_log();

View file

@ -1,21 +1,11 @@
extern crate amqp;
extern crate env_logger;
extern crate ofborg;
extern crate hubcaps;
extern crate hyper;
extern crate hyper_native_tls;
use std::env;
use amqp::Basic;
use ofborg::config;
use ofborg::easyamqp;
use ofborg::easyamqp::TypedWrappers;
use ofborg::easyamqp::{self, TypedWrappers};
use ofborg::tasks;
use ofborg::worker;
use std::env;
fn main() {
let cfg = config::load(env::args().nth(1).unwrap().as_ref());
ofborg::setup_log();

View file

@ -1,16 +1,11 @@
extern crate amqp;
extern crate env_logger;
extern crate ofborg;
use ofborg::config;
use ofborg::easyamqp::{self, TypedWrappers};
use ofborg::tasks;
use ofborg::worker;
use std::env;
use std::path::PathBuf;
use ofborg::config;
use ofborg::easyamqp;
use ofborg::easyamqp::TypedWrappers;
use ofborg::tasks;
use ofborg::worker;
fn main() {
let cfg = config::load(env::args().nth(1).unwrap().as_ref());
ofborg::setup_log();

View file

@ -1,19 +1,13 @@
extern crate amqp;
extern crate env_logger;
extern crate ofborg;
use ofborg::config;
use ofborg::easyamqp;
use ofborg::message::{buildjob, Pr, Repo};
use ofborg::notifyworker;
use ofborg::tasks::build;
use std::env;
use std::thread;
use std::time::Duration;
use ofborg::message::{Pr, Repo};
use ofborg::config;
use ofborg::easyamqp;
use ofborg::message::buildjob;
use ofborg::notifyworker;
use ofborg::tasks::build;
fn main() {
let cfg = config::load(env::args().nth(1).unwrap().as_ref());
ofborg::setup_log();

View file

@ -1,21 +1,15 @@
extern crate amqp;
extern crate env_logger;
extern crate ofborg;
extern crate sys_info;
use amqp::Basic;
use ofborg::checkout;
use ofborg::config;
use ofborg::easyamqp::{self, TypedWrappers};
use ofborg::stats;
use ofborg::tasks;
use ofborg::worker;
use std::env;
use std::path::Path;
use std::process;
use amqp::Basic;
use ofborg::easyamqp;
use ofborg::easyamqp::TypedWrappers;
use ofborg::stats;
use ofborg::worker;
fn main() {
let memory_info = sys_info::mem_info().expect("Unable to get memory information from OS");

View file

@ -1,11 +1,7 @@
extern crate amqp;
extern crate env_logger;
extern crate ofborg;
use std::env;
use ofborg::config;
use ofborg::nix;
use std::env;
use std::fs::File;
use std::io::Read;
use std::path::Path;

View file

@ -1,14 +1,9 @@
extern crate amqp;
extern crate hyper;
extern crate ofborg;
use ofborg::{config, easyamqp, stats, tasks, worker};
use std::env;
use amqp::Basic;
use hyper::server::{Request, Response, Server};
use ofborg::easyamqp::TypedWrappers;
use ofborg::{config, easyamqp, stats, tasks, worker};
use std::env;
use std::thread;
fn main() {

View file

@ -1,8 +1,6 @@
use crate::clone;
use crate::clone::GitClonable;
use md5;
use std::ffi::OsStr;
use std::ffi::OsString;
use crate::clone::{self, GitClonable};
use std::ffi::{OsStr, OsString};
use std::fs;
use std::io::{Error, ErrorKind};
use std::path::{Path, PathBuf};

View file

@ -1,4 +1,5 @@
use fs2::FileExt;
use std::ffi::OsStr;
use std::fs;
use std::io::{Error, ErrorKind};

View file

@ -16,11 +16,16 @@ pub fn parse(text: &str) -> Option<Vec<Instruction>> {
}
}
named!(normal_token(CompleteStr) -> CompleteStr,
verify!(take_while1!(|c: char| c.is_ascii_graphic()),
|s: CompleteStr| !s.0.eq_ignore_ascii_case("@grahamcofborg"))
named!(
normal_token(CompleteStr) -> CompleteStr,
verify!(
take_while1!(|c: char| c.is_ascii_graphic()),
|s: CompleteStr| !s.0.eq_ignore_ascii_case("@grahamcofborg")
)
);
named!(parse_line_impl(CompleteStr) -> Option<Vec<Instruction>>, alt!(
named!(
parse_line_impl(CompleteStr) -> Option<Vec<Instruction>>,
alt!(
do_parse!(
res: ws!(many1!(ws!(preceded!(
alt!(tag_no_case!("@grahamcofborg") | tag_no_case!("@ofborg")),
@ -41,12 +46,11 @@ named!(parse_line_impl(CompleteStr) -> Option<Vec<Instruction>>, alt!(
// commands couldn't be handled?
value!(None, many_till!(take!(1), tag_no_case!("@grahamcofborg")))
)
)))) >>
eof!() >>
(Some(res.into_iter().filter_map(|x| x).collect()))
) |
value!(None)
));
)))) >> eof!()
>> (Some(res.into_iter().filter_map(|x| x).collect()))
) | value!(None)
)
);
pub fn parse_line(text: &str) -> Option<Vec<Instruction>> {
match parse_line_impl(CompleteStr(text)) {

View file

@ -1,8 +1,3 @@
extern crate amqp;
extern crate env_logger;
use hubcaps;
pub struct CommitStatus<'a> {
api: hubcaps::statuses::Statuses<'a>,
sha: String,

View file

@ -1,10 +1,11 @@
use crate::acl;
use crate::nix::Nix;
use hubcaps::{Credentials, Github, InstallationTokenGenerator, JWTCredentials};
use hyper::net::HttpsConnector;
use hyper::Client;
use hyper_native_tls::NativeTlsClient;
use serde_json;
use std::collections::HashMap;
use std::fs::File;
use std::io::Read;

View file

@ -1,6 +1,6 @@
use crate::config::RabbitMQConfig;
use crate::ofborg;
use amqp;
use amqp::Basic;
pub struct ConsumeConfig {

View file

@ -1,7 +1,5 @@
extern crate amqp;
extern crate env_logger;
use crate::nix;
use std::fs::File;
use std::path::Path;

View file

@ -7,9 +7,6 @@
#[macro_use]
extern crate serde_derive;
extern crate serde;
extern crate serde_json;
#[macro_use]
extern crate log;
@ -17,20 +14,6 @@ extern crate log;
#[macro_use]
extern crate nom;
extern crate amqp;
extern crate chrono;
extern crate either;
extern crate env_logger;
extern crate fs2;
extern crate hubcaps;
extern crate hyper;
extern crate hyper_native_tls;
extern crate lru_cache;
extern crate md5;
extern crate separator;
extern crate tempfile;
extern crate uuid;
use std::env;
pub mod acl;

View file

@ -1,4 +1,5 @@
use fs2::FileExt;
use std::fs;
use std::io::Error;
use std::path::PathBuf;

View file

@ -1,8 +1,10 @@
use crate::nix::Nix;
use tempfile::NamedTempFile;
use std::collections::{HashMap, HashSet};
use std::io::Write;
use std::path::Path;
use tempfile::NamedTempFile;
#[derive(Deserialize, Debug, Eq, PartialEq)]
pub struct ImpactedMaintainers(HashMap<Maintainer, Vec<Package>>);

View file

@ -1,6 +1,5 @@
use crate::commentparser::Subset;
use crate::message::{Pr, Repo};
use serde_json;
#[derive(Serialize, Deserialize, Debug)]
pub struct BuildJob {

View file

@ -1,4 +1,5 @@
use crate::message::{Pr, Repo};
use hubcaps::checks::Conclusion;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]

View file

@ -1,6 +1,5 @@
use crate::message::{Pr, Repo};
use crate::worker;
use serde_json;
pub fn from(data: &[u8]) -> Result<EvaluationJob, serde_json::error::Error> {
serde_json::from_slice(&data)

View file

@ -1,17 +1,16 @@
use crate::asynccmd::{AsyncCmd, SpawnedAsyncCmd};
use crate::ofborg::partition_result;
use tempfile::tempfile;
use std::collections::HashMap;
use std::env;
use std::ffi::OsStr;
use std::fmt;
use std::fs;
use std::io::BufRead;
use std::io::BufReader;
use std::io::Seek;
use std::io::SeekFrom;
use std::io::{BufRead, BufReader, Seek, SeekFrom};
use std::path::Path;
use std::process::{Command, Stdio};
use tempfile::tempfile;
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum File {

View file

@ -1,16 +1,11 @@
//! Evaluates the expression like Hydra would, with regards to
//! architecture support and recursed packages.
use crate::nix;
/// Evaluates the expression like Hydra would, with regards to
/// architecture support and recursed packages.
use crate::nixstats::EvaluationStats;
use crate::outpathdiff;
use serde_json;
use std::fs;
use std::fs::File;
use std::io::Read;
use std::io::Seek;
use std::io::SeekFrom;
use std::io::Write;
use std::io::{BufRead, BufReader};
use std::fs::{self, File};
use std::io::{BufRead, BufReader, Read, Seek, SeekFrom, Write};
use std::path::PathBuf;
pub struct HydraNixEnv {

View file

@ -1,5 +1,6 @@
//! Statistics emitted by Nix when NIX_SHOW_STATS=1
use separator::Separatable;
/// Statistics emitted by Nix when NIX_SHOW_STATS=1
use std::collections::HashMap;
#[derive(Deserialize)]

View file

@ -1,7 +1,8 @@
use crate::worker::Action;
use amqp::protocol::basic::{BasicProperties, Deliver};
use amqp::Basic;
use amqp::{Channel, Consumer};
use amqp::{Basic, Channel, Consumer};
use std::marker::Send;
pub struct NotifyWorker<T: SimpleNotifyWorker> {

View file

@ -1,7 +1,7 @@
use crate::nix;
use crate::nixenv::Error as NixEnvError;
use crate::nixenv::HydraNixEnv;
use crate::nixenv::{Error as NixEnvError, HydraNixEnv};
use crate::nixstats::{EvaluationStats, EvaluationStatsDiff};
use std::collections::{HashMap, HashSet};
use std::io::BufRead;
use std::path::PathBuf;

View file

@ -1,7 +1,5 @@
use amqp::protocol::basic::BasicProperties;
use amqp::Basic;
use amqp::Channel;
use serde_json;
use amqp::{Basic, Channel};
include!(concat!(env!("OUT_DIR"), "/events.rs"));

View file

@ -1,6 +1,7 @@
use crate::maintainers::{Maintainer, MaintainersByPackage};
use crate::outpathdiff::PackageArch;
use crate::tasks;
use std::collections::HashMap;
pub struct StdenvTagger {

View file

@ -1,7 +1,3 @@
extern crate amqp;
extern crate env_logger;
extern crate uuid;
use crate::checkout;
use crate::commentparser;
use crate::message::buildresult::{BuildResult, BuildStatus, V1Tag};
@ -9,10 +5,12 @@ use crate::message::{buildjob, buildlogmsg};
use crate::nix;
use crate::notifyworker;
use crate::worker;
use amqp::protocol::basic::{BasicProperties, Deliver};
use std::collections::VecDeque;
use uuid::Uuid;
use std::collections::VecDeque;
pub struct BuildWorker {
cloner: checkout::CachedCloner,
nix: nix::Nix,

View file

@ -2,6 +2,7 @@ use crate::checkout::CachedProjectCo;
use crate::commitstatus::CommitStatus;
use crate::evalchecker::EvalChecker;
use crate::tasks::eval::{EvaluationComplete, EvaluationStrategy, StepResult};
use std::path::Path;
#[derive(Default)]

View file

@ -1,14 +1,17 @@
pub mod stdenvs;
pub use self::stdenvs::Stdenvs;
mod nixpkgs;
pub use self::nixpkgs::NixpkgsStrategy;
mod generic;
mod nixpkgs;
pub mod stdenvs;
pub use self::generic::GenericStrategy;
pub use self::nixpkgs::NixpkgsStrategy;
pub use self::stdenvs::Stdenvs;
use crate::checkout::CachedProjectCo;
use crate::commitstatus::{CommitStatus, CommitStatusError};
use crate::evalchecker::EvalChecker;
use crate::message::buildjob::BuildJob;
use hubcaps::checks::CheckRunOptions;
use std::path::Path;
pub trait EvaluationStrategy {

View file

@ -2,29 +2,29 @@ use crate::checkout::CachedProjectCo;
use crate::commentparser::Subset;
use crate::commitstatus::CommitStatus;
use crate::evalchecker::EvalChecker;
use crate::maintainers;
use crate::maintainers::ImpactedMaintainers;
use crate::maintainers::{self, ImpactedMaintainers};
use crate::message::buildjob::BuildJob;
use crate::message::evaluationjob::EvaluationJob;
use crate::nix;
use crate::nix::Nix;
use crate::nix::{self, Nix};
use crate::nixenv::HydraNixEnv;
use crate::outpathdiff::{OutPathDiff, PackageArch};
use crate::tagger::{MaintainerPRTagger, PathsTagger, RebuildTagger};
use crate::tagger::{PkgsAddedRemovedTagger, StdenvTagger};
use crate::tagger::{
MaintainerPRTagger, PathsTagger, PkgsAddedRemovedTagger, RebuildTagger, StdenvTagger,
};
use crate::tasks::eval::{
stdenvs::Stdenvs, Error, EvaluationComplete, EvaluationStrategy, StepResult,
};
use crate::tasks::evaluate::make_gist;
use crate::tasks::evaluate::update_labels;
use crate::tasks::evaluate::{make_gist, update_labels};
use chrono::Utc;
use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output};
use hubcaps::gists::Gists;
use hubcaps::issues::{Issue, IssueRef};
use hubcaps::repositories::Repository;
use uuid::Uuid;
use std::collections::HashMap;
use std::path::Path;
use uuid::Uuid;
pub struct NixpkgsStrategy<'a> {
job: &'a EvaluationJob,

View file

@ -1,5 +1,6 @@
use crate::files::file_to_str;
use crate::nix;
use std::path::PathBuf;
enum StdenvFrom {

View file

@ -1,8 +1,4 @@
/// This is what evaluates every pull-request
extern crate amqp;
extern crate env_logger;
extern crate uuid;
use crate::acl::ACL;
use crate::checkout;
use crate::commitstatus::{CommitStatus, CommitStatusError};
@ -10,16 +6,16 @@ use crate::config::GithubAppVendingMachine;
use crate::files::file_to_str;
use crate::message::{buildjob, evaluationjob};
use crate::nix;
use crate::stats;
use crate::stats::Event;
use crate::stats::{self, Event};
use crate::systems;
use crate::tasks::eval;
use crate::worker;
use amqp::protocol::basic::{BasicProperties, Deliver};
use hubcaps;
use hubcaps::checks::CheckRunOptions;
use hubcaps::gists::Gists;
use hubcaps::issues::Issue;
use std::collections::HashMap;
use std::path::Path;
use std::sync::RwLock;

View file

@ -1,12 +1,9 @@
extern crate amqp;
extern crate env_logger;
use crate::acl;
use crate::ghevent;
use crate::message::{evaluationjob, Pr, Repo};
use crate::worker;
use amqp::protocol::basic::{BasicProperties, Deliver};
use serde_json;
pub struct EvaluationFilterWorker {
acl: acl::ACL,

View file

@ -1,15 +1,10 @@
extern crate amqp;
extern crate env_logger;
extern crate uuid;
use crate::acl;
use crate::commentparser;
use crate::ghevent;
use crate::message::{buildjob, evaluationjob, Pr, Repo};
use crate::worker;
use amqp::protocol::basic::{BasicProperties, Deliver};
use hubcaps;
use serde_json;
use uuid::Uuid;
pub struct GitHubCommentWorker {

View file

@ -1,15 +1,12 @@
extern crate amqp;
extern crate env_logger;
use crate::config::GithubAppVendingMachine;
use crate::message::buildjob::{BuildJob, QueuedBuildJobs};
use crate::message::buildresult::{BuildResult, BuildStatus, LegacyBuildResult};
use crate::message::Repo;
use crate::worker;
use amqp::protocol::basic::{BasicProperties, Deliver};
use chrono::{DateTime, Utc};
use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output};
use serde_json;
pub struct GitHubCommentPoster {
github_vend: GithubAppVendingMachine,

View file

@ -1,15 +1,12 @@
extern crate amqp;
extern crate env_logger;
use crate::message::buildlogmsg::{BuildLogMsg, BuildLogStart};
use crate::message::buildresult::BuildResult;
use crate::worker;
use crate::writetoline::LineWriter;
use amqp::protocol::basic::{BasicProperties, Deliver};
use lru_cache::LruCache;
use serde_json;
use std::fs;
use std::fs::{File, OpenOptions};
use std::fs::{self, File, OpenOptions};
use std::io::Write;
use std::path::{Component, PathBuf};

View file

@ -1,10 +1,7 @@
extern crate amqp;
extern crate env_logger;
use crate::stats;
use crate::worker;
use amqp::protocol::basic::{BasicProperties, Deliver};
use serde_json;
pub struct StatCollectorWorker<E> {
events: E,

View file

@ -1,8 +1,7 @@
use amqp::protocol::basic::{BasicProperties, Deliver};
use amqp::Basic;
use amqp::{Channel, Consumer};
use amqp::{Basic, Channel, Consumer};
use serde::Serialize;
use serde_json;
use std::marker::Send;
pub struct Worker<T: SimpleWorker> {

View file

@ -1,9 +1,5 @@
use std::fs::File;
use std::io::BufRead;
use std::io::BufReader;
use std::io::Seek;
use std::io::SeekFrom;
use std::io::Write;
use std::io::{BufRead, BufReader, Seek, SeekFrom, Write};
pub struct LineWriter {
file: File,