From eaf283af360c1c786d51a3ea115e442531850224 Mon Sep 17 00:00:00 2001 From: Vasilito Date: Fri, 8 May 2026 07:39:37 +0100 Subject: [PATCH] fix: extract PKGBUILD build()/package() bodies for Custom templates - extract_bash_function() extracts bash function bodies by brace-matching - Custom template now populates build_script from build() body - Custom template now populates install_script from package() body - Fixes 'custom builds require prepare/build/install instructions' error --- .../system/cub/source/cub-lib/src/pkgbuild.rs | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/local/recipes/system/cub/source/cub-lib/src/pkgbuild.rs b/local/recipes/system/cub/source/cub-lib/src/pkgbuild.rs index cdc1781ad..6a992346f 100644 --- a/local/recipes/system/cub/source/cub-lib/src/pkgbuild.rs +++ b/local/recipes/system/cub/source/cub-lib/src/pkgbuild.rs @@ -58,6 +58,22 @@ pub fn convert_pkgbuild(content: &str) -> Result { let mut warnings = detect_linuxisms(content); let mut actions_required = Vec::new(); + let build_body = if matches!(template, BuildTemplate::Custom) { + extract_bash_function(content, "build") + } else { + None + }; + let package_body = if matches!(template, BuildTemplate::Custom) { + extract_bash_function(content, "package") + } else { + None + }; + + if template == BuildTemplate::Custom && build_body.is_none() && package_body.is_none() { + warnings.push("Custom build detected but could not extract build() or package() function body".to_string()); + actions_required.push("review the PKGBUILD build() and package() functions manually".to_string()); + } + let mapped_runtime = map_dep_list(&depends, &mut warnings, &mut actions_required); let mapped_build = map_dep_list(&makedepends, &mut warnings, &mut actions_required); let mapped_check = map_dep_list(&checkdepends, &mut warnings, &mut actions_required); @@ -117,6 +133,8 @@ pub fn convert_pkgbuild(content: &str) -> Result { }, build: BuildSection { template, + build_script: build_body.into_iter().collect(), + install_script: package_body.into_iter().collect(), ..BuildSection::default() }, install: InstallSection::default(), @@ -326,6 +344,37 @@ pub fn detect_build_template(content: &str) -> BuildTemplate { } } +pub fn extract_bash_function(content: &str, name: &str) -> Option { + for pattern in &[format!("{name}() {{"), format!("function {name} () {{"), format!("{name} () {{")] { + if let Some(pos) = content.find(pattern) { + let start = pos + pattern.len(); + let rest = &content[start..]; + let mut depth = 1u32; + let mut end = 0usize; + for (i, ch) in rest.char_indices() { + match ch { + '{' => depth += 1, + '}' => { + depth -= 1; + if depth == 0 { + end = i; + break; + } + } + _ => {} + } + } + if end > 0 { + let body = rest[..end].trim().to_string(); + if !body.is_empty() { + return Some(body); + } + } + } + } + None +} + pub fn detect_linuxisms(content: &str) -> Vec { let lowered = content.to_ascii_lowercase(); let checks = [