Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor import style #1701

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

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

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ http = "0.2"
hyper = { version = "0.14.24", optional = true, features = ["server"] }
is-terminal = "0.4.5"
jobserver = "0.1"
jsonwebtoken = { version = "8", optional = true }
jwt = { package = "jsonwebtoken", version = "8", optional = true }
lazy_static = "1.0.0"
libc = "0.2.140"
linked-hash-map = "0.5"
Expand All @@ -60,8 +60,7 @@ reqwest = { version = "0.11", features = ["json", "blocking", "stream"], optiona
retry = "2"
semver = "1.0"
sha2 = { version = "0.10.6", optional = true }
serde = "1.0"
serde_derive = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
strip-ansi-escapes = "0.1"
tar = "0.4.36"
Expand Down Expand Up @@ -137,7 +136,7 @@ unstable = []
# Enables distributed support in the sccache client
dist-client = ["flate2", "hyper", "reqwest", "url", "sha2"]
# Enables the sccache-dist binary
dist-server = ["crossbeam-utils", "jsonwebtoken", "flate2", "libmount", "nix", "openssl", "reqwest", "rouille", "syslog", "void", "version-compare"]
dist-server = ["crossbeam-utils", "jwt", "flate2", "libmount", "nix", "openssl", "reqwest", "rouille", "syslog", "void", "version-compare"]
# Enables dist tests with external requirements
dist-tests = ["dist-client", "dist-server"]

Expand Down
21 changes: 1 addition & 20 deletions src/bin/sccache-dist/main.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
extern crate base64;
extern crate crossbeam_utils;
extern crate env_logger;
extern crate flate2;
extern crate jsonwebtoken as jwt;

#[cfg(not(target_os = "freebsd"))]
extern crate libmount;

#[macro_use]
extern crate log;
extern crate nix;
extern crate openssl;
extern crate rand;
extern crate reqwest;
extern crate sccache;
#[macro_use]
extern crate serde_derive;
extern crate serde_json;
extern crate syslog;
extern crate tar;
extern crate void;

use anyhow::{bail, Context, Error, Result};
use base64::Engine;
Expand All @@ -36,6 +16,7 @@ use sccache::dist::{
};
use sccache::util::daemonize;
use sccache::util::BASE64_URL_SAFE_ENGINE;
use serde::{Deserialize, Serialize};
use std::collections::{btree_map, BTreeMap, HashMap, HashSet};
use std::env;
use std::io;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/sccache-dist/token_check.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::jwt;
use anyhow::{bail, Context, Result};
use base64::Engine;
use sccache::dist::http::{ClientAuthCheck, ClientVisibleMsg};
use sccache::util::{new_reqwest_blocking_client, BASE64_URL_SAFE_ENGINE};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::result::Result as StdResult;
use std::sync::Mutex;
Expand Down
1 change: 1 addition & 0 deletions src/cache/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::config::Config;
feature = "webdav"
))]
use crate::config::{self, CacheType};
use async_trait::async_trait;
use fs_err as fs;
use std::fmt;
use std::io::{self, Cursor, Read, Seek, Write};
Expand Down
1 change: 1 addition & 0 deletions src/cache/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use crate::cache::{Cache, CacheRead, CacheWrite, Storage};
use crate::lru_disk_cache::Error as LruError;
use crate::lru_disk_cache::LruDiskCache;
use async_trait::async_trait;
use std::ffi::{OsStr, OsString};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
Expand Down
1 change: 1 addition & 0 deletions src/cache/gcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::errors::*;
use opendal::Operator;
use opendal::{layers::LoggingLayer, services::Gcs};
use reqsign::{GoogleBuilder, GoogleToken, GoogleTokenLoad};
use serde::Deserialize;
use url::Url;

