1313# *******************************************************************************
1414"""
1515Parse known_good.json and create repos.json for multi-repository CodeQL analysis.
16+
17+ Uses scripts.tooling.lib.known_good for consistent parsing of known_good.json.
1618"""
1719
1820import json
1921import os
2022import sys
21- import subprocess
2223from pathlib import Path
2324
25+ # Add scripts directory to path for imports from tooling library
26+ sys .path .insert (0 , str (Path (__file__ ).parent .parent .parent / "scripts" ))
2427
25- def install_dependencies ():
26- """Ensure jq is installed (for reference, though we use Python's json)."""
27- try :
28- subprocess .run (["sudo" , "apt-get" , "update" ], check = True , capture_output = True )
29- subprocess .run (["sudo" , "apt-get" , "install" , "-y" , "jq" ], check = True , capture_output = True )
30- except subprocess .CalledProcessError as e :
31- print (f"Warning: Failed to install jq: { e } " , file = sys .stderr )
28+ from tooling .lib .known_good import load_known_good
3229
3330
3431def parse_known_good (json_file = "./known_good.json" ):
3532 """
3633 Parse known_good.json and transform modules into repository objects.
3734
35+ Uses the centralized scripts.tooling.lib.known_good library for parsing.
36+
3837 Args:
3938 json_file: Path to known_good.json file
4039
@@ -49,39 +48,34 @@ def parse_known_good(json_file="./known_good.json"):
4948 sys .exit (1 )
5049
5150 try :
52- with open ( json_path , "r" ) as f :
53- data = json . load ( f )
54- except json . JSONDecodeError as e :
55- print (f"Error: Failed to parse JSON : { e } " , file = sys .stderr )
51+ # Use the centralized library to parse known_good.json
52+ known_good = load_known_good ( json_path )
53+ except Exception as e :
54+ print (f"Error: Failed to parse known_good.json : { e } " , file = sys .stderr )
5655 sys .exit (1 )
5756
5857 # Extract target_sw modules
59- modules = data . get ( " modules" , {}) .get ("target_sw" , {})
58+ modules = known_good . modules .get ("target_sw" , {})
6059
6160 # Transform modules into repository objects
6261 repos = []
6362 module_outputs = {}
6463
65- for name , config in modules .items ():
66- repo_url = config .get ("repo" , "" )
67- version = config .get ("version" , "" )
68- branch = config .get ("branch" , "" )
69- hash_val = config .get ("hash" , "" )
70-
71- # Use version, branch, or hash (in that order of preference)
72- ref = version or branch or hash_val
64+ for name , module in modules .items ():
65+ repo_url = module .repo
66+ ref = module .version or module .branch or module .commit_hash
7367
7468 repo_obj = {"name" : name , "url" : repo_url , "version" : ref , "path" : f"repos/{ name } " }
7569 repos .append (repo_obj )
7670
7771 # Store module outputs for GITHUB_OUTPUT compatibility
7872 module_outputs [f"{ name } _url" ] = repo_url
79- if version :
80- module_outputs [f"{ name } _version" ] = version
81- if branch :
82- module_outputs [f"{ name } _branch" ] = branch
83- if hash_val :
84- module_outputs [f"{ name } _hash" ] = hash_val
73+ if module . version :
74+ module_outputs [f"{ name } _version" ] = module . version
75+ if module . branch :
76+ module_outputs [f"{ name } _branch" ] = module . branch
77+ if module . commit_hash :
78+ module_outputs [f"{ name } _hash" ] = module . commit_hash
8579
8680 return repos , len (modules ), module_outputs
8781
0 commit comments