summaryrefslogtreecommitdiff
path: root/src/pkgtoolkit
diff options
context:
space:
mode:
authorNamilskyy <alive6863@gmail.com>2025-11-29 12:36:24 +0300
committerNamilskyy <alive6863@gmail.com>2025-11-29 12:36:56 +0300
commit11ccd034109224849fff54c12785e454deba6741 (patch)
tree8e789990f6dcedfa6058e2e26147f8e97108df3f /src/pkgtoolkit
parent4920b032cf998b2edc6c52942f4d012eead6a169 (diff)
Fixed much warnings, some refactors and additions.
Diffstat (limited to 'src/pkgtoolkit')
-rw-r--r--src/pkgtoolkit/pkgtools.rs136
1 files changed, 102 insertions, 34 deletions
diff --git a/src/pkgtoolkit/pkgtools.rs b/src/pkgtoolkit/pkgtools.rs
index 100c5e2..f44a283 100644
--- a/src/pkgtoolkit/pkgtools.rs
+++ b/src/pkgtoolkit/pkgtools.rs
@@ -1,19 +1,19 @@
// I think I should split this file into a few smaller ones.
use crate::cfg::config::Config;
-use core::arch;
-use std::{io,
- fs::{self, File, create_dir_all},
- str,
- path::Path,
- process::Command,};
-
-use emissary_core::i2np::tunnel::build;
-// use emissary_core::i2np::tunnel::build;
+use std::{
+ fs::{self, File, create_dir_all},
+ io,
+ path::Path,
+ process::Command,
+ str};
+
+ // use emissary_core::i2np::tunnel::build;
use flate2::read::GzDecoder;
use serde::{Deserialize, Serialize};
use tar::Archive;
use toml;
+use cc;
#[derive(Serialize, Debug, Deserialize, Clone)]
pub enum archs {
@@ -32,6 +32,7 @@ pub struct Package {
descr: Option<String>,
}
+#[allow(dead_code)]
#[derive(Deserialize, Debug, Clone)]
struct Install {
package: Package,
@@ -43,6 +44,7 @@ struct Install {
custom_script: Option<String>,
}
+#[allow(dead_code)]
#[derive(Deserialize, Debug)]
struct Setts {
env: Option<String>, // Export environment variables if this needed
@@ -57,7 +59,8 @@ pub enum BuildSystems {
Cargo
}
-#[derive(Deserialize, Debug)]
+#[allow(dead_code)]
+#[derive(Deserialize)]
struct Build {
build_system: BuildSystems,
env: Option<String>,
@@ -71,17 +74,76 @@ impl archs {
archs::Aarch64 => "aarch64",
archs::X86 => "x86",
archs::ArmV7 => "armv7",
- archs::ArmV8 => "armv8",
- _ => "unknown",
+ archs::ArmV8 => "armv8"
}
}
}
+#[allow(dead_code)]
impl Package {
- fn builder_backend(BuildParameters: Build) -> Result<bool, std::io::Error> {
- todo!()
+ fn builder_backend(&mut self) -> Result<bool, std::io::Error> {
+ let config: Config = Config::parse().unwrap();
+ let metadata = Self::loadmeta(self).unwrap();
+ let path = Path::new(&config.paths.cache_dir).join(format!("{}-{}/BUILD", metadata.0.package.name, metadata.0.package.version));
+ let _ = create_dir_all(&path);
+
+ if metadata.2.is_none() {
+ Err(std::io::Error::new(std::io::ErrorKind::NotFound, "BUILD file not found"))?
+ }
+
+ match metadata.2.unwrap().build_system {
+ BuildSystems::Make => {
+ let _setup = Command::new("make")
+ .arg("all")
+ .arg("all")
+ .output();
+ }
+
+ BuildSystems::CMake => {
+ let _setup = Command::new("cmake")
+ .arg("-S")
+ .arg(&path)
+ .arg("-B")
+ .arg(&path)
+ .output();
+
+ let _make = Command::new("make")
+ .arg("-C")
+ .arg(&path)
+ .output();
+ }
+
+ _ => {
+ Err(std::io::Error::new(std::io::ErrorKind::NotFound, "BUILD file not found"))?
+ }
+ }
+
+ Ok(true)
}
+ /// Extracts a .tar.gz archive to the cache directory specified in Config.
+ ///
+ /// This function handles opening the archive file, decompressing it with GzDecoder,
+ /// and unpacking the contents into the configured cache directory.
+ ///
+ /// # Arguments
+ /// * `path_to_archive` - A string representing the path to the .tar.gz file.
+ ///
+ /// # Returns
+ /// * `Ok(())` if the archive is successfully unpacked.
+ /// * `Err(std::io::Error)` if there's an issue opening, reading, or unpacking the archive.
+ fn extract_archive(path_to_archive: &str) -> Result<(), std::io::Error> {
+ let config = Config::parse().unwrap();
+ create_dir_all(&config.paths.cache_dir)?;
+
+ let file = File::open(path_to_archive)?;
+ let gz = GzDecoder::new(file);
+ let mut archive = Archive::new(gz);
+
+ // Unpack directly into the cache directory
+ archive.unpack(&config.paths.cache_dir)?;
+ Ok(())
+ }
/// Load meta information from the .mesk archive.
///
@@ -188,16 +250,21 @@ impl Package {
/// * Returns an error if INSTALL file is empty.
///
// TODO: Add meta-files validation here.
+ /// Checks if the archive contains INSTALL, SETTS and BUILD files.
+ ///
+ /// Checks if INSTALL file exists and is not empty. If it does not exist or is empty, returns an error.
+ ///
+ /// Checks if SETTS and BUILD files exist and are not empty. If they do not exist or are empty, logs a warning.
+ /// # Errors
+ /// * Returns an error if INSTALL file does not exist or is empty.
+ /// * Returns an error if INSTALL file is empty.
+ ///
+ // TODO: Add meta-files validation here.
pub fn check(path_to_archive: String) -> Result<bool, std::io::Error> {
- let config: Config = Config::parse().unwrap();
+ // Call the new extraction function
+ Self::extract_archive(&path_to_archive)?;
- create_dir_all(&config.paths.cache_dir)?;
-
- let file = File::open(&path_to_archive)?;
- let gz = GzDecoder::new(file);
- let mut archive = Archive::new(gz);
-
- archive.unpack(&config.paths.cache_dir)?;
+ let config = Config::parse().unwrap();
let install_path = Path::new(&config.paths.cache_dir).join("INSTALL");
let setts_path = Path::new(&config.paths.cache_dir).join("SETTS");
@@ -244,18 +311,19 @@ impl Package {
let install_content: Result<Install, toml::de::Error> = toml::from_str(&content);
log::info!("Validating arch...");
- if std::env::consts::ARCH != install_content.unwrap().package.arch.as_str() {
- log::error!("Arch mismatch. Package arch: {:?}, Host arch: {}", install_content.clone().unwrap().package.arch, std::env::consts::ARCH);
+ if std::env::consts::ARCH != install_content.as_ref().map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e.to_string()))?.package.arch.as_str() {
+ let pkg_arch = &install_content.unwrap().package.arch; // Safe because of previous check/unwrap
+ log::error!("Arch mismatch. Package arch: {:?}, Host arch: {}", pkg_arch, std::env::consts::ARCH);
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"Arch mismatch",
));
}
-
-
Ok(true)
}
+
+
/// Builds the package according to the BUILD file in the archive.
///
@@ -276,37 +344,37 @@ impl Package {
// BUILD NOT EMPTY. SOURCE: -> BUILD -> INSTALL -> SETTS
// BUILD EMPTY. BIN: -> INSTALL -> SETTS
- enum strategies {
+ enum Strategies {
BIN,
SOURCE
}
- let mut strategy = strategies::SOURCE; //default
+ let strategy; //default
if build_meta.is_none() {
log::info!("BUILD file is empty. Skipping build, preparing to install");
- strategy = strategies::BIN;
+ strategy = Strategies::BIN;
} else {
- strategy = strategies::SOURCE;
+ strategy = Strategies::SOURCE;
log::info!("BUILD file is not empty. Skipping install, preparing to build");
}
match strategy {
- strategies::BIN => {
+ Strategies::BIN => {
if install_meta.custom_script.is_none() {
log::info!("Strategy: BIN; No custom script. Running default install hook.");
} else {
log::info!("Strategy: BIN; Running custom script.");
let script = install_meta.custom_script.as_ref().unwrap();
if !script.starts_with("./") {
- let output = std::process::Command::new(format!("{}", script));
+ let _output = std::process::Command::new(format!("{}", script));
} else {
- let output = std::process::Command::new(format!("/bin/sh '{}'", script));
+ let _output = std::process::Command::new(format!("/bin/sh '{}'", script));
}
}
}
- strategies::SOURCE => {
+ Strategies::SOURCE => {
log::info!("Strategy: SOURCE; Running default build hook.");
todo!();
}