Skip to content

Commit 3bd8481

Browse files
authored
Merge pull request #7140 from NomicFoundation/isolated
feat: added isolated config option to build profile
2 parents 8e616e9 + 9279809 commit 3bd8481

32 files changed

+298
-74
lines changed

.changeset/tricky-toys-fetch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hardhat": patch
3+
---
4+
5+
Added `isolated` config option to the build profile configuration (https://github.com/NomicFoundation/hardhat/issues/7125) and remove the `--isolated` flag.

v-next/hardhat-verify/test/solc-versions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe("solc-versions", () => {
2828
},
2929
],
3030
overrides: {},
31+
isolated: false,
3132
preferWasm: false,
3233
};
3334
const expected = ["0.8.18", "0.7.2", "0.4.11"];
@@ -51,6 +52,7 @@ describe("solc-versions", () => {
5152
settings: {},
5253
},
5354
},
55+
isolated: false,
5456
preferWasm: false,
5557
};
5658
const expected = ["0.5.5", "0.6.4"];
@@ -83,6 +85,7 @@ describe("solc-versions", () => {
8385
settings: {},
8486
},
8587
},
88+
isolated: false,
8689
preferWasm: false,
8790
};
8891
const expected = ["0.8.18", "0.7.2", "0.5.5", "0.6.4"];
@@ -107,6 +110,7 @@ describe("solc-versions", () => {
107110
settings: {},
108111
},
109112
},
113+
isolated: false,
110114
preferWasm: false,
111115
};
112116
const expected = ["0.8.18", "0.8.18"];
@@ -135,6 +139,7 @@ describe("solc-versions", () => {
135139
settings: {},
136140
},
137141
},
142+
isolated: false,
138143
preferWasm: false,
139144
};
140145

@@ -165,6 +170,7 @@ describe("solc-versions", () => {
165170
settings: {},
166171
},
167172
},
173+
isolated: false,
168174
preferWasm: false,
169175
};
170176

v-next/hardhat/src/internal/builtin-plugins/solidity/build-profiles.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,3 @@ export const DEFAULT_BUILD_PROFILES = [
66
"solidity-tests",
77
"javascript-tests",
88
] as const;
9-
10-
export function shouldMergeCompilationJobs(buildProfile: string): boolean {
11-
return buildProfile !== "production";
12-
}

v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/build-system.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ import debug from "debug";
4747
import pMap from "p-map";
4848

4949
import { FileBuildResultType } from "../../../../types/solidity/build-system.js";
50-
import {
51-
DEFAULT_BUILD_PROFILE,
52-
shouldMergeCompilationJobs,
53-
} from "../build-profiles.js";
50+
import { DEFAULT_BUILD_PROFILE } from "../build-profiles.js";
5451

