Skip to content

Commit

Permalink
Merge pull request #417 from serpent-os/boulder-cmake-deps
Browse files Browse the repository at this point in the history
boulder/drafter: Auto add cmake deps on boulder new
  • Loading branch information
ikeycode authored Feb 10, 2025
2 parents 3081d11 + e38a97a commit fe4f9a7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions boulder/src/draft/build/cmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
//
// SPDX-License-Identifier: MPL-2.0

use regex::Regex;
use std::path::Path;

use fs_err as fs;

use crate::draft::build::{Error, Phases, State};
use crate::draft::File;
use moss::{dependency, Dependency};

pub fn phases() -> Phases {
Phases {
Expand All @@ -22,7 +28,26 @@ pub fn process(state: &mut State<'_>, file: &File<'_>) -> Result<(), Error> {

if file.file_name() == "CMakeLists.txt" {
state.increment_confidence(20);
scan_cmake(state, &file.path)?;
}

Ok(())
}

fn scan_cmake(state: &mut State<'_>, path: &Path) -> Result<(), Error> {
let contents = fs::read_to_string(path)?;

let regex_cmake = Regex::new(r"find_package\(([^ )]+)")?;

for captures in regex_cmake.captures_iter(&contents) {
if let Some(capture) = captures.get(1) {
let name = capture.as_str().to_owned();

state.add_dependency(Dependency {
kind: dependency::Kind::CMake,
name,
});
}
}
Ok(())
}

0 comments on commit fe4f9a7

Please sign in to comment.