@@ -225,7 +225,7 @@ def build_database(
225225 return database_dir
226226
227227
228- def generate_models (config , project : Project , database_dir : str ) -> None :
228+ def generate_models (config , args , project : Project , database_dir : str ) -> None :
229229 """
230230 Generate models for a project.
231231
@@ -243,6 +243,8 @@ def generate_models(config, project: Project, database_dir: str) -> None:
243243 generator .generateSources = should_generate_sources (project )
244244 generator .generateSummaries = should_generate_summaries (project )
245245 generator .setenvironment (database = database_dir , folder = name )
246+ generator .threads = args .codeql_threads
247+ generator .ram = args .codeql_ram
246248 generator .run ()
247249
248250
@@ -333,43 +335,44 @@ def pretty_name_from_artifact_name(artifact_name: str) -> str:
333335
334336def download_dca_databases (
335337 language : str ,
336- experiment_name : str ,
338+ experiment_names : list [ str ] ,
337339 pat : str ,
338340 projects : List [Project ],
339341) -> List [tuple [Project , str | None ]]:
340342 """
341343 Download databases from a DCA experiment.
342344 Args:
343- experiment_name : The name of the DCA experiment to download databases from.
345+ experiment_names : The names of the DCA experiments to download databases from.
344346 pat: Personal Access Token for GitHub API authentication.
345347 projects: List of projects to download databases for.
346348 Returns:
347349 List of (project_name, database_dir) pairs, where database_dir is None if the download failed.
348350 """
349351 print ("\n === Finding projects ===" )
350- response = get_json_from_github (
351- f"https://raw.githubusercontent.com/github/codeql-dca-main/data/{ experiment_name } /reports/downloads.json" ,
352- pat ,
353- )
354- targets = response ["targets" ]
355352 project_map = {project ["name" ]: project for project in projects }
356353 analyzed_databases = {}
357- for data in targets .values ():
358- downloads = data ["downloads" ]
359- analyzed_database = downloads ["analyzed_database" ]
360- artifact_name = analyzed_database ["artifact_name" ]
361- pretty_name = pretty_name_from_artifact_name (artifact_name )
362-
363- if not pretty_name in project_map :
364- print (f"Skipping { pretty_name } as it is not in the list of projects" )
365- continue
366-
367- if pretty_name in analyzed_databases :
368- print (
369- f"Skipping previous database { analyzed_databases [pretty_name ]['artifact_name' ]} for { pretty_name } "
370- )
354+ for experiment_name in experiment_names :
355+ response = get_json_from_github (
356+ f"https://raw.githubusercontent.com/github/codeql-dca-main/data/{ experiment_name } /reports/downloads.json" ,
357+ pat ,
358+ )
359+ targets = response ["targets" ]
360+ for data in targets .values ():
361+ downloads = data ["downloads" ]
362+ analyzed_database = downloads ["analyzed_database" ]
363+ artifact_name = analyzed_database ["artifact_name" ]
364+ pretty_name = pretty_name_from_artifact_name (artifact_name )
365+
366+ if not pretty_name in project_map :
367+ print (f"Skipping { pretty_name } as it is not in the list of projects" )
368+ continue
369+
370+ if pretty_name in analyzed_databases :
371+ print (
372+ f"Skipping previous database { analyzed_databases [pretty_name ]['artifact_name' ]} for { pretty_name } "
373+ )
371374
372- analyzed_databases [pretty_name ] = analyzed_database
375+ analyzed_databases [pretty_name ] = analyzed_database
373376
374377 def download_and_decompress (analyzed_database : dict ) -> str :
375378 artifact_name = analyzed_database ["artifact_name" ]
@@ -450,23 +453,6 @@ def main(config, args) -> None:
450453 if not os .path .exists (build_dir ):
451454 os .makedirs (build_dir )
452455
453- # Check if any of the MaD directories contain working directory changes in git
454- for project in projects :
455- mad_dir = get_mad_destination_for_project (config , project ["name" ])
456- if os .path .exists (mad_dir ):
457- git_status_output = subprocess .check_output (
458- ["git" , "status" , "-s" , mad_dir ], text = True
459- ).strip ()
460- if git_status_output :
461- print (
462- f"""ERROR: Working directory changes detected in { mad_dir } .
463-
464- Before generating new models, the existing models are deleted.
465-
466- To avoid loss of data, please commit your changes."""
467- )
468- sys .exit (1 )
469-
470456 database_results = []
471457 match get_strategy (config ):
472458 case "repo" :
@@ -477,8 +463,8 @@ def main(config, args) -> None:
477463 projects ,
478464 )
479465 case "dca" :
480- experiment_name = args .dca
481- if experiment_name is None :
466+ experiment_names = args .dca
467+ if experiment_names is None :
482468 print ("ERROR: --dca argument is required for DCA strategy" )
483469 sys .exit (1 )
484470
@@ -492,7 +478,7 @@ def main(config, args) -> None:
492478 pat = f .read ().strip ()
493479 database_results = download_dca_databases (
494480 language ,
495- experiment_name ,
481+ experiment_names ,
496482 pat ,
497483 projects ,
498484 )
@@ -518,7 +504,7 @@ def main(config, args) -> None:
518504
519505 for project , database_dir in database_results :
520506 if database_dir is not None :
521- generate_models (config , project , database_dir )
507+ generate_models (config , args , project , database_dir )
522508
523509
524510if __name__ == "__main__" :
@@ -529,14 +515,26 @@ def main(config, args) -> None:
529515 parser .add_argument (
530516 "--dca" ,
531517 type = str ,
532- help = "Name of a DCA run that built all the projects" ,
533- required = False ,
518+ help = "Name of a DCA run that built all the projects. Can be repeated, with sources taken from all provided runs, "
519+ "the last provided ones having priority" ,
520+ action = "append" ,
534521 )
535522 parser .add_argument (
536523 "--pat" ,
537524 type = str ,
538525 help = "Path to a file containing the PAT token required to grab DCA databases (the same as the one you use for DCA)" ,
539- required = False ,
526+ )
527+ parser .add_argument (
528+ "--codeql-ram" ,
529+ type = int ,
530+ help = "What `--ram` value to pass to `codeql` while generating models (by default the flag is not passed)" ,
531+ default = None ,
532+ )
533+ parser .add_argument (
534+ "--codeql-threads" ,
535+ type = int ,
536+ help = "What `--threads` value to pass to `codeql` (default %(default)s)" ,
537+ default = 0 ,
540538 )
541539 args = parser .parse_args ()
542540
0 commit comments