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

Replace lazy_static with once_cell #3704

Merged
merged 1 commit into from
Jul 13, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ uudoc = [ "zip" ]
[dependencies]
clap = { version = "3.1", features = ["wrap_help", "cargo"] }
clap_complete = "3.1"
once_cell = "1.13.0"
phf = "0.10.1"
lazy_static = { version="1.3" }
selinux = { version="0.2", optional = true }
textwrap = { version="0.15", features=["terminal_size"] }
uucore = { version=">=0.0.11", package="uucore", path="src/uucore" }
selinux = { version="0.2", optional = true }
zip = { version = "0.6.0", optional=true, default_features=false, features=["deflate"] }
# * uutils
uu_test = { optional=true, version="0.0.14", package="uu_test", path="src/uu/test" }
Expand Down
3 changes: 0 additions & 3 deletions src/uu/ls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ once_cell = "1.13.0"
atty = "0.2"
selinux = { version="0.2", optional = true }

[target.'cfg(unix)'.dependencies]
lazy_static = "1.4.0"

[[bin]]
name = "ls"
path = "src/main.rs"
Expand Down
13 changes: 4 additions & 9 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

#[macro_use]
extern crate uucore;
#[cfg(unix)]
#[macro_use]
extern crate lazy_static;

use clap::{crate_version, Arg, Command};
use glob::Pattern;
Expand Down Expand Up @@ -2251,16 +2248,16 @@ fn get_inode(metadata: &Metadata) -> String {
// Currently getpwuid is `linux` target only. If it's broken out into
// a posix-compliant attribute this can be updated...
#[cfg(unix)]
use once_cell::sync::Lazy;
#[cfg(unix)]
use std::sync::Mutex;
#[cfg(unix)]
use uucore::entries;
use uucore::quoting_style;

#[cfg(unix)]
fn cached_uid2usr(uid: u32) -> String {
lazy_static! {
static ref UID_CACHE: Mutex<HashMap<u32, String>> = Mutex::new(HashMap::new());
}
static UID_CACHE: Lazy<Mutex<HashMap<u32, String>>> = Lazy::new(|| Mutex::new(HashMap::new()));

let mut uid_cache = UID_CACHE.lock().unwrap();
uid_cache
Expand All @@ -2280,9 +2277,7 @@ fn display_uname(metadata: &Metadata, config: &Config) -> String {

#[cfg(all(unix, not(target_os = "redox")))]
fn cached_gid2grp(gid: u32) -> String {
lazy_static! {
static ref GID_CACHE: Mutex<HashMap<u32, String>> = Mutex::new(HashMap::new());
}
static GID_CACHE: Lazy<Mutex<HashMap<u32, String>>> = Lazy::new(|| Mutex::new(HashMap::new()));

let mut gid_cache = GID_CACHE.lock().unwrap();
gid_cache
Expand Down
2 changes: 1 addition & 1 deletion src/uucore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ nix = { version = "0.24.1", optional = true, default-features = false, features

[dev-dependencies]
clap = "3.1"
lazy_static = "1.3"
once_cell = "1.13"

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3", features = ["errhandlingapi", "fileapi", "handleapi", "winerror"] }
Expand Down
6 changes: 2 additions & 4 deletions src/uucore/src/lib/mods/backup_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ mod tests {
use std::env;
// Required to instantiate mutex in shared context
use clap::Command;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use std::sync::Mutex;

// The mutex is required here as by default all tests are run as separate
Expand All @@ -456,9 +456,7 @@ mod tests {
// occur if no precautions are taken. Thus we have all tests that rely on
// environment variables lock this empty mutex to ensure they don't access
// it concurrently.
lazy_static! {
static ref TEST_MUTEX: Mutex<()> = Mutex::new(());
}
static TEST_MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));

// Environment variable for "VERSION_CONTROL"
static ENV_VERSION_CONTROL: &str = "VERSION_CONTROL";
Expand Down
5 changes: 2 additions & 3 deletions tests/by-util/test_chmod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::common::util::*;
use once_cell::sync::Lazy;
use std::fs::{metadata, set_permissions, OpenOptions, Permissions};
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
use std::sync::Mutex;
Expand All @@ -11,9 +12,7 @@ use self::libc::umask;
static TEST_FILE: &str = "file";
static REFERENCE_FILE: &str = "reference";
static REFERENCE_PERMS: u32 = 0o247;
lazy_static! {
static ref UMASK_MUTEX: Mutex<()> = Mutex::new(());
}
static UMASK_MUTEX: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));

struct TestCase {
args: Vec<&'static str>,
Expand Down
7 changes: 0 additions & 7 deletions tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,9 @@ use std::os::unix::io::IntoRawFd;
use std::path::Path;
#[cfg(not(windows))]
use std::path::PathBuf;
#[cfg(not(windows))]
use std::sync::Mutex;
use std::thread::sleep;
use std::time::Duration;

#[cfg(not(windows))]
lazy_static! {
static ref UMASK_MUTEX: Mutex<()> = Mutex::new(());
}

const LONG_ARGS: &[&str] = &[
"-l",
"--long",
Expand Down
5 changes: 0 additions & 5 deletions tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#[macro_use]
mod common;

#[allow(unused_imports)]
#[cfg(unix)]
#[macro_use]
extern crate lazy_static;

#[cfg(unix)]
extern crate rust_users;

Expand Down