aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2019-02-07 21:18:55 +0800
committerGitHub <noreply@github.com>2019-02-07 21:18:55 +0800
commitc55974a485f97d0e3ce4b0b01431be8f02a0978b (patch)
tree9ece01d0216fa482e3abc4431167ed27c6fab8b0
parent2ef3af000378f66daa0212daaf23c807d018711e (diff)
parent2ff0f545f5535cf6d61b883583643750acae2fbc (diff)
downloaddexon-0x-contracts-c55974a485f97d0e3ce4b0b01431be8f02a0978b.tar
dexon-0x-contracts-c55974a485f97d0e3ce4b0b01431be8f02a0978b.tar.gz
dexon-0x-contracts-c55974a485f97d0e3ce4b0b01431be8f02a0978b.tar.bz2
dexon-0x-contracts-c55974a485f97d0e3ce4b0b01431be8f02a0978b.tar.lz
dexon-0x-contracts-c55974a485f97d0e3ce4b0b01431be8f02a0978b.tar.xz
dexon-0x-contracts-c55974a485f97d0e3ce4b0b01431be8f02a0978b.tar.zst
dexon-0x-contracts-c55974a485f97d0e3ce4b0b01431be8f02a0978b.zip
Merge pull request #1596 from 0xProject/fix/sol-compiler-args
Sol-compiler bug fixes
-rw-r--r--packages/sol-compiler/CHANGELOG.json12
-rw-r--r--packages/sol-compiler/src/compiler.ts11
-rw-r--r--packages/sol-compiler/src/solc/bin_paths.ts52
-rw-r--r--packages/sol-compiler/src/utils/compiler.ts23
-rw-r--r--packages/sol-compiler/src/utils/types.ts4
-rw-r--r--packages/sol-compiler/test/compiler_test.ts3
6 files changed, 43 insertions, 62 deletions
diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json
index dd65f3aed..cded2c3ad 100644
--- a/packages/sol-compiler/CHANGELOG.json
+++ b/packages/sol-compiler/CHANGELOG.json
@@ -5,6 +5,18 @@
{
"note": "Fix a bug when smart recompilation wasn't working because of remappings",
"pr": 1575
+ },
+ {
+ "note": "Fix a bug that made `opts` required instead of optional",
+ "pr": 1596
+ },
+ {
+ "note": "Remove `bin_paths` and fetch the list of Solidity compilers from Github",
+ "pr": 1596
+ },
+ {
+ "note": "Fix a bug causing `ast` and `legacyAST` to not be added to the artifacts even when requested",
+ "pr": 1596
}
]
},
diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts
index 67021d445..afa4cc5bb 100644
--- a/packages/sol-compiler/src/compiler.ts
+++ b/packages/sol-compiler/src/compiler.ts
@@ -21,7 +21,6 @@ import * as semver from 'semver';
import solc = require('solc');
import { compilerOptionsSchema } from './schemas/compiler_options_schema';
-import { binPaths } from './solc/bin_paths';
import {
addHexPrefixToContractBytecode,
compileDockerAsync,
@@ -29,6 +28,7 @@ import {
createDirIfDoesNotExistAsync,
getContractArtifactIfExistsAsync,
getDependencyNameToPackagePath,
+ getSolcJSReleasesAsync,
getSourcesWithDependencies,
getSourceTreeHash,
makeContractPathsRelative,
@@ -96,12 +96,12 @@ export class Compiler {
* @return An instance of the Compiler class.
*/
constructor(opts?: CompilerOptions) {
- assert.doesConformToSchema('opts', opts, compilerOptionsSchema);
+ const passedOpts = opts || {};
+ assert.doesConformToSchema('opts', passedOpts, compilerOptionsSchema);
// TODO: Look for config file in parent directories if not found in current directory
const config: CompilerOptions = fs.existsSync(CONFIG_FILE)
? JSON.parse(fs.readFileSync(CONFIG_FILE).toString())
: {};
- const passedOpts = opts || {};
assert.doesConformToSchema('compiler.json', config, compilerOptionsSchema);
this._contractsDir = path.resolve(passedOpts.contractsDir || config.contractsDir || DEFAULT_CONTRACTS_DIR);
this._solcVersionIfExists = passedOpts.solcVersion || config.solcVersion;
@@ -211,6 +211,7 @@ export class Compiler {
// map contract paths to data about them for later verification and persistence
const contractPathToData: ContractPathToData = {};
+ const solcJSReleases = await getSolcJSReleasesAsync();
const resolvedContractSources = [];
for (const contractName of contractNames) {
const spyResolver = new SpyResolver(this._resolver);
@@ -226,7 +227,7 @@ export class Compiler {
}
contractPathToData[contractSource.path] = contractData;
const solcVersion = _.isUndefined(this._solcVersionIfExists)
- ? semver.maxSatisfying(_.keys(binPaths), parseSolidityVersionRange(contractSource.source))
+ ? semver.maxSatisfying(_.keys(solcJSReleases), parseSolidityVersionRange(contractSource.source))
: this._solcVersionIfExists;
const isFirstContractWithThisVersion = _.isUndefined(versionToInputs[solcVersion]);
if (isFirstContractWithThisVersion) {
@@ -272,7 +273,7 @@ export class Compiler {
fullSolcVersion = versionCommandOutputParts[versionCommandOutputParts.length - 1].trim();
compilerOutput = await compileDockerAsync(solcVersion, input.standardInput);
} else {
- fullSolcVersion = binPaths[solcVersion];
+ fullSolcVersion = solcJSReleases[solcVersion];
compilerOutput = await compileSolcJSAsync(solcVersion, input.standardInput);
}
if (!_.isUndefined(compilerOutput.errors)) {
diff --git a/packages/sol-compiler/src/solc/bin_paths.ts b/packages/sol-compiler/src/solc/bin_paths.ts
deleted file mode 100644
index b653c0926..000000000
--- a/packages/sol-compiler/src/solc/bin_paths.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-export interface BinaryPaths {
- [key: string]: string;
-}
-
-export const binPaths: BinaryPaths = {
- '0.5.2': 'soljson-v0.5.2+commit.1df8f40c.js',
- '0.5.1': 'soljson-v0.5.1+commit.c8a2cb62.js',
- '0.5.0': 'soljson-v0.5.0+commit.1d4f565a.js',
- '0.4.25': 'soljson-v0.4.25+commit.59dbf8f1.js',
- '0.4.24': 'soljson-v0.4.24+commit.e67f0147.js',
- '0.4.23': 'soljson-v0.4.23+commit.124ca40d.js',
- '0.4.22': 'soljson-v0.4.22+commit.4cb486ee.js',
- '0.4.21': 'soljson-v0.4.21+commit.dfe3193c.js',
- '0.4.20': 'soljson-v0.4.20+commit.3155dd80.js',
- '0.4.19': 'soljson-v0.4.19+commit.c4cbbb05.js',
- '0.4.18': 'soljson-v0.4.18+commit.9cf6e910.js',
- '0.4.17': 'soljson-v0.4.17+commit.bdeb9e52.js',
- '0.4.16': 'soljson-v0.4.16+commit.d7661dd9.js',
- '0.4.15': 'soljson-v0.4.15+commit.bbb8e64f.js',
- '0.4.14': 'soljson-v0.4.14+commit.c2215d46.js',
- '0.4.13': 'soljson-v0.4.13+commit.fb4cb1a.js',
- '0.4.12': 'soljson-v0.4.12+commit.194ff033.js',
- '0.4.11': 'soljson-v0.4.11+commit.68ef5810.js',
- '0.4.10': 'soljson-v0.4.10+commit.f0d539ae.js',
- '0.4.9': 'soljson-v0.4.9+commit.364da425.js',
- '0.4.8': 'soljson-v0.4.8+commit.60cc1668.js',
- '0.4.7': 'soljson-v0.4.7+commit.822622cf.js',
- '0.4.6': 'soljson-v0.4.6+commit.2dabbdf0.js',
- '0.4.5': 'soljson-v0.4.5+commit.b318366e.js',
- '0.4.4': 'soljson-v0.4.4+commit.4633f3de.js',
- '0.4.3': 'soljson-v0.4.3+commit.2353da71.js',
- '0.4.2': 'soljson-v0.4.2+commit.af6afb04.js',
- '0.4.1': 'soljson-v0.4.1+commit.4fc6fc2c.js',
- '0.4.0': 'soljson-v0.4.0+commit.acd334c9.js',
- '0.3.6': 'soljson-v0.3.6+commit.3fc68da.js',
- '0.3.5': 'soljson-v0.3.5+commit.5f97274.js',
- '0.3.4': 'soljson-v0.3.4+commit.7dab890.js',
- '0.3.3': 'soljson-v0.3.3+commit.4dc1cb1.js',
- '0.3.2': 'soljson-v0.3.2+commit.81ae2a7.js',
- '0.3.1': 'soljson-v0.3.1+commit.c492d9b.js',
- '0.3.0': 'soljson-v0.3.0+commit.11d6736.js',
- '0.2.2': 'soljson-v0.2.2+commit.ef92f56.js',
- '0.2.1': 'soljson-v0.2.1+commit.91a6b35.js',
- '0.2.0': 'soljson-v0.2.0+commit.4dc2445.js',
- '0.1.7': 'soljson-v0.1.7+commit.b4e666c.js',
- '0.1.6': 'soljson-v0.1.6+commit.d41f8b7.js',
- '0.1.5': 'soljson-v0.1.5+commit.23865e3.js',
- '0.1.4': 'soljson-v0.1.4+commit.5f6c3cd.js',
- '0.1.3': 'soljson-v0.1.3+commit.28f561.js',
- '0.1.2': 'soljson-v0.1.2+commit.d0d36e3.js',
- '0.1.1': 'soljson-v0.1.1+commit.6ff4cd6.js',
-};
diff --git a/packages/sol-compiler/src/utils/compiler.ts b/packages/sol-compiler/src/utils/compiler.ts
index dffd07b1d..28049e453 100644
--- a/packages/sol-compiler/src/utils/compiler.ts
+++ b/packages/sol-compiler/src/utils/compiler.ts
@@ -9,11 +9,9 @@ import * as path from 'path';
import * as requireFromString from 'require-from-string';
import * as solc from 'solc';
-import { binPaths } from '../solc/bin_paths';
-
import { constants } from './constants';
import { fsWrapper } from './fs_wrapper';
-import { CompilationError } from './types';
+import { BinaryPaths, CompilationError } from './types';
/**
* Gets contract data on network or returns if an artifact does not exist.
@@ -119,6 +117,20 @@ export function parseDependencies(contractSource: ContractSource): string[] {
return dependencies;
}
+let solcJSReleasesCache: BinaryPaths | undefined;
+
+/**
+ * Fetches the list of available solidity compilers
+ */
+export async function getSolcJSReleasesAsync(): Promise<BinaryPaths> {
+ if (_.isUndefined(solcJSReleasesCache)) {
+ const versionList = await fetch('https://ethereum.github.io/solc-bin/bin/list.json');
+ const versionListJSON = await versionList.json();
+ solcJSReleasesCache = versionListJSON.releases;
+ }
+ return solcJSReleasesCache as BinaryPaths;
+}
+
/**
* Compiles the contracts and prints errors/warnings
* @param solcVersion Version of a solc compiler
@@ -239,7 +251,7 @@ export function getSourcesWithDependencies(
contractPath: string,
fullSources: { [sourceName: string]: { id: number } },
): { sourceCodes: { [sourceName: string]: string }; sources: { [sourceName: string]: { id: number } } } {
- const sources = { [contractPath]: { id: fullSources[contractPath].id } };
+ const sources = { [contractPath]: fullSources[contractPath] };
const sourceCodes = { [contractPath]: resolver.resolve(contractPath).source };
recursivelyGatherDependencySources(
resolver,
@@ -319,7 +331,8 @@ function recursivelyGatherDependencySources(
* @param solcVersion The compiler version. e.g. 0.5.0
*/
export async function getSolcJSAsync(solcVersion: string): Promise<solc.SolcInstance> {
- const fullSolcVersion = binPaths[solcVersion];
+ const solcJSReleases = await getSolcJSReleasesAsync();
+ const fullSolcVersion = solcJSReleases[solcVersion];
if (_.isUndefined(fullSolcVersion)) {
throw new Error(`${solcVersion} is not a known compiler version`);
}
diff --git a/packages/sol-compiler/src/utils/types.ts b/packages/sol-compiler/src/utils/types.ts
index 64328899d..f756c51bb 100644
--- a/packages/sol-compiler/src/utils/types.ts
+++ b/packages/sol-compiler/src/utils/types.ts
@@ -13,6 +13,10 @@ export interface ContractSourceData {
[contractName: string]: ContractSpecificSourceData;
}
+export interface BinaryPaths {
+ [key: string]: string;
+}
+
export interface ContractSpecificSourceData {
solcVersionRange: string;
sourceHash: Buffer;
diff --git a/packages/sol-compiler/test/compiler_test.ts b/packages/sol-compiler/test/compiler_test.ts
index 464aa8bb6..cae6bce05 100644
--- a/packages/sol-compiler/test/compiler_test.ts
+++ b/packages/sol-compiler/test/compiler_test.ts
@@ -23,6 +23,9 @@ describe('#Compiler', function(): void {
contractsDir,
contracts: constants.contracts,
};
+ it('should create a Compiler with empty opts', async () => {
+ const _compiler = new Compiler(); // tslint:disable-line no-unused-variable
+ });
it('should create an Exchange artifact with the correct unlinked binary', async () => {
compilerOpts.contracts = ['Exchange'];