aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-compiler
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2019-02-07 22:28:24 +0800
committerFabio Berger <me@fabioberger.com>2019-02-07 22:28:24 +0800
commit3dd652e7cf6da63831da143b73c13231a46da376 (patch)
tree52218d0b88717360fa8bfadf4bbf7e35b9ab5f66 /packages/sol-compiler
parent8de955f3d891620c90c668b4ac0b046e772d4da8 (diff)
parentf003298ce4c7a2201d2d59685b0d5d0411aeb55d (diff)
downloaddexon-0x-contracts-3dd652e7cf6da63831da143b73c13231a46da376.tar.gz
dexon-0x-contracts-3dd652e7cf6da63831da143b73c13231a46da376.tar.zst
dexon-0x-contracts-3dd652e7cf6da63831da143b73c13231a46da376.zip
Merge branch 'development' into addAnalyticsToDevToolsPages
* development: (51 commits) Publish Updated CHANGELOGS Updated CHANGELOGS Update packages/sol-compiler/CHANGELOG.json Update packages/sol-compiler/CHANGELOG.json Move from devDep to dep Fix linter Update CHANGELOG Re-run yarn since fails again on first run Add PR numbers Omit remapping in compiler settings equality checks Omit remapping in compiler settings equality checks Fix a bug when ast and legacyAST were not present in the artifacts even if requested Update yarn.lock Remove the bin_paths and fetch the solidity release list from github repo Remove postinstall hack Fix the undefined opts bug Fix sol-compiler bug with remappings causing smart recompilation to now work re-add postinstall hack Fix deps versions ...
Diffstat (limited to 'packages/sol-compiler')
-rw-r--r--packages/sol-compiler/CHANGELOG.json31
-rw-r--r--packages/sol-compiler/CHANGELOG.md11
-rw-r--r--packages/sol-compiler/package.json16
-rw-r--r--packages/sol-compiler/src/compiler.ts27
-rw-r--r--packages/sol-compiler/src/solc/bin_paths.ts52
-rw-r--r--packages/sol-compiler/src/utils/compiler.ts28
-rw-r--r--packages/sol-compiler/src/utils/types.ts4
-rw-r--r--packages/sol-compiler/test/compiler_test.ts3
8 files changed, 92 insertions, 80 deletions
diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json
index 021804ffa..ed9c45245 100644
--- a/packages/sol-compiler/CHANGELOG.json
+++ b/packages/sol-compiler/CHANGELOG.json
@@ -1,5 +1,36 @@
[
{
+ "version": "3.0.2",
+ "changes": [
+ {
+ "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
+ }
+ ],
+ "timestamp": 1549547375
+ },
+ {
+ "timestamp": 1549452781,
+ "version": "3.0.1",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
"version": "3.0.0",
"changes": [
{
diff --git a/packages/sol-compiler/CHANGELOG.md b/packages/sol-compiler/CHANGELOG.md
index 03a2b5b87..016509028 100644
--- a/packages/sol-compiler/CHANGELOG.md
+++ b/packages/sol-compiler/CHANGELOG.md
@@ -5,6 +5,17 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
+## v3.0.2 - _February 7, 2019_
+
+ * Fix a bug when smart recompilation wasn't working because of remappings (#1575)
+ * Fix a bug that made `opts` required instead of optional (#1596)
+ * Remove `bin_paths` and fetch the list of Solidity compilers from Github (#1596)
+ * Fix a bug causing `ast` and `legacyAST` to not be added to the artifacts even when requested (#1596)
+
+## v3.0.1 - _February 6, 2019_
+
+ * Dependencies updated
+
## v3.0.0 - _February 5, 2019_
* Upgrade the bignumber.js to v8.0.2 (#1517)
diff --git a/packages/sol-compiler/package.json b/packages/sol-compiler/package.json
index c16c6eb4a..3344c0b38 100644
--- a/packages/sol-compiler/package.json
+++ b/packages/sol-compiler/package.json
@@ -1,6 +1,6 @@
{
"name": "@0x/sol-compiler",
- "version": "3.0.0",
+ "version": "3.0.2",
"engines": {
"node": ">=6.12"
},
@@ -42,7 +42,7 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/sol-compiler/README.md",
"devDependencies": {
- "@0x/dev-utils": "^2.0.0",
+ "@0x/dev-utils": "^2.0.2",
"@0x/tslint-config": "^3.0.0",
"@types/chokidar": "^1.7.5",
"@types/mkdirp": "^0.5.2",
@@ -67,13 +67,13 @@
"zeppelin-solidity": "1.8.0"
},
"dependencies": {
- "@0x/assert": "^2.0.0",
- "@0x/json-schemas": "^3.0.0",
- "@0x/sol-resolver": "^2.0.0",
- "@0x/types": "^2.0.0",
+ "@0x/assert": "^2.0.2",
+ "@0x/json-schemas": "^3.0.2",
+ "@0x/sol-resolver": "^2.0.2",
+ "@0x/types": "^2.0.2",
"@0x/typescript-typings": "^4.0.0",
- "@0x/utils": "^4.0.1",
- "@0x/web3-wrapper": "^4.0.0",
+ "@0x/utils": "^4.0.3",
+ "@0x/web3-wrapper": "^4.0.2",
"@types/yargs": "^11.0.0",
"chalk": "^2.3.0",
"chokidar": "^2.0.4",
diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts
index efee3eb8a..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;
@@ -195,9 +195,7 @@ export class Compiler {
path.basename(contractSource.path, constants.SOLIDITY_FILE_EXTENSION),
);
} else {
- contractNamesToCompile = this._specifiedContracts.map(specifiedContract =>
- path.basename(specifiedContract, constants.SOLIDITY_FILE_EXTENSION),
- );
+ return this._specifiedContracts;
}
return contractNamesToCompile;
}
@@ -213,16 +211,14 @@ 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);
const contractSource = spyResolver.resolve(contractName);
- const sourceTreeHashHex = getSourceTreeHash(
- spyResolver,
- path.join(this._contractsDir, contractSource.path),
- ).toString('hex');
+ const sourceTreeHashHex = getSourceTreeHash(spyResolver, contractSource.path).toString('hex');
const contractData = {
- contractName,
+ contractName: path.basename(contractName, constants.SOLIDITY_FILE_EXTENSION),
currentArtifactIfExists: await getContractArtifactIfExistsAsync(this._artifactsDir, contractName),
sourceTreeHashHex: `0x${sourceTreeHashHex}`,
};
@@ -231,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) {
@@ -277,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)) {
@@ -329,7 +325,10 @@ export class Compiler {
} else {
const currentArtifact = contractData.currentArtifactIfExists as ContractArtifact;
const isUserOnLatestVersion = currentArtifact.schemaVersion === constants.LATEST_ARTIFACT_VERSION;
- const didCompilerSettingsChange = !_.isEqual(currentArtifact.compiler.settings, this._compilerSettings);
+ const didCompilerSettingsChange = !_.isEqual(
+ _.omit(currentArtifact.compiler.settings, 'remappings'),
+ _.omit(this._compilerSettings, 'remappings'),
+ );
const didSourceChange = currentArtifact.sourceTreeHashHex !== contractData.sourceTreeHashHex;
return !isUserOnLatestVersion || didCompilerSettingsChange || didSourceChange;
}
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 c75f76dac..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.
@@ -26,7 +24,10 @@ export async function getContractArtifactIfExistsAsync(
contractName: string,
): Promise<ContractArtifact | void> {
let contractArtifact;
- const currentArtifactPath = `${artifactsDir}/${contractName}.json`;
+ const currentArtifactPath = `${artifactsDir}/${path.basename(
+ contractName,
+ constants.SOLIDITY_FILE_EXTENSION,
+ )}.json`;
try {
const opts = {
encoding: 'utf8',
@@ -116,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
@@ -236,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,
@@ -316,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'];