From df872fdd5bff91a54eddd5c940166b6a38158038 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 16 Jan 2019 11:34:36 -0500 Subject: [PATCH] feat(compiler): add a new compiler api that checks for compatibility --- src/lib/core/plugin.js | 2 +- src/lib/modules/compiler/index.ts | 33 ++++++++++++++++++++++++++----- src/lib/modules/solidity/index.js | 2 +- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/lib/core/plugin.js b/src/lib/core/plugin.js index 58d5fd314..235b34394 100644 --- a/src/lib/core/plugin.js +++ b/src/lib/core/plugin.js @@ -94,7 +94,7 @@ Plugin.prototype.loadPlugin = function() { this.pluginModule = this.pluginModule.default; return new this.pluginModule(this); } - (this.pluginModule.call(this, this)); + this.pluginModule.call(this, this); }; Plugin.prototype.loadInternalPlugin = function() { diff --git a/src/lib/modules/compiler/index.ts b/src/lib/modules/compiler/index.ts index 5f96c3510..8f6e78867 100644 --- a/src/lib/modules/compiler/index.ts +++ b/src/lib/modules/compiler/index.ts @@ -1,3 +1,5 @@ +import {Callback} from "../../../typings/callbacks"; + const async = require("../../utils/async_extend.js"); import { Embark } from "../../../typings/embark"; import { CompilerPluginObject, Plugins } from "../../../typings/plugins"; @@ -27,15 +29,33 @@ class Compiler { }; async.eachObject(this.getAvailableCompilers(), - (extension: string, compiler: any, next: any) => { + (extension: string, compilers: any, next: any) => { const matchingFiles = contractFiles.filter(this.filesMatchingExtension(extension)); if (matchingFiles.length === 0) { return next(); } - compiler.call(compiler, matchingFiles, compilerOptions, (err: any, compileResult: any) => { - Object.assign(compiledObject, compileResult); - next(err, compileResult); + async.someLimit(compilers, 1, (compiler: any, someCb: Callback) => { + compiler.call(compiler, matchingFiles, compilerOptions, (err: any, compileResult: any) => { + if (err) { + return someCb(err); + } + if (compileResult === false) { + // Compiler not compatible, trying the next one + return someCb(null, false); + } + Object.assign(compiledObject, compileResult); + someCb(null, true); + }); + }, (err: Error, result: boolean) => { + if (err) { + return next(err); + } + if (!result) { + // No compiler was compatible + return next(new Error(__("No installed compiler was compatible with your version of %s files", extension))); + } + next(); }); }, (err: any) => { @@ -51,7 +71,10 @@ class Compiler { private getAvailableCompilers() { const available_compilers: { [index: string]: any } = {}; this.plugins.getPluginsProperty("compilers", "compilers").forEach((compilerObject: CompilerPluginObject) => { - available_compilers[compilerObject.extension] = compilerObject.cb; + if (!available_compilers[compilerObject.extension]) { + available_compilers[compilerObject.extension] = []; + } + available_compilers[compilerObject.extension].unshift(compilerObject.cb); }); return available_compilers; } diff --git a/src/lib/modules/solidity/index.js b/src/lib/modules/solidity/index.js index d7d6f342e..97f6c3704 100644 --- a/src/lib/modules/solidity/index.js +++ b/src/lib/modules/solidity/index.js @@ -77,7 +77,7 @@ class Solidity { } self.solcW = new SolcW(self.embark, {logger: self.logger, events: self.events, ipc: self.ipc, useDashboard: self.useDashboard, providerUrl: self.providerUrl}); - self.logger.info(__("loading solc compiler") + ".."); + self.logger.info(__("loading solc compiler") + "..."); self.solcW.load_compiler(function (err) { self.solcAlreadyLoaded = true; callback(err);