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 std::path::Path;
22
23use super::PackageParser;
24
25/// Parser for Autotools configure scripts.
26///
27/// Extracts the parent directory name as the package name without parsing file contents.
28pub struct AutotoolsConfigureParser;
29
30impl PackageParser for AutotoolsConfigureParser {
31    const PACKAGE_TYPE: PackageType = PackageType::Autotools;
32
33    fn is_match(path: &Path) -> bool {
34        path.file_name()
35            .and_then(|name| name.to_str())
36            .is_some_and(|name| name == "configure" || name == "configure.ac")
37    }
38
39    fn extract_packages(path: &Path) -> Vec<PackageData> {
40        let name = path
41            .parent()
42            .and_then(|p| p.file_name())
43            .and_then(|n| n.to_str())
44            .map(|s| s.to_string());
45
46        vec![PackageData {
47            package_type: Some(Self::PACKAGE_TYPE),
48            name,
49            datasource_id: Some(DatasourceId::AutotoolsConfigure),
50            ..Default::default()
51        }]
52    }
53}
54
55crate::register_parser!(
56    "Autotools configure script",
57    &["**/configure", "**/configure.ac"],
58    "autotools",
59    "C",
60    Some("https://www.gnu.org/software/autoconf/"),
61);