Skip to content

Commit

Permalink
update to cargo 0.63/git2 0.14
Browse files Browse the repository at this point in the history
the main change seems to be that registries no longer have an explicit
update() call, but instead return `Poll` on queries with a helper to
block until the Poll is ready.

upstream change for reference:
rust-lang/cargo#10064

Signed-off-by: Fabian Grünbichler <[email protected]>
  • Loading branch information
Fabian-Gruenbichler committed Oct 28, 2022
1 parent 991fc70 commit 908798b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2021"
[dependencies]
ansi_term = "0.12"
anyhow = "1.0"
cargo = "0.57"
cargo = "0.63"
chrono = "0.4"
env_logger = "0.9"
filetime = "0.2"
Expand All @@ -22,7 +22,7 @@ flate2 = "1"
# libgit2 is too old - 1.1.0 vs 1.3.0 needed by newer git2 crates.
#git2 = "= 0.13.21"
#libgit2-sys = "= 0.12.22+1.1.0"
git2 = "0.13.23"
git2 = "0.14"
glob = "0.3"
itertools = "0.10"
log = "0.4"
Expand Down
9 changes: 6 additions & 3 deletions src/bin/debcargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ use structopt::{
StructOpt,
};

use debcargo::build_order::{build_order, BuildOrderArgs};
use debcargo::crates::{update_crates_io, CrateInfo};
use debcargo::crates::CrateInfo;
use debcargo::debian::DebInfo;
use debcargo::errors::Result;
use debcargo::package::*;
use debcargo::{
build_order::{build_order, BuildOrderArgs},
crates::invalidate_crates_io_cache,
};

#[derive(Debug, Clone, StructOpt)]
#[structopt(name = "debcargo", about = "Package Rust crates for Debian.")]
Expand Down Expand Up @@ -54,7 +57,7 @@ fn real_main() -> Result<()> {
.get_matches();
use Opt::*;
match Opt::from_clap(&m) {
Update => update_crates_io(),
Update => invalidate_crates_io_cache(),
DebSrcName {
crate_name,
version,
Expand Down
31 changes: 24 additions & 7 deletions src/crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cargo::{
},
ops,
ops::{PackageOpts, Packages},
sources::registry::RegistrySource,
sources::RegistrySource,
util::{interning::InternedString, toml::read_manifest, FileLock},
Config,
};
Expand Down Expand Up @@ -60,18 +60,25 @@ fn hash<H: Hash>(hashable: &H) -> u64 {
}

fn fetch_candidates(registry: &mut PackageRegistry, dep: &Dependency) -> Result<Vec<Summary>> {
let mut summaries = registry.query_vec(dep, false)?;
let mut summaries = match registry.query_vec(dep, false) {
std::task::Poll::Ready(res) => res?,
std::task::Poll::Pending => {
registry.block_until_ready()?;
return fetch_candidates(registry, dep);
}
};
summaries.sort_by(|a, b| b.package_id().partial_cmp(&a.package_id()).unwrap());
Ok(summaries)
}

pub fn update_crates_io() -> Result<()> {
pub fn invalidate_crates_io_cache() -> Result<()> {
let config = Config::default()?;
let _lock = config.acquire_package_cache_lock()?;
let source_id = SourceId::crates_io(&config)?;
let yanked_whitelist = HashSet::new();
let mut r = RegistrySource::remote(source_id, &yanked_whitelist, &config);
r.update()
let mut r = RegistrySource::remote(source_id, &yanked_whitelist, &config)?;
r.invalidate_cache();
Ok(())
}

pub fn crate_name_ver_to_dep(crate_name: &str, version: Option<&str>) -> Result<Dependency> {
Expand Down Expand Up @@ -112,13 +119,22 @@ impl CrateInfo {
let yanked_whitelist = HashSet::new();

let mut source = source_id.load(&config, &yanked_whitelist)?;
source.update()?;

let package_id = match version {
None | Some("") => {
let dep = Dependency::parse(crate_name, None, source_id)?;
let mut package_id: Option<PackageId> = None;
source.query(&dep, &mut |p| package_id = Some(p.package_id()))?;
loop {
match source.query(&dep, &mut |p| package_id = Some(p.package_id())) {
std::task::Poll::Ready(res) => {
res?;
break;
}
std::task::Poll::Pending => {
source.block_until_ready()?;
}
}
}
package_id.unwrap()
}
Some(version) => PackageId::new(crate_name, version, source_id)?,
Expand Down Expand Up @@ -147,6 +163,7 @@ impl CrateInfo {
jobs: None,
targets: Vec::new(),
to_package: Packages::Default,
keep_going: false,
};

// as of cargo 0.41 this returns a FileLock with a temp path, instead of the one
Expand Down

0 comments on commit 908798b

Please sign in to comment.