aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-compiler
diff options
context:
space:
mode:
Diffstat (limited to 'packages/sol-compiler')
-rw-r--r--packages/sol-compiler/CHANGELOG.json36
-rw-r--r--packages/sol-compiler/CHANGELOG.md16
-rw-r--r--packages/sol-compiler/package.json27
-rw-r--r--packages/sol-compiler/src/compiler.ts114
-rw-r--r--packages/sol-compiler/src/index.ts20
-rw-r--r--packages/sol-compiler/src/utils/compiler.ts4
-rw-r--r--packages/sol-compiler/tsconfig.json1
-rw-r--r--packages/sol-compiler/typedoc-tsconfig.json8
8 files changed, 169 insertions, 57 deletions
diff --git a/packages/sol-compiler/CHANGELOG.json b/packages/sol-compiler/CHANGELOG.json
index b334e4937..69cc7fa0f 100644
--- a/packages/sol-compiler/CHANGELOG.json
+++ b/packages/sol-compiler/CHANGELOG.json
@@ -1,5 +1,41 @@
[
{
+ "timestamp": 1537907159,
+ "version": "1.1.5",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "timestamp": 1537875740,
+ "version": "1.1.4",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "timestamp": 1537541580,
+ "version": "1.1.3",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
+ "timestamp": 1536142250,
+ "version": "1.1.2",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
"timestamp": 1535377027,
"version": "1.1.1",
"changes": [
diff --git a/packages/sol-compiler/CHANGELOG.md b/packages/sol-compiler/CHANGELOG.md
index 8243a2cf8..0fc0ff7b1 100644
--- a/packages/sol-compiler/CHANGELOG.md
+++ b/packages/sol-compiler/CHANGELOG.md
@@ -5,6 +5,22 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
+## v1.1.5 - _September 25, 2018_
+
+ * Dependencies updated
+
+## v1.1.4 - _September 25, 2018_
+
+ * Dependencies updated
+
+## v1.1.3 - _September 21, 2018_
+
+ * Dependencies updated
+
+## v1.1.2 - _September 5, 2018_
+
+ * Dependencies updated
+
## v1.1.1 - _August 27, 2018_
* Dependencies updated
diff --git a/packages/sol-compiler/package.json b/packages/sol-compiler/package.json
index f60edc1f9..9d1610180 100644
--- a/packages/sol-compiler/package.json
+++ b/packages/sol-compiler/package.json
@@ -1,6 +1,6 @@
{
"name": "@0xproject/sol-compiler",
- "version": "1.1.1",
+ "version": "1.1.5",
"engines": {
"node": ">=6.12"
},
@@ -8,8 +8,7 @@
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
"scripts": {
- "watch_without_deps": "yarn pre_build && tsc -w",
- "build": "yarn pre_build && tsc",
+ "build": "yarn pre_build && tsc -b",
"pre_build": "run-s update_contract_fixtures",
"update_contract_fixtures": "copyfiles 'test/fixtures/contracts/**/*' ./lib",
"test": "yarn run_mocha",
@@ -21,7 +20,7 @@
"migrate": "npm run build; node lib/src/cli.js migrate",
"lint": "tslint --project .",
"test:circleci": "yarn test:coverage",
- "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES"
+ "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
},
"config": {
"postpublish": {
@@ -42,8 +41,8 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/sol-compiler/README.md",
"devDependencies": {
- "@0xproject/dev-utils": "^1.0.6",
- "@0xproject/tslint-config": "^1.0.6",
+ "@0xproject/dev-utils": "^1.0.10",
+ "@0xproject/tslint-config": "^1.0.7",
"@types/mkdirp": "^0.5.2",
"@types/require-from-string": "^1.2.0",
"@types/semver": "^5.5.0",
@@ -65,16 +64,16 @@
"zeppelin-solidity": "1.8.0"
},
"dependencies": {
- "@0xproject/assert": "^1.0.7",
- "@0xproject/json-schemas": "^1.0.1-rc.6",
- "@0xproject/sol-resolver": "^1.0.7",
- "@0xproject/types": "^1.0.1-rc.6",
- "@0xproject/typescript-typings": "^1.0.5",
- "@0xproject/utils": "^1.0.7",
- "@0xproject/web3-wrapper": "^2.0.1",
+ "@0xproject/assert": "^1.0.11",
+ "@0xproject/json-schemas": "^1.0.4",
+ "@0xproject/sol-resolver": "^1.0.11",
+ "@0xproject/types": "^1.1.1",
+ "@0xproject/typescript-typings": "^2.0.2",
+ "@0xproject/utils": "^1.0.11",
+ "@0xproject/web3-wrapper": "^3.0.1",
"@types/yargs": "^11.0.0",
"chalk": "^2.3.0",
- "ethereum-types": "^1.0.5",
+ "ethereum-types": "^1.0.8",
"ethereumjs-util": "^5.1.1",
"lodash": "^4.17.5",
"mkdirp": "^0.5.1",
diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts
index 7c76f3e52..a29367485 100644
--- a/packages/sol-compiler/src/compiler.ts
+++ b/packages/sol-compiler/src/compiler.ts
@@ -10,7 +10,7 @@ import {
} from '@0xproject/sol-resolver';
import { fetchAsync, logUtils } from '@0xproject/utils';
import chalk from 'chalk';
-import { CompilerOptions, ContractArtifact, ContractVersionData } from 'ethereum-types';
+import { CompilerOptions, ContractArtifact, ContractVersionData, StandardOutput } from 'ethereum-types';
import * as ethUtil from 'ethereumjs-util';
import * as fs from 'fs';
import * as _ from 'lodash';
@@ -94,7 +94,7 @@ export class Compiler {
if (await fsWrapper.doesFileExistAsync(compilerBinFilename)) {
solcjs = (await fsWrapper.readFileAsync(compilerBinFilename)).toString();
} else {
- logUtils.log(`Downloading ${fullSolcVersion}...`);
+ logUtils.warn(`Downloading ${fullSolcVersion}...`);
const url = `${constants.BASE_COMPILER_URL}${fullSolcVersion}`;
const response = await fetchAsync(url);
const SUCCESS_STATUS = 200;
@@ -110,6 +110,21 @@ export class Compiler {
const solcInstance = solc.setupMethods(requireFromString(solcjs, compilerBinFilename));
return { solcInstance, fullSolcVersion };
}
+ private static _addHexPrefixToContractBytecode(compiledContract: solc.StandardContractOutput): void {
+ if (!_.isUndefined(compiledContract.evm)) {
+ if (!_.isUndefined(compiledContract.evm.bytecode) && !_.isUndefined(compiledContract.evm.bytecode.object)) {
+ compiledContract.evm.bytecode.object = ethUtil.addHexPrefix(compiledContract.evm.bytecode.object);
+ }
+ if (
+ !_.isUndefined(compiledContract.evm.deployedBytecode) &&
+ !_.isUndefined(compiledContract.evm.deployedBytecode.object)
+ ) {
+ compiledContract.evm.deployedBytecode.object = ethUtil.addHexPrefix(
+ compiledContract.evm.deployedBytecode.object,
+ );
+ }
+ }
+ }
/**
* Instantiates a new instance of the Compiler class.
* @param opts Optional compiler options
@@ -144,22 +159,40 @@ export class Compiler {
public async compileAsync(): Promise<void> {
await createDirIfDoesNotExistAsync(this._artifactsDir);
await createDirIfDoesNotExistAsync(SOLC_BIN_DIR);
- let contractNamesToCompile: string[] = [];
+ await this._compileContractsAsync(this._getContractNamesToCompile(), true);
+ }
+ /**
+ * Compiles Solidity files specified during instantiation, and returns the
+ * compiler output given by solc. Return value is an array of outputs:
+ * Solidity modules are batched together by version required, and each
+ * element of the returned array corresponds to a compiler version, and
+ * each element contains the output for all of the modules compiled with
+ * that version.
+ */
+ public async getCompilerOutputsAsync(): Promise<StandardOutput[]> {
+ const promisedOutputs = this._compileContractsAsync(this._getContractNamesToCompile(), false);
+ return promisedOutputs;
+ }
+ private _getContractNamesToCompile(): string[] {
+ let contractNamesToCompile;
if (this._specifiedContracts === ALL_CONTRACTS_IDENTIFIER) {
const allContracts = this._nameResolver.getAll();
contractNamesToCompile = _.map(allContracts, contractSource =>
path.basename(contractSource.path, constants.SOLIDITY_FILE_EXTENSION),
);
} else {
- contractNamesToCompile = this._specifiedContracts;
+ contractNamesToCompile = this._specifiedContracts.map(specifiedContract =>
+ path.basename(specifiedContract, constants.SOLIDITY_FILE_EXTENSION),
+ );
}
- await this._compileContractsAsync(contractNamesToCompile);
+ return contractNamesToCompile;
}
/**
- * Compiles contract and saves artifact to artifactsDir.
+ * Compiles contracts, and, if `shouldPersist` is true, saves artifacts to artifactsDir.
* @param fileName Name of contract with '.sol' extension.
+ * @return an array of compiler outputs, where each element corresponds to a different version of solc-js.
*/
- private async _compileContractsAsync(contractNames: string[]): Promise<void> {
+ private async _compileContractsAsync(contractNames: string[], shouldPersist: boolean): Promise<StandardOutput[]> {
// batch input contracts together based on the version of the compiler that they require.
const versionToInputs: VersionToInputs = {};
@@ -200,10 +233,12 @@ export class Compiler {
versionToInputs[solcVersion].contractsToCompile.push(contractSource.path);
}
+ const compilerOutputs: StandardOutput[] = [];
+
const solcVersions = _.keys(versionToInputs);
for (const solcVersion of solcVersions) {
const input = versionToInputs[solcVersion];
- logUtils.log(
+ logUtils.warn(
`Compiling ${input.contractsToCompile.length} contracts (${
input.contractsToCompile
}) with Solidity v${solcVersion}...`,
@@ -212,18 +247,34 @@ export class Compiler {
const { solcInstance, fullSolcVersion } = await Compiler._getSolcAsync(solcVersion);
const compilerOutput = this._compile(solcInstance, input.standardInput);
+ compilerOutputs.push(compilerOutput);
for (const contractPath of input.contractsToCompile) {
- await this._verifyAndPersistCompiledContractAsync(
- contractPath,
- contractPathToData[contractPath].currentArtifactIfExists,
- contractPathToData[contractPath].sourceTreeHashHex,
- contractPathToData[contractPath].contractName,
- fullSolcVersion,
- compilerOutput,
- );
+ const contractName = contractPathToData[contractPath].contractName;
+
+ const compiledContract = compilerOutput.contracts[contractPath][contractName];
+ if (_.isUndefined(compiledContract)) {
+ throw new Error(
+ `Contract ${contractName} not found in ${contractPath}. Please make sure your contract has the same name as it's file name`,
+ );
+ }
+
+ Compiler._addHexPrefixToContractBytecode(compiledContract);
+
+ if (shouldPersist) {
+ await this._persistCompiledContractAsync(
+ contractPath,
+ contractPathToData[contractPath].currentArtifactIfExists,
+ contractPathToData[contractPath].sourceTreeHashHex,
+ contractName,
+ fullSolcVersion,
+ compilerOutput,
+ );
+ }
}
}
+
+ return compilerOutputs;
}
private _shouldCompile(contractData: ContractData): boolean {
if (_.isUndefined(contractData.currentArtifactIfExists)) {
@@ -236,7 +287,7 @@ export class Compiler {
return !isUserOnLatestVersion || didCompilerSettingsChange || didSourceChange;
}
}
- private async _verifyAndPersistCompiledContractAsync(
+ private async _persistCompiledContractAsync(
contractPath: string,
currentArtifactIfExists: ContractArtifact | void,
sourceTreeHashHex: string,
@@ -244,32 +295,13 @@ export class Compiler {
fullSolcVersion: string,
compilerOutput: solc.StandardOutput,
): Promise<void> {
- const compiledData = compilerOutput.contracts[contractPath][contractName];
- if (_.isUndefined(compiledData)) {
- throw new Error(
- `Contract ${contractName} not found in ${contractPath}. Please make sure your contract has the same name as it's file name`,
- );
- }
- if (!_.isUndefined(compiledData.evm)) {
- if (!_.isUndefined(compiledData.evm.bytecode) && !_.isUndefined(compiledData.evm.bytecode.object)) {
- compiledData.evm.bytecode.object = ethUtil.addHexPrefix(compiledData.evm.bytecode.object);
- }
- if (
- !_.isUndefined(compiledData.evm.deployedBytecode) &&
- !_.isUndefined(compiledData.evm.deployedBytecode.object)
- ) {
- compiledData.evm.deployedBytecode.object = ethUtil.addHexPrefix(
- compiledData.evm.deployedBytecode.object,
- );
- }
- }
-
+ const compiledContract = compilerOutput.contracts[contractPath][contractName];
const sourceCodes = _.mapValues(
compilerOutput.sources,
(_1, sourceFilePath) => this._resolver.resolve(sourceFilePath).source,
);
const contractVersion: ContractVersionData = {
- compilerOutput: compiledData,
+ compilerOutput: compiledContract,
sources: compilerOutput.sources,
sourceCodes,
sourceTreeHashHex,
@@ -299,7 +331,7 @@ export class Compiler {
const artifactString = utils.stringifyWithFormatting(newArtifact);
const currentArtifactPath = `${this._artifactsDir}/${contractName}.json`;
await fsWrapper.writeFileAsync(currentArtifactPath, artifactString);
- logUtils.log(`${contractName} artifact saved!`);
+ logUtils.warn(`${contractName} artifact saved!`);
}
private _compile(solcInstance: solc.SolcInstance, standardInput: solc.StandardInput): solc.StandardOutput {
const compiled: solc.StandardOutput = JSON.parse(
@@ -315,13 +347,13 @@ export class Compiler {
if (!_.isEmpty(errors)) {
errors.forEach(error => {
const normalizedErrMsg = getNormalizedErrMsg(error.formattedMessage || error.message);
- logUtils.log(chalk.red(normalizedErrMsg));
+ logUtils.warn(chalk.red(normalizedErrMsg));
});
throw new Error('Compilation errors encountered');
} else {
warnings.forEach(warning => {
const normalizedWarningMsg = getNormalizedErrMsg(warning.formattedMessage || warning.message);
- logUtils.log(chalk.yellow(normalizedWarningMsg));
+ logUtils.warn(chalk.yellow(normalizedWarningMsg));
});
}
}
diff --git a/packages/sol-compiler/src/index.ts b/packages/sol-compiler/src/index.ts
index f8c2b577a..829e515ff 100644
--- a/packages/sol-compiler/src/index.ts
+++ b/packages/sol-compiler/src/index.ts
@@ -1,8 +1,28 @@
export { Compiler } from './compiler';
export {
+ AbiDefinition,
CompilerOptions,
CompilerSettings,
+ DataItem,
+ DevdocOutput,
+ ErrorSeverity,
+ ErrorType,
+ EventAbi,
+ EventParameter,
+ EvmBytecodeOutput,
+ EvmOutput,
+ FallbackAbi,
+ FunctionAbi,
+ MethodAbi,
+ ConstructorAbi,
+ ConstructorStateMutability,
+ ContractAbi,
OutputField,
CompilerSettingsMetadata,
OptimizerSettings,
+ ParamDescription,
+ SolcError,
+ StandardContractOutput,
+ StandardOutput,
+ StateMutability,
} from 'ethereum-types';
diff --git a/packages/sol-compiler/src/utils/compiler.ts b/packages/sol-compiler/src/utils/compiler.ts
index c918ed1f3..c153beb0f 100644
--- a/packages/sol-compiler/src/utils/compiler.ts
+++ b/packages/sol-compiler/src/utils/compiler.ts
@@ -26,7 +26,7 @@ export async function getContractArtifactIfExistsAsync(
contractArtifact = JSON.parse(contractArtifactString);
return contractArtifact;
} catch (err) {
- logUtils.log(`Artifact for ${contractName} does not exist`);
+ logUtils.warn(`Artifact for ${contractName} does not exist`);
return undefined;
}
}
@@ -37,7 +37,7 @@ export async function getContractArtifactIfExistsAsync(
*/
export async function createDirIfDoesNotExistAsync(dirPath: string): Promise<void> {
if (!fsWrapper.doesPathExistSync(dirPath)) {
- logUtils.log(`Creating directory at ${dirPath}...`);
+ logUtils.warn(`Creating directory at ${dirPath}...`);
await fsWrapper.mkdirpAsync(dirPath);
}
}
diff --git a/packages/sol-compiler/tsconfig.json b/packages/sol-compiler/tsconfig.json
index 63cbc75c3..c6ffbb99b 100644
--- a/packages/sol-compiler/tsconfig.json
+++ b/packages/sol-compiler/tsconfig.json
@@ -2,6 +2,7 @@
"extends": "../../tsconfig",
"compilerOptions": {
"outDir": "lib",
+ "rootDir": ".",
"strictFunctionTypes": false
},
"include": ["./src/**/*", "./test/**/*"]
diff --git a/packages/sol-compiler/typedoc-tsconfig.json b/packages/sol-compiler/typedoc-tsconfig.json
new file mode 100644
index 000000000..22897c131
--- /dev/null
+++ b/packages/sol-compiler/typedoc-tsconfig.json
@@ -0,0 +1,8 @@
+{
+ "extends": "../../typedoc-tsconfig",
+ "compilerOptions": {
+ "outDir": "lib",
+ "strictFunctionTypes": false
+ },
+ "include": ["./src/**/*", "./test/**/*"]
+}