debug_dependency_detection.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/usr/bin/env python3
  2. """
  3. Debug script to trace dependency detection for GCC.
  4. This script will help identify where the incorrect dependencies are coming from.
  5. """
  6. import logging
  7. import json
  8. from pathlib import Path
  9. # Set up detailed logging
  10. logging.basicConfig(
  11. level=logging.DEBUG,
  12. format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
  13. )
  14. # Import autusm components
  15. from src.autusm.usm_integration import USMIntegration
  16. from src.autusm.analyzer import SourceAnalyzer
  17. from src.autusm.metadata import MetadataExtractor
  18. from src.autusm.manifest import ManifestGenerator
  19. from src.autusm.models import PackageInfo, BuildSystem, BuildSystemType
  20. def debug_dependency_detection():
  21. """Debug the dependency detection process."""
  22. print("=== DEBUGGING DEPENDENCY DETECTION FOR GCC ===\n")
  23. # Path to the extracted GCC source
  24. gcc_source_dir = Path("test_output1")
  25. if not gcc_source_dir.exists():
  26. print(f"ERROR: GCC source directory not found at {gcc_source_dir}")
  27. return
  28. print(f"Analyzing GCC source at: {gcc_source_dir}\n")
  29. # 1. Check USM autoprovides
  30. print("1. CHECKING USM AUTOPROVIDES...")
  31. usm_integration = USMIntegration()
  32. if usm_integration.is_available():
  33. print("USM is available, getting autoprovides...")
  34. autoprovides = usm_integration.get_autoprovides(gcc_source_dir)
  35. print(f"USM autoprovides returned: {json.dumps(autoprovides, indent=2)}")
  36. else:
  37. print("USM is not available on this system")
  38. print("\n" + "="*60 + "\n")
  39. # 2. Check metadata extraction
  40. print("2. CHECKING METADATA EXTRACTION...")
  41. metadata_extractor = MetadataExtractor()
  42. package_info = metadata_extractor.extract(gcc_source_dir)
  43. print(f"Extracted package name: {package_info.name}")
  44. print(f"Extracted version: {package_info.version}")
  45. print(f"Extracted runtime dependencies: {package_info.runtime_dependencies}")
  46. print(f"Extracted build dependencies: {package_info.build_dependencies}")
  47. print("\n" + "="*60 + "\n")
  48. # 3. Check source code analysis
  49. print("3. CHECKING SOURCE CODE ANALYSIS...")
  50. analyzer = SourceAnalyzer()
  51. # Analyze dependencies in source code
  52. try:
  53. source_dependencies = analyzer.analyze_dependencies(gcc_source_dir)
  54. print(f"Source code dependencies: {json.dumps(source_dependencies, indent=2)}")
  55. except Exception as e:
  56. print(f"Error analyzing source dependencies: {e}")
  57. print("\n" + "="*60 + "\n")
  58. # 4. Check manifest generation
  59. print("4. CHECKING MANIFEST GENERATION...")
  60. manifest_generator = ManifestGenerator()
  61. # Create a basic build system for GCC
  62. build_system = BuildSystem(
  63. type=BuildSystemType.AUTOTOOLS,
  64. config_files=[],
  65. build_files=[],
  66. detected_commands=[],
  67. custom_args={}
  68. )
  69. # Generate manifest (add a summary if missing)
  70. if not package_info.summary:
  71. package_info.summary = "GNU Compiler Collection"
  72. manifest = manifest_generator.generate(package_info, build_system)
  73. print(f"Generated manifest dependencies:")
  74. print(f" Runtime: {manifest.depends.runtime}")
  75. print(f" Build: {manifest.depends.build}")
  76. print(f" Manage: {manifest.depends.manage}")
  77. # Check the _convert_to_resource_refs method specifically
  78. print("\n5. TESTING _convert_to_resource_refs METHOD...")
  79. # Test with various inputs
  80. test_deps = ["libc", "generic_format_parser", "gcc", "make"]
  81. for dep in test_deps:
  82. converted = manifest_generator._convert_to_resource_refs([dep])
  83. print(f" '{dep}' -> {converted}")
  84. print("\n" + "="*60 + "\n")
  85. # 6. Check current manifest file
  86. print("6. CHECKING CURRENT MANIFEST.USM FILE...")
  87. manifest_file = gcc_source_dir / "MANIFEST.usm"
  88. if manifest_file.exists():
  89. with open(manifest_file, 'r') as f:
  90. current_manifest = json.load(f)
  91. print("Current manifest dependencies:")
  92. if "depends" in current_manifest and "runtime" in current_manifest["depends"]:
  93. print(f" Runtime: {current_manifest['depends']['runtime']}")
  94. else:
  95. print(" No runtime dependencies found in current manifest")
  96. else:
  97. print("No MANIFEST.usm file found")
  98. if __name__ == "__main__":
  99. debug_dependency_detection()