Skip to content

Commit d70bcb0

Browse files
committed
Allow rustup to handle unavailable packages
Before this, if a package was unavailable (like nightly is at the moment), it would error out with a message like "error: missing key: 'url'" because at the moment a few of the rust-analysis packages didn't build. This resulted in the `channel-rust-nightly.toml` to be created with blocks like this: ```toml [pkg.rust-analysis.target.aarch64-apple-ios] available = false [pkg.rust-analysis.target.aarch64-linux-android] available = false [pkg.rust-analysis.target.aarch64-unknown-fuchsia] available = false [pkg.rust-analysis.target.aarch64-unknown-linux-gnu] available = true hash = "be50ffa6f94770929b53bae553977cb6d78b03506f033d14a7251c7b0cdb9035" url = "https://static.rust-lang.org/dist/2017-04-13/rust-analysis-nightly-aarch64-unknown-linux-gnu.tar.gz" ``` rustup assumed that there'd always be a `hash` and `url`, which is not the case when packages are unavaible. This patch then just updates rustup to handle their absence.
1 parent 270aaa5 commit d70bcb0

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

src/rustup-dist/src/manifest.rs

+37-15
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ pub enum PackageTargets {
4141

4242
#[derive(Clone, Debug, PartialEq)]
4343
pub struct TargetedPackage {
44-
pub available: bool,
45-
pub url: String,
46-
pub hash: String,
44+
pub url_and_hash: Option<UrlAndHash>,
4745
pub components: Vec<Component>,
4846
pub extensions: Vec<Component>,
4947
}
5048

49+
#[derive(Clone, Debug, PartialEq)]
50+
pub struct UrlAndHash {
51+
pub url: String,
52+
pub hash: String,
53+
}
54+
5155
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
5256
pub struct Component {
5357
pub pkg: String,
@@ -226,15 +230,25 @@ impl TargetedPackage {
226230
pub fn from_toml(mut table: toml::Table, path: &str) -> Result<Self> {
227231
let components = try!(get_array(&mut table, "components", path));
228232
let extensions = try!(get_array(&mut table, "extensions", path));
229-
Ok(TargetedPackage {
230-
available: try!(get_bool(&mut table, "available", path)),
231-
url: try!(get_string(&mut table, "url", path)),
232-
hash: try!(get_string(&mut table, "hash", path)),
233-
components: try!(Self::toml_to_components(components,
234-
&format!("{}{}.", path, "components"))),
235-
extensions: try!(Self::toml_to_components(extensions,
236-
&format!("{}{}.", path, "extensions"))),
237-
})
233+
234+
if try!(get_bool(&mut table, "available", path)) {
235+
Ok(TargetedPackage {
236+
url_and_hash: Some(UrlAndHash {
237+
url: try!(get_string(&mut table, "url", path)),
238+
hash: try!(get_string(&mut table, "hash", path)),
239+
}),
240+
components: try!(Self::toml_to_components(components,
241+
&format!("{}{}.", path, "components"))),
242+
extensions: try!(Self::toml_to_components(extensions,
243+
&format!("{}{}.", path, "extensions"))),
244+
})
245+
} else {
246+
Ok(TargetedPackage {
247+
url_and_hash: None,
248+
components: vec![],
249+
extensions: vec![],
250+
})
251+
}
238252
}
239253
pub fn to_toml(self) -> toml::Table {
240254
let extensions = Self::components_to_toml(self.extensions);
@@ -246,12 +260,20 @@ impl TargetedPackage {
246260
if !components.is_empty() {
247261
result.insert("components".to_owned(), toml::Value::Array(components));
248262
}
249-
result.insert("hash".to_owned(), toml::Value::String(self.hash));
250-
result.insert("url".to_owned(), toml::Value::String(self.url));
251-
result.insert("available".to_owned(), toml::Value::Boolean(self.available));
263+
if let Some(UrlAndHash { url, hash }) = self.url_and_hash {
264+
result.insert("hash".to_owned(), toml::Value::String(hash));
265+
result.insert("url".to_owned(), toml::Value::String(url));
266+
result.insert("available".to_owned(), toml::Value::Boolean(true));
267+
} else {
268+
result.insert("available".to_owned(), toml::Value::Boolean(false));
269+
}
252270
result
253271
}
254272

273+
pub fn available(&self) -> bool {
274+
self.url_and_hash.is_some()
275+
}
276+
255277
fn toml_to_components(arr: toml::Array, path: &str) -> Result<Vec<Component>> {
256278
let mut result = Vec::new();
257279

src/rustup-dist/src/manifestation.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! platform components from a distribution server.
33
44
use config::Config;
5-
use manifest::{Component, Manifest, TargetedPackage};
5+
use manifest::{Component, Manifest, TargetedPackage, UrlAndHash};
66
use dist::{download_and_check, DownloadCfg, TargetTriple, DEFAULT_DIST_SERVER, File};
77
use component::{Components, Transaction, TarGzPackage, Package};
88
use temp;
@@ -106,7 +106,7 @@ impl Manifestation {
106106
use manifest::*;
107107
let pkg: Option<&Package> = new_manifest.get_package(&c.pkg).ok();
108108
let target_pkg: Option<&TargetedPackage> = pkg.and_then(|p| p.get_target(c.target.as_ref()).ok());
109-
target_pkg.map(|tp| tp.available) != Some(true)
109+
target_pkg.map(|tp| tp.available()) != Some(true)
110110
}).cloned().collect();
111111

112112
if !unavailable_components.is_empty() {
@@ -118,8 +118,11 @@ impl Manifestation {
118118
for component in components_to_install {
119119
let package = try!(new_manifest.get_package(&component.pkg));
120120
let target_package = try!(package.get_target(component.target.as_ref()));
121-
let c_u_h = (component, target_package.url.clone(), target_package.hash.clone());
122-
components_urls_and_hashes.push(c_u_h);
121+
122+
if let Some(UrlAndHash { ref url, ref hash }) = target_package.url_and_hash {
123+
let c_u_h = (component, url.clone(), hash.clone());
124+
components_urls_and_hashes.push(c_u_h);
125+
}
123126
}
124127

125128
let altered = temp_cfg.dist_server != DEFAULT_DIST_SERVER;

src/rustup/toolchain.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ impl<'a> Toolchain<'a> {
474474
component: component.clone(),
475475
required: true,
476476
installed: installed,
477-
available: component_target_pkg.available,
477+
available: component_target_pkg.available(),
478478
});
479479
}
480480

@@ -493,7 +493,7 @@ impl<'a> Toolchain<'a> {
493493
component: extension.clone(),
494494
required: false,
495495
installed: installed,
496-
available: extension_target_pkg.available,
496+
available: extension_target_pkg.available(),
497497
});
498498
}
499499

tests/cli-v2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ fn make_component_unavailable(config: &Config, name: &str, target: &TargetTriple
667667
{
668668
let mut std_pkg = manifest.packages.get_mut(name).unwrap();
669669
let mut target_pkg = std_pkg.targets.get_mut(target).unwrap();
670-
target_pkg.available = false;
670+
target_pkg.url_and_hash = None;
671671
}
672672
let ref manifest_str = manifest.stringify();
673673
rustup_utils::raw::write_file(manifest_path, manifest_str).unwrap();

0 commit comments

Comments
 (0)