updated build-script format
This commit is contained in:
@ -3,20 +3,20 @@ use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::process;
|
||||
|
||||
use super::*;
|
||||
use crate::utils::parser;
|
||||
use crate::commands::pkglink::pkglink;
|
||||
|
||||
|
||||
pub fn install(repo: &String, pkgname: &String) -> Result<(), bool> {
|
||||
let var_path = get_var_path();
|
||||
let var_path = super::get_var_path();
|
||||
let pkg_md_path = var_path.join(format!("{}/{}.md", repo, pkgname));
|
||||
|
||||
if !pkg_md_path.exists() {
|
||||
upload_from_repo(&repo, &pkgname, &pkg_md_path)?;
|
||||
}
|
||||
|
||||
check_dependency(&repo, &pkg_md_path)?;
|
||||
check_build_dependency(&repo, &pkg_md_path)?;
|
||||
check_run_dependency(&pkg_md_path)?;
|
||||
download(&pkgname, &pkg_md_path)?;
|
||||
|
||||
let src_dir = PathBuf::from("/pkg/src").join(&pkgname);
|
||||
@ -94,8 +94,8 @@ fn upload_from_repo(repo: &String, pkgname: &String, pkg_md_path: &Path) -> Resu
|
||||
}
|
||||
}
|
||||
|
||||
fn check_dependency(repo: &String, pkg_md_path: &Path) -> Result<(), bool> {
|
||||
let deps = match parser::get_deps(&pkg_md_path) {
|
||||
fn check_build_dependency(repo: &String, pkg_md_path: &Path) -> Result<(), bool> {
|
||||
let deps = match parser::get_build_deps(&pkg_md_path) {
|
||||
Ok(deps) => deps,
|
||||
Err(e) => {
|
||||
eprintln!("Failed to parse dependencies {}: {}", &pkg_md_path.to_str().unwrap(), e);
|
||||
@ -117,6 +117,41 @@ fn check_dependency(repo: &String, pkg_md_path: &Path) -> Result<(), bool> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_run_dependency(pkg_md_path: &Path) -> Result<(), bool> {
|
||||
let deps = match parser::get_run_deps(pkg_md_path) {
|
||||
Ok(deps) => deps,
|
||||
Err(e) => {
|
||||
eprintln!("Failed to parse dependencies {}: {}", pkg_md_path.display(), e);
|
||||
return Err(false);
|
||||
}
|
||||
};
|
||||
|
||||
let repo_list = match parser::get_repo_list() {
|
||||
Ok(repos) => repos,
|
||||
Err(e) => {
|
||||
eprintln!("Failed to get repository list: {}", e);
|
||||
return Err(false)
|
||||
}
|
||||
};
|
||||
for dependency in deps.split_whitespace() {
|
||||
let mut found = false;
|
||||
|
||||
for repo_name in &repo_list {
|
||||
let path = format!("/pkg/{}/{}/", repo_name, dependency);
|
||||
if Path::new(&path).exists() {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
install_all(&dependency.to_string());
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn download(pkgname: &String, pkg_md_path: &Path) -> Result<(), bool> {
|
||||
let url = match parser::get_url(pkg_md_path) {
|
||||
@ -259,6 +294,8 @@ fn build(
|
||||
return Err(false);
|
||||
}
|
||||
|
||||
config(&src_dir, &pkg_md_path)?;
|
||||
|
||||
if let Err(e) = fs::remove_dir_all(src_dir) {
|
||||
eprintln!("Failed to remove source directory: {}", e);
|
||||
return Err(false);
|
||||
@ -266,3 +303,33 @@ fn build(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn config(
|
||||
src_dir: &Path,
|
||||
pkg_md_path: &Path,
|
||||
) -> Result<(), bool> {
|
||||
let config_script = match parser::get_config_script(pkg_md_path) {
|
||||
Ok(script) => script,
|
||||
Err(_) => { return Ok(()) }
|
||||
};
|
||||
|
||||
let output = Command::new("zsh")
|
||||
.arg("-c")
|
||||
.arg(&config_script)
|
||||
.current_dir(src_dir)
|
||||
.output();
|
||||
|
||||
if let Err(e) = output {
|
||||
eprintln!("Failed to execute config script: {}", e);
|
||||
return Err(false);
|
||||
}
|
||||
|
||||
let output = output.unwrap();
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
eprintln!("Script failed with error: {}", stderr);
|
||||
return Err(false);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user