generated from EmbarkStudios/opensource-template
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update deps * Update deny * Update CHANGELOG * Add features lockfile to prevent test failures * Only fetch crates for target * Add support for sparse crates.io index * Remove commented out line * Fix test * Update CHANGELOG * Split test * Only need this for --all-features
- Loading branch information
1 parent
6aa02ee
commit 7fda552
Showing
7 changed files
with
1,428 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
pub(super) struct ComboIndex { | ||
git: Option<crates_index::Index>, | ||
http: Option<crates_index::SparseIndex>, | ||
} | ||
|
||
impl ComboIndex { | ||
#[inline] | ||
fn krate(&self, name: &str) -> Option<crates_index::Crate> { | ||
// Attempt http first, as this will be the default in future cargo versions | ||
// and using it when it is not the defaul indicates the user has opted in | ||
self.http | ||
.as_ref() | ||
.and_then(|h| h.crate_from_cache(name).ok()) | ||
.or_else(|| self.git.as_ref().and_then(|g| g.crate_(name))) | ||
} | ||
} | ||
|
||
#[inline] | ||
pub(super) fn open() -> ComboIndex { | ||
ComboIndex { | ||
git: crates_index::Index::new_cargo_default().ok(), | ||
http: crates_index::SparseIndex::from_url("sparse+https://index.crates.io/").ok(), | ||
} | ||
} | ||
|
||
/// Due to <https://github.com/rust-lang/cargo/issues/11319>, we can't actually | ||
/// trust cargo to give us the correct package metadata, so we instead use the | ||
/// (presumably) correct data from the the index | ||
pub(super) fn fix_features(index: &ComboIndex, krate: &mut cargo_metadata::Package) { | ||
if krate | ||
.source | ||
.as_ref() | ||
.map_or(true, |src| !src.is_crates_io()) | ||
{ | ||
return; | ||
} | ||
|
||
if let Some(entry) = index.krate(&krate.name) { | ||
let features = entry.versions().iter().find_map(|v| { | ||
if let Ok(iv) = v.version().parse::<semver::Version>() { | ||
if iv == krate.version { | ||
Some(v.features()) | ||
} else { | ||
None | ||
} | ||
} else { | ||
None | ||
} | ||
}); | ||
|
||
if let Some(features) = features { | ||
for (ikey, ivalue) in features { | ||
if !krate.features.contains_key(ikey) { | ||
krate.features.insert(ikey.clone(), ivalue.clone()); | ||
} | ||
} | ||
|
||
// The index entry features might not have the `dep:<crate>` | ||
// used with weak features if the crate version was | ||
// published with cargo <1.60.0 version, so we need to | ||
// manually fix that up since we depend on that format | ||
let missing_deps: Vec<_> = krate | ||
.features | ||
.iter() | ||
.flat_map(|(_, sf)| sf.iter()) | ||
.filter_map(|sf| { | ||
let pf = crate::ParsedFeature::from(sf.as_str()); | ||
|
||
if let super::features::Feature::Simple(simple) = pf.feat() { | ||
if krate.features.contains_key(simple) { | ||
None | ||
} else { | ||
Some(simple.to_owned()) | ||
} | ||
} else { | ||
None | ||
} | ||
}) | ||
.collect(); | ||
|
||
for missing in missing_deps { | ||
let dep_feature = format!("dep:{missing}"); | ||
krate.features.insert(missing, vec![dep_feature]); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.