diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-24 17:38:22 -0500 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-24 17:38:22 -0500 |
| commit | 6891388e661c2bbf965a330ff73bf8c08a7dbf7d (patch) | |
| tree | ff2f518c1dfdb558a162c73b3ee3f2a0b44d5adc /src/tools | |
| parent | 48291a9dda821a81957b44034572c0ec62728f35 (diff) | |
| download | rust-6891388e661c2bbf965a330ff73bf8c08a7dbf7d.tar.gz rust-6891388e661c2bbf965a330ff73bf8c08a7dbf7d.zip | |
x.py fmt after previous deignore
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/build-manifest/src/main.rs | 270 |
1 files changed, 160 insertions, 110 deletions
diff --git a/src/tools/build-manifest/src/main.rs b/src/tools/build-manifest/src/main.rs index 7e76604355d..481163a1a9a 100644 --- a/src/tools/build-manifest/src/main.rs +++ b/src/tools/build-manifest/src/main.rs @@ -6,16 +6,16 @@ #![deny(warnings)] -use toml; use serde::Serialize; +use toml; use std::collections::BTreeMap; +use std::collections::HashMap; use std::env; use std::fs::{self, File}; use std::io::{self, Read, Write}; -use std::path::{PathBuf, Path}; +use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; -use std::collections::HashMap; static HOSTS: &[&str] = &[ "aarch64-unknown-linux-gnu", @@ -154,10 +154,7 @@ static DOCS_TARGETS: &[&str] = &[ "x86_64-unknown-linux-gnu", ]; -static MINGW: &[&str] = &[ - "i686-pc-windows-gnu", - "x86_64-pc-windows-gnu", -]; +static MINGW: &[&str] = &["i686-pc-windows-gnu", "x86_64-pc-windows-gnu"]; #[derive(Serialize)] #[serde(rename_all = "kebab-case")] @@ -193,7 +190,9 @@ struct Target { } impl Target { - fn unavailable() -> Self { Self::default() } + fn unavailable() -> Self { + Self::default() + } } #[derive(Serialize)] @@ -209,10 +208,12 @@ impl Component { } macro_rules! t { - ($e:expr) => (match $e { - Ok(e) => e, - Err(e) => panic!("{} failed with {}", stringify!($e), e), - }) + ($e:expr) => { + match $e { + Ok(e) => e, + Err(e) => panic!("{} failed with {}", stringify!($e), e), + } + }; } struct Builder { @@ -323,10 +324,21 @@ fn main() { miri_git_commit_hash: None, should_sign, - }.build(); + } + .build(); } -enum PkgType { RustSrc, Cargo, Rls, Clippy, Rustfmt, LlvmTools, Lldb, Miri, Other } +enum PkgType { + RustSrc, + Cargo, + Rls, + Clippy, + Rustfmt, + LlvmTools, + Lldb, + Miri, + Other, +} impl PkgType { fn from_component(component: &str) -> Self { @@ -362,8 +374,8 @@ impl Builder { self.rls_git_commit_hash = self.git_commit_hash("rls", "x86_64-unknown-linux-gnu"); self.clippy_git_commit_hash = self.git_commit_hash("clippy", "x86_64-unknown-linux-gnu"); self.rustfmt_git_commit_hash = self.git_commit_hash("rustfmt", "x86_64-unknown-linux-gnu"); - self.llvm_tools_git_commit_hash = self.git_commit_hash("llvm-tools", - "x86_64-unknown-linux-gnu"); + self.llvm_tools_git_commit_hash = + self.git_commit_hash("llvm-tools", "x86_64-unknown-linux-gnu"); self.lldb_git_commit_hash = self.git_commit_hash("lldb", "x86_64-unknown-linux-gnu"); self.miri_git_commit_hash = self.git_commit_hash("miri", "x86_64-unknown-linux-gnu"); @@ -381,11 +393,14 @@ impl Builder { /// Right now, we do this only for Miri. fn check_toolstate(&mut self) { let toolstates: Option<HashMap<String, String>> = - File::open(self.input.join("toolstates-linux.json")).ok() + File::open(self.input.join("toolstates-linux.json")) + .ok() .and_then(|f| serde_json::from_reader(&f).ok()); let toolstates = toolstates.unwrap_or_else(|| { - println!("WARNING: `toolstates-linux.json` missing/malformed; \ - assuming all tools failed"); + println!( + "WARNING: `toolstates-linux.json` missing/malformed; \ + assuming all tools failed" + ); HashMap::default() // Use empty map if anything went wrong. }); // Mark some tools as missing based on toolstate. @@ -442,16 +457,36 @@ impl Builder { fn add_profiles_to(&mut self, manifest: &mut Manifest) { let mut profile = |name, pkgs| self.profile(name, &mut manifest.profiles, pkgs); profile("minimal", &["rustc", "cargo", "rust-std", "rust-mingw"]); - profile("default", &[ - "rustc", "cargo", "rust-std", "rust-mingw", - "rust-docs", "rustfmt-preview", "clippy-preview" - ]); - profile("complete", &[ - "rustc", "cargo", "rust-std", "rust-mingw", - "rust-docs", "rustfmt-preview", "clippy-preview", - "rls-preview", "rust-src", "llvm-tools-preview", - "lldb-preview", "rust-analysis", "miri-preview" - ]); + profile( + "default", + &[ + "rustc", + "cargo", + "rust-std", + "rust-mingw", + "rust-docs", + "rustfmt-preview", + "clippy-preview", + ], + ); + profile( + "complete", + &[ + "rustc", + "cargo", + "rust-std", + "rust-mingw", + "rust-docs", + "rustfmt-preview", + "clippy-preview", + "rls-preview", + "rust-src", + "llvm-tools-preview", + "lldb-preview", + "rust-analysis", + "miri-preview", + ], + ); // The compiler libraries are not stable for end users, and they're also huge, so we only // `rustc-dev` for nightly users, and only in the "complete" profile. It's still possible @@ -462,10 +497,9 @@ impl Builder { } fn add_renames_to(&self, manifest: &mut Manifest) { - let mut rename = |from: &str, to: &str| manifest.renames.insert( - from.to_owned(), - Rename { to: to.to_owned() } - ); + let mut rename = |from: &str, to: &str| { + manifest.renames.insert(from.to_owned(), Rename { to: to.to_owned() }) + }; rename("rls", "rls-preview"); rename("rustfmt", "rustfmt-preview"); rename("clippy", "clippy-preview"); @@ -474,10 +508,11 @@ impl Builder { fn rust_package(&mut self, manifest: &Manifest) -> Package { let mut pkg = Package { - version: self.cached_version("rust") - .as_ref() - .expect("Couldn't find Rust version") - .clone(), + version: self + .cached_version("rust") + .as_ref() + .expect("Couldn't find Rust version") + .clone(), git_commit_hash: self.cached_git_commit_hash("rust").clone(), target: BTreeMap::new(), }; @@ -486,7 +521,7 @@ impl Builder { pkg.target.insert(host.to_string(), target); } else { pkg.target.insert(host.to_string(), Target::unavailable()); - continue + continue; } } pkg @@ -527,14 +562,12 @@ impl Builder { ]); extensions.extend( - TARGETS.iter() + TARGETS + .iter() .filter(|&&target| target != host) - .map(|target| Component::from_str("rust-std", target)) - ); - extensions.extend( - HOSTS.iter() - .map(|target| Component::from_str("rustc-dev", target)) + .map(|target| Component::from_str("rust-std", target)), ); + extensions.extend(HOSTS.iter().map(|target| Component::from_str("rustc-dev", target))); extensions.push(Component::from_str("rust-src", "*")); // If the components/extensions don't actually exist for this @@ -542,7 +575,7 @@ impl Builder { // lists. let has_component = |c: &Component| { if c.target == "*" { - return true + return true; } let pkg = match manifest.pkg.get(&c.pkg) { Some(p) => p, @@ -564,26 +597,29 @@ impl Builder { }) } - fn profile(&mut self, - profile_name: &str, - dst: &mut BTreeMap<String, Vec<String>>, - pkgs: &[&str]) { + fn profile( + &mut self, + profile_name: &str, + dst: &mut BTreeMap<String, Vec<String>>, + pkgs: &[&str], + ) { dst.insert(profile_name.to_owned(), pkgs.iter().map(|s| (*s).to_owned()).collect()); } - fn extend_profile(&mut self, - profile_name: &str, - dst: &mut BTreeMap<String, Vec<String>>, - pkgs: &[&str]) { - dst.get_mut(profile_name).expect("existing profile") + fn extend_profile( + &mut self, + profile_name: &str, + dst: &mut BTreeMap<String, Vec<String>>, + pkgs: &[&str], + ) { + dst.get_mut(profile_name) + .expect("existing profile") .extend(pkgs.iter().map(|s| (*s).to_owned())); } - fn package(&mut self, - pkgname: &str, - dst: &mut BTreeMap<String, Package>, - targets: &[&str]) { - let (version, mut is_present) = self.cached_version(pkgname) + fn package(&mut self, pkgname: &str, dst: &mut BTreeMap<String, Package>, targets: &[&str]) { + let (version, mut is_present) = self + .cached_version(pkgname) .as_ref() .cloned() .map(|version| (version, true)) @@ -594,46 +630,52 @@ impl Builder { is_present = false; // Pretend the component is entirely missing. } - let targets = targets.iter().map(|name| { - if is_present { - // The component generally exists, but it might still be missing for this target. - let filename = self.filename(pkgname, name); - let digest = match self.digests.remove(&filename) { - Some(digest) => digest, - // This component does not exist for this target -- skip it. - None => return (name.to_string(), Target::unavailable()), - }; - let xz_filename = filename.replace(".tar.gz", ".tar.xz"); - let xz_digest = self.digests.remove(&xz_filename); - - (name.to_string(), Target { - available: true, - url: Some(self.url(&filename)), - hash: Some(digest), - xz_url: xz_digest.as_ref().map(|_| self.url(&xz_filename)), - xz_hash: xz_digest, - components: None, - extensions: None, - }) - } else { - // If the component is not present for this build add it anyway but mark it as - // unavailable -- this way rustup won't allow upgrades without --force - (name.to_string(), Target::unavailable()) - } - }).collect(); - - dst.insert(pkgname.to_string(), Package { - version, - git_commit_hash: self.cached_git_commit_hash(pkgname).clone(), - target: targets, - }); + let targets = targets + .iter() + .map(|name| { + if is_present { + // The component generally exists, but it might still be missing for this target. + let filename = self.filename(pkgname, name); + let digest = match self.digests.remove(&filename) { + Some(digest) => digest, + // This component does not exist for this target -- skip it. + None => return (name.to_string(), Target::unavailable()), + }; + let xz_filename = filename.replace(".tar.gz", ".tar.xz"); + let xz_digest = self.digests.remove(&xz_filename); + + ( + name.to_string(), + Target { + available: true, + url: Some(self.url(&filename)), + hash: Some(digest), + xz_url: xz_digest.as_ref().map(|_| self.url(&xz_filename)), + xz_hash: xz_digest, + components: None, + extensions: None, + }, + ) + } else { + // If the component is not present for this build add it anyway but mark it as + // unavailable -- this way rustup won't allow upgrades without --force + (name.to_string(), Target::unavailable()) + } + }) + .collect(); + + dst.insert( + pkgname.to_string(), + Package { + version, + git_commit_hash: self.cached_git_commit_hash(pkgname).clone(), + target: targets, + }, + ); } fn url(&self, filename: &str) -> String { - format!("{}/{}/{}", - self.s3_address, - self.date, - filename) + format!("{}/{}/{}", self.s3_address, self.date, filename) } fn filename(&self, component: &str, target: &str) -> String { @@ -689,14 +731,14 @@ impl Builder { fn untar<F>(&self, component: &str, target: &str, dir: F) -> Option<String> where - F: FnOnce(String) -> String + F: FnOnce(String) -> String, { let mut cmd = Command::new("tar"); let filename = self.filename(component, target); cmd.arg("xf") - .arg(self.input.join(&filename)) - .arg(dir(filename.replace(".tar.gz", ""))) - .arg("-O"); + .arg(self.input.join(&filename)) + .arg(dir(filename.replace(".tar.gz", ""))) + .arg("-O"); let output = t!(cmd.output()); if output.status.success() { Some(String::from_utf8_lossy(&output.stdout).trim().to_string()) @@ -707,10 +749,11 @@ impl Builder { fn hash(&self, path: &Path) -> String { let sha = t!(Command::new("shasum") - .arg("-a").arg("256") - .arg(path.file_name().unwrap()) - .current_dir(path.parent().unwrap()) - .output()); + .arg("-a") + .arg("256") + .arg(path.file_name().unwrap()) + .current_dir(path.parent().unwrap()) + .output()); assert!(sha.status.success()); let filename = path.file_name().unwrap().to_str().unwrap(); @@ -734,11 +777,15 @@ impl Builder { .arg("--no-tty") .arg("--yes") .arg("--batch") - .arg("--passphrase-fd").arg("0") - .arg("--personal-digest-preferences").arg("SHA512") + .arg("--passphrase-fd") + .arg("0") + .arg("--personal-digest-preferences") + .arg("SHA512") .arg("--armor") - .arg("--output").arg(&asc) - .arg("--detach-sign").arg(path) + .arg("--output") + .arg(&asc) + .arg("--detach-sign") + .arg(path) .stdin(Stdio::piped()); let mut child = t!(cmd.spawn()); t!(child.stdin.take().unwrap().write_all(self.gpg_passphrase.as_bytes())); @@ -748,8 +795,11 @@ impl Builder { fn write_channel_files(&self, channel_name: &str, manifest: &Manifest) { self.write(&toml::to_string(&manifest).unwrap(), channel_name, ".toml"); self.write(&manifest.date, channel_name, "-date.txt"); - self.write(manifest.pkg["rust"].git_commit_hash.as_ref().unwrap(), - channel_name, "-git-commit-hash.txt"); + self.write( + manifest.pkg["rust"].git_commit_hash.as_ref().unwrap(), + channel_name, + "-git-commit-hash.txt", + ); } fn write(&self, contents: &str, channel_name: &str, suffix: &str) { |
