Skip to content

Commit 60d2410

Browse files
committed
Auto merge of #1063 - erickt:url-and-hash, r=brson
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. Closes #1063
2 parents 2d8e6c0 + ea39fe0 commit 60d2410

File tree

5 files changed

+56
-28
lines changed

5 files changed

+56
-28
lines changed

src/rustup-dist/src/manifest.rs

+43-17
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,
44+
pub bins: Option<PackageBins>,
45+
pub components: Vec<Component>,
46+
pub extensions: Vec<Component>,
47+
}
48+
49+
#[derive(Clone, Debug, PartialEq)]
50+
pub struct PackageBins {
4551
pub url: String,
4652
pub hash: String,
4753
pub xz_url: Option<String>,
4854
pub xz_hash: Option<String>,
49-
pub components: Vec<Component>,
50-
pub extensions: Vec<Component>,
5155
}
5256

5357
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
@@ -232,17 +236,27 @@ impl TargetedPackage {
232236
pub fn from_toml(mut table: toml::Table, path: &str) -> Result<Self> {
233237
let components = try!(get_array(&mut table, "components", path));
234238
let extensions = try!(get_array(&mut table, "extensions", path));
235-
Ok(TargetedPackage {
236-
available: try!(get_bool(&mut table, "available", path)),
237-
url: try!(get_string(&mut table, "url", path)),
238-
hash: try!(get_string(&mut table, "hash", path)),
239-
xz_url: get_string(&mut table, "xz_url", path).ok(),
240-
xz_hash: get_string(&mut table, "xz_hash", path).ok(),
241-
components: try!(Self::toml_to_components(components,
242-
&format!("{}{}.", path, "components"))),
243-
extensions: try!(Self::toml_to_components(extensions,
244-
&format!("{}{}.", path, "extensions"))),
245-
})
239+
240+
if try!(get_bool(&mut table, "available", path)) {
241+
Ok(TargetedPackage {
242+
bins: Some(PackageBins {
243+
url: try!(get_string(&mut table, "url", path)),
244+
hash: try!(get_string(&mut table, "hash", path)),
245+
xz_url: get_string(&mut table, "xz_url", path).ok(),
246+
xz_hash: get_string(&mut table, "xz_hash", path).ok(),
247+
}),
248+
components: try!(Self::toml_to_components(components,
249+
&format!("{}{}.", path, "components"))),
250+
extensions: try!(Self::toml_to_components(extensions,
251+
&format!("{}{}.", path, "extensions"))),
252+
})
253+
} else {
254+
Ok(TargetedPackage {
255+
bins: None,
256+
components: vec![],
257+
extensions: vec![],
258+
})
259+
}
246260
}
247261
pub fn to_toml(self) -> toml::Table {
248262
let extensions = Self::components_to_toml(self.extensions);
@@ -254,12 +268,24 @@ impl TargetedPackage {
254268
if !components.is_empty() {
255269
result.insert("components".to_owned(), toml::Value::Array(components));
256270
}
257-
result.insert("hash".to_owned(), toml::Value::String(self.hash));
258-
result.insert("url".to_owned(), toml::Value::String(self.url));
259-
result.insert("available".to_owned(), toml::Value::Boolean(self.available));
271+
if let Some(bins) = self.bins.clone() {
272+
result.insert("hash".to_owned(), toml::Value::String(bins.hash));
273+
result.insert("url".to_owned(), toml::Value::String(bins.url));
274+
if let (Some(xz_hash), Some(xz_url)) = (bins.xz_hash, bins.xz_url) {
275+
result.insert("xz_hash".to_owned(), toml::Value::String(xz_hash));
276+
result.insert("xz_url".to_owned(), toml::Value::String(xz_url));
277+
}
278+
result.insert("available".to_owned(), toml::Value::Boolean(true));
279+
} else {
280+
result.insert("available".to_owned(), toml::Value::Boolean(false));
281+
}
260282
result
261283
}
262284

285+
pub fn available(&self) -> bool {
286+
self.bins.is_some()
287+
}
288+
263289
fn toml_to_components(arr: toml::Array, path: &str) -> Result<Vec<Component>> {
264290
let mut result = Vec::new();
265291

src/rustup-dist/src/manifestation.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Manifestation {
112112
use manifest::*;
113113
let pkg: Option<&Package> = new_manifest.get_package(&c.pkg).ok();
114114
let target_pkg: Option<&TargetedPackage> = pkg.and_then(|p| p.get_target(c.target.as_ref()).ok());
115-
target_pkg.map(|tp| tp.available) != Some(true)
115+
target_pkg.map(|tp| tp.available()) != Some(true)
116116
}).cloned().collect();
117117

118118
if !unavailable_components.is_empty() {
@@ -124,12 +124,14 @@ impl Manifestation {
124124
for component in components_to_install {
125125
let package = try!(new_manifest.get_package(&component.pkg));
126126
let target_package = try!(package.get_target(component.target.as_ref()));
127+
128+
let bins = target_package.bins.as_ref().expect("components available");
127129
let c_u_h =
128-
if let (Some(url), Some(hash)) = (target_package.xz_url.clone(),
129-
target_package.xz_hash.clone()) {
130+
if let (Some(url), Some(hash)) = (bins.xz_url.clone(),
131+
bins.xz_hash.clone()) {
130132
(component, Format::Xz, url, hash)
131133
} else {
132-
(component, Format::Gz, target_package.url.clone(), target_package.hash.clone())
134+
(component, Format::Gz, bins.url.clone(), bins.hash.clone())
133135
};
134136
components_urls_and_hashes.push(c_u_h);
135137
}

src/rustup-dist/tests/manifest.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ fn parse_smoke_test() {
2626
assert!(rust_pkg.version.contains("1.3.0"));
2727

2828
let rust_target_pkg = rust_pkg.get_target(Some(&x86_64_unknown_linux_gnu)).unwrap();
29-
assert_eq!(rust_target_pkg.available, true);
30-
assert_eq!(rust_target_pkg.url, "example.com");
31-
assert_eq!(rust_target_pkg.hash, "...");
29+
assert_eq!(rust_target_pkg.available(), true);
30+
assert_eq!(rust_target_pkg.bins.clone().unwrap().url, "example.com");
31+
assert_eq!(rust_target_pkg.bins.clone().unwrap().hash, "...");
3232

3333
let ref component = rust_target_pkg.components[0];
3434
assert_eq!(component.pkg, "rustc");
@@ -40,7 +40,7 @@ fn parse_smoke_test() {
4040

4141
let docs_pkg = pkg.get_package("rust-docs").unwrap();
4242
let docs_target_pkg = docs_pkg.get_target(Some(&x86_64_unknown_linux_gnu)).unwrap();
43-
assert_eq!(docs_target_pkg.url, "example.com");
43+
assert_eq!(docs_target_pkg.bins.clone().unwrap().url, "example.com");
4444
}
4545

4646
#[test]

src/rustup/toolchain.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ impl<'a> Toolchain<'a> {
491491
component: component.clone(),
492492
required: true,
493493
installed: installed,
494-
available: component_target_pkg.available,
494+
available: component_target_pkg.available(),
495495
});
496496
}
497497

@@ -510,7 +510,7 @@ impl<'a> Toolchain<'a> {
510510
component: extension.clone(),
511511
required: false,
512512
installed: installed,
513-
available: extension_target_pkg.available,
513+
available: extension_target_pkg.available(),
514514
});
515515
}
516516

tests/cli-v2.rs

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

0 commit comments

Comments
 (0)