@@ -50,19 +50,16 @@ use compile::output::contracts::VersionedContracts;
5050use compilers:: multi:: MultiCompiler ;
5151use derivative:: Derivative ;
5252use foundry_compilers_artifacts:: solc:: {
53- output_selection:: OutputSelection ,
5453 sources:: { Source , SourceCompilationKind , Sources } ,
5554 Contract , Severity , SourceFile , StandardJsonCompilerInput ,
5655} ;
5756use foundry_compilers_core:: error:: { Result , SolcError , SolcIoError } ;
5857use output:: sources:: { VersionedSourceFile , VersionedSourceFiles } ;
5958use project:: ProjectCompiler ;
6059use semver:: Version ;
61- use solang_parser:: pt:: SourceUnitPart ;
6260use solc:: SolcSettings ;
6361use std:: {
6462 collections:: { BTreeMap , HashMap , HashSet } ,
65- fs,
6663 path:: { Path , PathBuf } ,
6764} ;
6865
@@ -361,62 +358,24 @@ impl<T: ArtifactOutput, C: Compiler> Project<C, T> {
361358 Ok ( ( ) )
362359 }
363360
364- /// Runs solc compiler without requesting any output and collects a mapping from contract names
365- /// to source files containing artifact with given name.
366- fn collect_contract_names_solc ( & self ) -> Result < HashMap < String , Vec < PathBuf > > >
367- where
368- T : Clone ,
369- C : Clone ,
370- {
371- let mut temp_project = ( * self ) . clone ( ) ;
372- temp_project. no_artifacts = true ;
373- temp_project. settings . update_output_selection ( |selection| {
374- * selection = OutputSelection :: common_output_selection ( [ "abi" . to_string ( ) ] ) ;
375- } ) ;
376-
377- let output = temp_project. compile ( ) ?;
378-
379- if output. has_compiler_errors ( ) {
380- return Err ( SolcError :: msg ( output) ) ;
381- }
382-
383- let contracts = output. into_artifacts ( ) . fold (
384- HashMap :: new ( ) ,
385- |mut contracts : HashMap < _ , Vec < _ > > , ( id, _) | {
386- contracts. entry ( id. name ) . or_default ( ) . push ( id. source ) ;
387- contracts
388- } ,
389- ) ;
390-
391- Ok ( contracts)
392- }
393-
394- /// Parses project sources via solang parser, collecting mapping from contract name to source
395- /// files containing artifact with given name. On parser failure, fallbacks to
396- /// [Self::collect_contract_names_solc].
361+ /// Parses the sources in memory and collects all the contract names mapped to their file paths.
397362 fn collect_contract_names ( & self ) -> Result < HashMap < String , Vec < PathBuf > > >
398363 where
399364 T : Clone ,
400365 C : Clone ,
401366 {
402367 let graph = Graph :: < C :: ParsedSource > :: resolve ( & self . paths ) ?;
403368 let mut contracts: HashMap < String , Vec < PathBuf > > = HashMap :: new ( ) ;
404-
405- for file in graph. files ( ) . keys ( ) {
406- let src = fs:: read_to_string ( file) . map_err ( |e| SolcError :: io ( e, file) ) ?;
407- let Ok ( ( parsed, _) ) = solang_parser:: parse ( & src, 0 ) else {
408- return self . collect_contract_names_solc ( ) ;
409- } ;
410-
411- for part in parsed. 0 {
412- if let SourceUnitPart :: ContractDefinition ( contract) = part {
413- if let Some ( name) = contract. name {
414- contracts. entry ( name. name ) . or_default ( ) . push ( file. clone ( ) ) ;
415- }
369+ if !graph. is_empty ( ) {
370+ for node in graph. nodes ( 0 ) {
371+ for contract_name in node. data . contract_names ( ) {
372+ contracts
373+ . entry ( contract_name. clone ( ) )
374+ . or_default ( )
375+ . push ( node. path ( ) . to_path_buf ( ) ) ;
416376 }
417377 }
418378 }
419-
420379 Ok ( contracts)
421380 }
422381
0 commit comments