summaryrefslogtreecommitdiffstats
path: root/src/tools/cargo/crates
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /src/tools/cargo/crates
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/cargo/crates')
-rw-r--r--src/tools/cargo/crates/cargo-platform/Cargo.toml3
-rw-r--r--src/tools/cargo/crates/cargo-test-support/src/compare.rs2
-rw-r--r--src/tools/cargo/crates/cargo-test-support/src/diff.rs2
-rw-r--r--src/tools/cargo/crates/cargo-test-support/src/lib.rs48
-rw-r--r--src/tools/cargo/crates/cargo-util/Cargo.toml4
-rw-r--r--src/tools/cargo/crates/cargo-util/src/paths.rs39
-rw-r--r--src/tools/cargo/crates/crates-io/Cargo.toml2
-rw-r--r--src/tools/cargo/crates/crates-io/lib.rs4
-rw-r--r--src/tools/cargo/crates/home/Cargo.toml3
-rw-r--r--src/tools/cargo/crates/home/src/lib.rs1
-rw-r--r--src/tools/cargo/crates/resolver-tests/src/lib.rs21
-rw-r--r--src/tools/cargo/crates/xtask-bump-check/Cargo.toml3
-rw-r--r--src/tools/cargo/crates/xtask-bump-check/src/xtask.rs24
13 files changed, 120 insertions, 36 deletions
diff --git a/src/tools/cargo/crates/cargo-platform/Cargo.toml b/src/tools/cargo/crates/cargo-platform/Cargo.toml
index 016ead686..786948ff3 100644
--- a/src/tools/cargo/crates/cargo-platform/Cargo.toml
+++ b/src/tools/cargo/crates/cargo-platform/Cargo.toml
@@ -1,8 +1,9 @@
[package]
name = "cargo-platform"
-version = "0.1.5"
+version = "0.1.6"
edition.workspace = true
license.workspace = true
+rust-version = "1.70.0" # MSRV:3
homepage = "https://github.com/rust-lang/cargo"
repository = "https://github.com/rust-lang/cargo"
documentation = "https://docs.rs/cargo-platform"
diff --git a/src/tools/cargo/crates/cargo-test-support/src/compare.rs b/src/tools/cargo/crates/cargo-test-support/src/compare.rs
index 09e3a5a0c..d9e8d5454 100644
--- a/src/tools/cargo/crates/cargo-test-support/src/compare.rs
+++ b/src/tools/cargo/crates/cargo-test-support/src/compare.rs
@@ -236,6 +236,8 @@ fn substitute_macros(input: &str) -> String {
("[SKIPPING]", " Skipping"),
("[WAITING]", " Waiting"),
("[PUBLISHED]", " Published"),
+ ("[BLOCKING]", " Blocking"),
+ ("[GENERATED]", " Generated"),
];
let mut result = input.to_owned();
for &(pat, subst) in &macros {
diff --git a/src/tools/cargo/crates/cargo-test-support/src/diff.rs b/src/tools/cargo/crates/cargo-test-support/src/diff.rs
index 3fedc839b..cd0c97385 100644
--- a/src/tools/cargo/crates/cargo-test-support/src/diff.rs
+++ b/src/tools/cargo/crates/cargo-test-support/src/diff.rs
@@ -132,7 +132,7 @@ pub fn render_colored_changes<T: fmt::Display>(changes: &[Change<T>]) -> String
Change::Remove(i, s) => (format!("{:<4} ", i), '-', red, s),
Change::Keep(x, y, s) => (format!("{:<4}{:<4} ", x, y), ' ', dim, s),
};
- write!(
+ writeln!(
buffer,
"{dim}{nums}{reset}{bold}{sign}{reset}{color}{text}{reset}"
)
diff --git a/src/tools/cargo/crates/cargo-test-support/src/lib.rs b/src/tools/cargo/crates/cargo-test-support/src/lib.rs
index 1a8742720..ec74ce0b2 100644
--- a/src/tools/cargo/crates/cargo-test-support/src/lib.rs
+++ b/src/tools/cargo/crates/cargo-test-support/src/lib.rs
@@ -13,6 +13,7 @@ use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use std::str;
use std::sync::OnceLock;
+use std::thread::JoinHandle;
use std::time::{self, Duration};
use anyhow::{bail, Result};
@@ -1470,3 +1471,50 @@ pub fn symlink_supported() -> bool {
pub fn no_such_file_err_msg() -> String {
std::io::Error::from_raw_os_error(2).to_string()
}
+
+/// Helper to retry a function `n` times.
+///
+/// The function should return `Some` when it is ready.
+pub fn retry<F, R>(n: u32, mut f: F) -> R
+where
+ F: FnMut() -> Option<R>,
+{
+ let mut count = 0;
+ let start = std::time::Instant::now();
+ loop {
+ if let Some(r) = f() {
+ return r;
+ }
+ count += 1;
+ if count > n {
+ panic!(
+ "test did not finish within {n} attempts ({:?} total)",
+ start.elapsed()
+ );
+ }
+ sleep_ms(100);
+ }
+}
+
+#[test]
+#[should_panic(expected = "test did not finish")]
+fn retry_fails() {
+ retry(2, || None::<()>);
+}
+
+/// Helper that waits for a thread to finish, up to `n` tenths of a second.
+pub fn thread_wait_timeout<T>(n: u32, thread: JoinHandle<T>) -> T {
+ retry(n, || thread.is_finished().then_some(()));
+ thread.join().unwrap()
+}
+
+/// Helper that runs some function, and waits up to `n` tenths of a second for
+/// it to finish.
+pub fn threaded_timeout<F, R>(n: u32, f: F) -> R
+where
+ F: FnOnce() -> R + Send + 'static,
+ R: Send + 'static,
+{
+ let thread = std::thread::spawn(|| f());
+ thread_wait_timeout(n, thread)
+}
diff --git a/src/tools/cargo/crates/cargo-util/Cargo.toml b/src/tools/cargo/crates/cargo-util/Cargo.toml
index cba00f917..616a79c5e 100644
--- a/src/tools/cargo/crates/cargo-util/Cargo.toml
+++ b/src/tools/cargo/crates/cargo-util/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "cargo-util"
-version = "0.2.7"
+version = "0.2.8"
rust-version.workspace = true
edition.workspace = true
license.workspace = true
@@ -10,12 +10,12 @@ description = "Miscellaneous support code used by Cargo."
[dependencies]
anyhow.workspace = true
-sha2.workspace = true
filetime.workspace = true
hex.workspace = true
jobserver.workspace = true
libc.workspace = true
same-file.workspace = true
+sha2.workspace = true
shell-escape.workspace = true
tempfile.workspace = true
tracing.workspace = true
diff --git a/src/tools/cargo/crates/cargo-util/src/paths.rs b/src/tools/cargo/crates/cargo-util/src/paths.rs
index 888ca1af5..f405c8f97 100644
--- a/src/tools/cargo/crates/cargo-util/src/paths.rs
+++ b/src/tools/cargo/crates/cargo-util/src/paths.rs
@@ -180,6 +180,19 @@ pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()>
.with_context(|| format!("failed to write `{}`", path.display()))
}
+/// Writes a file to disk atomically.
+///
+/// write_atomic uses tempfile::persist to accomplish atomic writes.
+pub fn write_atomic<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> {
+ let path = path.as_ref();
+ let mut tmp = TempFileBuilder::new()
+ .prefix(path.file_name().unwrap())
+ .tempfile_in(path.parent().unwrap())?;
+ tmp.write_all(contents.as_ref())?;
+ tmp.persist(path)?;
+ Ok(())
+}
+
/// Equivalent to [`write()`], but does not write anything if the file contents
/// are identical to the given contents.
pub fn write_if_changed<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<()> {
@@ -681,7 +694,8 @@ pub fn create_dir_all_excluded_from_backups_atomic(p: impl AsRef<Path>) -> Resul
// we can infer from it's another cargo process doing work.
if let Err(e) = fs::rename(tempdir.path(), path) {
if !path.exists() {
- return Err(anyhow::Error::from(e));
+ return Err(anyhow::Error::from(e))
+ .with_context(|| format!("failed to create directory `{}`", path.display()));
}
}
Ok(())
@@ -775,6 +789,29 @@ fn exclude_from_time_machine(path: &Path) {
#[cfg(test)]
mod tests {
use super::join_paths;
+ use super::write;
+ use super::write_atomic;
+
+ #[test]
+ fn write_works() {
+ let original_contents = "[dependencies]\nfoo = 0.1.0";
+
+ let tmpdir = tempfile::tempdir().unwrap();
+ let path = tmpdir.path().join("Cargo.toml");
+ write(&path, original_contents).unwrap();
+ let contents = std::fs::read_to_string(&path).unwrap();
+ assert_eq!(contents, original_contents);
+ }
+ #[test]
+ fn write_atomic_works() {
+ let original_contents = "[dependencies]\nfoo = 0.1.0";
+
+ let tmpdir = tempfile::tempdir().unwrap();
+ let path = tmpdir.path().join("Cargo.toml");
+ write_atomic(&path, original_contents).unwrap();
+ let contents = std::fs::read_to_string(&path).unwrap();
+ assert_eq!(contents, original_contents);
+ }
#[test]
fn join_paths_lists_paths_on_error() {
diff --git a/src/tools/cargo/crates/crates-io/Cargo.toml b/src/tools/cargo/crates/crates-io/Cargo.toml
index d06dacdfa..f1b92602e 100644
--- a/src/tools/cargo/crates/crates-io/Cargo.toml
+++ b/src/tools/cargo/crates/crates-io/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "crates-io"
-version = "0.39.0"
+version = "0.39.1"
rust-version.workspace = true
edition.workspace = true
license.workspace = true
diff --git a/src/tools/cargo/crates/crates-io/lib.rs b/src/tools/cargo/crates/crates-io/lib.rs
index 757241fd3..1764ce527 100644
--- a/src/tools/cargo/crates/crates-io/lib.rs
+++ b/src/tools/cargo/crates/crates-io/lib.rs
@@ -38,6 +38,10 @@ pub struct Crate {
pub max_version: String,
}
+/// This struct is serialized as JSON and sent as metadata ahead of the crate
+/// tarball when publishing crates to a crate registry like crates.io.
+///
+/// see <https://doc.rust-lang.org/cargo/reference/registry-web-api.html#publish>
#[derive(Serialize, Deserialize)]
pub struct NewCrate {
pub name: String,
diff --git a/src/tools/cargo/crates/home/Cargo.toml b/src/tools/cargo/crates/home/Cargo.toml
index 03bd555a2..702a14e55 100644
--- a/src/tools/cargo/crates/home/Cargo.toml
+++ b/src/tools/cargo/crates/home/Cargo.toml
@@ -1,7 +1,8 @@
[package]
name = "home"
-version = "0.5.7" # also update `html_root_url` in `src/lib.rs`
+version = "0.5.8"
authors = ["Brian Anderson <andersrb@gmail.com>"]
+rust-version = "1.70.0" # MSRV:3
documentation = "https://docs.rs/home"
edition.workspace = true
include = [
diff --git a/src/tools/cargo/crates/home/src/lib.rs b/src/tools/cargo/crates/home/src/lib.rs
index 0e1e975e4..4aee7383b 100644
--- a/src/tools/cargo/crates/home/src/lib.rs
+++ b/src/tools/cargo/crates/home/src/lib.rs
@@ -18,7 +18,6 @@
//!
//! [discussion]: https://github.com/rust-lang/rust/pull/46799#issuecomment-361156935
-#![doc(html_root_url = "https://docs.rs/home/0.5.6")]
#![deny(rust_2018_idioms)]
pub mod env;
diff --git a/src/tools/cargo/crates/resolver-tests/src/lib.rs b/src/tools/cargo/crates/resolver-tests/src/lib.rs
index 9bdeb8674..e2cbcee62 100644
--- a/src/tools/cargo/crates/resolver-tests/src/lib.rs
+++ b/src/tools/cargo/crates/resolver-tests/src/lib.rs
@@ -12,7 +12,7 @@ use std::task::Poll;
use std::time::Instant;
use cargo::core::dependency::DepKind;
-use cargo::core::resolver::{self, ResolveOpts, VersionPreferences};
+use cargo::core::resolver::{self, ResolveOpts, VersionOrdering, VersionPreferences};
use cargo::core::Resolve;
use cargo::core::{Dependency, PackageId, Registry, Summary};
use cargo::core::{GitReference, SourceId};
@@ -190,15 +190,17 @@ pub fn resolve_with_config_raw(
.unwrap();
let opts = ResolveOpts::everything();
let start = Instant::now();
- let max_rust_version = None;
+ let mut version_prefs = VersionPreferences::default();
+ if config.cli_unstable().minimal_versions {
+ version_prefs.version_ordering(VersionOrdering::MinimumVersionsFirst)
+ }
let resolve = resolver::resolve(
&[(summary, opts)],
&[],
&mut registry,
- &VersionPreferences::default(),
+ &version_prefs,
Some(config),
true,
- max_rust_version,
);
// The largest test in our suite takes less then 30 sec.
@@ -982,14 +984,17 @@ fn meta_test_multiple_versions_strategy() {
/// Assert `xs` contains `elems`
#[track_caller]
-pub fn assert_contains<A: PartialEq>(xs: &[A], elems: &[A]) {
+pub fn assert_contains<A: PartialEq + std::fmt::Debug>(xs: &[A], elems: &[A]) {
for elem in elems {
- assert!(xs.contains(elem));
+ assert!(
+ xs.contains(elem),
+ "missing element\nset: {xs:?}\nmissing: {elem:?}"
+ );
}
}
#[track_caller]
-pub fn assert_same<A: PartialEq>(a: &[A], b: &[A]) {
- assert_eq!(a.len(), b.len());
+pub fn assert_same<A: PartialEq + std::fmt::Debug>(a: &[A], b: &[A]) {
+ assert_eq!(a.len(), b.len(), "not equal\n{a:?}\n{b:?}");
assert_contains(b, a);
}
diff --git a/src/tools/cargo/crates/xtask-bump-check/Cargo.toml b/src/tools/cargo/crates/xtask-bump-check/Cargo.toml
index e878f7dda..c8a472adc 100644
--- a/src/tools/cargo/crates/xtask-bump-check/Cargo.toml
+++ b/src/tools/cargo/crates/xtask-bump-check/Cargo.toml
@@ -11,5 +11,6 @@ cargo.workspace = true
cargo-util.workspace = true
clap.workspace = true
git2.workspace = true
-tracing.workspace = true
+semver.workspace = true
tracing-subscriber.workspace = true
+tracing.workspace = true
diff --git a/src/tools/cargo/crates/xtask-bump-check/src/xtask.rs b/src/tools/cargo/crates/xtask-bump-check/src/xtask.rs
index 4bf3f03d5..b99ac8b32 100644
--- a/src/tools/cargo/crates/xtask-bump-check/src/xtask.rs
+++ b/src/tools/cargo/crates/xtask-bump-check/src/xtask.rs
@@ -22,8 +22,8 @@ use cargo::core::Registry;
use cargo::core::SourceId;
use cargo::core::Workspace;
use cargo::sources::source::QueryKind;
+use cargo::util::cache_lock::CacheLockMode;
use cargo::util::command_prelude::*;
-use cargo::util::ToSemver;
use cargo::CargoResult;
use cargo_util::ProcessBuilder;
@@ -148,26 +148,13 @@ fn bump_check(args: &clap::ArgMatches, config: &cargo::util::Config) -> CargoRes
anyhow::bail!(msg)
}
- // Tracked by https://github.com/obi1kenobi/cargo-semver-checks/issues/511
- let exclude_args = [
- "--exclude",
- "cargo-credential-1password",
- "--exclude",
- "cargo-credential-libsecret",
- "--exclude",
- "cargo-credential-macos-keychain",
- "--exclude",
- "cargo-credential-wincred",
- ];
-
// Even when we test against baseline-rev, we still need to make sure a
// change doesn't violate SemVer rules against crates.io releases. The
// possibility of this happening is nearly zero but no harm to check twice.
let mut cmd = ProcessBuilder::new("cargo");
cmd.arg("semver-checks")
.arg("check-release")
- .arg("--workspace")
- .args(&exclude_args);
+ .arg("--workspace");
config.shell().status("Running", &cmd)?;
cmd.exec()?;
@@ -176,8 +163,7 @@ fn bump_check(args: &clap::ArgMatches, config: &cargo::util::Config) -> CargoRes
cmd.arg("semver-checks")
.arg("--workspace")
.arg("--baseline-rev")
- .arg(referenced_commit.id().to_string())
- .args(&exclude_args);
+ .arg(referenced_commit.id().to_string());
config.shell().status("Running", &cmd)?;
cmd.exec()?;
}
@@ -290,7 +276,7 @@ fn beta_and_stable_branch(repo: &git2::Repository) -> CargoResult<[git2::Branch<
tracing::trace!("branch `{name}` is not in the format of `<remote>/rust-<semver>`");
continue;
};
- let Ok(version) = version.to_semver() else {
+ let Ok(version) = version.parse::<semver::Version>() else {
tracing::trace!("branch `{name}` is not a valid semver: `{version}`");
continue;
};
@@ -361,7 +347,7 @@ fn check_crates_io<'a>(
) -> CargoResult<()> {
let source_id = SourceId::crates_io(config)?;
let mut registry = PackageRegistry::new(config)?;
- let _lock = config.acquire_package_cache_lock()?;
+ let _lock = config.acquire_package_cache_lock(CacheLockMode::DownloadExclusive)?;
registry.lock_patches();
config.shell().status(
STATUS,