5552
import {
5653
getArtifactsDeclarationFile,
@@ -131,6 +128,9 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
131128

132129
await this.#downloadConfiguredCompilers(options?.quiet);
133130

131+
const buildProfileName = options?.buildProfile ?? DEFAULT_BUILD_PROFILE;
132+
const { buildProfile } = this.#getBuildProfile(buildProfileName);
133+
134134
const compilationJobsResult = await this.getCompilationJobs(
135135
rootFilePaths,
136136
options,
@@ -212,7 +212,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
212212
indexedIndividualJobs,
213213
compilationResult,
214214
emitArtifactsResult,
215-
options,
215+
buildProfile.isolated,
216216
);
217217
}),
218218
);
@@ -292,8 +292,6 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
292292
rootFilePaths: string[],
293293
options?: GetCompilationJobsOptions,
294294
): Promise<CompilationJobCreationError | GetCompilationJobsResult> {
295-
const isolated = options?.isolated ?? false;
296-
297295
await this.#downloadConfiguredCompilers(options?.quiet);
298296

299297
const dependencyGraph = await buildDependencyGraph(
@@ -389,6 +387,8 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
389387
// Select which files to compile
390388
const rootFilesToCompile: Set<string> = new Set();
391389

390+
const isolated = buildProfile.isolated;
391+
392392
for (const [rootFile, compilationJob] of indexedIndividualJobs.entries()) {
393393
const jobHash = await compilationJob.getBuildId();
394394
const cacheResult = this.#compileCache[rootFile];
@@ -432,7 +432,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
432432
}
433433
}
434434

435-
if (!isolated && shouldMergeCompilationJobs(buildProfileName)) {
435+
if (!isolated) {
436436
// non-isolated mode
437437
log(`Merging compilation jobs`);
438438

@@ -895,7 +895,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
895895
indexedIndividualJobs: Map<string, CompilationJob>,
896896
result: CompilationResult,
897897
emitArtifactsResult: EmitArtifactsResult,
898-
options: BuildOptions | undefined,
898+
isolated: boolean,
899899
): Promise<void> {
900900
const rootFilePaths = result.compilationJob.dependencyGraph
901901
.getRoots()
@@ -928,7 +928,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
928928

929929
this.#compileCache[rootFilePath] = {
930930
jobHash,
931-
isolated: options?.isolated === true,
931+
isolated,
932932
artifactPaths,
933933
buildInfoPath: emitArtifactsResult.buildInfoPath,
934934
buildInfoOutputPath: emitArtifactsResult.buildInfoOutputPath,

v-next/hardhat/src/internal/builtin-plugins/solidity/config.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const sourcePathsType = conditionalUnionType(
2626
"Expected a string or an array of strings",
2727
);
2828

29+
const commonSolcUserConfigType = z.object({
30+
isolated: z.boolean().optional(),
31+
});
32+
2933
const solcUserConfigType = z.object({
3034
version: z.string(),
3135
settings: z.any().optional(),
@@ -36,12 +40,14 @@ const solcUserConfigType = z.object({
3640

3741
// NOTE: This is only to match the setup present in ./type-extensions.ts
3842
const singleVersionSolcUserConfigType = solcUserConfigType.extend({
43+
isolated: z.boolean().optional(),
3944
preferWasm: z.boolean().optional(),
4045
});
4146

42-
const multiVersionSolcUserConfigType = z.object({
47+
const multiVersionSolcUserConfigType = commonSolcUserConfigType.extend({
4348
compilers: z.array(solcUserConfigType).nonempty(),
4449
overrides: z.record(z.string(), solcUserConfigType).optional(),
50+
isolated: z.boolean().optional(),
4551
preferWasm: z.boolean().optional(),
4652
version: incompatibleFieldType("This field is incompatible with `compilers`"),
4753
settings: incompatibleFieldType(
@@ -216,6 +222,7 @@ function resolveSolidityConfig(
216222
settings: {},
217223
})),
218224
overrides: {},
225+
isolated: false,
219226
preferWasm: false,
220227
},
221228
},
@@ -234,6 +241,7 @@ function resolveSolidityConfig(
234241
},
235242
],
236243
overrides: {},
244+
isolated: solidityConfig.isolated ?? false,
237245
preferWasm: solidityConfig.preferWasm ?? false,
238246
},
239247
},
@@ -263,6 +271,7 @@ function resolveSolidityConfig(
263271
},
264272
),
265273
),
274+
isolated: solidityConfig.isolated ?? false,
266275
},
267276
},
268277
npmFilesToBuild: solidityConfig.npmFilesToBuild ?? [],
@@ -275,6 +284,7 @@ function resolveSolidityConfig(
275284
for (const [profileName, profile] of Object.entries(
276285
solidityConfig.profiles,
277286
)) {
287+
const isolated = profile.isolated ?? profileName === "production";
278288
const preferWasm = profile.preferWasm ?? profileName === "production";
279289

280290
if ("version" in profile) {
@@ -286,6 +296,7 @@ function resolveSolidityConfig(
286296
},
287297
],
288298
overrides: {},
299+
isolated,
289300
preferWasm,
290301
};
291302
continue;
@@ -309,6 +320,7 @@ function resolveSolidityConfig(
309320
},
310321
),
311322
),
323+
isolated,
312324
preferWasm,
313325
};
314326
}
@@ -318,6 +330,7 @@ function resolveSolidityConfig(
318330
if (!(profile in profiles)) {
319331
profiles[profile] = {
320332
...profiles.default,
333+
isolated: profile === "production",
321334
preferWasm: profile === "production",
322335
};
323336
}

v-next/hardhat/src/internal/builtin-plugins/solidity/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ const buildTask = task("build", "Builds your project")
1919
description: "The default build profile to use",
2020
defaultValue: "default",
2121
})
22-
.addFlag({
23-
name: "isolated",
24-
description: "Use isolated mode, which prioritizes reproducibility",
25-
})
2622
.addVariadicArgument({
2723
name: "files",
2824
description: "An optional list of files to compile",

v-next/hardhat/src/internal/builtin-plugins/solidity/tasks/build.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ interface CompileActionArguments {
1010
files: string[];
1111
quiet: boolean;
1212
defaultBuildProfile: string | undefined;
13-
isolated: boolean;
1413
}
1514

1615
const buildAction: NewTaskActionFunction<CompileActionArguments> = async (
17-
{ force, files, quiet, defaultBuildProfile, isolated },
16+
{ force, files, quiet, defaultBuildProfile },
1817
{ solidity, globalOptions },
1918
) => {
2019
const rootPaths =
@@ -34,7 +33,6 @@ const buildAction: NewTaskActionFunction<CompileActionArguments> = async (
3433
force,
3534
buildProfile,
3635
quiet,
37-
isolated,
3836
});
3937

4038
throwIfSolidityBuildFailed(results);

v-next/hardhat/src/internal/builtin-plugins/solidity/type-extensions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ declare module "../../../types/config.js" {
1616
}
1717

1818
export interface SingleVersionSolcUserConfig extends SolcUserConfig {
19+
isolated?: boolean;
1920
preferWasm?: boolean;
2021
}
2122

2223
export interface MultiVersionSolcUserConfig {
24+
isolated?: boolean;
2325
preferWasm?: boolean;
2426
compilers: SolcUserConfig[];
2527
overrides?: Record<string, SolcUserConfig>;
@@ -55,6 +57,7 @@ declare module "../../../types/config.js" {
5557
}
5658

5759
export interface SolidityBuildProfileConfig {
60+
isolated: boolean;
5861
preferWasm: boolean;
5962
compilers: SolcConfig[];
6063
overrides: Record<string, SolcConfig>;

v-next/hardhat/test/internal/builtin-plugins/solidity/build-system/build-system.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ describe(
8888
},
8989
],
9090
overrides: {},
91+
isolated: false,
9192
preferWasm: false,
9293
},
9394
},

v-next/hardhat/test/internal/builtin-plugins/solidity/build-system/partial-compilation/add-a-dependant.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe("Partial compilation", () => {
105105
const project = new TestProjectWrapper(_project, hre);
106106

107107
// Compile first time
108-
await project.compile({ isolated: true });
108+
await project.compile({ defaultBuildProfile: "production" });
109109
const firstSnapshot = await project.getSnapshot();
110110

111111
assertFileCounts(firstSnapshot, 1, 1, 1);
@@ -117,7 +117,7 @@ describe("Partial compilation", () => {
117117
);
118118

119119
// Compile second time
120-
await project.compile({ isolated: true });
120+
await project.compile({ defaultBuildProfile: "production" });
121121
const secondSnapshot = await project.getSnapshot();
122122

123123
assertFileCounts(secondSnapshot, 2, 2, 2);

0 commit comments

Comments
 (0)