Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moss/boulder: Add perl providers #340

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boulder/src/package/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl<'a> Chain<'a> {
Box::new(handler::binary),
Box::new(handler::elf),
Box::new(handler::pkg_config),
Box::new(handler::perl),
Box::new(handler::python),
Box::new(handler::cmake),
// Catch-all if not excluded
Expand Down
36 changes: 36 additions & 0 deletions boulder/src/package/analysis/handler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::{path::PathBuf, process::Command};

use moss::{dependency, Dependency, Provider};
Expand Down Expand Up @@ -117,6 +119,40 @@ pub fn pkg_config(bucket: &mut BucketMut, info: &mut PathInfo) -> Result<Respons
Ok(Decision::NextHandler.into())
}

pub fn perl(bucket: &mut BucketMut, info: &mut PathInfo) -> Result<Response, BoxError> {
let file_path = info.path.clone().into_os_string().into_string().unwrap_or_default();
let is_pm_file = file_path.contains("perl") && info.file_name().ends_with(".pm");

if !is_pm_file {
return Ok(Decision::NextHandler.into());
}

let reader = BufReader::new(File::open(&info.path)?);

for line in reader.lines() {
match line {
Ok(line) => {
if line.starts_with("package") {
let perl_module = line
.strip_prefix("package")
.unwrap()
.trim_start()
.strip_suffix(";")
.unwrap_or_default();
bucket.providers.insert(Provider {
kind: dependency::Kind::Perl,
name: perl_module.to_string(),
});
break;
}
}
Err(e) => println!("ERROR: {}", e),
}
}

Ok(Decision::NextHandler.into())
}

pub fn python(bucket: &mut BucketMut, info: &mut PathInfo) -> Result<Response, BoxError> {
let file_path = info.path.clone().into_os_string().into_string().unwrap_or_default();
let is_dist_info = file_path.contains(".dist-info") && info.file_name().ends_with("METADATA");
Expand Down
4 changes: 4 additions & 0 deletions crates/stone/src/payload/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pub enum Dependency {

/// An emul32-compatible pkgconfig .pc dependency (lib32/*.pc)
PkgConfig32,

/// A Perl module
Perl,
}

#[repr(u8)]
Expand Down Expand Up @@ -146,6 +149,7 @@ fn decode_dependency(i: u8) -> Result<Dependency, DecodeError> {
6 => Dependency::Binary,
7 => Dependency::SystemBinary,
8 => Dependency::PkgConfig32,
9 => Dependency::Perl,
_ => return Err(DecodeError::UnknownDependency(i)),
};
Ok(result)
Expand Down
5 changes: 5 additions & 0 deletions moss/src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ pub enum Kind {

/// Exported 32-bit pkgconfig provider
PkgConfig32,

/// Perl module
Perl,
}

/// Convert payload dependency types to our internal representation
Expand All @@ -74,6 +77,7 @@ impl From<payload::meta::Dependency> for Kind {
payload::meta::Dependency::Binary => Kind::Binary,
payload::meta::Dependency::SystemBinary => Kind::SystemBinary,
payload::meta::Dependency::PkgConfig32 => Kind::PkgConfig32,
payload::meta::Dependency::Perl => Kind::Perl,
}
}
}
Expand All @@ -91,6 +95,7 @@ impl From<Kind> for payload::meta::Dependency {
Kind::Binary => Self::Binary,
Kind::SystemBinary => Self::SystemBinary,
Kind::PkgConfig32 => Self::PkgConfig32,
Kind::Perl => Self::Perl,
}
}
}
Expand Down
Loading