@@ -108,7 +108,7 @@ use crate::{
108108 filter:: SparseOutputFilter ,
109109 output:: { AggregatedCompilerOutput , Builds } ,
110110 report,
111- resolver:: GraphEdges ,
111+ resolver:: { GraphEdges , ResolvedSources } ,
112112 ArtifactOutput , CompilerSettings , Graph , Project , ProjectCompileOutput , Sources ,
113113} ;
114114use foundry_compilers_core:: error:: Result ;
@@ -128,6 +128,8 @@ pub struct ProjectCompiler<
128128 /// Contains the relationship of the source files and their imports
129129 edges : GraphEdges < C :: ParsedSource > ,
130130 project : & ' a Project < C , T > ,
131+ /// A mapping from a source file path to the primary profile name selected for it.
132+ primary_profiles : HashMap < PathBuf , & ' a str > ,
131133 /// how to compile all the sources
132134 sources : CompilerSources < ' a , C :: Language , C :: Settings > ,
133135}
@@ -152,7 +154,8 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
152154 sources. retain ( |f, _| filter. is_match ( f) )
153155 }
154156 let graph = Graph :: resolve_sources ( & project. paths , sources) ?;
155- let ( sources, edges) = graph. into_sources_by_version ( project) ?;
157+ let ResolvedSources { sources, primary_profiles, edges } =
158+ graph. into_sources_by_version ( project) ?;
156159
157160 // If there are multiple different versions, and we can use multiple jobs we can compile
158161 // them in parallel.
@@ -162,7 +165,7 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
162165 sources,
163166 } ;
164167
165- Ok ( Self { edges, project, sources } )
168+ Ok ( Self { edges, primary_profiles , project, sources } )
166169 }
167170
168171 /// Compiles all the sources of the `Project` in the appropriate mode
@@ -199,7 +202,7 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
199202 /// - check cache
200203 fn preprocess ( self ) -> Result < PreprocessedState < ' a , T , C > > {
201204 trace ! ( "preprocessing" ) ;
202- let Self { edges, project, mut sources } = self ;
205+ let Self { edges, project, mut sources, primary_profiles } = self ;
203206
204207 // convert paths on windows to ensure consistency with the `CompilerOutput` `solc` emits,
205208 // which is unix style `/`
@@ -209,7 +212,7 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
209212 // retain and compile only dirty sources and all their imports
210213 sources. filter ( & mut cache) ;
211214
212- Ok ( PreprocessedState { sources, cache } )
215+ Ok ( PreprocessedState { sources, cache, primary_profiles } )
213216 }
214217}
215218
@@ -224,6 +227,9 @@ struct PreprocessedState<'a, T: ArtifactOutput<CompilerContract = C::CompilerCon
224227
225228 /// Cache that holds `CacheEntry` objects if caching is enabled and the project is recompiled
226229 cache : ArtifactsCache < ' a , T , C > ,
230+
231+ /// A mapping from a source file path to the primary profile name selected for it.
232+ primary_profiles : HashMap < PathBuf , & ' a str > ,
227233}
228234
229235impl < ' a , T : ArtifactOutput < CompilerContract = C :: CompilerContract > , C : Compiler >
@@ -232,7 +238,7 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
232238 /// advance to the next state by compiling all sources
233239 fn compile ( self ) -> Result < CompiledState < ' a , T , C > > {
234240 trace ! ( "compiling" ) ;
235- let PreprocessedState { sources, mut cache } = self ;
241+ let PreprocessedState { sources, mut cache, primary_profiles } = self ;
236242
237243 let mut output = sources. compile ( & mut cache) ?;
238244
@@ -243,7 +249,7 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
243249 // contracts again
244250 output. join_all ( cache. project ( ) . root ( ) ) ;
245251
246- Ok ( CompiledState { output, cache } )
252+ Ok ( CompiledState { output, cache, primary_profiles } )
247253 }
248254}
249255
@@ -252,6 +258,7 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
252258struct CompiledState < ' a , T : ArtifactOutput < CompilerContract = C :: CompilerContract > , C : Compiler > {
253259 output : AggregatedCompilerOutput < C > ,
254260 cache : ArtifactsCache < ' a , T , C > ,
261+ primary_profiles : HashMap < PathBuf , & ' a str > ,
255262}
256263
257264impl < ' a , T : ArtifactOutput < CompilerContract = C :: CompilerContract > , C : Compiler >
@@ -263,7 +270,7 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
263270 /// successful
264271 #[ instrument( skip_all, name = "write-artifacts" ) ]
265272 fn write_artifacts ( self ) -> Result < ArtifactsState < ' a , T , C > > {
266- let CompiledState { output, cache } = self ;
273+ let CompiledState { output, cache, primary_profiles } = self ;
267274
268275 let project = cache. project ( ) ;
269276 let ctx = cache. output_ctx ( ) ;
@@ -275,6 +282,7 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
275282 & output. sources ,
276283 ctx,
277284 & project. paths ,
285+ & primary_profiles,
278286 )
279287 } else if output. has_error (
280288 & project. ignored_error_codes ,
@@ -287,6 +295,7 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
287295 & output. sources ,
288296 ctx,
289297 & project. paths ,
298+ & primary_profiles,
290299 )
291300 } else {
292301 trace ! (
@@ -300,6 +309,7 @@ impl<'a, T: ArtifactOutput<CompilerContract = C::CompilerContract>, C: Compiler>
300309 & output. sources ,
301310 & project. paths ,
302311 ctx,
312+ & primary_profiles,
303313 ) ?;
304314
305315 // emits all the build infos, if they exist
0 commit comments