mirror of
https://github.com/rust-lang/cargo
synced 2024-08-28 03:39:31 +00:00
Auto merge of #12217 - weihanglo:1.70-cleanup, r=epage
refactor: housekeeping for 1.70.0
This commit is contained in:
commit
58bbd2ed54
3
.github/workflows/main.yml
vendored
3
.github/workflows/main.yml
vendored
|
@ -12,9 +12,6 @@ defaults:
|
|||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
|
||||
|
||||
jobs:
|
||||
# Check Code style quickly by running `rustfmt` over all code
|
||||
rustfmt:
|
||||
|
|
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -274,10 +274,8 @@ dependencies = [
|
|||
"ignore",
|
||||
"im-rc",
|
||||
"indexmap",
|
||||
"is-terminal",
|
||||
"itertools",
|
||||
"jobserver",
|
||||
"lazy_static",
|
||||
"lazycell",
|
||||
"libc",
|
||||
"libgit2-sys",
|
||||
|
@ -2658,7 +2656,6 @@ version = "0.0.0"
|
|||
dependencies = [
|
||||
"cargo",
|
||||
"cargo-util",
|
||||
"is-terminal",
|
||||
"lazy_static",
|
||||
"proptest",
|
||||
"varisat",
|
||||
|
|
|
@ -45,7 +45,6 @@ humantime = "2.0.0"
|
|||
ignore = "0.4.7"
|
||||
im-rc = "15.0.0"
|
||||
indexmap = "1"
|
||||
is-terminal = "0.4.4"
|
||||
itertools = "0.10.0"
|
||||
jobserver = "0.1.26"
|
||||
lazy_static = "1.3.0"
|
||||
|
@ -136,10 +135,8 @@ humantime.workspace = true
|
|||
ignore.workspace = true
|
||||
im-rc.workspace = true
|
||||
indexmap.workspace = true
|
||||
is-terminal.workspace = true
|
||||
itertools.workspace = true
|
||||
jobserver.workspace = true
|
||||
lazy_static.workspace = true
|
||||
lazycell.workspace = true
|
||||
libc.workspace = true
|
||||
libgit2-sys.workspace = true
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use filetime::{self, FileTime};
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::io::{self, ErrorKind};
|
||||
|
@ -9,15 +8,11 @@ use std::path::{Path, PathBuf};
|
|||
use std::process::Command;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Mutex;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
static CARGO_INTEGRATION_TEST_DIR: &str = "cit";
|
||||
|
||||
lazy_static! {
|
||||
// TODO: Use `SyncOnceCell` when stable
|
||||
static ref GLOBAL_ROOT: Mutex<Option<PathBuf>> = Mutex::new(None);
|
||||
|
||||
static ref TEST_ROOTS: Mutex<HashMap<String, PathBuf>> = Default::default();
|
||||
}
|
||||
static GLOBAL_ROOT: OnceLock<Mutex<Option<PathBuf>>> = OnceLock::new();
|
||||
|
||||
/// This is used when running cargo is pre-CARGO_TARGET_TMPDIR
|
||||
/// TODO: Remove when CARGO_TARGET_TMPDIR grows old enough.
|
||||
|
@ -31,7 +26,10 @@ fn global_root_legacy() -> PathBuf {
|
|||
}
|
||||
|
||||
fn set_global_root(tmp_dir: Option<&'static str>) {
|
||||
let mut lock = GLOBAL_ROOT.lock().unwrap();
|
||||
let mut lock = GLOBAL_ROOT
|
||||
.get_or_init(|| Default::default())
|
||||
.lock()
|
||||
.unwrap();
|
||||
if lock.is_none() {
|
||||
let mut root = match tmp_dir {
|
||||
Some(tmp_dir) => PathBuf::from(tmp_dir),
|
||||
|
@ -44,7 +42,10 @@ fn set_global_root(tmp_dir: Option<&'static str>) {
|
|||
}
|
||||
|
||||
pub fn global_root() -> PathBuf {
|
||||
let lock = GLOBAL_ROOT.lock().unwrap();
|
||||
let lock = GLOBAL_ROOT
|
||||
.get_or_init(|| Default::default())
|
||||
.lock()
|
||||
.unwrap();
|
||||
match lock.as_ref() {
|
||||
Some(p) => p.clone(),
|
||||
None => unreachable!("GLOBAL_ROOT not set yet"),
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
//! Common executables that can be reused by various tests.
|
||||
|
||||
use crate::{basic_manifest, paths, project, Project};
|
||||
use lazy_static::lazy_static;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Mutex;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
lazy_static! {
|
||||
static ref ECHO_WRAPPER: Mutex<Option<PathBuf>> = Mutex::new(None);
|
||||
static ref ECHO: Mutex<Option<PathBuf>> = Mutex::new(None);
|
||||
}
|
||||
static ECHO_WRAPPER: OnceLock<Mutex<Option<PathBuf>>> = OnceLock::new();
|
||||
static ECHO: OnceLock<Mutex<Option<PathBuf>>> = OnceLock::new();
|
||||
|
||||
/// Returns the path to an executable that works as a wrapper around rustc.
|
||||
///
|
||||
/// The wrapper will echo the command line it was called with to stderr.
|
||||
pub fn echo_wrapper() -> PathBuf {
|
||||
let mut lock = ECHO_WRAPPER.lock().unwrap();
|
||||
let mut lock = ECHO_WRAPPER
|
||||
.get_or_init(|| Default::default())
|
||||
.lock()
|
||||
.unwrap();
|
||||
if let Some(path) = &*lock {
|
||||
return path.clone();
|
||||
}
|
||||
|
@ -53,7 +54,7 @@ pub fn echo_wrapper() -> PathBuf {
|
|||
///
|
||||
/// Do not expect this to be anything fancy.
|
||||
pub fn echo() -> PathBuf {
|
||||
let mut lock = ECHO.lock().unwrap();
|
||||
let mut lock = ECHO.get_or_init(|| Default::default()).lock().unwrap();
|
||||
if let Some(path) = &*lock {
|
||||
return path.clone();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ publish = false
|
|||
[dependencies]
|
||||
cargo.workspace = true
|
||||
cargo-util.workspace = true
|
||||
is-terminal.workspace = true
|
||||
lazy_static.workspace = true
|
||||
proptest.workspace = true
|
||||
varisat.workspace = true
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::io::IsTerminal;
|
||||
|
||||
use cargo::core::dependency::DepKind;
|
||||
use cargo::core::Dependency;
|
||||
use cargo::util::Config;
|
||||
|
@ -21,7 +23,7 @@ use proptest::prelude::*;
|
|||
proptest! {
|
||||
#![proptest_config(ProptestConfig {
|
||||
max_shrink_iters:
|
||||
if is_ci() || !is_terminal::IsTerminal::is_terminal(&std::io::stderr()){
|
||||
if is_ci() || !std::io::stderr().is_terminal() {
|
||||
// This attempts to make sure that CI will fail fast,
|
||||
0
|
||||
} else {
|
||||
|
|
|
@ -14,16 +14,6 @@ use super::list_commands;
|
|||
use crate::command_prelude::*;
|
||||
use cargo::core::features::HIDDEN;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
// Maps from commonly known external commands (not builtin to cargo) to their
|
||||
// description, for the help page. Reserved for external subcommands that are
|
||||
// core within the rust ecosystem (esp ones that might become internal in the future).
|
||||
static ref KNOWN_EXTERNAL_COMMAND_DESCRIPTIONS: HashMap<&'static str, &'static str> = HashMap::from([
|
||||
("clippy", "Checks a package to catch common mistakes and improve your Rust code."),
|
||||
("fmt", "Formats all bin and lib files of the current crate using rustfmt."),
|
||||
]);
|
||||
}
|
||||
|
||||
pub fn main(config: &mut LazyConfig) -> CliResult {
|
||||
let args = cli().try_get_matches()?;
|
||||
|
||||
|
@ -128,15 +118,28 @@ Run with 'cargo -Z [FLAG] [COMMAND]'",
|
|||
}
|
||||
|
||||
if expanded_args.flag("list") {
|
||||
// Maps from commonly known external commands (not builtin to cargo)
|
||||
// to their description, for the help page. Reserved for external
|
||||
// subcommands that are core within the rust ecosystem (esp ones that
|
||||
// might become internal in the future).
|
||||
let known_external_command_descriptions = HashMap::from([
|
||||
(
|
||||
"clippy",
|
||||
"Checks a package to catch common mistakes and improve your Rust code.",
|
||||
),
|
||||
(
|
||||
"fmt",
|
||||
"Formats all bin and lib files of the current crate using rustfmt.",
|
||||
),
|
||||
]);
|
||||
drop_println!(config, "Installed Commands:");
|
||||
for (name, command) in list_commands(config) {
|
||||
let known_external_desc = KNOWN_EXTERNAL_COMMAND_DESCRIPTIONS.get(name.as_str());
|
||||
let known_external_desc = known_external_command_descriptions.get(name.as_str());
|
||||
match command {
|
||||
CommandInfo::BuiltIn { about } => {
|
||||
assert!(
|
||||
known_external_desc.is_none(),
|
||||
"KNOWN_EXTERNAL_COMMANDS shouldn't contain builtin \"{}\"",
|
||||
name
|
||||
"known_external_commands shouldn't contain builtin `{name}`",
|
||||
);
|
||||
let summary = about.unwrap_or_default();
|
||||
let summary = summary.lines().next().unwrap_or(&summary); // display only the first line
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::hash::Hash;
|
|||
use std::path::Path;
|
||||
use std::ptr;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use serde::de;
|
||||
use serde::ser;
|
||||
|
@ -13,10 +14,7 @@ use crate::core::source::SourceId;
|
|||
use crate::util::interning::InternedString;
|
||||
use crate::util::{CargoResult, ToSemver};
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref PACKAGE_ID_CACHE: Mutex<HashSet<&'static PackageIdInner>> =
|
||||
Mutex::new(HashSet::new());
|
||||
}
|
||||
static PACKAGE_ID_CACHE: OnceLock<Mutex<HashSet<&'static PackageIdInner>>> = OnceLock::new();
|
||||
|
||||
/// Identifier for a specific version of a package in a specific source.
|
||||
#[derive(Clone, Copy, Eq, PartialOrd, Ord)]
|
||||
|
@ -147,7 +145,10 @@ impl PackageId {
|
|||
version,
|
||||
source_id,
|
||||
};
|
||||
let mut cache = PACKAGE_ID_CACHE.lock().unwrap();
|
||||
let mut cache = PACKAGE_ID_CACHE
|
||||
.get_or_init(|| Default::default())
|
||||
.lock()
|
||||
.unwrap();
|
||||
let inner = cache.get(&inner).cloned().unwrap_or_else(|| {
|
||||
let inner = Box::leak(Box::new(inner));
|
||||
cache.insert(inner);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::fmt;
|
||||
use std::io::prelude::*;
|
||||
use std::io::IsTerminal;
|
||||
|
||||
use is_terminal::IsTerminal;
|
||||
use termcolor::Color::{Cyan, Green, Red, Yellow};
|
||||
use termcolor::{self, Color, ColorSpec, StandardStream, WriteColor};
|
||||
|
||||
|
|
|
@ -13,11 +13,10 @@ use std::hash::{self, Hash};
|
|||
use std::path::{Path, PathBuf};
|
||||
use std::ptr;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::OnceLock;
|
||||
use url::Url;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref SOURCE_ID_CACHE: Mutex<HashSet<&'static SourceIdInner>> = Default::default();
|
||||
}
|
||||
static SOURCE_ID_CACHE: OnceLock<Mutex<HashSet<&'static SourceIdInner>>> = OnceLock::new();
|
||||
|
||||
/// Unique identifier for a source of packages.
|
||||
///
|
||||
|
@ -118,7 +117,10 @@ impl SourceId {
|
|||
|
||||
/// Interns the value and returns the wrapped type.
|
||||
fn wrap(inner: SourceIdInner) -> SourceId {
|
||||
let mut cache = SOURCE_ID_CACHE.lock().unwrap();
|
||||
let mut cache = SOURCE_ID_CACHE
|
||||
.get_or_init(|| Default::default())
|
||||
.lock()
|
||||
.unwrap();
|
||||
let inner = cache.get(&inner).cloned().unwrap_or_else(|| {
|
||||
let inner = Box::leak(Box::new(inner));
|
||||
cache.insert(inner);
|
||||
|
|
|
@ -217,8 +217,6 @@ fn run_doc_tests(
|
|||
|
||||
if doctest_in_workspace {
|
||||
add_path_args(ws, unit, &mut p);
|
||||
// FIXME(swatinem): remove the `unstable-options` once rustdoc stabilizes the `test-run-directory` option
|
||||
p.arg("-Z").arg("unstable-options");
|
||||
p.arg("--test-run-directory")
|
||||
.arg(unit.pkg.root().to_path_buf());
|
||||
} else {
|
||||
|
|
|
@ -10,14 +10,13 @@ use std::path::Path;
|
|||
use std::ptr;
|
||||
use std::str;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
fn leak(s: String) -> &'static str {
|
||||
Box::leak(s.into_boxed_str())
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref STRING_CACHE: Mutex<HashSet<&'static str>> = Mutex::new(HashSet::new());
|
||||
}
|
||||
static STRING_CACHE: OnceLock<Mutex<HashSet<&'static str>>> = OnceLock::new();
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct InternedString {
|
||||
|
@ -64,7 +63,10 @@ impl Eq for InternedString {}
|
|||
|
||||
impl InternedString {
|
||||
pub fn new(str: &str) -> InternedString {
|
||||
let mut cache = STRING_CACHE.lock().unwrap();
|
||||
let mut cache = STRING_CACHE
|
||||
.get_or_init(|| Default::default())
|
||||
.lock()
|
||||
.unwrap();
|
||||
let s = cache.get(str).cloned().unwrap_or_else(|| {
|
||||
let s = leak(str.to_string());
|
||||
cache.insert(s);
|
||||
|
|
Loading…
Reference in a new issue