diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-03-05 11:05:26 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-03-12 10:37:27 +0800 |
commit | 13299158d1e22d1af1cd36434fc403a74743ecb1 (patch) | |
tree | 9b35435c6f8641d2dc3d7bfd530c7c4f040a1f51 /packages/deployer/src/compiler.ts | |
parent | a6571b09d2087ffb9a4860c0db3d7344321fe2c3 (diff) | |
download | dexon-0x-contracts-13299158d1e22d1af1cd36434fc403a74743ecb1.tar.gz dexon-0x-contracts-13299158d1e22d1af1cd36434fc403a74743ecb1.tar.zst dexon-0x-contracts-13299158d1e22d1af1cd36434fc403a74743ecb1.zip |
Add sol-cover implementation
Diffstat (limited to 'packages/deployer/src/compiler.ts')
-rw-r--r-- | packages/deployer/src/compiler.ts | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/packages/deployer/src/compiler.ts b/packages/deployer/src/compiler.ts index 149ca5d6d..7c60a099b 100644 --- a/packages/deployer/src/compiler.ts +++ b/packages/deployer/src/compiler.ts @@ -1,6 +1,10 @@ +import { promisify } from '@0xproject/utils'; import * as ethUtil from 'ethereumjs-util'; +import * as fs from 'fs'; +import 'isomorphic-fetch'; import * as _ from 'lodash'; import * as path from 'path'; +import * as requireFromString from 'require-from-string'; import solc = require('solc'); import * as Web3 from 'web3'; @@ -15,7 +19,6 @@ import { ContractSourceData, ContractSources, ContractSpecificSourceData, - ImportContents, } from './utils/types'; import { utils } from './utils/utils'; @@ -186,9 +189,18 @@ export class Compiler { } const fullSolcVersion = binPaths[contractSpecificSourceData.solcVersion]; - const solcBinPath = `./solc/solc_bin/${fullSolcVersion}`; - const solcBin = require(solcBinPath); - const solcInstance = solc.setupMethods(solcBin); + const compiler_bin_filename = path.join(__dirname, '../../solc_bin', fullSolcVersion); + let solcjs: string; + if (fs.existsSync(compiler_bin_filename)) { + solcjs = fs.readFileSync(compiler_bin_filename).toString(); + } else { + utils.consoleLog(`Downloading ${fullSolcVersion}...`); + const url = `https://ethereum.github.io/solc-bin/bin/${fullSolcVersion}`; + const response = await fetch(url); + solcjs = await response.text(); + fs.writeFileSync(compiler_bin_filename, solcjs); + } + const solcInstance = solc.setupMethods(requireFromString(solcjs, compiler_bin_filename)); utils.consoleLog(`Compiling ${fileName}...`); const source = this._contractSources[fileName]; @@ -210,11 +222,14 @@ export class Compiler { this._solcErrors.add(normalizedErrMsg); }); } - const contractName = path.basename(fileName, constants.SOLIDITY_FILE_EXTENSION); const contractIdentifier = `${fileName}:${contractName}`; const abi: Web3.ContractAbi = JSON.parse(compiled.contracts[contractIdentifier].interface); - const unlinked_binary = `0x${compiled.contracts[contractIdentifier].bytecode}`; + const bytecode = `0x${compiled.contracts[contractIdentifier].bytecode}`; + const runtimeBytecode = `0x${compiled.contracts[contractIdentifier].runtimeBytecode}`; + const sourceMap = compiled.contracts[contractIdentifier].srcmap; + const sourceMapRuntime = compiled.contracts[contractIdentifier].srcmapRuntime; + const sources = _.keys(compiled.sources); const updated_at = Date.now(); const contractNetworkData: ContractNetworkData = { solc_version: contractSpecificSourceData.solcVersion, @@ -222,8 +237,12 @@ export class Compiler { source_tree_hash: sourceTreeHash, optimizer_enabled: this._optimizerEnabled, abi, - unlinked_binary, + bytecode, + runtime_bytecode: runtimeBytecode, updated_at, + source_map: sourceMap, + source_map_runtime: sourceMapRuntime, + sources, }; let newArtifact: ContractArtifact; @@ -284,13 +303,13 @@ export class Compiler { * @param importPath Path to an imported dependency. * @return Import contents object containing source code of dependency. */ - private _findImportsIfSourcesExist(importPath: string): ImportContents { + private _findImportsIfSourcesExist(importPath: string): solc.ImportContents { const fileName = path.basename(importPath); const source = this._contractSources[fileName]; if (_.isUndefined(source)) { throw new Error(`Contract source not found for ${fileName}`); } - const importContents: ImportContents = { + const importContents: solc.ImportContents = { contents: source, }; return importContents; |