|
1 | 1 | import { execFile } from "child_process";
|
2 | 2 | import * as fs from "fs";
|
| 3 | +import os from "node:os"; |
| 4 | +import path from "node:path"; |
| 5 | +import * as semver from "semver"; |
3 | 6 | import { CompilerInput, CompilerOutput } from "../../../types";
|
4 | 7 | import { HardhatError } from "../../core/errors";
|
5 | 8 | import { ERRORS } from "../../core/errors-list";
|
@@ -68,14 +71,31 @@ export class Compiler implements ICompiler {
|
68 | 71 | }
|
69 | 72 |
|
70 | 73 | export class NativeCompiler implements ICompiler {
|
71 |
| - constructor(private _pathToSolc: string) {} |
| 74 | + constructor(private _pathToSolc: string, private _solcVersion?: string) {} |
72 | 75 |
|
73 | 76 | public async compile(input: CompilerInput) {
|
| 77 | + const args = ["--standard-json"]; |
| 78 | + |
| 79 | + // Logic to make sure that solc default import callback is not being used. |
| 80 | + // If solcVersion is not defined or <= 0.6.8, do not add extra args. |
| 81 | + if (this._solcVersion !== undefined) { |
| 82 | + if (semver.gte(this._solcVersion, "0.8.22")) { |
| 83 | + // version >= 0.8.22 |
| 84 | + args.push("--no-import-callback"); |
| 85 | + } else if (semver.gte(this._solcVersion, "0.6.9")) { |
| 86 | + // version >= 0.6.9 |
| 87 | + const tmpFolder = path.join(os.tmpdir(), "hardhat-solc"); |
| 88 | + fs.mkdirSync(tmpFolder, { recursive: true }); |
| 89 | + args.push(`--base-path`); |
| 90 | + args.push(tmpFolder); |
| 91 | + } |
| 92 | + } |
| 93 | + |
74 | 94 | const output: string = await new Promise((resolve, reject) => {
|
75 | 95 | try {
|
76 | 96 | const process = execFile(
|
77 | 97 | this._pathToSolc,
|
78 |
| - [`--standard-json`], |
| 98 | + args, |
79 | 99 | {
|
80 | 100 | maxBuffer: 1024 * 1024 * 500,
|
81 | 101 | },
|
|
0 commit comments