Skip to content

Commit f6c1171

Browse files
committed
moss/boulder: Add perl providers
Reads the "package" from .pm files to grok the provider.
1 parent c97fd68 commit f6c1171

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

boulder/src/package/analysis.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl<'a> Chain<'a> {
3737
Box::new(handler::binary),
3838
Box::new(handler::elf),
3939
Box::new(handler::pkg_config),
40+
Box::new(handler::perl),
4041
Box::new(handler::python),
4142
Box::new(handler::cmake),
4243
Box::new(handler::compressman),

boulder/src/package/analysis/handler.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use filetime::FileTime;
22
use itertools::Itertools;
33
use std::{
44
fs::File,
5-
io::{BufReader, BufWriter, Write},
5+
io::{BufRead, BufReader, BufWriter, Write},
66
os::unix::fs::symlink,
77
path::{Component, Path, PathBuf},
88
process::Command,
@@ -64,6 +64,40 @@ pub fn binary(bucket: &mut BucketMut<'_>, info: &mut PathInfo) -> Result<Respons
6464
Ok(Decision::NextHandler.into())
6565
}
6666

67+
pub fn perl(bucket: &mut BucketMut<'_>, info: &mut PathInfo) -> Result<Response, BoxError> {
68+
let file_path = info.path.clone().into_os_string().into_string().unwrap_or_default();
69+
let is_pm_file = file_path.contains("perl") && info.file_name().ends_with(".pm");
70+
71+
if !is_pm_file {
72+
return Ok(Decision::NextHandler.into());
73+
}
74+
75+
let reader = BufReader::new(File::open(&info.path)?);
76+
77+
for line in reader.lines() {
78+
match line {
79+
Ok(line) => {
80+
if line.starts_with("package") {
81+
let perl_module = line
82+
.strip_prefix("package")
83+
.unwrap()
84+
.trim_start()
85+
.strip_suffix(";")
86+
.unwrap_or_default();
87+
bucket.providers.insert(Provider {
88+
kind: dependency::Kind::Perl,
89+
name: perl_module.to_owned(),
90+
});
91+
break;
92+
}
93+
}
94+
Err(e) => println!("ERROR: {e}"),
95+
}
96+
}
97+
98+
Ok(Decision::NextHandler.into())
99+
}
100+
67101
pub fn pkg_config(bucket: &mut BucketMut<'_>, info: &mut PathInfo) -> Result<Response, BoxError> {
68102
let file_name = info.file_name();
69103

crates/stone/src/payload/meta.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ pub enum Dependency {
5050

5151
/// An emul32-compatible pkgconfig .pc dependency (lib32/*.pc)
5252
PkgConfig32,
53+
54+
/// A Perl module
55+
Perl,
5356
}
5457

5558
#[repr(u8)]
@@ -146,6 +149,7 @@ fn decode_dependency(i: u8) -> Result<Dependency, DecodeError> {
146149
6 => Dependency::Binary,
147150
7 => Dependency::SystemBinary,
148151
8 => Dependency::PkgConfig32,
152+
9 => Dependency::Perl,
149153
_ => return Err(DecodeError::UnknownDependency(i)),
150154
};
151155
Ok(result)

moss/src/dependency.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ pub enum Kind {
5959

6060
/// Exported 32-bit pkgconfig provider
6161
PkgConfig32,
62+
63+
/// Perl module
64+
Perl,
6265
}
6366

6467
/// Convert payload dependency types to our internal representation
@@ -74,6 +77,7 @@ impl From<payload::meta::Dependency> for Kind {
7477
payload::meta::Dependency::Binary => Kind::Binary,
7578
payload::meta::Dependency::SystemBinary => Kind::SystemBinary,
7679
payload::meta::Dependency::PkgConfig32 => Kind::PkgConfig32,
80+
payload::meta::Dependency::Perl => Kind::Perl,
7781
}
7882
}
7983
}
@@ -91,6 +95,7 @@ impl From<Kind> for payload::meta::Dependency {
9195
Kind::Binary => Self::Binary,
9296
Kind::SystemBinary => Self::SystemBinary,
9397
Kind::PkgConfig32 => Self::PkgConfig32,
98+
Kind::Perl => Self::Perl,
9499
}
95100
}
96101
}

0 commit comments

Comments
 (0)