From 5708c3fa9bbb8c5c5897b70338e1353f86b2be35 Mon Sep 17 00:00:00 2001 From: Miao ZhiCheng Date: Tue, 25 Apr 2023 11:33:33 +0300 Subject: [PATCH 1/5] Native loading strategy to support TRUFFLE_NATIVE_SOLC_PATH --- .../src/compilerSupplier/loadingStrategies/Native.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compile-solidity/src/compilerSupplier/loadingStrategies/Native.ts b/packages/compile-solidity/src/compilerSupplier/loadingStrategies/Native.ts index a6cc2e9b239..e0ef875a8c4 100644 --- a/packages/compile-solidity/src/compilerSupplier/loadingStrategies/Native.ts +++ b/packages/compile-solidity/src/compilerSupplier/loadingStrategies/Native.ts @@ -5,7 +5,7 @@ const { NoVersionError } = require("../errors"); export class Native { load() { const versionString = this.validateAndGetSolcVersion(); - const command = "solc --standard-json"; + const command = (process.env.TRUFFLE_NATIVE_SOLC_PATH || "solc") + " --standard-json"; const maxBuffer = 1024 * 1024 * 10; try { From 3e686704f7e018476f48488518e8e4a183a0b516 Mon Sep 17 00:00:00 2001 From: Miao ZhiCheng Date: Thu, 27 Apr 2023 20:51:48 +0300 Subject: [PATCH 2/5] Update Native.ts --- .../src/compilerSupplier/loadingStrategies/Native.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compile-solidity/src/compilerSupplier/loadingStrategies/Native.ts b/packages/compile-solidity/src/compilerSupplier/loadingStrategies/Native.ts index e0ef875a8c4..1b76bfe77da 100644 --- a/packages/compile-solidity/src/compilerSupplier/loadingStrategies/Native.ts +++ b/packages/compile-solidity/src/compilerSupplier/loadingStrategies/Native.ts @@ -5,7 +5,7 @@ const { NoVersionError } = require("../errors"); export class Native { load() { const versionString = this.validateAndGetSolcVersion(); - const command = (process.env.TRUFFLE_NATIVE_SOLC_PATH || "solc") + " --standard-json"; + const command = `${process.env.TRUFFLE_NATIVE_SOLC_PATH || "solc"} --standard-json`; const maxBuffer = 1024 * 1024 * 10; try { From 48a99811a33722576ddf27c8220c0746dec9b995 Mon Sep 17 00:00:00 2001 From: cds-amal Date: Sat, 29 Apr 2023 20:29:55 -0400 Subject: [PATCH 3/5] Hook up Native Path --- .../compile-solidity/src/compilerSupplier/index.ts | 9 ++++++--- .../src/compilerSupplier/loadingStrategies/Native.ts | 10 ++++++++-- packages/config/src/configDefaults.ts | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/compile-solidity/src/compilerSupplier/index.ts b/packages/compile-solidity/src/compilerSupplier/index.ts index f24f688087a..b8954d801d1 100644 --- a/packages/compile-solidity/src/compilerSupplier/index.ts +++ b/packages/compile-solidity/src/compilerSupplier/index.ts @@ -17,11 +17,14 @@ export class CompilerSupplier { private version: string; private docker: boolean; private strategyOptions: StrategyOptions; + private nativePath: string; constructor({ events, solcConfig }) { - const { version, docker, compilerRoots, dockerTagsUrl, spawn } = solcConfig; + const { version, docker, compilerRoots, dockerTagsUrl, spawn, nativePath } = + solcConfig; this.version = version ? version : defaultSolcVersion; this.docker = docker; + this.nativePath = nativePath; this.strategyOptions = {}; if (version) this.strategyOptions.version = this.version; if (dockerTagsUrl) this.strategyOptions.dockerTagsUrl = dockerTagsUrl; @@ -44,7 +47,7 @@ export class CompilerSupplier { if (useDocker) { strategy = new Docker(this.strategyOptions); } else if (useNative) { - strategy = new Native(); + strategy = new Native(this.nativePath); } else if (useSpecifiedLocal) { strategy = new Local(); } else if (isValidVersionRange) { @@ -83,7 +86,7 @@ export class CompilerSupplier { if (useDocker) { strategy = new Docker(this.strategyOptions); } else if (useNative) { - strategy = new Native(); + strategy = new Native(this.nativePath); } else if (useSpecifiedLocal) { strategy = new Local(); } else if (isValidVersionRange) { diff --git a/packages/compile-solidity/src/compilerSupplier/loadingStrategies/Native.ts b/packages/compile-solidity/src/compilerSupplier/loadingStrategies/Native.ts index 9375e2c8ced..b73e841b298 100644 --- a/packages/compile-solidity/src/compilerSupplier/loadingStrategies/Native.ts +++ b/packages/compile-solidity/src/compilerSupplier/loadingStrategies/Native.ts @@ -3,9 +3,15 @@ const { normalizeSolcVersion } = require("../normalizeSolcVersion"); const { NoVersionError } = require("../errors"); export class Native { + private solcPath: string; + + constructor(solcPath: string) { + this.solcPath = solcPath; + } + load() { const versionString = this.validateAndGetSolcVersion(); - const command = `${process.env.TRUFFLE_NATIVE_SOLC_PATH || "solc"} --standard-json`; + const command = `${this.solcPath} --standard-json`; const maxBuffer = 1024 * 1024 * 50; try { @@ -25,7 +31,7 @@ export class Native { validateAndGetSolcVersion() { let version; try { - version = execSync("solc --version"); + version = execSync(`${this.solcPath} --version`); } catch (error) { throw new NoNativeError(error); } diff --git a/packages/config/src/configDefaults.ts b/packages/config/src/configDefaults.ts index 3c499284824..1a08d1d1d83 100644 --- a/packages/config/src/configDefaults.ts +++ b/packages/config/src/configDefaults.ts @@ -62,6 +62,7 @@ export const getInitialConfig = ({ }, compilers: { solc: { + nativePath: `{process.env.TRUFFLE_NATIVE_SOLC_PATH || "solc"}`, settings: { //Note: The default solc version is *not* set here! //It's set in compilerSupplier/index.js in compile-solidity From b8bd147dd2f533ef92e075d6aadfc1a36a165573 Mon Sep 17 00:00:00 2001 From: cds-amal Date: Fri, 12 May 2023 21:36:32 -0400 Subject: [PATCH 4/5] Update packages/config/src/configDefaults.ts --- packages/config/src/configDefaults.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/config/src/configDefaults.ts b/packages/config/src/configDefaults.ts index 1a08d1d1d83..e27dad4331e 100644 --- a/packages/config/src/configDefaults.ts +++ b/packages/config/src/configDefaults.ts @@ -62,7 +62,7 @@ export const getInitialConfig = ({ }, compilers: { solc: { - nativePath: `{process.env.TRUFFLE_NATIVE_SOLC_PATH || "solc"}`, + nativePath: `${process.env.TRUFFLE_NATIVE_SOLC_PATH || "solc"}`, settings: { //Note: The default solc version is *not* set here! //It's set in compilerSupplier/index.js in compile-solidity From 63ce524e4de7f714716e941094fbf36a26848c5d Mon Sep 17 00:00:00 2001 From: cds-amal Date: Fri, 12 May 2023 22:41:00 -0400 Subject: [PATCH 5/5] RangeUtils should create Native with nativePath --- .../src/compilerSupplier/rangeUtils.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/compile-solidity/src/compilerSupplier/rangeUtils.ts b/packages/compile-solidity/src/compilerSupplier/rangeUtils.ts index 9bc410d6a70..2f266710a43 100644 --- a/packages/compile-solidity/src/compilerSupplier/rangeUtils.ts +++ b/packages/compile-solidity/src/compilerSupplier/rangeUtils.ts @@ -3,6 +3,7 @@ import fs from "fs-extra"; import semver from "semver"; import { Native, Local } from "./loadingStrategies"; import { CompilerSupplier } from "./index"; +import TruffleConfig from "@truffle/config"; /** * takes a version string which may be native or local, and resolves @@ -16,7 +17,8 @@ export function resolveToRange(version?: string): string { //if version was native or local, must determine what version that //actually corresponds to if (version === "native") { - return new Native().load().version(); + const nativePath = TruffleConfig.default().compilers.solc.nativePath; + return new Native(nativePath).load().version(); } else if (fs.existsSync(version) && path.isAbsolute(version)) { return new Local().load(version).version(); } @@ -40,11 +42,13 @@ export function rangeContainsAtLeast( ); //the following line doesn't, despite the flag, but does work with version ranges const rangeAtLeast = !!( - semver.validRange(range, { loose: true }) && - !semver.gtr(comparisonVersion, range, { - includePrerelease: true, - loose: true - }) //intersects will throw if given undefined so must ward against + ( + semver.validRange(range, { loose: true }) && + !semver.gtr(comparisonVersion, range, { + includePrerelease: true, + loose: true + }) + ) //intersects will throw if given undefined so must ward against ); return individualAtLeast || rangeAtLeast; }