1
Fork 0

Make a distinction between cmake modules and pkgconfig modules

This commit is contained in:
Joshua Goins 2023-01-21 14:47:36 -05:00
parent 4c9a8b2210
commit 2bd32595bd

View file

@ -1,56 +1,115 @@
use std::fmt::format;
use std::fs::File; use std::fs::File;
use std::io::{BufRead, BufReader}; use std::io::{BufRead, BufReader};
use std::process::Command; use std::process::Command;
use fancy_regex::Regex; use fancy_regex::Regex;
fn install_packages(package_list: &Vec<String>) { #[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<Package>) -> Vec<String> {
let mut installable_packages: Vec<String> = Vec::new();
// we must first find which packages provide these: // we must first find which packages provide these:
for package in package_list { for package in package_list {
let pkgconfig_name = format!("*/{}.pc", package.to_lowercase()); println!("Finding {}", package.getFilename());
let output = Command::new("dnf") let output = Command::new("dnf")
.arg("provides") .arg("provides")
.arg(pkgconfig_name) .arg(package.getFilename())
.output() .output()
.expect("Failed to execute command"); .expect("Failed to execute command");
let output = String::from_utf8(output.stdout).unwrap(); let output = String::from_utf8(output.stdout).unwrap();
println!("output: {}", output);
let first_line = output.lines().next().unwrap(); let first_line = output.lines().next().unwrap();
println!("First line: {}", first_line); println!("First line: {}", first_line);
let re = Regex::new(r"[^\s]+(?=\s:\s)").unwrap(); 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); 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() { fn main() {
let file = File::open("test-log").unwrap(); let file = File::open("missing-kcolorpicker.log").unwrap();
let reader = BufReader::new(file); let reader = BufReader::new(file);
let mut package_list: Vec<String> = vec![]; let mut package_list: Vec<Package> = vec![];
for line in reader.lines() { for line in reader.lines() {
let line = line.unwrap(); let line = line.unwrap();
// TODO: change to pkgconfig message if line.contains(" required by 'virtual:world', not found") {
if line.contains("Could NOT find") { println!("Found pkgconfig error, parsing now...");
println!("Found CMake 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(); let package = &re.captures(&line).unwrap().unwrap().get(1).unwrap().as_str();
println!("Found package: {}", package); 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); println!("Found the following packages to install: {:#?}", package_list);
install_packages(&package_list); println!("{:#?}", install_packages(&package_list));
} }