Skip to main content

provenant/parsers/
autotools.rs

1//! Parser for Autotools configure scripts.
2//!
3//! Extracts basic package metadata from Autotools configure files by using
4//! the parent directory name as the package name.
5//!
6//! # Supported Formats
7//! - configure (Autotools configure script)
8//! - configure.ac (Autoconf input file)
9//!
10//! # Key Features
11//! - Lightweight detection based on parent directory name
12//! - No file content parsing required
13//!
14//! # Implementation Notes
15//! - This parser does NOT read file contents, only extracts parent directory name
16//! - configure.in is NOT supported (deprecated legacy format)
17//! - Returns minimal PackageData with only package_type and name fields
18
19use crate::models::PackageData;
20use crate::models::{DatasourceId, PackageType};
21use packageurl::PackageUrl;
22use std::path::Path;
23
24use super::PackageParser;
25
26/// Parser for Autotools configure scripts.
27///
28/// Extracts the parent directory name as the package name without parsing file contents.
29pub struct AutotoolsConfigureParser;
30
31impl PackageParser for AutotoolsConfigureParser {
32    const PACKAGE_TYPE: PackageType = PackageType::Autotools;
33
34    fn is_match(path: &Path) -> bool {
35        path.file_name()
36            .and_then(|name| name.to_str())
37            .is_some_and(|name| name == "configure" || name == "configure.ac")
38    }
39
40    fn extract_packages(path: &Path) -> Vec<PackageData> {
41        let name = path
42            .parent()
43            .and_then(|p| p.file_name())
44            .and_then(|n| n.to_str())
45            .map(|s| s.to_string())
46            .or_else(|| {
47                path.file_name()
48                    .is_some_and(|name| name == "configure" || name == "configure.ac")
49                    .then_some("input".to_string())
50            });
51
52        let purl = name.as_deref().and_then(|name| {
53            PackageUrl::new(Self::PACKAGE_TYPE.as_str(), name)
54                .ok()
55                .map(|purl| purl.to_string())
56        });
57
58        vec![PackageData {
59            package_type: Some(Self::PACKAGE_TYPE),
60            name,
61            datasource_id: Some(DatasourceId::AutotoolsConfigure),
62            purl,
63            ..Default::default()
64        }]
65    }
66}
67
68crate::register_parser!(
69    "Autotools configure script",
70    &["**/configure", "**/configure.ac"],
71    "autotools",
72    "C",
73    Some("https://www.gnu.org/software/autoconf/"),
74);