diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-03-16 00:57:27 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-03-16 00:57:27 +0800 |
commit | 76029cbf0915df36266bd5e51add07755297ddda (patch) | |
tree | e1692f8cc4ea4642292c61f65ba3911ded26de8e /packages/deployer/src/compiler.ts | |
parent | b9c1653c1cf6984d56b7825d8747b48d797fa39e (diff) | |
parent | 4a27a7dc581fc6c8a3d4e212ca3712c249a5b417 (diff) | |
download | dexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.tar dexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.tar.gz dexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.tar.bz2 dexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.tar.lz dexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.tar.xz dexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.tar.zst dexon-0x-contracts-76029cbf0915df36266bd5e51add07755297ddda.zip |
Merge branch 'development' into feature/sra-report/collection-tests
* development: (97 commits)
Keep console.log in monorepo-scripts
Enable coverage for all other packages with tests
Fix parallel coverage results reporting
Fix linter issuesx
Remove outdated comment
Add script copying to build command
Add postpublish script to sol-cov
Move configuration into package.json configs section
Transform input data before encoding for callAsync and getABIEncodedTransactionData
Update CHANGELOGs
Consolidate all console.log into the @0xproject/utils package
Update coverage badge to show development coverage
Configure post build hook
Notify coveralls after all tasks have finished
Address feedback
Revert "Report all coverage reports together"
Separate published packages and typescript typings on README
Consolidate docs generation and uploading logic
Use async/await instead of promise syntax
Move changelog entry
...
Diffstat (limited to 'packages/deployer/src/compiler.ts')
-rw-r--r-- | packages/deployer/src/compiler.ts | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/packages/deployer/src/compiler.ts b/packages/deployer/src/compiler.ts index 149ca5d6d..83977709b 100644 --- a/packages/deployer/src/compiler.ts +++ b/packages/deployer/src/compiler.ts @@ -1,6 +1,10 @@ +import { logUtils, 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'; @@ -56,9 +59,9 @@ export class Compiler { }; const source = await fsWrapper.readFileAsync(contentPath, opts); sources[fileName] = source; - utils.consoleLog(`Reading ${fileName} source...`); + logUtils.log(`Reading ${fileName} source...`); } catch (err) { - utils.consoleLog(`Could not find file at ${contentPath}`); + logUtils.log(`Could not find file at ${contentPath}`); } } else { try { @@ -68,7 +71,7 @@ export class Compiler { ...nestedSources, }; } catch (err) { - utils.consoleLog(`${contentPath} is not a directory or ${constants.SOLIDITY_FILE_EXTENSION} file`); + logUtils.log(`${contentPath} is not a directory or ${constants.SOLIDITY_FILE_EXTENSION} file`); } } } @@ -161,7 +164,7 @@ export class Compiler { }); await Promise.all(_.map(fileNames, async fileName => this._compileContractAsync(fileName))); this._solcErrors.forEach(errMsg => { - utils.consoleLog(errMsg); + logUtils.log(errMsg); }); } /** @@ -186,11 +189,24 @@ export class Compiler { } const fullSolcVersion = binPaths[contractSpecificSourceData.solcVersion]; - const solcBinPath = `./solc/solc_bin/${fullSolcVersion}`; - const solcBin = require(solcBinPath); - const solcInstance = solc.setupMethods(solcBin); + const compilerBinFilename = path.join(__dirname, '../../solc_bin', fullSolcVersion); + let solcjs: string; + const isCompilerAvailableLocally = fs.existsSync(compilerBinFilename); + if (isCompilerAvailableLocally) { + solcjs = fs.readFileSync(compilerBinFilename).toString(); + } else { + logUtils.log(`Downloading ${fullSolcVersion}...`); + const url = `${constants.BASE_COMPILER_URL}${fullSolcVersion}`; + const response = await fetch(url); + if (response.status !== 200) { + throw new Error(`Failed to load ${fullSolcVersion}`); + } + solcjs = await response.text(); + fs.writeFileSync(compilerBinFilename, solcjs); + } + const solcInstance = solc.setupMethods(requireFromString(solcjs, compilerBinFilename)); - utils.consoleLog(`Compiling ${fileName}...`); + logUtils.log(`Compiling ${fileName}...`); const source = this._contractSources[fileName]; const input = { [fileName]: source, @@ -210,11 +226,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 +241,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; @@ -247,7 +270,7 @@ export class Compiler { const artifactString = utils.stringifyWithFormatting(newArtifact); const currentArtifactPath = `${this._artifactsDir}/${contractName}.json`; await fsWrapper.writeFileAsync(currentArtifactPath, artifactString); - utils.consoleLog(`${fileName} artifact saved!`); + logUtils.log(`${fileName} artifact saved!`); } /** * Sets the source tree hash for a file and its dependencies. @@ -284,13 +307,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; @@ -300,7 +323,7 @@ export class Compiler { */ private async _createArtifactsDirIfDoesNotExistAsync(): Promise<void> { if (!fsWrapper.doesPathExistSync(this._artifactsDir)) { - utils.consoleLog('Creating artifacts directory...'); + logUtils.log('Creating artifacts directory...'); await fsWrapper.mkdirAsync(this._artifactsDir); } } @@ -321,7 +344,7 @@ export class Compiler { contractArtifact = JSON.parse(contractArtifactString); return contractArtifact; } catch (err) { - utils.consoleLog(`Artifact for ${fileName} does not exist`); + logUtils.log(`Artifact for ${fileName} does not exist`); return undefined; } } |