@@ -61,8 +61,9 @@ import { SolcConfigSelector } from "./solc-config-selection.js";
61
61
const log = debug ( "hardhat:core:solidity:build-system" ) ;
62
62
63
63
interface CompilationResult {
64
- compilerOutput : CompilerOutput ,
65
- cached : boolean
64
+ compilationJob : CompilationJob ;
65
+ compilerOutput : CompilerOutput ;
66
+ cached : boolean ;
66
67
}
67
68
68
69
export interface SolidityBuildSystemOptions {
@@ -144,19 +145,20 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
144
145
if ( cachedCompilerOutput !== undefined ) {
145
146
log ( `Using cached compiler output for build ${ buildId } ` ) ;
146
147
return {
148
+ compilationJob,
147
149
compilerOutput : cachedCompilerOutput ,
148
150
cached : true ,
149
151
} ;
150
152
}
151
153
}
152
154
153
- const compilerOutput = await this . runCompilationJob ( compilationJob , runCompilationJobOptions ) ;
154
-
155
- if ( ! this . #hasCompilationErrors( compilerOutput ) ) {
156
- await this . #compilerOutputCache. setJson ( buildId , compilerOutput ) ;
157
- }
155
+ const compilerOutput = await this . runCompilationJob (
156
+ compilationJob ,
157
+ runCompilationJobOptions ,
158
+ ) ;
158
159
159
160
return {
161
+ compilationJob,
160
162
compilerOutput,
161
163
cached : false ,
162
164
} ;
@@ -169,12 +171,27 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
169
171
} ,
170
172
) ;
171
173
172
- void this . #compilerOutputCache. clean ( ) ;
173
-
174
- const isSuccessfulBuild = results . every (
174
+ const uncachedResults = results . filter ( ( result ) => ! result . cached ) ;
175
+ const uncachedSuccessfulResults = uncachedResults . filter (
175
176
( result ) => ! this . #hasCompilationErrors( result . compilerOutput ) ,
176
177
) ;
177
178
179
+ // NOTE: We're not waiting for the writes and clean to finish because we
180
+ // will only care about the result of these operations in subsequent runs
181
+ void Promise . all (
182
+ uncachedSuccessfulResults . map ( async ( result ) => {
183
+ return this . #compilerOutputCache. setJson (
184
+ result . compilationJob . getBuildId ( ) ,
185
+ result . compilerOutput ,
186
+ ) ;
187
+ } ) ,
188
+ ) . then ( ( ) => {
189
+ return this . #compilerOutputCache. clean ( ) ;
190
+ } ) ;
191
+
192
+ const isSuccessfulBuild =
193
+ uncachedResults . length === uncachedSuccessfulResults . length ;
194
+
178
195
const contractArtifactsGeneratedByCompilationJob : Map <
179
196
CompilationJob ,
180
197
ReadonlyMap < string , string [ ] >
@@ -204,38 +221,34 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
204
221
205
222
const resultsMap : Map < string , FileBuildResult > = new Map ( ) ;
206
223
207
- for ( let i = 0 ; i < compilationJobs . length ; i ++ ) {
208
- const compilationJob = compilationJobs [ i ] ;
209
- const result = results [ i ] ;
210
-
224
+ for ( const result of results ) {
211
225
const contractArtifactsGenerated = isSuccessfulBuild
212
- ? contractArtifactsGeneratedByCompilationJob . get ( compilationJob )
226
+ ? contractArtifactsGeneratedByCompilationJob . get ( result . compilationJob )
213
227
: new Map ( ) ;
214
228
215
229
assertHardhatInvariant (
216
230
contractArtifactsGenerated !== undefined ,
217
231
"We emitted contract artifacts for all the jobs if the build was successful" ,
218
232
) ;
219
233
220
- const buildId = compilationJob . getBuildId ( ) ;
234
+ const buildId = result . compilationJob . getBuildId ( ) ;
221
235
222
- const errors =
223
- result !== undefined
224
- ? await Promise . all (
225
- ( result . compilerOutput . errors ?? [ ] ) . map ( ( error ) =>
226
- this . remapCompilerError ( compilationJob , error , true ) ,
227
- ) ,
228
- )
229
- : [ ] ;
236
+ const errors = await Promise . all (
237
+ ( result . compilerOutput . errors ?? [ ] ) . map ( ( error ) =>
238
+ this . remapCompilerError ( result . compilationJob , error , true ) ,
239
+ ) ,
240
+ ) ;
230
241
231
242
this . #printSolcErrorsAndWarnings( errors ) ;
232
243
233
244
const successfulResult =
234
- result === undefined || ! this . #hasCompilationErrors( result . compilerOutput ) ;
245
+ result === undefined ||
246
+ ! this . #hasCompilationErrors( result . compilerOutput ) ;
235
247
236
- for ( const [ publicSourceName , root ] of compilationJob . dependencyGraph
237
- . getRoots ( )
238
- . entries ( ) ) {
248
+ for ( const [
249
+ publicSourceName ,
250
+ root ,
251
+ ] of result . compilationJob . dependencyGraph . getRoots ( ) . entries ( ) ) {
239
252
if ( ! successfulResult ) {
240
253
resultsMap . set ( formatRootPath ( publicSourceName , root ) , {
241
254
type : FileBuildResultType . BUILD_FAILURE ,
0 commit comments