Skip to content
Open
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
49 changes: 49 additions & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ anstyle = "1.0.13"
anstyle-hyperlink = "1.0.1"
anstyle-progress = "0.1.0"
anyhow = "1.0.102"
async-trait = "0.1.89"
base64 = "0.22.1"
blake3 = "1.8.3"
build-rs = { version = "0.3.4", path = "crates/build-rs" }
Expand All @@ -49,6 +50,8 @@ curl = "0.4.49"
curl-sys = "=0.4.83"
filetime = "0.2.27"
flate2 = { version = "1.1.9", default-features = false, features = ["zlib-rs"] }
futures = { version = "0.3", default-features = false, features = ["std", "executor"]}
futures-timer = "3.0.3"
git2 = "0.20.4"
git2-curl = "0.21.0"
# When updating this, also see if `gix-transport` further down needs updating or some auth-related tests will fail.
Expand All @@ -60,6 +63,7 @@ heck = "0.5.0"
hex = "0.4.3"
hmac = "0.12.1"
home = "0.5.12"
http = "1.4.0"
http-auth = { version = "0.1.10", default-features = false }
ignore = "0.4.25"
im-rc = "15.1.0"
Expand Down Expand Up @@ -164,6 +168,7 @@ anstyle.workspace = true
anstyle-hyperlink = { workspace = true, features = ["file"] }
anstyle-progress.workspace = true
anyhow.workspace = true
async-trait.workspace = true
base64.workspace = true
blake3.workspace = true
cargo-credential.workspace = true
Expand All @@ -178,6 +183,8 @@ curl = { workspace = true, features = ["http2"] }
curl-sys.workspace = true
filetime.workspace = true
flate2.workspace = true
futures.workspace = true
futures-timer.workspace = true
git2.workspace = true
git2-curl.workspace = true
gix.workspace = true
Expand All @@ -186,6 +193,7 @@ heck.workspace = true
hex.workspace = true
hmac.workspace = true
home.workspace = true
http.workspace = true
http-auth.workspace = true
ignore.workspace = true
im-rc.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions crates/cargo-test-support/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,6 @@ impl HttpServer {
url,
body,
};
println!("req: {:#?}", req);
let response = self.route(&req);
let buf = buf.get_mut();
write!(buf, "HTTP/1.1 {}\r\n", response.code).unwrap();
Expand Down Expand Up @@ -1029,7 +1028,7 @@ impl HttpServer {
Response {
code: 401,
headers: vec![
r#"WWW-Authenticate: Cargo login_url="https://test-registry-login/me""#.to_string(),
r#"www-authenticate: Cargo login_url="https://test-registry-login/me""#.to_string(),
],
body: b"Unauthorized message from server.".to_vec(),
}
Expand Down
24 changes: 10 additions & 14 deletions crates/resolver-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
pub mod helpers;
pub mod sat;

use std::cell::RefCell;
use std::cmp::{max, min};
use std::collections::{BTreeMap, HashSet};
use std::fmt;
use std::task::Poll;
use std::time::Instant;

use cargo::core::Resolve;
Expand Down Expand Up @@ -131,15 +131,15 @@ pub fn resolve_with_global_context_raw(
) -> CargoResult<Resolve> {
struct MyRegistry<'a> {
list: &'a [Summary],
used: HashSet<PackageId>,
used: RefCell<HashSet<PackageId>>,
}
impl<'a> Registry for MyRegistry<'a> {
fn query(
&mut self,
async fn query(
&self,
dep: &Dependency,
kind: QueryKind,
f: &mut dyn FnMut(IndexSummary),
) -> Poll<CargoResult<()>> {
) -> CargoResult<()> {
for summary in self.list.iter() {
let matched = match kind {
QueryKind::Exact => dep.matches(summary),
Expand All @@ -148,11 +148,11 @@ pub fn resolve_with_global_context_raw(
QueryKind::Normalized => true,
};
if matched {
self.used.insert(summary.package_id());
self.used.borrow_mut().insert(summary.package_id());
f(IndexSummary::Candidate(summary.clone()));
}
}
Poll::Ready(Ok(()))
Ok(())
}

fn describe_source(&self, _src: SourceId) -> String {
Expand All @@ -162,22 +162,18 @@ pub fn resolve_with_global_context_raw(
fn is_replaced(&self, _src: SourceId) -> bool {
false
}

fn block_until_ready(&mut self) -> CargoResult<()> {
Ok(())
}
}
impl<'a> Drop for MyRegistry<'a> {
fn drop(&mut self) {
if std::thread::panicking() && self.list.len() != self.used.len() {
if std::thread::panicking() && self.list.len() != self.used.get_mut().len() {
// we found a case that causes a panic and did not use all of the input.
// lets print the part of the input that was used for minimization.
eprintln!(
"Part used before drop: {:?}",
PrettyPrintRegistry(
self.list
.iter()
.filter(|s| { self.used.contains(&s.package_id()) })
.filter(|s| { self.used.get_mut().contains(&s.package_id()) })
.cloned()
.collect()
)
Expand All @@ -187,7 +183,7 @@ pub fn resolve_with_global_context_raw(
}
let mut registry = MyRegistry {
list: registry,
used: HashSet::new(),
used: RefCell::new(HashSet::new()),
};

let root_summary =
Expand Down
1 change: 1 addition & 0 deletions crates/xtask-bump-check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ git2.workspace = true
semver.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
futures.workspace = true

[lints]
workspace = true
13 changes: 3 additions & 10 deletions crates/xtask-bump-check/src/xtask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use std::collections::HashMap;
use std::fmt::Write;
use std::fs;
use std::task;

use cargo::CargoResult;
use cargo::core::Package;
Expand Down Expand Up @@ -433,15 +432,9 @@ fn check_crates_io<'a>(
let current = member.version();
let version_req = format!(">={current}");
let query = Dependency::parse(*name, Some(&version_req), source_id)?;
let possibilities = loop {
// Exact to avoid returning all for path/git
match registry.query_vec(&query, QueryKind::Exact) {
task::Poll::Ready(res) => {
break res?;
}
task::Poll::Pending => registry.block_until_ready()?,
}
};
// Exact to avoid returning all for path/git
let possibilities =
futures::executor::block_on(registry.query_vec(&query, QueryKind::Exact))?;
if possibilities.is_empty() {
tracing::trace!("dep `{name}` has no version greater than or equal to `{current}`");
} else {
Expand Down
45 changes: 22 additions & 23 deletions src/cargo/core/compiler/future_incompat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ use crate::sources::source::QueryKind;
use crate::util::CargoResult;
use crate::util::cache_lock::CacheLockMode;
use anyhow::{Context, bail, format_err};
use futures::StreamExt;
use futures::stream::FuturesUnordered;
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::fmt::Write as _;
use std::io::{Read, Write};
use std::task::Poll;

pub const REPORT_PREAMBLE: &str = "\
The following warnings were discovered during the build. These warnings are an
Expand Down Expand Up @@ -308,15 +309,15 @@ fn get_updates(ws: &Workspace<'_>, package_ids: &BTreeSet<PackageId>) -> Option<
.ok()?;
// Create a set of updated registry sources.
let map = SourceConfigMap::new(ws.gctx()).ok()?;
let mut package_ids: BTreeSet<_> = package_ids
let package_ids: BTreeSet<_> = package_ids
.iter()
.filter(|pkg_id| pkg_id.source_id().is_registry())
.collect();
let source_ids: HashSet<_> = package_ids
.iter()
.map(|pkg_id| pkg_id.source_id())
.collect();
let mut sources: HashMap<_, _> = source_ids
let sources: HashMap<_, _> = source_ids
.into_iter()
.filter_map(|sid| {
let source = map.load(sid, &HashSet::new()).ok()?;
Expand All @@ -325,28 +326,26 @@ fn get_updates(ws: &Workspace<'_>, package_ids: &BTreeSet<PackageId>) -> Option<
.collect();

// Query the sources for new versions, mapping `package_ids` into `summaries`.
let mut summaries = Vec::new();
while !package_ids.is_empty() {
package_ids.retain(|&pkg_id| {
let Some(source) = sources.get_mut(&pkg_id.source_id()) else {
return false;
};
let Ok(dep) = Dependency::parse(pkg_id.name(), None, pkg_id.source_id()) else {
return false;
};
match source.query_vec(&dep, QueryKind::Exact) {
Poll::Ready(Ok(sum)) => {
summaries.push((pkg_id, sum));
false
}
Poll::Ready(Err(_)) => false,
Poll::Pending => true,
let summaries = futures::executor::block_on(async move {
let mut summaries = Vec::new();
let mut pending = FuturesUnordered::new();
for pkg_id in package_ids {
if let Some(source) = sources.get(&pkg_id.source_id())
&& let Ok(dep) = Dependency::parse(pkg_id.name(), None, pkg_id.source_id())
{
pending.push(async move {
let sum = source.query_vec(&dep, QueryKind::Exact).await.ok()?;
Some((pkg_id, sum))
});
}
});
for (_, source) in sources.iter_mut() {
source.block_until_ready().ok()?;
}
}
while let Some(next) = pending.next().await {
if let Some(next) = next {
summaries.push(next);
}
}
Some(summaries)
})?;

let mut updates = String::new();
for (pkg_id, summaries) in summaries {
Expand Down
Loading