test_gcc_build_system_detection.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python3
  2. """
  3. Test script to reproduce the GCC build system detection issue.
  4. """
  5. import os
  6. import tempfile
  7. import shutil
  8. from pathlib import Path
  9. from src.autusm.analyzer import SourceAnalyzer
  10. def create_mock_gcc_structure(base_dir):
  11. """Create a mock GCC directory structure with both autotools and cargo files."""
  12. # Create root-level autotools files
  13. (base_dir / "configure.ac").touch()
  14. (base_dir / "Makefile.am").touch()
  15. (base_dir / "autogen.sh").touch()
  16. # Create a subdirectory with cargo files (like libformat_parser)
  17. libformat_dir = base_dir / "libformat_parser"
  18. libformat_dir.mkdir()
  19. (libformat_dir / "Cargo.toml").touch()
  20. (libformat_dir / "Cargo.lock").touch()
  21. # Add some other subdirectories to make it more realistic
  22. (base_dir / "gcc").mkdir()
  23. (base_dir / "libstdc++-v3").mkdir()
  24. (base_dir / "libgcc").mkdir()
  25. def test_build_system_detection():
  26. """Test that build system detection prioritizes root-level build systems."""
  27. with tempfile.TemporaryDirectory() as temp_dir:
  28. base_dir = Path(temp_dir)
  29. create_mock_gcc_structure(base_dir)
  30. analyzer = SourceAnalyzer()
  31. build_system = analyzer.detect_build_system(base_dir)
  32. print(f"Detected build system: {build_system.type.value}")
  33. print(f"Config files: {build_system.config_files}")
  34. # This should detect AUTOTOOLS, not CARGO
  35. if build_system.type.value == "autotools":
  36. print("✓ PASS: Correctly detected autotools")
  37. return True
  38. else:
  39. print("✗ FAIL: Incorrectly detected cargo instead of autotools")
  40. return False
  41. if __name__ == "__main__":
  42. success = test_build_system_detection()
  43. exit(0 if success else 1)