#[derive(Copy, Clone)]
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ use crate::dist;
use crate::dist::pkg;
use crate::mock_command::CommandCreatorSync;
use crate::util::{hash_all, Digest, HashToDigest};
use async_trait::async_trait;
use fs_err as fs;
use lazy_static::lazy_static;
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use std::ffi::{OsStr, OsString};
Expand Down
1 change: 1 addition & 0 deletions src/compiler/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::compiler::{gcc, write_temp_file, Cacheable, CompileCommand, CompilerA
use crate::mock_command::{CommandCreator, CommandCreatorSync, RunCommand};
use crate::util::{run_input_output, OsStrExt};
use crate::{counted_array, dist};
use async_trait::async_trait;
use fs::File;
use fs_err as fs;
use semver::{BuildMetadata, Prerelease, Version};
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ use crate::dist::pkg;
use crate::lru_disk_cache;
use crate::mock_command::{exit_status, CommandChild, CommandCreatorSync, RunCommand};
use crate::util::{fmt_duration_as_secs, ref_env, run_input_output};
use async_trait::async_trait;
use filetime::FileTime;
use fs::File;
use fs_err as fs;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::ffi::{OsStr, OsString};
use std::fmt;
Expand Down Expand Up @@ -2126,6 +2128,7 @@ mod test_dist {
PathTransformer, ProcessOutput, RunJobResult, SchedulerStatusResult, ServerId,
SubmitToolchainResult, Toolchain,
};
use async_trait::async_trait;
use std::path::{Path, PathBuf};
use std::sync::{atomic::AtomicBool, Arc};

Expand Down
1 change: 1 addition & 0 deletions src/compiler/diab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::errors::*;
use crate::mock_command::{CommandCreatorSync, RunCommand};
use crate::util::{run_input_output, OsStrExt};
use crate::{counted_array, dist};
use async_trait::async_trait;
use fs::File;
use fs_err as fs;
use log::Level::Trace;
Expand Down
1 change: 1 addition & 0 deletions src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::compiler::{clang, Cacheable, ColorMode, CompileCommand, CompilerArgum
use crate::mock_command::{CommandCreatorSync, RunCommand};
use crate::util::{run_input_output, OsStrExt};
use crate::{counted_array, dist};
use async_trait::async_trait;
use fs::File;
use fs_err as fs;
use log::Level::Trace;
Expand Down
1 change: 1 addition & 0 deletions src/compiler/msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::compiler::{
use crate::mock_command::{CommandCreatorSync, RunCommand};
use crate::util::{run_input_output, OsStrExt};
use crate::{counted_array, dist};
use async_trait::async_trait;
use fs::File;
use fs_err as fs;
use log::Level::Debug;
Expand Down
1 change: 1 addition & 0 deletions src/compiler/nvcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::compiler::{gcc, write_temp_file, Cacheable, CompileCommand, CompilerA
use crate::mock_command::{CommandCreator, CommandCreatorSync, RunCommand};
use crate::util::{run_input_output, OsStrExt};
use crate::{counted_array, dist};
use async_trait::async_trait;
use fs::File;
use fs_err as fs;
use log::Level::Trace;
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ use crate::mock_command::{CommandCreatorSync, RunCommand};
use crate::util::{fmt_duration_as_secs, hash_all, hash_all_archives, run_input_output, Digest};
use crate::util::{ref_env, HashToDigest, OsStrExt};
use crate::{counted_array, dist};
use async_trait::async_trait;
use filetime::FileTime;
use fs_err as fs;
use lazy_static::lazy_static;
use log::Level::Trace;
#[cfg(feature = "dist-client")]
#[cfg(feature = "dist-client")]
Expand Down
12 changes: 9 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
use directories::ProjectDirs;
use fs::File;
use fs_err as fs;
use lazy_static::lazy_static;
use regex::Regex;
use serde::de::{Deserialize, DeserializeOwned, Deserializer};
#[cfg(any(feature = "dist-client", feature = "dist-server"))]
#[cfg(any(feature = "dist-client", feature = "dist-server"))]
use serde::ser::{Serialize, Serializer};
use serde::ser::Serializer;
use serde::{
de::{DeserializeOwned, Deserializer},
Deserialize, Serialize,
};
#[cfg(test)]
use serial_test::serial;
use std::collections::HashMap;
Expand Down Expand Up @@ -860,6 +863,8 @@ pub mod scheduler {

use crate::errors::*;

use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type")]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -911,6 +916,7 @@ pub mod scheduler {
#[cfg(feature = "dist-server")]
pub mod server {
use super::HTTPUrl;
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
use std::path::{Path, PathBuf};

Expand Down
3 changes: 3 additions & 0 deletions src/dist/client_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ mod code_grant_pkce {
use base64::Engine;
use futures::channel::oneshot;
use hyper::{Body, Method, Request, Response, StatusCode};
use lazy_static::lazy_static;
use rand::{rngs::OsRng, RngCore};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::collections::HashMap;
use std::sync::mpsc;
Expand Down Expand Up @@ -279,6 +281,7 @@ mod implicit {
};
use futures::channel::oneshot;
use hyper::{Body, Method, Request, Response, StatusCode};
use lazy_static::lazy_static;
use std::collections::HashMap;
use std::sync::mpsc;
use std::sync::Mutex;
Expand Down
5 changes: 4 additions & 1 deletion src/dist/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub use self::server::{

mod common {
use http::header;
use serde::{Deserialize, Serialize};
#[cfg(feature = "dist-server")]
use std::collections::HashMap;
use std::fmt;
Expand Down Expand Up @@ -249,12 +250,13 @@ pub mod urls {

#[cfg(feature = "dist-server")]
mod server {
use crate::jwt;
use crate::util::new_reqwest_blocking_client;
use byteorder::{BigEndian, ReadBytesExt};
use flate2::read::ZlibDecoder as ZlibReadDecoder;
use lazy_static::lazy_static;
use rand::{rngs::OsRng, RngCore};
use rouille::accept;
use serde::Serialize;
use std::collections::HashMap;
use std::io::Read;
use std::net::SocketAddr;
Expand Down Expand Up @@ -1066,6 +1068,7 @@ mod client {
SchedulerStatusResult, SubmitToolchainResult, Toolchain,
};

use async_trait::async_trait;
use byteorder::{BigEndian, WriteBytesExt};
use flate2::write::ZlibEncoder as ZlibWriteEncoder;
use flate2::Compression;
Expand Down
2 changes: 2 additions & 0 deletions src/dist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
// limitations under the License.

use crate::compiler;
use async_trait::async_trait;
use rand::{rngs::OsRng, RngCore};
use serde::{Deserialize, Serialize};
use std::ffi::OsString;
use std::fmt;
use std::io::{self, Read};
Expand Down
9 changes: 0 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,11 @@
#![allow(clippy::type_complexity, clippy::new_without_default)]
#![recursion_limit = "256"]

#[macro_use]
extern crate async_trait;
#[cfg(feature = "jsonwebtoken")]
use jsonwebtoken as jwt;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
#[cfg(feature = "rouille")]
#[macro_use(router)]
extern crate rouille;
#[macro_use]
extern crate serde_derive;

// To get macros in scope, this has to be first.
#[cfg(test)]
#[macro_use]
Expand Down
1 change: 1 addition & 0 deletions src/mock_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

use crate::errors::*;
use crate::jobserver::{Acquired, Client};
use async_trait::async_trait;
use std::boxed::Box;
use std::ffi::{OsStr, OsString};
use std::fmt;
Expand Down
1 change: 1 addition & 0 deletions src/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::compiler::ColorMode;
use crate::server::{DistInfo, ServerInfo};
use serde::{Deserialize, Serialize};
use std::ffi::OsString;

/// A client request.
Expand Down
1 change: 1 addition & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use futures::channel::mpsc;
use futures::future::FutureExt;
use futures::{future, stream, Sink, SinkExt, Stream, StreamExt, TryFutureExt};
use number_prefix::NumberPrefix;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::env;
use std::ffi::{OsStr, OsString};
Expand Down
1 change: 1 addition & 0 deletions src/test/mock_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use crate::cache::{Cache, CacheWrite, Storage};
use crate::errors::*;
use async_trait::async_trait;
use futures::channel::mpsc;
use std::sync::Arc;
use std::time::Duration;
Expand Down