Skip to content

Commit

Permalink
feat: add abbs_update_checksums_core::ParseErrors fallback to acbs-…
Browse files Browse the repository at this point in the history
…build
  • Loading branch information
eatradish committed May 28, 2024
1 parent ae68588 commit 5ad8cda
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion buildit-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ fancy-regex = "0.13"
thiserror ="1.0"
tracing = "0.1.40"
once_cell = "1.19.0"
abbs-update-checksum-core = { git = "https://github.com/AOSC-Dev/abbs-update-checksum", package = "abbs-update-checksum-core", rev = "91d6276a933bc75f32638b5fdbdede79e6821eb6" }
abbs-update-checksum-core = { git = "https://github.com/AOSC-Dev/abbs-update-checksum", package = "abbs-update-checksum-core", rev = "332ac55b6e96a9edc671c56ba03cd20bfe60e49c" }
51 changes: 42 additions & 9 deletions buildit-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::github::{find_version_by_packages, print_stdout_and_stderr, update_abbs};
use abbs_update_checksum_core::get_new_spec;
use abbs_update_checksum_core::{get_new_spec, ParseErrors};
use anyhow::{bail, Context};
use github::get_spec;
use once_cell::sync::Lazy;
Expand All @@ -9,7 +9,7 @@ use std::{
process::Command,
};
use tokio::{fs, task::spawn_blocking};
use tracing::{error, info};
use tracing::{error, info, warn};

pub mod github;

Expand Down Expand Up @@ -80,12 +80,10 @@ pub async fn find_update_and_update_checksum(
}

let absolute_abbs_path = std::fs::canonicalize(abbs_path)?;

let abbs_path_shared = absolute_abbs_path.clone();
let pkg_shared = pkg.to_owned();

info!("Writting new checksum ...");
let res = write_new_spec(abbs_path_shared, pkg_shared).await;
let res = write_new_spec(absolute_abbs_path, pkg_shared).await;

if let Err(e) = res {
// cleanup repo
Expand Down Expand Up @@ -164,7 +162,9 @@ pub async fn find_update_and_update_checksum(
bail!("{pkg} has no update")
}

async fn write_new_spec(abbs_path_shared: PathBuf, pkg_shared: String) -> anyhow::Result<()> {
async fn write_new_spec(abbs_path: PathBuf, pkg: String) -> anyhow::Result<()> {
let pkg_shared = pkg.clone();
let abbs_path_shared = abbs_path.clone();
let (mut spec, p) = spawn_blocking(move || get_spec(&abbs_path_shared, &pkg_shared)).await??;

for i in 1..=5 {
Expand All @@ -178,13 +178,46 @@ async fn write_new_spec(abbs_path_shared: PathBuf, pkg_shared: String) -> anyhow
return Ok(());
}
Err(e) => {
error!("Failed to get new spec: {e}");
if i == 5 {
bail!("{e}");
if let Some(e) = e.downcast_ref::<ParseErrors>() {
warn!("{e}, try use acbs-build fallback to get new checksum ...");
acbs_build_gw(&pkg, &abbs_path)?;
} else {
error!("Failed to get new spec: {e}");
if i == 5 {
bail!("{e}");
}
}
}
}
}

Ok(())
}

fn acbs_build_gw(pkg_shared: &str, abbs_path_shared: &Path) -> anyhow::Result<()> {
let output = Command::new("acbs-build")
.arg("-gw")
.arg(pkg_shared)
.arg("--log-dir")
.arg(&abbs_path_shared.join("acbs-log"))
.arg("--cache-dir")
.arg(&abbs_path_shared.join("acbs-cache"))
.arg("--temp-dir")
.arg(&abbs_path_shared.join("acbs-temp"))
.arg("--tree-dir")
.arg(abbs_path_shared)
.current_dir(abbs_path_shared)
.output()
.context("Running acbs-build to update checksums")?;

print_stdout_and_stderr(&output);

if !output.status.success() {
bail!(
"Failed to run acbs-build to update checksum: {}",
String::from_utf8_lossy(&output.stderr)
);
}

Ok(())
}

0 comments on commit 5ad8cda

Please sign in to comment.