Skip to content

Commit

Permalink
Merge pull request #6238 from NomicFoundation/dont-parse-build-infos
Browse files Browse the repository at this point in the history
Don't parse build infos
  • Loading branch information
alcuadrado authored Feb 10, 2025
2 parents 14ebbdb + 6817cc3 commit 8a9ff54
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const runSolidityTests: NewTaskActionFunction<TestActionArguments> = async (
throwIfSolidityBuildFailed(results);

const buildInfos = await getBuildInfos(results, hre.artifacts);
const artifacts = await getArtifacts(results, buildInfos);
const artifacts = await getArtifacts(results);
const testSuiteIds = artifacts.map((artifact) => artifact.id);

console.log("Running Solidity tests");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type {
CompilationJobCreationError,
FailedFileBuildResult,
FileBuildResult,
SolidityBuildInfo,
} from "../../../types/solidity.js";
import type { BuildInfoAndOutput, Artifact as EdrArtifact } from "@ignored/edr";

Expand Down Expand Up @@ -68,8 +67,10 @@ export async function getBuildInfos(
results: SuccessfulSolidityBuildResults,
artifactManager: ArtifactManager,
): Promise<BuildInfoAndOutput[]> {
const buildIds = Array.from(new Set(results.values())).map(
({ buildId }) => buildId,
const buildIds = await Promise.all(
Array.from(new Set(results.values())).map(async ({ compilationJob }) =>
compilationJob.getBuildId(),
),
);

return Promise.all(
Expand Down Expand Up @@ -109,49 +110,25 @@ export async function getBuildInfos(
* build result has a corresponding artifact generated property.
*
* @param results The successful Solidity build results.
* @param artifactManager The artifact manager.
* @returns The artifacts in the format expected by the EDR.
*/
export async function getArtifacts(
results: SuccessfulSolidityBuildResults,
buildInfos: BuildInfoAndOutput[],
): Promise<EdrArtifact[]> {
const solcVersions = Object.fromEntries(
buildInfos.map(({ buildInfo }) => {
const solidityBuildInfo: SolidityBuildInfo = JSON.parse(
new TextDecoder("utf-8").decode(buildInfo),
);

return [solidityBuildInfo.id, solidityBuildInfo.solcVersion];
}),
);

const contractArtifacts = Array.from(results.entries())
.map(([source, result]) => {
return result.contractArtifactsGenerated.map((artifactPath) => ({
source,
buildId: result.buildId,
solcVersion: result.compilationJob.solcConfig.version,
artifactPath,
}));
})
.flat();

return Promise.all(
contractArtifacts.map(async ({ source, buildId, artifactPath }) => {
contractArtifacts.map(async ({ source, artifactPath, solcVersion }) => {
const artifact: HardhatArtifact = await readJsonFile(artifactPath);

const solcVersion = solcVersions[buildId];

// This is only safe because of how we currently interact with getArtifacts
// i.e. we first call build, then we get the build infos, and the we call
// this function with the results. If the usage pattern of this function
// changes, these invariants might not hold anymore and should be
// transformed into other errors instead.
assertHardhatInvariant(
solcVersion !== undefined,
"solcVersion should not be undefined",
);

const id = {
name: artifact.contractName,
solcVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function getArtifactsDeclarationFile(artifacts: Artifact[]): string {
};`,
);

return `// This file was autogenerated by Hardhat-viem, do not edit it.
return `// This file was autogenerated by Hardhat, do not edit it.
// prettier-ignore
// tslint:disable
// eslint-disable
Expand All @@ -90,7 +90,7 @@ export function getDuplicatedContractNamesDeclarationFile(
return "";
}

return `// This file was autogenerated by Hardhat-viem, do not edit it.
return `// This file was autogenerated by Hardhat, do not edit it.
// prettier-ignore
// tslint:disable
// eslint-disable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
"We emitted contract artifacts for all the jobs if the build was successful",
);

const buildId = await result.compilationJob.getBuildId();

const errors = await Promise.all(
(result.compilerOutput.errors ?? []).map((error) =>
this.remapCompilerError(result.compilationJob, error, true),
Expand All @@ -251,7 +249,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
if (!successfulResult) {
resultsMap.set(formatRootPath(publicSourceName, root), {
type: FileBuildResultType.BUILD_FAILURE,
buildId,
compilationJob: result.compilationJob,
errors,
});

Expand All @@ -261,7 +259,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
if (result.cached) {
resultsMap.set(formatRootPath(publicSourceName, root), {
type: FileBuildResultType.CACHE_HIT,
buildId,
compilationJob: result.compilationJob,
contractArtifactsGenerated:
contractArtifactsGenerated.get(publicSourceName) ?? [],
warnings: errors,
Expand All @@ -272,7 +270,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {

resultsMap.set(formatRootPath(publicSourceName, root), {
type: FileBuildResultType.BUILD_SUCCESS,
buildId,
compilationJob: result.compilationJob,
contractArtifactsGenerated:
contractArtifactsGenerated.get(publicSourceName) ?? [],
warnings: errors,
Expand Down
6 changes: 3 additions & 3 deletions v-next/hardhat/src/types/solidity/build-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,21 @@ export type FileBuildResult =

export interface CacheHitFileBuildResult {
type: FileBuildResultType.CACHE_HIT;
buildId: string;
compilationJob: CompilationJob;
contractArtifactsGenerated: string[];
warnings: CompilerOutputError[];
}

export interface SuccessfulFileBuildResult {
type: FileBuildResultType.BUILD_SUCCESS;
buildId: string;
compilationJob: CompilationJob;
contractArtifactsGenerated: string[];
warnings: CompilerOutputError[];
}

export interface FailedFileBuildResult {
type: FileBuildResultType.BUILD_FAILURE;
buildId: string;
compilationJob: CompilationJob;
errors: CompilerOutputError[];
}

Expand Down

0 comments on commit 8a9ff54

Please sign in to comment.