|
4 | 4 | //! via `x.py dist hash-and-sign`; the cmdline arguments are set up
|
5 | 5 | //! by rustbuild (in `src/bootstrap/dist.rs`).
|
6 | 6 |
|
| 7 | +mod checksum; |
7 | 8 | mod manifest;
|
8 | 9 | mod versions;
|
9 | 10 |
|
10 |
| -use crate::manifest::{Component, FileHash, Manifest, Package, Rename, Target}; |
| 11 | +use crate::checksum::Checksums; |
| 12 | +use crate::manifest::{Component, Manifest, Package, Rename, Target}; |
11 | 13 | use crate::versions::{PkgType, Versions};
|
12 |
| -use rayon::prelude::*; |
13 |
| -use sha2::Digest; |
14 | 14 | use std::collections::{BTreeMap, HashMap, HashSet};
|
15 | 15 | use std::env;
|
16 |
| -use std::error::Error; |
17 | 16 | use std::fs::{self, File};
|
18 |
| -use std::io::{self, BufReader, Read, Write}; |
| 17 | +use std::io::{self, Read, Write}; |
19 | 18 | use std::path::{Path, PathBuf};
|
20 | 19 | use std::process::{Command, Stdio};
|
21 |
| -use std::sync::Mutex; |
22 |
| -use std::time::Instant; |
23 | 20 |
|
24 | 21 | static HOSTS: &[&str] = &[
|
25 | 22 | "aarch64-apple-darwin",
|
@@ -186,6 +183,7 @@ macro_rules! t {
|
186 | 183 |
|
187 | 184 | struct Builder {
|
188 | 185 | versions: Versions,
|
| 186 | + checksums: Checksums, |
189 | 187 | shipped_files: HashSet<String>,
|
190 | 188 |
|
191 | 189 | input: PathBuf,
|
@@ -240,6 +238,7 @@ fn main() {
|
240 | 238 |
|
241 | 239 | Builder {
|
242 | 240 | versions: Versions::new(&channel, &input).unwrap(),
|
| 241 | + checksums: t!(Checksums::new()), |
243 | 242 | shipped_files: HashSet::new(),
|
244 | 243 |
|
245 | 244 | input,
|
@@ -276,6 +275,8 @@ impl Builder {
|
276 | 275 | if let Some(path) = std::env::var_os("BUILD_MANIFEST_SHIPPED_FILES_PATH") {
|
277 | 276 | self.write_shipped_files(&Path::new(&path));
|
278 | 277 | }
|
| 278 | + |
| 279 | + t!(self.checksums.store_cache()); |
279 | 280 | }
|
280 | 281 |
|
281 | 282 | /// If a tool does not pass its tests, don't ship it.
|
@@ -321,7 +322,7 @@ impl Builder {
|
321 | 322 | self.add_renames_to(&mut manifest);
|
322 | 323 | manifest.pkg.insert("rust".to_string(), self.rust_package(&manifest));
|
323 | 324 |
|
324 |
| - self.fill_missing_hashes(&mut manifest); |
| 325 | + self.checksums.fill_missing_checksums(&mut manifest); |
325 | 326 |
|
326 | 327 | manifest
|
327 | 328 | }
|
@@ -595,41 +596,6 @@ impl Builder {
|
595 | 596 | assert!(t!(child.wait()).success());
|
596 | 597 | }
|
597 | 598 |
|
598 |
| - fn fill_missing_hashes(&self, manifest: &mut Manifest) { |
599 |
| - // First collect all files that need hashes |
600 |
| - let mut need_hashes = HashSet::new(); |
601 |
| - crate::manifest::visit_file_hashes(manifest, |file_hash| { |
602 |
| - if let FileHash::Missing(path) = file_hash { |
603 |
| - need_hashes.insert(path.clone()); |
604 |
| - } |
605 |
| - }); |
606 |
| - |
607 |
| - let collected = Mutex::new(HashMap::new()); |
608 |
| - let collection_start = Instant::now(); |
609 |
| - println!( |
610 |
| - "collecting hashes for {} tarballs across {} threads", |
611 |
| - need_hashes.len(), |
612 |
| - rayon::current_num_threads().min(need_hashes.len()), |
613 |
| - ); |
614 |
| - need_hashes.par_iter().for_each(|path| match fetch_hash(path) { |
615 |
| - Ok(hash) => { |
616 |
| - collected.lock().unwrap().insert(path, hash); |
617 |
| - } |
618 |
| - Err(err) => eprintln!("error while fetching the hash for {}: {}", path.display(), err), |
619 |
| - }); |
620 |
| - let collected = collected.into_inner().unwrap(); |
621 |
| - println!("collected {} hashes in {:.2?}", collected.len(), collection_start.elapsed()); |
622 |
| - |
623 |
| - crate::manifest::visit_file_hashes(manifest, |file_hash| { |
624 |
| - if let FileHash::Missing(path) = file_hash { |
625 |
| - match collected.get(path) { |
626 |
| - Some(hash) => *file_hash = FileHash::Present(hash.clone()), |
627 |
| - None => panic!("missing hash for file {}", path.display()), |
628 |
| - } |
629 |
| - } |
630 |
| - }) |
631 |
| - } |
632 |
| - |
633 | 599 | fn write_channel_files(&mut self, channel_name: &str, manifest: &Manifest) {
|
634 | 600 | self.write(&toml::to_string(&manifest).unwrap(), channel_name, ".toml");
|
635 | 601 | self.write(&manifest.date, channel_name, "-date.txt");
|
@@ -660,10 +626,3 @@ impl Builder {
|
660 | 626 | t!(std::fs::write(path, content.as_bytes()));
|
661 | 627 | }
|
662 | 628 | }
|
663 |
| - |
664 |
| -fn fetch_hash(path: &Path) -> Result<String, Box<dyn Error>> { |
665 |
| - let mut file = BufReader::new(File::open(path)?); |
666 |
| - let mut sha256 = sha2::Sha256::default(); |
667 |
| - std::io::copy(&mut file, &mut sha256)?; |
668 |
| - Ok(hex::encode(sha256.finalize())) |
669 |
| -} |
0 commit comments