Skip to content

Deduplicate entries in the archive of stable standalone installers #770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
24 changes: 21 additions & 3 deletions blacksmith/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ impl Blacksmith {

let latest_stable_version = &blacksmith.stable_version.clone().unwrap();

// We need to use a map to deduplicate entries and sort them in the correct order.
// There are multiple entries for stable 1.8.0, 1.14.0, 1.15.1, 1.49.0 in MANIFESTS_URL.
// Keys contain (minor_version, patch_version) and values contain (full_version, platforms).
let mut previous_stable_version_map: BTreeMap<(u32, u32), (String, Vec<String>)> =
BTreeMap::new();

// Go over stable versions in https://static.rust-lang.org/manifests.txt in reverse order.
let manifests_content = reqwest::blocking::get(MANIFESTS_URL)?.text()?;
let stable_manifest_url_regex = regex::Regex::new(
Expand All @@ -140,14 +146,19 @@ impl Blacksmith {

// Check if it's a stable version.
if let Some(captures) = stable_manifest_url_regex.captures(&(manifest_url)) {
minor = captures.get(1).unwrap().as_str();
patch = captures.get(2).unwrap().as_str();
minor = captures.get(1).unwrap().as_str().parse::<u32>().unwrap();
patch = captures.get(2).unwrap().as_str().parse::<u32>().unwrap();
} else {
continue;
}

let full_version = format!("1.{}.{}", minor, patch);

// Check if we already processed that version.
if previous_stable_version_map.contains_key(&(minor, patch)) {
continue;
}

// Skip latest stable version.
if &full_version == latest_stable_version {
continue;
Expand All @@ -169,6 +180,9 @@ impl Blacksmith {

let version = rust.version.split(' ').next().unwrap().to_string();

// Sanity check.
assert_eq!(&full_version, &version);

let platforms = rust
.target
.into_iter()
Expand All @@ -181,9 +195,13 @@ impl Blacksmith {
})
.collect::<Vec<_>>();

previous_stable_version_map.insert((minor, patch), (version, platforms));
}

for (_, (version, platforms)) in previous_stable_version_map.into_iter().rev() {
blacksmith
.previous_stable_versions
.push((version.clone(), platforms));
.push((version, platforms));
}

blacksmith.last_update = unix_time();
Expand Down
Loading