#!/usr/bin/env python3 """ Test script to reproduce the GCC build system detection issue. """ import os import tempfile import shutil from pathlib import Path from src.autusm.analyzer import SourceAnalyzer def create_mock_gcc_structure(base_dir): """Create a mock GCC directory structure with both autotools and cargo files.""" # Create root-level autotools files (base_dir / "configure.ac").touch() (base_dir / "Makefile.am").touch() (base_dir / "autogen.sh").touch() # Create a subdirectory with cargo files (like libformat_parser) libformat_dir = base_dir / "libformat_parser" libformat_dir.mkdir() (libformat_dir / "Cargo.toml").touch() (libformat_dir / "Cargo.lock").touch() # Add some other subdirectories to make it more realistic (base_dir / "gcc").mkdir() (base_dir / "libstdc++-v3").mkdir() (base_dir / "libgcc").mkdir() def test_build_system_detection(): """Test that build system detection prioritizes root-level build systems.""" with tempfile.TemporaryDirectory() as temp_dir: base_dir = Path(temp_dir) create_mock_gcc_structure(base_dir) analyzer = SourceAnalyzer() build_system = analyzer.detect_build_system(base_dir) print(f"Detected build system: {build_system.type.value}") print(f"Config files: {build_system.config_files}") # This should detect AUTOTOOLS, not CARGO if build_system.type.value == "autotools": print("✓ PASS: Correctly detected autotools") return True else: print("✗ FAIL: Incorrectly detected cargo instead of autotools") return False if __name__ == "__main__": success = test_build_system_detection() exit(0 if success else 1)