1
1
import type { CompileCache } from "./cache.js" ;
2
2
import type { DependencyGraphImplementation } from "./dependency-graph.js" ;
3
3
import type { Artifact } from "../../../../types/artifacts.js" ;
4
- import type { SolcConfig , SolidityConfig } from "../../../../types/config.js" ;
4
+ import type {
5
+ SolcConfig ,
6
+ SolidityBuildProfileConfig ,
7
+ SolidityConfig ,
8
+ } from "../../../../types/config.js" ;
5
9
import type { HookManager } from "../../../../types/hooks.js" ;
6
10
import type {
7
11
SolidityBuildSystem ,
@@ -45,10 +49,7 @@ import debug from "debug";
45
49
import pMap from "p-map" ;
46
50
47
51
import { FileBuildResultType } from "../../../../types/solidity/build-system.js" ;
48
- import {
49
- DEFAULT_BUILD_PROFILE ,
50
- shouldMergeCompilationJobs ,
51
- } from "../build-profiles.js" ;
52
+ import { DEFAULT_BUILD_PROFILE } from "../build-profiles.js" ;
52
53
53
54
import {
54
55
getArtifactsDeclarationFile ,
@@ -127,6 +128,11 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
127
128
128
129
await this . #downloadConfiguredCompilers( options ?. quiet ) ;
129
130
131
+ const buildProfileName = options ?. buildProfile ?? DEFAULT_BUILD_PROFILE ;
132
+ const buildProfile = this . #getBuildProfile( buildProfileName ) ;
133
+
134
+ const isolated = this . #isIsolated( buildProfile . isolated , options ?. isolated ) ;
135
+
130
136
const compilationJobsResult = await this . getCompilationJobs (
131
137
rootFilePaths ,
132
138
options ,
@@ -210,7 +216,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
210
216
indexedIndividualJobs ,
211
217
compilationResult ,
212
218
emitArtifactsResult ,
213
- options ,
219
+ isolated ,
214
220
) ;
215
221
} ) ,
216
222
) ;
@@ -299,21 +305,13 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
299
305
) ;
300
306
301
307
const buildProfileName = options ?. buildProfile ?? DEFAULT_BUILD_PROFILE ;
302
-
303
- if ( this . #options. solidityConfig . profiles [ buildProfileName ] === undefined ) {
304
- throw new HardhatError (
305
- HardhatError . ERRORS . CORE . SOLIDITY . BUILD_PROFILE_NOT_FOUND ,
306
- {
307
- buildProfileName,
308
- } ,
309
- ) ;
310
- }
308
+ const buildProfile = this . #getBuildProfile( buildProfileName ) ;
311
309
312
310
log ( `Using build profile ${ buildProfileName } ` ) ;
313
311
314
312
const solcConfigSelector = new SolcConfigSelector (
315
313
buildProfileName ,
316
- this . #options . solidityConfig . profiles [ buildProfileName ] ,
314
+ buildProfile ,
317
315
dependencyGraph ,
318
316
) ;
319
317
@@ -388,6 +386,8 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
388
386
// Select which files to compile
389
387
const rootFilesToCompile : Set < string > = new Set ( ) ;
390
388
389
+ const isolated = this . #isIsolated( buildProfile . isolated , options ?. isolated ) ;
390
+
391
391
for ( const [ rootFile , compilationJob ] of indexedIndividualJobs . entries ( ) ) {
392
392
const jobHash = await compilationJob . getBuildId ( ) ;
393
393
const cacheResult = this . #compileCache[ rootFile ] ;
@@ -397,7 +397,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
397
397
options ?. force === true ||
398
398
cacheResult === undefined ||
399
399
cacheResult . jobHash !== jobHash ||
400
- cacheResult . isolated !== options ?. isolated
400
+ cacheResult . isolated !== isolated
401
401
) {
402
402
rootFilesToCompile . add ( rootFile ) ;
403
403
continue ;
@@ -424,10 +424,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
424
424
}
425
425
}
426
426
427
- if (
428
- options ?. isolated !== true &&
429
- shouldMergeCompilationJobs ( buildProfileName )
430
- ) {
427
+ if ( ! isolated ) {
431
428
// non-isolated mode
432
429
log ( `Merging compilation jobs` ) ;
433
430
@@ -803,6 +800,34 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
803
800
this . #downloadedCompilers = true ;
804
801
}
805
802
803
+ #getBuildProfile(
804
+ buildProfileNameOption ?: string ,
805
+ ) : SolidityBuildProfileConfig {
806
+ const buildProfileName = buildProfileNameOption ?? DEFAULT_BUILD_PROFILE ;
807
+ const buildProfile =
808
+ this . #options. solidityConfig . profiles [ buildProfileName ] ;
809
+
810
+ if ( buildProfile === undefined ) {
811
+ throw new HardhatError (
812
+ HardhatError . ERRORS . CORE . SOLIDITY . BUILD_PROFILE_NOT_FOUND ,
813
+ {
814
+ buildProfileName,
815
+ } ,
816
+ ) ;
817
+ }
818
+
819
+ return buildProfile ;
820
+ }
821
+
822
+ #isIsolated(
823
+ isolatedBuildProfile : boolean ,
824
+ isolatedOption ?: boolean ,
825
+ ) : boolean {
826
+ // NOTE: Run in isolated mode if it has been explicitly requested or the build profile demands it
827
+ // TODO: Consider allowing overriding the build profile's isolated mode via options
828
+ return isolatedBuildProfile || isolatedOption === true ;
829
+ }
830
+
806
831
#getAllCompilerVersions( ) : Set < string > {
807
832
return new Set (
808
833
Object . values ( this . #options. solidityConfig . profiles )
@@ -854,7 +879,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
854
879
indexedIndividualJobs : Map < string , CompilationJob > ,
855
880
result : CompilationResult ,
856
881
emitArtifactsResult : EmitArtifactsResult ,
857
- options : BuildOptions | undefined ,
882
+ isolated : boolean ,
858
883
) : Promise < void > {
859
884
const rootFilePaths = result . compilationJob . dependencyGraph
860
885
. getRoots ( )
@@ -887,7 +912,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
887
912
888
913
this . #compileCache[ rootFilePath ] = {
889
914
jobHash,
890
- isolated : options ?. isolated === true ,
915
+ isolated,
891
916
artifactPaths,
892
917
buildInfoPath : emitArtifactsResult . buildInfoPath ,
893
918
buildInfoOutputPath : emitArtifactsResult . buildInfoOutputPath ,
0 commit comments