mirror of
https://gitlab.redox-os.org/redox-os/redox.git
synced 2026-06-17 15:34:18 +08:00
Remove sha256 support
Sha256 is slower than blake3 and all recipes use blake3 now.
This commit is contained in:
parent
48e5ef02eb
commit
91f885bddb
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -1242,7 +1242,6 @@ dependencies = [
|
||||
"pkgar-keys",
|
||||
"redoxer",
|
||||
"serde",
|
||||
"sha2",
|
||||
"termion",
|
||||
"toml 0.5.11",
|
||||
"walkdir",
|
||||
@ -1571,17 +1570,6 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"cpufeatures",
|
||||
"digest 0.10.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha3"
|
||||
version = "0.8.2"
|
||||
|
||||
@ -26,7 +26,6 @@ pkgar = "0.1.7"
|
||||
pkgar-keys = "0.1.0"
|
||||
redoxer = "0.2"
|
||||
serde = { version = "1.0.110", features = ["derive"] }
|
||||
sha2 = "0.10"
|
||||
termion = "1.5.5"
|
||||
toml = "0.5.6"
|
||||
walkdir = "2.3.1"
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
use cookbook::blake3::blake3_progress;
|
||||
use cookbook::recipe::{Recipe, SourceRecipe, BuildKind, BuildRecipe, PackageRecipe};
|
||||
use cookbook::sha256::sha256_progress;
|
||||
use cookbook::recipe_find::recipe_find;
|
||||
use std::{
|
||||
env,
|
||||
@ -250,7 +249,7 @@ fi"#);
|
||||
command.arg("submodule").arg("update").arg("--init").arg("--recursive");
|
||||
run_command(command)?;
|
||||
},
|
||||
Some(SourceRecipe::Tar { tar, blake3, sha256, patches, script }) => {
|
||||
Some(SourceRecipe::Tar { tar, blake3, patches, script }) => {
|
||||
if ! source_dir.is_dir() {
|
||||
// Download tar
|
||||
//TODO: replace wget
|
||||
@ -292,26 +291,6 @@ fi"#);
|
||||
);
|
||||
}
|
||||
|
||||
//TODO: if blake3 is set, remove sha256
|
||||
if let Some(sha256) = sha256 {
|
||||
// Calculate sha256
|
||||
let source_tar_sha256 = sha256_progress(&source_tar).map_err(|err| format!(
|
||||
"failed to calculate sha256 of '{}': {}\n{:?}",
|
||||
source_tar.display(),
|
||||
err,
|
||||
err
|
||||
))?;
|
||||
|
||||
// Check if it matches recipe
|
||||
if &source_tar_sha256 != sha256 {
|
||||
return Err(format!(
|
||||
"calculated sha256 '{}' does not match recipe sha256 '{}'",
|
||||
source_tar_sha256,
|
||||
sha256
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Create source.tmp
|
||||
let source_dir_tmp = recipe_dir.join("source.tmp");
|
||||
create_dir_clean(&source_dir_tmp)?;
|
||||
@ -430,7 +409,7 @@ fn build(recipe_dir: &Path, source_dir: &Path, target_dir: &Path, build: &BuildR
|
||||
eprintln!("DEBUG: '{}' newer than '{}'", source_dir.display(), stage_dir.display());
|
||||
remove_all(&stage_dir)?;
|
||||
}
|
||||
|
||||
|
||||
if ! stage_dir.is_dir() {
|
||||
// Create stage.tmp
|
||||
let stage_dir_tmp = target_dir.join("stage.tmp");
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
pub mod blake3;
|
||||
pub mod recipe;
|
||||
pub mod sha256;
|
||||
pub mod recipe_find;
|
||||
|
||||
mod progress_bar;
|
||||
|
||||
@ -24,8 +24,6 @@ pub enum SourceRecipe {
|
||||
/// The optional blake3 sum of the tar file. Please specify this to make reproducible
|
||||
/// builds more reliable
|
||||
blake3: Option<String>,
|
||||
/// The optional sha256 sum of the tar file. This is a slower alternative to a blake3 sum
|
||||
sha256: Option<String>,
|
||||
/// A list of patch files to apply to the source
|
||||
#[serde(default)]
|
||||
patches: Vec<String>,
|
||||
@ -118,7 +116,7 @@ mod tests {
|
||||
let recipe: Recipe = toml::from_str(r#"
|
||||
[source]
|
||||
tar = "http://downloads.xiph.org/releases/ogg/libogg-1.3.3.tar.xz"
|
||||
sha256 = "4f3fc6178a533d392064f14776b23c397ed4b9f48f5de297aba73b643f955c08"
|
||||
sha256 = "8220c0e4082fa26c07b10bfe31f641d2e33ebe1d1bb0b20221b7016bc8b78a3a"
|
||||
|
||||
[build]
|
||||
template = "custom"
|
||||
@ -128,8 +126,7 @@ mod tests {
|
||||
assert_eq!(recipe, Recipe {
|
||||
source: Some(SourceRecipe::Tar {
|
||||
tar: "http://downloads.xiph.org/releases/ogg/libogg-1.3.3.tar.xz".to_string(),
|
||||
blake3: None,
|
||||
sha256: Some("4f3fc6178a533d392064f14776b23c397ed4b9f48f5de297aba73b643f955c08".to_string()),
|
||||
blake3: Some("8220c0e4082fa26c07b10bfe31f641d2e33ebe1d1bb0b20221b7016bc8b78a3a".to_string()),
|
||||
patches: Vec::new(),
|
||||
script: None,
|
||||
}),
|
||||
|
||||
@ -1,45 +0,0 @@
|
||||
use std::{
|
||||
fs,
|
||||
io::{Read, Result},
|
||||
path::Path,
|
||||
time::Duration,
|
||||
};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use crate::progress_bar::{ProgressBar, ProgressBarRead};
|
||||
|
||||
pub fn sha256<R: Read>(r: &mut R) -> Result<String> {
|
||||
let mut hasher = Sha256::default();
|
||||
|
||||
let mut data = vec![0; 4 * 1024 * 1024];
|
||||
loop {
|
||||
let count = r.read(&mut data)?;
|
||||
if count == 0 {
|
||||
break;
|
||||
}
|
||||
|
||||
hasher.update(&data[..count]);
|
||||
}
|
||||
|
||||
Ok(format!("{:x}", hasher.finalize()))
|
||||
}
|
||||
|
||||
pub fn sha256_progress<P: AsRef<Path>>(path: P) -> Result<String> {
|
||||
let len = fs::metadata(&path)?.len();
|
||||
|
||||
let mut f = fs::File::open(&path)?;
|
||||
|
||||
let mut pb = ProgressBar::new(len);
|
||||
pb.message("sha256: ");
|
||||
pb.set_max_refresh_rate(Some(Duration::new(1, 0)));
|
||||
pb.set_units(pbr::Units::Bytes);
|
||||
|
||||
let res = {
|
||||
let mut pbr = ProgressBarRead::new(&mut pb, &mut f);
|
||||
sha256(&mut pbr)
|
||||
};
|
||||
|
||||
pb.finish_println("");
|
||||
|
||||
res
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user