From 2bd32595bdc91b717d4defcda0b361a6bcaad12e Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 21 Jan 2023 14:47:36 -0500 Subject: [PATCH] Make a distinction between cmake modules and pkgconfig modules --- src/main.rs | 85 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index a6bb8ee..f23b1b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,56 +1,115 @@ +use std::fmt::format; use std::fs::File; use std::io::{BufRead, BufReader}; use std::process::Command; use fancy_regex::Regex; -fn install_packages(package_list: &Vec) { +#[derive(Debug)] +enum PackageType { + CMakeModule, + PkgConfigModule +} + +#[derive(Debug)] +struct Package { + package_type: PackageType, + name: String +} + +impl Package { + pub fn newPkgConfig(name: &str) -> Self { + Self { + package_type: PackageType::PkgConfigModule, + name: name.to_string() + } + } + + pub fn newCMakeModule(name: &str) -> Self { + Self { + package_type: PackageType::CMakeModule, + name: name.to_string() + } + } + + pub fn getFilename(&self) -> String { + match self.package_type { + PackageType::PkgConfigModule => { + format!("*/{}.pc", self.name.to_lowercase()) + } + PackageType::CMakeModule => { + format!("*/{}Config.cmake", self.name) + } + } + } +} + +fn install_packages(package_list: &Vec) -> Vec { + let mut installable_packages: Vec = Vec::new(); + // we must first find which packages provide these: for package in package_list { - let pkgconfig_name = format!("*/{}.pc", package.to_lowercase()); + println!("Finding {}", package.getFilename()); let output = Command::new("dnf") .arg("provides") - .arg(pkgconfig_name) + .arg(package.getFilename()) .output() .expect("Failed to execute command"); let output = String::from_utf8(output.stdout).unwrap(); + println!("output: {}", output); let first_line = output.lines().next().unwrap(); println!("First line: {}", first_line); let re = Regex::new(r"[^\s]+(?=\s:\s)").unwrap(); - let package : &str = &re.captures(first_line).unwrap().unwrap().get(0).unwrap().as_str(); + let package : &str = re.captures(first_line).unwrap().unwrap().get(0).unwrap().as_str(); println!("FOUND PACKAGE TO INSTALL: {}", package); - let install_package = package.strip_suffix(".i686").unwrap(); + installable_packages.push(package.parse().unwrap()); } + + return installable_packages; } fn main() { - let file = File::open("test-log").unwrap(); + let file = File::open("missing-kcolorpicker.log").unwrap(); let reader = BufReader::new(file); - let mut package_list: Vec = vec![]; + let mut package_list: Vec = vec![]; for line in reader.lines() { let line = line.unwrap(); - // TODO: change to pkgconfig message - if line.contains("Could NOT find") { - println!("Found CMake error, parsing now..."); + if line.contains(" required by 'virtual:world', not found") { + println!("Found pkgconfig error, parsing now..."); - let re = Regex::new(r"Could\sNOT\sfind\s(\w+)\s").unwrap(); + println!("Line: {}", line); + + let re = Regex::new(r"--\s+Package\s\'(\w+)\'").unwrap(); let package = &re.captures(&line).unwrap().unwrap().get(1).unwrap().as_str(); println!("Found package: {}", package); - package_list.push(package.to_string()); + package_list.push(Package::newPkgConfig(package)); + } + + if line.contains("Could not find a package configuration file provided") { + println!("CMake error!"); + + println!("Line: {}", line); + + let re = Regex::new(r#"\"(\w+)\""#).unwrap(); + + let package = &re.captures(&line).unwrap().unwrap().get(1).unwrap().as_str(); + println!("Found package: {}", package); + + package_list.push(Package::newCMakeModule(package)); } } println!("Found the following packages to install: {:#?}", package_list); - install_packages(&package_list); + println!("{:#?}", install_packages(&package_list)); } \ No newline at end of file